Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

switch to exports.qbx_core #4

Merged
merged 1 commit into from
Oct 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 4 additions & 6 deletions client/exports.lua
Original file line number Diff line number Diff line change
Expand Up @@ -140,16 +140,15 @@ end
exports('InjuriedPerson', InjuriedPerson)

function EmergencyCall(message, phonenumber, anonymous)
local PlayerData = QBCore.Functions.GetPlayerData()
local data = {
tencodeid = phonenumber.."call",
tencode = Config.TenCodes[phonenumber.."call"].tencode,
location = GetLocation(GetEntityCoords(cache.ped)),
gender = GetGender(),
type = 0,
coords = GetEntityCoords(cache.ped),
name = not anonymous and PlayerData.charinfo.lastname .. " " .. PlayerData.charinfo.firstname,
number = not anonymous and PlayerData.charinfo.phone,
name = not anonymous and QBX.PlayerData.charinfo.lastname .. " " .. QBX.PlayerData.charinfo.firstname,
number = not anonymous and QBX.PlayerData.charinfo.phone,
information = message,
title = Config.TenCodes[phonenumber.."call"].title,
jobs = Config.TenCodes[phonenumber.."call"].jobs
Expand All @@ -166,13 +165,12 @@ local function Code99(servicetype)
service = 'ems99'
end
if not service then return end
local PlayerData = QBCore.Functions.GetPlayerData()
local data = {
tencodeid = service,
tencode = Config.TenCodes[service].tencode,
location = GetLocation(GetEntityCoords(cache.ped)),
name = PlayerData.charinfo.lastname .. " " .. PlayerData.charinfo.firstname,
callsign = PlayerData.metadata.callsign,
name = QBX.PlayerData.charinfo.lastname .. " " .. QBX.PlayerData.charinfo.firstname,
callsign = QBX.PlayerData.metadata.callsign,
type = 1,
coords = GetEntityCoords(cache.ped),
title = Config.TenCodes[service].title,
Expand Down
44 changes: 19 additions & 25 deletions client/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ function GetVehicleData(vehicle)
Data.id = NetworkGetNetworkIdFromEntity(vehicle)
Data.speed = GetEntitySpeed(vehicle)
Data.name = GetLabelText(GetDisplayNameFromVehicleModel(GetEntityModel(vehicle)))
Data.name = Data.name == 'NULL' and QBCore.Shared.Vehicles[model].name or Data.name
Data.name = Data.name == 'NULL' and exports.qbx_core:GetVehiclesByName().Vehicles[model].name or Data.name

local primary, secondary = GetVehicleColours(vehicle)
local color1, color2 = Lang:t('colors.' .. primary), Lang:t('colors.' .. secondary)
Expand All @@ -46,8 +46,7 @@ end
--- returns the player's gender
---@return string
function GetGender()
local PlayerData = QBCore.Functions.GetPlayerData()
return PlayerData.charinfo.gender
return tostring(QBX.PlayerData.charinfo.gender)
end

--- returns the heading of the player
Expand All @@ -68,7 +67,7 @@ end
local WeaponClasses = {
[2685387236] = Lang:t('WeaponClasses.melee'),
[416676503] = Lang:t('WeaponClasses.gun'),
[-95776620] = Lang:t('WeaponClasses.submachinegun'),
[-95776620] = Lang:t('WeaponClasses.submachinegun'),
[860033945] = Lang:t('WeaponClasses.shotgun'),
[970310034] = Lang:t('WeaponClasses.assaultrifle'),
[1159398588] = Lang:t('WeaponClasses.lightmachinegun'),
Expand Down Expand Up @@ -111,8 +110,7 @@ local fightAntiSpam = false
local function fight(ped)
if ped ~= cache.ped then return end

local PlayerData = QBCore.Functions.GetPlayerData()
if CheckJob(Config.Events.fight.jobwhitelist, PlayerData.job) and PlayerData.job.onduty then return end
if CheckJob(Config.Events.fight.jobwhitelist, QBX.PlayerData.job) and QBX.PlayerData.job.onduty then return end

fightAntiSpam = true
exports['qbx-dispatch']:Fight()
Expand All @@ -127,8 +125,7 @@ local function shotfired(ped)
if IsPedCurrentWeaponSilenced(ped) and math.random() <= 0.98 then return end
-- 2% chance to trigger the event if the weapon is silenced, ( real life weapons are not 100% silent ;c )

local PlayerData = QBCore.Functions.GetPlayerData()
if CheckJob(Config.Events.shotsfired.jobwhitelist, PlayerData.job) and PlayerData.job.onduty then return end
if CheckJob(Config.Events.shotsfired.jobwhitelist, QBX.PlayerData.job) and QBX.PlayerData.job.onduty then return end

shotsfiredAntiSpam = true
if cache.vehicle then
Expand Down Expand Up @@ -193,9 +190,8 @@ end
RegisterNetEvent('qbx-dispatch:client:AddCall', function(Data, CallId)
if DispatchDisabled then return end
if not Data or not LocalPlayer.state.isLoggedIn then return end
local PlayerData = QBCore.Functions.GetPlayerData()
if Data.jobs and not CheckJob(Data.jobs, PlayerData.job) then return end
if Config.OnlyOnDuty and not PlayerData.job.onduty then return end
if Data.jobs and not CheckJob(Data.jobs, QBX.PlayerData.job) then return end
if Config.OnlyOnDuty and not QBX.PlayerData.job.onduty then return end
if not Data.coords then return end
if Data.speed then Data.speed = (Config.UseMPH and math.ceil(Data.speed * 2.236936) .. " Mph") or (math.ceil(Data.speed * 3.6) .. " Km/h") end

Expand All @@ -206,7 +202,7 @@ RegisterNetEvent('qbx-dispatch:client:AddCall', function(Data, CallId)
})

local sound = Config.TenCodes[Data.tencodeid].sound
if PlayerData.metadata.mutedispatch or not sound then return end
if QBX.PlayerData.metadata.mutedispatch or not sound then return end
if not sound.custom then PlaySound(-1, sound.name, sound.ref, false, false, true) return end
TriggerServerEvent("InteractSound_SV:PlayOnSource", sound.name, sound.volume or 0.25) -- For Custom Sounds
end)
Expand All @@ -217,9 +213,8 @@ end)
---@param CallId number
RegisterNetEvent("qbx-dispatch:client:AddBlip", function(coords, data, CallId)
if DispatchDisabled then return end
local PlayerData = QBCore.Functions.GetPlayerData()
if not data.jobs or not CheckJob(data.jobs, PlayerData.job) then return end
if not (not Config.OnlyOnDuty or PlayerData.job.onduty) then return end
if not data?.jobs or not CheckJob(data?.jobs, QBX.PlayerData.job) then return end
if not (not Config.OnlyOnDuty or QBX.PlayerData.job.onduty) then return end
local alpha = 255
local radiusAlpha = 128
local blip, radius
Expand Down Expand Up @@ -294,21 +289,21 @@ RegisterNetEvent("qbx-dispatch:client:ClearBlips", function()
end
radiuses = {}
blips = {}
QBCore.Functions.Notify(Lang:t('success.clearedblips'), "success")
exports.qbx_core:Notify(Lang:t('success.clearedblips'), "success")
end)

--- Disables the dispatch
RegisterNetEvent("qbx-dispatch:client:DisableDispatch", function()
DispatchDisabled = not DispatchDisabled
QBCore.Functions.Notify(DispatchDisabled and Lang:t('success.disableddispatch') or Lang:t('success.enableddispatch'), "success")
exports.qbx_core:Notify(DispatchDisabled and Lang:t('success.disableddispatch') or Lang:t('success.enableddispatch'), "success")
end)

--- Sends a message to the dispatch when someone send a message to 911 (NPWD)
RegisterNetEvent('qbx-dispatch:NPWD:Text911', function(message)
local msg = message
if string.len(msg) <= 0 then QBCore.Functions.Notify(Lang:t('error.nomessage'), 'error') return end
if exports['qbx-policejob']:IsHandcuffed() then QBCore.Functions.Notify(Lang:t('error.handcuffed'), 'error') return end
if exports.npwd:isPhoneDisabled() then QBCore.Functions.Notify(Lang:t('error.disabledphone'), 'error') return end
if string.len(msg) <= 0 then exports.qbx_core:Notify(Lang:t('error.nomessage'), 'error') return end
if exports['qbx-policejob']:IsHandcuffed() then exports.qbx_core:Notify(Lang:t('error.handcuffed'), 'error') return end
if exports.npwd:isPhoneDisabled() then exports.qbx_core:Notify(Lang:t('error.disabledphone'), 'error') return end

local anonymous = (((Config.AllowAnonText and string.split(message, " ")[1] == "anon") and true) or false)
if anonymous then message = string.gsub(message, "anon ", "") end
Expand All @@ -318,9 +313,9 @@ end)
--- Sends a message to the dispatch when someone send a message to 912 (NPWD)
RegisterNetEvent('qbx-dispatch:NPWD:Text912', function(message)
local msg = message
if string.len(msg) <= 0 then QBCore.Functions.Notify(Lang:t('error.nomessage'), 'error') return end
if exports['qbx-policejob']:IsHandcuffed() then QBCore.Functions.Notify(Lang:t('error.handcuffed'), 'error') return end
if exports.npwd:isPhoneDisabled() then QBCore.Functions.Notify(Lang:t('error.disabledphone'), 'error') return end
if string.len(msg) <= 0 then exports.qbx_core:Notify(Lang:t('error.nomessage'), 'error') return end
if exports['qbx-policejob']:IsHandcuffed() then exports.qbx_core:Notify(Lang:t('error.handcuffed'), 'error') return end
if exports.npwd:isPhoneDisabled() then exports.qbx_core:Notify(Lang:t('error.disabledphone'), 'error') return end

local anonymous = (((Config.AllowAnonText and string.split(message, " ")[1] == "anon") and true) or false)
if anonymous then message = string.gsub(message, "anon ", "") end
Expand All @@ -330,7 +325,6 @@ end)

--#region Keybinds
--- Accepting and denying calls

lib.addKeybind({
name = 'acceptdispatch',
description = Lang:t('general.acceptdispatchcall'),
Expand All @@ -347,4 +341,4 @@ lib.addKeybind({
end
})
---
--#endregion Keybinds
--#endregion Keybinds
12 changes: 7 additions & 5 deletions fxmanifest.lua
Original file line number Diff line number Diff line change
@@ -1,19 +1,21 @@
fx_version 'cerulean'
game 'gta5'

version '1.0.4'
author 'Tonybyn_Mp4'
description 'Dispatch resource for the Qbox framework'
version '1.1.0'

shared_scripts {
'@qbx-core/import.lua',
"@qbx_core/import.lua",
'@ox_lib/init.lua',
'@qbx-core/shared/locale.lua',
'@qbx_core/shared/locale.lua',
'locales/en.lua',
'locales/*.lua',
'config.lua',
}

modules {
'qbx-core:core'
"qbx_core:client:playerdata"
}

client_scripts {
Expand All @@ -38,4 +40,4 @@ dependencies {
}

lua54 'yes'
use_experimental_fxv2_oal 'yes'
use_experimental_fxv2_oal 'yes'
10 changes: 5 additions & 5 deletions server/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@ RegisterServerEvent("qbx-dispatch:server:AddCall", function(info)
end)

lib.addCommand('mutedispatch', {help = Lang:t('commands.mutedispatch')}, function(source, _)
local Player = QBCore.Functions.GetPlayer(source)
Player.Functions.SetMetaData('mutedispatch', not Player.PlayerData.metadata['mutedispatch'])
QBCore.Player.Save(source)
local player = exports.qbx_core:GetPlayer(source)
player.Functions.SetMetaData('mutedispatch', not player.PlayerData.metadata['mutedispatch'])
exports.qbx_core:Save(source)
end)

lib.addCommand('disabledispatch', {help = Lang:t('commands.disabledispatch')}, function(source, _)
local job = QBCore.Functions.GetPlayer(source).PlayerData.job
local job = exports.qbx_core:GetPlayer(source).PlayerData.job
if not Config.DispatchJobs.Types[job.type] or not Config.DispatchJobs.Jobs[job.name] then return end

TriggerClientEvent('qbx-dispatch:client:DisableDispatch', source)
Expand Down Expand Up @@ -80,4 +80,4 @@ lib.callback.register('qbx-dispatch:server:GetLastCall', function(source)
return {blipid = calls[i].id}
end
end
end)
end)