Skip to content

Commit

Permalink
Merge pull request #14 from SOH69/main
Browse files Browse the repository at this point in the history
Update
  • Loading branch information
SOH69 authored Dec 12, 2023
2 parents 82130fa + b56d9a1 commit a8bfee7
Show file tree
Hide file tree
Showing 17 changed files with 196 additions and 25 deletions.
10 changes: 10 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
name: Lint
on: [push, pull_request]
jobs:
lint:
name: Lint Resource
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Lint
uses: iLLeniumStudios/fivem-lua-lint-action@v2
2 changes: 2 additions & 0 deletions client/bridge/ox.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ if Shared.Inventory == "ox" then
Radio:ESXInit()
elseif Shared.Core == "qb" then
Radio:QBInit()
elseif Shared.Core == "qbox" then
Radio:QboxInit()
end
end)
end
61 changes: 61 additions & 0 deletions client/bridge/qbox.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
if Shared.Core == "qbox" then
function Radio:QboxInit(data)
local PlayerData = data or exports.qbx_core:GetPlayer()
if PlayerData then
Radio.PlayerJob = PlayerData.job.type
Radio.PlayerGang = PlayerData.gang.name
Radio.PlayerDuty = PlayerData.job.onduty
end

local rec = {}
for k, v in pairs(Shared.RestrictedChannels) do
if v.type == 'job' and lib.table.contains(v.name, Radio.PlayerJob) then
rec[#rec+1] = k
elseif v.type == 'gang' and lib.table.contains(v.name, Radio.PlayerGang) then
rec[#rec+1] = k
end
end
Radio.favourite = rec
for _, val in ipairs(Radio.userData.favourite) do
if not lib.table.contains(Radio.favourite, val) then
Radio.favourite[#Radio.favourite+1] = val
end
end
Radio:doRadioCheck()
end

RegisterNetEvent('QBCore:Server:OnPlayerLoaded', function()
Radio:QboxInit()
end)

-- Resets state on logout, in case of character change.
RegisterNetEvent('QBCore:Client:OnPlayerUnload', function()
Radio.PlayerItems = {}
Radio.hasRadio = false
Radio:leaveradio()
end)

RegisterNetEvent('QBCore:Client:OnJobUpdate', function(job)
Radio.PlayerJob = job.type
Radio:QboxInit()
end)

RegisterNetEvent('QBCore:Client:OnGangUpdate', function(gang)
Radio.PlayerGang = gang.name
Radio:QboxInit()
end)

RegisterNetEvent("QBCore:Client:SetDuty", function(newDuty)
Radio.PlayerDuty = newDuty
end)

AddEventHandler('gameEventTriggered', function(event, data)
if event ~= "CEventNetworkEntityDamage" then return end
if not IsEntityAPed(data[1]) then return end
if data[4] and NetworkGetPlayerIndexFromPed(data[1]) == cache.playerId and IsEntityDead(cache.ped) then
if LocalPlayer.state.isLoggedIn and Radio.onRadio and Radio.hasRadio and Radio.RadioChannel ~= 0 then
Radio:leaveradio()
end
end
end)
end
4 changes: 3 additions & 1 deletion client/event.lua
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ AddEventHandler('onResourceStart', function(resource)
if GetCurrentResourceName() == resource then
if Shared.Core == 'qb' and LocalPlayer.state.isLoggedIn then
Radio:QBInit()
elseif Shared.Core == 'qbx' and LocalPlayer.state.isLoggedIn then
Radio:QboxInit()
elseif Shared.Core == 'esx' and ESX.IsPlayerLoaded() then
Radio:ESXInit()
end
Expand Down Expand Up @@ -38,7 +40,7 @@ RegisterNetEvent('mm_radio:client:use', function()
time = Radio:CalculateTimeToDisplay(),
street = Radio:getCrossroads(),
maxChannel = Shared.MaxFrequency,
locale = Radio.locale.ui
locale = Radio.locale
})

updateTime()
Expand Down
24 changes: 18 additions & 6 deletions client/function.lua
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,6 @@ function Radio:doRadioCheck()
end
self.hasRadio = _hasRadio
end
if not self.hasRadio and self.onRadio and Shared.Inventory then
self:leaveradio()
end
end

function Radio:leaveradio()
Expand All @@ -88,7 +85,7 @@ function Radio:update()
userData = Radio.userData,
time = self:CalculateTimeToDisplay(),
street = self:getCrossroads(),
locale = self.locale.ui
locale = self.locale
})
end

Expand Down Expand Up @@ -164,7 +161,22 @@ lib.addKeybind({
defaultKey = 'EQUALS',
onPressed = function()
if not Radio.usingRadio then
TriggerEvent('mm_radio:client:use')
if Shared.Inventory and Radio.hasRadio then
TriggerEvent('mm_radio:client:use')
elseif not Shared.Inventory then
TriggerEvent('mm_radio:client:use')
end
end
end
})

CreateThread(function()
while true do
Wait(1000)
if LocalPlayer.state.isLoggedIn then
if not Radio.hasRadio and Radio.onRadio and Shared.Inventory then
Radio:leaveradio()
end
end
end
})
end)
21 changes: 21 additions & 0 deletions client/interface.lua
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,27 @@ if not Radio.userData.favourite then
}
end

RegisterNetEvent('mm_radio:client:removedata', function()
DeleteResourceKvp('radioSettings')
Radio.userData = {
favourite = {},
playerlist = {
show = false,
coords = {
x = 15.0,
y = 40.0
}
}
}
if Shared.Core == 'qb' and LocalPlayer.state.isLoggedIn then
Radio:QBInit()
elseif Shared.Core == 'qbx' and LocalPlayer.state.isLoggedIn then
Radio:QboxInit()
elseif Shared.Core == 'esx' and ESX.IsPlayerLoaded() then
Radio:ESXInit()
end
end)

if not Shared.Ready then
return error('UI has not been built, refer to the readme or download a release build.\n ^3https://github.com/SOH69/mm_radio/releases/', 0)
end
2 changes: 1 addition & 1 deletion fxmanifest.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ fx_version 'cerulean'
game "gta5"

author "Master Mind"
version '1.6.0'
version '1.8.0'

lua54 'yes'

Expand Down
13 changes: 13 additions & 0 deletions server/bridge.lua
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@ if Shared.Core == "qb" then
QBCore.Functions.CreateUseableItem("radio", function(source)
TriggerClientEvent('mm_radio:client:use', source)
end)
elseif Shared.Core == 'qbx' then
if not Shared.Ready then return end

exports.qbx_core:CreateUseableItem("radio", function(source, item)
TriggerClientEvent('mm_radio:client:use', source)
end)
elseif Shared.Core == "esx" then
ESX = exports['es_extended']:getSharedObject()

Expand All @@ -26,10 +32,17 @@ function GetUserName(source)
if Player then
return Player.PlayerData.charinfo.firstname .. ' ' .. Player.PlayerData.charinfo.lastname
end
elseif Shared.Core == 'qbx' then
local Player = exports.qbx_core:GetPlayer(source)
if Player then
return Player.PlayerData.charinfo.firstname .. ' ' .. Player.PlayerData.charinfo.lastname
end
elseif Shared.Core == "esx" and ESX then
local xPlayer = ESX.GetPlayerFromId(source)
if xPlayer then
return xPlayer.getName()
end
else
return GetPlayerName(source)
end
end
11 changes: 9 additions & 2 deletions server/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ RegisterNetEvent('mm_radio:server:removeFromRadioChannel', function(channel)
TriggerClientEvent('mm_radio:client:radioListUpdate', -1, channels[channel], channel)
end)

AddEventHandler("playerDropped", function(reason)
AddEventHandler("playerDropped", function()
local plyid = source

for id, channel in pairs (channels) do
Expand All @@ -34,11 +34,18 @@ if Shared.UseCommand or not Shared.Inventory then
lib.addCommand('radio', {
help = 'Open Radio Menu',
params = {},
}, function(source, args, raw)
}, function(source)
TriggerClientEvent('mm_radio:client:use', source)
end)
end

lib.addCommand('remradiodata', {
help = 'Remove Radio Data',
params = {},
}, function(source)
TriggerClientEvent('mm_radio:client:removedata', source)
end)

lib.versionCheck('SOH69/mm_radio')

if not Shared.Ready then
Expand Down
2 changes: 2 additions & 0 deletions shared/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ Shared.UseCommand = false -- set to true to use command to open radio (item requ

if GetResourceState('qb-core') == 'started' then -- change your core script
Shared.Core = 'qb' -- dont touch this
elseif GetResourceState('qbx_core') == 'started' then -- change your core script
Shared.Core = 'qbx' -- dont touch this
elseif GetResourceState('es_extended') == 'started' then -- change your core script
Shared.Core = 'esx' -- dont touch this
else
Expand Down
14 changes: 7 additions & 7 deletions ui/src/components/body.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,11 @@
</div>
<div class="flex flex-col">
{#if $RADIODATA.onRadio}
<div class="text-white text-[1.5vh] font-bold">{$RADIODATA.locale.header}</div>
<div class="text-white text-[1vh] font-medium">{$RADIODATA.locale.frequency}: {$RADIODATA.channel} MHz</div>
<button class="bg-[#FF453AFF] w-full h-[2vh] text-white rounded-[0.3vw] font-bold flex justify-center items-center text-[1vh] mt-1" on:click={() => SendNUI('leave')}>{$RADIODATA.locale.disconnect}</button>
<div class="text-white text-[1.5vh] font-bold">{$RADIODATA.locale['ui.header']}</div>
<div class="text-white text-[1vh] font-medium">{$RADIODATA.locale['ui.frequency']}: {$RADIODATA.channel} MHz</div>
<button class="bg-[#FF453AFF] w-full h-[2vh] text-white rounded-[0.3vw] font-bold flex justify-center items-center text-[1vh] mt-1" on:click={() => SendNUI('leave')}>{$RADIODATA.locale['ui.disconnect']}</button>
{:else}
<div class="text-white text-[1.5vh] font-bold">{$RADIODATA.locale.notconnected}</div>
<div class="text-white text-[1.5vh] font-bold">{$RADIODATA.locale['ui.notconnected']}</div>
{/if}
</div>
</div>
Expand All @@ -81,15 +81,15 @@
<div class="w-full rounded-[0.3vw] bg-[#18162F] flex py-4 text-white drop-shadow-md justify-between">
<button class="grow flex flex-col justify-center items-center gap-[0.5vh]" on:click={changeTab('channel')}>
<i class="fa-solid fa-list-ul"></i>
<span class="text-[0.8vh]">{$RADIODATA.locale.channels}</span>
<span class="text-[0.8vh]">{$RADIODATA.locale['ui.channels']}</span>
</button>
<button class="grow flex flex-col justify-center items-center gap-[0.5vh]" on:click={changeTab('connect')}>
<i class="fa-solid fa-walkie-talkie"></i>
<span class="text-[0.8vh]">{$RADIODATA.locale.radio}</span>
<span class="text-[0.8vh]">{$RADIODATA.locale['ui.radio']}</span>
</button>
<button class="grow flex flex-col justify-center items-center gap-[0.5vh]" style="color:{$RADIODATA.onRadio? 'white':'#AAAFB4'}" disabled="{!$RADIODATA.onRadio}" on:click={changeTab('members')}>
<i class="fa-solid fa-user-tag"></i>
<span class="text-[0.8vh]">{$RADIODATA.locale.members}</span>
<span class="text-[0.8vh]">{$RADIODATA.locale['ui.members']}</span>
</button>
</div>

Expand Down
4 changes: 2 additions & 2 deletions ui/src/components/channel.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@
<div class="w-full h-[4vh] bg-[#18162F] flex px-4 pt-2 gap-[1vh]">
<button class="flex flex-col items-center justify-center grow gap-[0.2vh]" style="color: {currenttab=='favourite'? "white":"#212146"};" on:click={() => changeTab('favourite')}>
<i class="fa-solid fa-star text-[1.8vh]"></i>
<span class="text-[0.8vh]">{$RADIODATA.locale.favorites}</span>
<span class="text-[0.8vh]">{$RADIODATA.locale['ui.favorites']}</span>
</button>
<button class="flex flex-col items-center justify-center grow gap-[0.2vh]" style="color: {currenttab=='recomended'? "white":"#212146"};" on:click={() => changeTab('recomended')}>
<i class="fa-solid fa-clock text-[1.8vh]"></i>
<span class="text-[0.8vh]">{$RADIODATA.locale.recommended}</span>
<span class="text-[0.8vh]">{$RADIODATA.locale['ui.recommended']}</span>
</button>
</div>
2 changes: 1 addition & 1 deletion ui/src/components/connect.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
<span>0</span>
</button>
<button class="w-[4.5vh] h-[4.5vh] rounded-full bg-[#18162F] flex justify-center items-center" on:click={() => removeNumber()}>
<span class="text-[1vh]">{$RADIODATA.locale.clear}</span>
<span class="text-[1vh]">{$RADIODATA.locale['ui.clear']}</span>
</button>
</div>
</div>
11 changes: 10 additions & 1 deletion ui/src/components/overlay.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,22 @@
if (moving) {
right -= e.movementX;
top += e.movementY;
right = Math.min(Math.max(right, 0), window.innerWidth - node.offsetWidth);
top = Math.min(Math.max(top, 0), window.innerHeight - node.offsetHeight);
node.style.top = `${top}px`;
node.style.right = `${right}px`;
RADIODATA.update((old: any) => {
return { ...old, userData: { ...old.userData, playerlist: { ...old.userData.playerlist, coords: { x: right, y: top } } } }
})
}
});
window.addEventListener('mouseup', () => {
moving = false;
SendNUI('updatePlayerListPosition', { y: top, x: right })
});
SHOWFORCEPLAYERLIST.subscribe(() => {
Expand All @@ -58,7 +67,7 @@

{#if isPlayerListVisible}
{#if $RADIODATA.onRadio}
<div class="w-[15vw] absolute z-[1000] text-right select-none" style="top: {$RADIODATA.userData.playerlist.coords.y}px; right: {$RADIODATA.userData.playerlist.coords.x}px;cursor:{$SHOW? 'move':'no-drop'}" use:dragMe>
<div class="max-w-[15vw] absolute z-[1000] text-right select-none" style="top: {$RADIODATA.userData.playerlist.coords.y}px; right: {$RADIODATA.userData.playerlist.coords.x}px;cursor:{$SHOW? 'move':'no-drop'}" use:dragMe>
{#each Object.entries($PLAYERLIST) as [id, player], index (id)}
<div class="text-[1.7vh] font-bold px-2" style="color: {player.isTalking? "white":"rgb(1, 176, 240)"}">{player.name}</div>
{/each}
Expand Down
2 changes: 1 addition & 1 deletion ui/src/components/playerlist.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,6 @@
</div>

<div class="w-full h-[4] px-4">
<button class="w-full py-3 bg-[#18162F] flex justify-center items-center gap-[1vh] text-white text-[1vh] rounded-[0.3vw] font-bold drop-shadow-md" on:click={()=> showPlayerList()}>{$SHOWPLAYERLIST? $RADIODATA.locale.hide_overlay:$RADIODATA.locale.show_overlay}</button>
<button class="w-full py-3 bg-[#18162F] flex justify-center items-center gap-[1vh] text-white text-[1vh] rounded-[0.3vw] font-bold drop-shadow-md" on:click={()=> showPlayerList()}>{$SHOWPLAYERLIST? $RADIODATA.locale['ui.hide_overlay']:$RADIODATA.locale['ui.show_overlay']}</button>
</div>
{/if}
Loading

0 comments on commit a8bfee7

Please sign in to comment.