diff --git a/server/main.lua b/server/main.lua index c20b6365d..f543ab8bb 100644 --- a/server/main.lua +++ b/server/main.lua @@ -121,17 +121,6 @@ AddEventHandler('onResourceStart', function(resourceName) end end) --- Functions - -local function checkWeapon(source, item) - local ped = GetPlayerPed(source) - local weapon = GetSelectedPedWeapon(ped) - local weaponInfo = QBCore.Shared.Weapons[weapon] - if weaponInfo and weaponInfo.name == item.name then - RemoveWeaponFromPed(ped, weapon) - end -end - -- Events RegisterNetEvent('qb-inventory:server:openVending', function(data) @@ -181,8 +170,56 @@ RegisterNetEvent('qb-inventory:server:useItem', function(item) if not itemData then return end local itemInfo = QBCore.Shared.Items[itemData.name] if itemData.type == 'weapon' then - TriggerClientEvent('qb-weapons:client:UseWeapon', src, itemData, itemData.info.quality and itemData.info.quality > 0) - TriggerClientEvent('qb-inventory:client:ItemBox', src, itemInfo, 'use') + TriggerClientEvent('qb-weapons:client:UseWeapon', source, itemData, itemData.info.quality and itemData.info.quality > 0) + TriggerClientEvent('qb-inventory:client:ItemBox', source, itemInfo, 'use') + elseif itemData.name == 'id_card' then + UseItem(itemData.name, source, itemData) + TriggerClientEvent('qb-inventory:client:ItemBox', source, itemInfo, 'use') + local playerPed = GetPlayerPed(source) + local playerCoords = GetEntityCoords(playerPed) + local players = QBCore.Functions.GetPlayers() + local gender = item.info.gender == 0 and 'Male' or 'Female' + for _, v in pairs(players) do + local targetPed = GetPlayerPed(v) + local dist = #(playerCoords - GetEntityCoords(targetPed)) + if dist < 3.0 then + TriggerClientEvent('chat:addMessage', v, { + template = '', + args = { + 'ID Card', + item.info.citizenid, + item.info.firstname, + item.info.lastname, + item.info.birthdate, + gender, + item.info.nationality + } + }) + end + end + elseif itemData.name == 'driver_license' then + UseItem(itemData.name, source, itemData) + TriggerClientEvent('qb-inventory:client:ItemBox', source, itemInfo, 'use') + local playerPed = GetPlayerPed(source) + local playerCoords = GetEntityCoords(playerPed) + local players = QBCore.Functions.GetPlayers() + for _, v in pairs(players) do + local targetPed = GetPlayerPed(v) + local dist = #(playerCoords - GetEntityCoords(targetPed)) + if dist < 3.0 then + TriggerClientEvent('chat:addMessage', v, { + template = '', + args = { + 'Drivers License', + item.info.firstname, + item.info.lastname, + item.info.birthdate, + item.info.type + } + } + ) + end + end else UseItem(itemData.name, src, itemData) TriggerClientEvent('qb-inventory:client:ItemBox', src, itemInfo, 'use') @@ -217,9 +254,9 @@ end) RegisterNetEvent('qb-inventory:server:snowball', function(action) if action == 'add' then - AddItem(source, 'weapon_snowball', 1, false, false, 'qb-inventory:server:snowball') + AddItem(source, 'weapon_snowball') elseif action == 'remove' then - RemoveItem(source, 'weapon_snowball', 1, false, 'qb-inventory:server:snowball') + RemoveItem(source, 'weapon_snowball') end end) @@ -238,8 +275,8 @@ QBCore.Functions.CreateCallback('qb-inventory:server:createDrop', function(sourc end local playerPed = GetPlayerPed(src) local playerCoords = GetEntityCoords(playerPed) - if RemoveItem(src, item.name, item.amount, item.fromSlot, 'dropped item') then - if item.type == 'weapon' then checkWeapon(src, item) end + if RemoveItem(src, item.name, item.amount, item.fromSlot) then + if item.type == 'weapon' then SetCurrentPedWeapon(playerPed, `WEAPON_UNARMED`, true) end TaskPlayAnim(playerPed, 'pickup_object', 'pickup_low', 8.0, -8.0, 2000, 0, 0, false, false, false) local bag = CreateObjectNoOffset(Config.ItemDropObject, playerCoords.x + 0.5, playerCoords.y + 0.5, playerCoords.z, true, true, false) local dropId = NetworkGetNetworkIdFromEntity(bag) @@ -357,19 +394,19 @@ QBCore.Functions.CreateCallback('qb-inventory:server:giveItem', function(source, return end - local removeItem = RemoveItem(source, item, giveAmount, slot, 'Item given to ID #'..target) + local removeItem = RemoveItem(source, item, giveAmount, slot, 'Item given to ID #' .. target) if not removeItem then cb(false) return end - local giveItem = AddItem(target, item, giveAmount, false, info, 'Item given from ID #'..source) + local giveItem = AddItem(target, item, giveAmount, false, info, 'Item given from ID #' .. source) if not giveItem then cb(false) return end - if itemInfo.type == 'weapon' then checkWeapon(source, item) end + if itemInfo.type == 'weapon' then SetCurrentPedWeapon(playerPed, `WEAPON_UNARMED`, true) end TriggerClientEvent('qb-inventory:client:giveAnim', source) TriggerClientEvent('qb-inventory:client:ItemBox', source, itemInfo, 'remove', giveAmount) TriggerClientEvent('qb-inventory:client:giveAnim', target) @@ -423,7 +460,6 @@ RegisterNetEvent('qb-inventory:server:SetInventoryData', function(fromInventory, if fromItem then if not toItem and toAmount > fromItem.amount then return end - if fromInventory == 'player' and toInventory ~= 'player' then checkWeapon(src, fromItem) end local fromId = getIdentifier(fromInventory, src) local toId = getIdentifier(toInventory, src)