Skip to content

Commit

Permalink
fix: event namings and missing commands
Browse files Browse the repository at this point in the history
  • Loading branch information
mafewtm committed Oct 31, 2024
1 parent 778f602 commit 4dd0a25
Show file tree
Hide file tree
Showing 3 changed files with 87 additions and 33 deletions.
34 changes: 17 additions & 17 deletions client/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ local function dnaHash(s)
return h
end

RegisterNetEvent('evidence:client:SetStatus', function(statusId, time)
RegisterNetEvent('qbx_evidence:client:setStatus', function(statusId, time)
if time > 0 and statusList[statusId] then
if not currentStatusList?[statusId] or currentStatusList[statusId].time < 20 then
currentStatusList[statusId] = {
Expand All @@ -61,35 +61,35 @@ RegisterNetEvent('evidence:client:SetStatus', function(statusId, time)
elseif statusList[statusId] then
currentStatusList[statusId] = nil
end
TriggerServerEvent('evidence:server:UpdateStatus', currentStatusList)
TriggerServerEvent('qbx_evidence:server:updateStatus', currentStatusList)
end)

RegisterNetEvent('evidence:client:AddBlooddrop', function(bloodId, citizenid, bloodtype, coords)
RegisterNetEvent('qbx_evidence:client:addBloodDrop', function(bloodId, citizenid, bloodtype, coords)
bloodDrops[bloodId] = {
citizenid = citizenid,
bloodtype = bloodtype,
coords = vec3(coords.x, coords.y, coords.z - 0.9)
}
end)

RegisterNetEvent('evidence:client:RemoveBlooddrop', function(bloodId)
RegisterNetEvent('qbx_evidence:client:removeBloodDrop', function(bloodId)
bloodDrops[bloodId] = nil
currentBloodDrop = 0
end)

RegisterNetEvent('evidence:client:AddFingerPrint', function(fingerId, fingerprint, coords)
RegisterNetEvent('qbx_evidence:client:addFingerPrint', function(fingerId, fingerprint, coords)
fingerprints[fingerId] = {
fingerprint = fingerprint,
coords = vec3(coords.x, coords.y, coords.z - 0.9)
}
end)

RegisterNetEvent('evidence:client:RemoveFingerprint', function(fingerId)
RegisterNetEvent('qbx_evidence:client:removeFingerprint', function(fingerId)
fingerprints[fingerId] = nil
currentFingerprint = 0
end)

RegisterNetEvent('evidence:client:ClearBlooddropsInArea', function()
RegisterNetEvent('qbx_evidence:client:clearBloodDropsInArea', function()
local pos = GetEntityCoords(cache.ped)
local bloodDropList = {}
if lib.progressCircle({
Expand All @@ -112,28 +112,28 @@ RegisterNetEvent('evidence:client:ClearBlooddropsInArea', function()
bloodDropList[#bloodDropList + 1] = bloodId
end
end
TriggerServerEvent('evidence:server:ClearBlooddrops', bloodDropList)
TriggerServerEvent('qbx_evidence:server:clearBloodDrops', bloodDropList)
exports.qbx_core:Notify(locale('blood_cleared'), 'success')
end
else
exports.qbx_core:Notify(locale('canceled'), 'error')
end
end)

RegisterNetEvent('evidence:client:AddCasing', function(casingId, weapon, coords, serie)
RegisterNetEvent('qbx_evidence:client:addCasing', function(casingId, weapon, coords, serie)
casings[casingId] = {
type = weapon,
serie = serie and serie or locale('serial_not_visible'),
coords = vec3(coords.x, coords.y, coords.z - 0.9)
}
end)

RegisterNetEvent('evidence:client:RemoveCasing', function(casingId)
RegisterNetEvent('qbx_evidence:client:removeCasing', function(casingId)
casings[casingId] = nil
currentCasing = 0
end)

RegisterNetEvent('evidence:client:ClearCasingsInArea', function()
RegisterNetEvent('qbx_evidence:client:clearCasingsInArea', function()
local pos = GetEntityCoords(cache.ped)
local casingList = {}

Expand All @@ -157,7 +157,7 @@ RegisterNetEvent('evidence:client:ClearCasingsInArea', function()
casingList[#casingList + 1] = casingId
end
end
TriggerServerEvent('evidence:server:ClearCasings', casingList)
TriggerServerEvent('qbx_evidence:server:clearCasings', casingList)
exports.qbx_core:Notify(locale('casing_cleared'), 'success')
end
else
Expand All @@ -175,7 +175,7 @@ local function updateStatus()
currentStatusList[k].time = 0
end
end
TriggerServerEvent('evidence:server:UpdateStatus', currentStatusList)
TriggerServerEvent('qbx_evidence:server:updateStatus', currentStatusList)
end
if shotAmount > 0 then
shotAmount = 0
Expand All @@ -193,7 +193,7 @@ local function onPlayerShooting()
shotAmount += 1
if shotAmount > 5 and not currentStatusList?.gunpowder then
if math.random(1, 10) <= 7 then
TriggerEvent('evidence:client:SetStatus', 'gunpowder', 200)
TriggerEvent('qbx_evidence:client:setStatus', 'gunpowder', 200)
end
end
dropBulletCasing(cache.weapon, cache.ped)
Expand Down Expand Up @@ -259,7 +259,7 @@ CreateThread(function()
ammotype = casings[currentCasing].type,
serie = casings[currentCasing].serie
},
serverEventOnPickup = 'evidence:server:AddCasingToInventory'
serverEventOnPickup = 'qbx_evidence:server:addCasingToInventory'
})
end

Expand All @@ -274,7 +274,7 @@ CreateThread(function()
dnalabel = dnaHash(bloodDrops[currentBloodDrop].citizenid),
bloodtype = bloodDrops[currentBloodDrop].bloodtype
},
serverEventOnPickup = 'evidence:server:AddBlooddropToInventory'
serverEventOnPickup = 'qbx_evidence:server:addBloodDropToInventory'
})
end

Expand All @@ -288,7 +288,7 @@ CreateThread(function()
street = getStreetLabel(fingerprints[currentFingerprint].coords),
fingerprint = fingerprints[currentFingerprint].fingerprint
},
serverEventOnPickup = 'evidence:server:AddFingerprintToInventory'
serverEventOnPickup = 'qbx_evidence:server:addFingerprintToInventory'
})
end
end
Expand Down
54 changes: 54 additions & 0 deletions server/commands.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
local function dnaHash(s)
return string.gsub(s, '.', function(c)
return string.format('%02x', string.byte(c))
end)
end

local function IsLeoAndOnDuty(player, minGrade)
local job = player.PlayerData.job
if job and job.type == 'leo' and job.onduty then
return job.grade.level >= (minGrade or 0)
end
end

local function checkLeoAndOnDuty(player, minGrade)
if IsLeoAndOnDuty(player, minGrade) then return true end
exports.qbx_core:Notify(player.PlayerData.source, locale('error.on_duty_police_only'), 'error')
end

lib.addCommand('clearcasings', {help = locale('commands.clear_casign')}, function(source)
local player = exports.qbx_core:GetPlayer(source)
if not checkLeoAndOnDuty(player) then return end
TriggerClientEvent('qbx_evidence:client:clearCasingsInArea', source)
end)

lib.addCommand('clearblood', {help = locale('commands.clearblood')}, function(source)
local player = exports.qbx_core:GetPlayer(source)
if not checkLeoAndOnDuty(player) then return end
TriggerClientEvent('qbx_evidence:client:clearBloodDropsInArea', source)
end)

lib.addCommand('takedna', {
help = locale('commands.takedna'),
params = {{
name = 'id',
type = 'playerId',
help = locale('info.player_id')
}},
}, function(source, args)
local player = exports.qbx_core:GetPlayer(source)
local otherPlayer = exports.qbx_core:GetPlayer(args.id)

if not checkLeoAndOnDuty(player) then return end
if not player.Functions.RemoveItem('empty_evidence_bag', 1) then
return exports.qbx_core:Notify(source, locale('error.have_evidence_bag'), 'error')
end

local info = {
label = locale('info.dna_sample'),
type = 'dna',
dnalabel = dnaHash(otherPlayer.PlayerData.citizenid),
description = dnaHash(otherPlayer.PlayerData.citizenid)
}
if not player.Functions.AddItem('filled_evidence_bag', 1, false, info) then return end
end)
32 changes: 16 additions & 16 deletions server/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ local function generateId(table)
return id
end

lib.callback.register('police:GetPlayerStatus', function(_, targetSrc)
lib.callback.register('qbx_evidence:server:getPlayerStatus', function(_, targetSrc)
local player = exports.qbx_core:GetPlayer(targetSrc)
if not player or not next(playerStatus[targetSrc]) then return {} end
local status = playerStatus[targetSrc]
Expand All @@ -25,7 +25,7 @@ lib.callback.register('police:GetPlayerStatus', function(_, targetSrc)
return statList
end)

RegisterNetEvent('evidence:server:UpdateStatus', function(data)
RegisterNetEvent('qbx_evidence:server:updateStatus', function(data)
playerStatus[source] = data
end)

Expand All @@ -35,25 +35,25 @@ RegisterNetEvent('evidence:server:CreateBloodDrop', function(citizenid, bloodtyp
dna = citizenid,
bloodtype = bloodtype
}
TriggerClientEvent('evidence:client:AddBlooddrop', -1, bloodId, citizenid, bloodtype, coords)
TriggerClientEvent('qbx_evidence:client:addBloodDrop', -1, bloodId, citizenid, bloodtype, coords)
end)

RegisterNetEvent('evidence:server:CreateFingerDrop', function(coords)
RegisterNetEvent('qbx_evidence:server:createFingerDrop', function(coords)
local player = exports.qbx_core:GetPlayer(source)
local fingerId = generateId(fingerDrops)
fingerDrops[fingerId] = player.PlayerData.metadata.fingerprint
TriggerClientEvent('evidence:client:AddFingerPrint', -1, fingerId, player.PlayerData.metadata.fingerprint, coords)
TriggerClientEvent('qbx_evidence:client:addFingerPrint', -1, fingerId, player.PlayerData.metadata.fingerprint, coords)
end)

RegisterNetEvent('evidence:server:ClearBlooddrops', function(bloodDropList)
RegisterNetEvent('qbx_evidence:server:clearBloodDrops', function(bloodDropList)
if not bloodDropList or not next(bloodDropList) then return end
for _, v in pairs(bloodDropList) do
TriggerClientEvent('evidence:client:RemoveBlooddrop', -1, v)
TriggerClientEvent('qbx_evidence:client:removeBloodDrop', -1, v)
bloodDrops[v] = nil
end
end)

RegisterNetEvent('evidence:server:AddBlooddropToInventory', function(bloodId, bloodInfo)
RegisterNetEvent('qbx_evidence:server:addBloodDropToInventory', function(bloodId, bloodInfo)
local src = source
local player = exports.qbx_core:GetPlayer(src)
local playerName = player.PlayerData.charinfo.firstname..' '..player.PlayerData.charinfo.lastname
Expand All @@ -70,12 +70,12 @@ RegisterNetEvent('evidence:server:AddBlooddropToInventory', function(bloodId, bl
return exports.qbx_core:Notify(src, locale('error.have_evidence_bag'), 'error')
end
if exports.ox_inventory:AddItem(src, 'filled_evidence_bag', 1, metadata) then
TriggerClientEvent('evidence:client:RemoveBlooddrop', -1, bloodId)
TriggerClientEvent('qbx_evidence:client:removeBloodDrop', -1, bloodId)
bloodDrops[bloodId] = nil
end
end)

RegisterNetEvent('evidence:server:AddFingerprintToInventory', function(fingerId, fingerInfo)
RegisterNetEvent('qbx_evidence:server:addFingerprintToInventory', function(fingerId, fingerInfo)
local src = source
local player = exports.qbx_core:GetPlayer(src)
local playerName = player.PlayerData.charinfo.firstname..' '..player.PlayerData.charinfo.lastname
Expand All @@ -90,7 +90,7 @@ RegisterNetEvent('evidence:server:AddFingerprintToInventory', function(fingerId,
return exports.qbx_core:Notify(src, locale('error.have_evidence_bag'), 'error')
end
if exports.ox_inventory:AddItem(src, 'filled_evidence_bag', 1, metadata) then
TriggerClientEvent('evidence:client:RemoveFingerprint', -1, fingerId)
TriggerClientEvent('qbx_evidence:client:removeFingerprint', -1, fingerId)
fingerDrops[fingerId] = nil
end
end)
Expand All @@ -101,19 +101,19 @@ RegisterNetEvent('evidence:server:CreateCasing', function(weapon, serial, coords
if not serieNumber then
serieNumber = serial
end
TriggerClientEvent('evidence:client:AddCasing', -1, casingId, weapon, coords, serieNumber)
TriggerClientEvent('qbx_evidence:client:addCasing', -1, casingId, weapon, coords, serieNumber)
end)

RegisterNetEvent('evidence:server:ClearCasings', function(casingList)
RegisterNetEvent('qbx_evidence:server:clearCasings', function(casingList)
if casingList and next(casingList) then
for _, v in pairs(casingList) do
TriggerClientEvent('evidence:client:RemoveCasing', -1, v)
TriggerClientEvent('qbx_evidence:client:removeCasing', -1, v)
casings[v] = nil
end
end
end)

RegisterNetEvent('evidence:server:AddCasingToInventory', function(casingId, casingInfo)
RegisterNetEvent('qbx_evidence:server:addCasingToInventory', function(casingId, casingInfo)
local src = source
local player = exports.qbx_core:GetPlayer(src)
local playerName = player.PlayerData.charinfo.firstname..' '..player.PlayerData.charinfo.lastname
Expand All @@ -130,7 +130,7 @@ RegisterNetEvent('evidence:server:AddCasingToInventory', function(casingId, casi
return exports.qbx_core:Notify(src, locale('error.have_evidence_bag'), 'error')
end
if exports.ox_inventory:AddItem(src, 'filled_evidence_bag', 1, metadata) then
TriggerClientEvent('evidence:client:RemoveCasing', -1, casingId)
TriggerClientEvent('qbx_evidence:client:removeCasing', -1, casingId)
casings[casingId] = nil
end
end)

0 comments on commit 4dd0a25

Please sign in to comment.