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

Added Chat Messages for id's again #515

Closed
wants to merge 5 commits into from
Closed
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
78 changes: 57 additions & 21 deletions server/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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 = '<div class="chat-message advert" style="background: linear-gradient(to right, rgba(5, 5, 5, 0.6), #74807c); display: flex;"><div style="margin-right: 10px;"><i class="far fa-id-card" style="height: 100%;"></i><strong> {0}</strong><br> <strong>Civ ID:</strong> {1} <br><strong>First Name:</strong> {2} <br><strong>Last Name:</strong> {3} <br><strong>Birthdate:</strong> {4} <br><strong>Gender:</strong> {5} <br><strong>Nationality:</strong> {6}</div></div>',
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 = '<div class="chat-message advert" style="background: linear-gradient(to right, rgba(5, 5, 5, 0.6), #657175); display: flex;"><div style="margin-right: 10px;"><i class="far fa-id-card" style="height: 100%;"></i><strong> {0}</strong><br> <strong>First Name:</strong> {1} <br><strong>Last Name:</strong> {2} <br><strong>Birth Date:</strong> {3} <br><strong>Licenses:</strong> {4}</div></div>',
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')
Expand Down Expand Up @@ -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)

Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
Loading