Skip to content

Commit

Permalink
feat: remove scully_emotes dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
mafewtm committed Oct 18, 2024
1 parent 2c63b7a commit dc2c444
Show file tree
Hide file tree
Showing 4 changed files with 93 additions and 8 deletions.
27 changes: 25 additions & 2 deletions client/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,34 @@ end
local function toggleRadio(toggle)
radioMenu = toggle
SetNuiFocus(radioMenu, radioMenu)

if radioMenu then
exports.scully_emotemenu:playEmoteByCommand('wt')
local prop = lib.callback.await('qbx_radio:server:spawnProp', false)
local radio = NetworkGetEntityFromNetworkId(prop)

if DoesEntityExist(radio) then
local bone = GetPedBoneIndex(cache.ped, 28422)

local hasControl = lib.waitFor(function()
local isOwner = NetworkGetEntityOwner(radio) == cache.playerId

if isOwner then return true end

NetworkRequestControlOfEntity(radio)
end, locale('failed_get_control'), 3000)

if not hasControl then return end

SetEntityCollision(radio, false, false)
AttachEntityToEntity(radio, cache.ped, bone, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, true, true, false, true, 1, true)
end

lib.playAnim(cache.ped, 'cellphone@', 'cellphone_text_read_base', 2.0, 2.0, -1, 51, 0.0, false, 0, false)
SendNUIMessage({type = 'open'})
else
exports.scully_emotemenu:cancelEmote()
ClearPedTasks(cache.ped)
DetachEntity(cache.ped, true, false)
TriggerServerEvent('qbx_radio:server:deleteProp')
SendNUIMessage({type = 'close'})
end
end
Expand Down
10 changes: 6 additions & 4 deletions fxmanifest.lua
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
fx_version 'cerulean'
game 'gta5'
version '1.0.0'

description 'qbx_radio'
name 'qbx_radio'
description 'Radio resource for QBox'
repository 'https://github.com/Qbox-project/qbx_radio'
version '1.0.0'

ox_lib 'locale'

shared_scripts {
'@ox_lib/init.lua',
'@qbx_core/modules/lib.lua'
Expand All @@ -18,7 +20,7 @@ client_scripts {

server_script 'server/main.lua'

ui_page "html/index.html"
ui_page 'html/index.html'

files {
'html/index.html',
Expand All @@ -33,4 +35,4 @@ files {
dependency 'pma-voice'

lua54 'yes'
use_experimental_fxv2_oal 'yes'
use_experimental_fxv2_oal 'yes'
4 changes: 3 additions & 1 deletion locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,7 @@
"new_volume": "New volume: ",
"new_channel": "New channel: ",
"clicksOn": "Mic clicks are now on",
"clicksOff": "Mic clicks are now off"
"clicksOff": "Mic clicks are now off",
"failed_spawn": "Failed to spawn radioprop",
"failed_get_control": "Failed to gain control of radio prop"
}
60 changes: 59 additions & 1 deletion server/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ lib.versionCheck('Qbox-project/qbx_radio')

local config = require 'config.shared'
local restrictedChannels = config.restrictedChannels
local playerRadios = {}

exports.qbx_core:CreateUseableItem('radio', function(source)
TriggerClientEvent('qbx_radio:client:use', source)
Expand All @@ -20,4 +21,61 @@ for channel, jobs in pairs(restrictedChannels) do
local player = exports.qbx_core:GetPlayer(source)
return jobs[player.PlayerData.job.name] and player.PlayerData.job.onduty
end)
end
end

---@param source number
local function deleteProp(source)
local prop = playerRadios[source]

if prop then
if DoesEntityExist(prop) then
DeleteEntity(prop)
end

playerRadios[source] = nil
end
end

---@param source number
---@return number?
lib.callback.register('qbx_radio:server:spawnProp', function(source)
local ped = GetPlayerPed(source)
local coords = GetEntityCoords(ped)
local object = CreateObject(`prop_cs_hand_radio`, coords.x, coords.y, coords.z, true, false, false)

local propExists = lib.waitFor(function()
if DoesEntityExist(object) then
return true
end
end, locale('failed_spawn'), 2000)

if not propExists then return end

playerRadios[source] = object

local netId = NetworkGetNetworkIdFromEntity(object)

SetEntityIgnoreRequestControlFilter(object, true)

return netId
end)

AddEventHandler('playerDropped', function()
local src = source

deleteProp(src)
end)

AddEventHandler('onResourceStop', function(resource)
if resource ~= cache.resource then return end

for i = 1, #playerRadios do
deleteProp(i)
end
end)

RegisterNetEvent('qbx_radio:server:deleteProp', function()
local src = source

deleteProp(src)
end)

0 comments on commit dc2c444

Please sign in to comment.