Skip to content

Commit

Permalink
fix(client): giveitem vehicle check
Browse files Browse the repository at this point in the history
  • Loading branch information
thelindat committed Dec 20, 2023
1 parent dc9c72e commit 14d5e02
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions client.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1591,6 +1591,16 @@ end

exports('giveItemToTarget', giveItemToTarget)

local function isGiveTargetValid(ped, coords)
if cache.vehicle and GetVehiclePedIsIn(ped, false) == cache.vehicle then
return true
end

local entity = Utils.Raycast(1|2|4|8|16, coords + vec3(0, 0, 0.5), 0.2)

return entity == ped and IsEntityVisible(ped)
end

RegisterNUICallback('giveItem', function(data, cb)
cb(1)

Expand All @@ -1602,9 +1612,8 @@ RegisterNUICallback('giveItem', function(data, cb)

if nearbyCount == 1 then
local option = nearbyPlayers[1]
local entity = Utils.Raycast(1|2|4|8|16, option.coords + vec3(0, 0, 0.5), 0.2)

if entity ~= option.ped or not IsEntityVisible(option.ped) then return end
if not isGiveTargetValid(option.ped, option.coords) then return end

return giveItemToTarget(GetPlayerServerId(option.id), data.slot, data.count)
end
Expand All @@ -1613,9 +1622,8 @@ RegisterNUICallback('giveItem', function(data, cb)

for i = 1, #nearbyPlayers do
local option = nearbyPlayers[i]
local entity = Utils.Raycast(1|2|4|8|16, option.coords + vec3(0, 0, 0.5), 0.2)

if entity == option.ped and IsEntityVisible(option.ped) then
if isGiveTargetValid(option.ped, option.coords) then
local playerName = GetPlayerName(option.id)
option.id = GetPlayerServerId(option.id)
option.label = ('[%s] %s'):format(option.id, playerName)
Expand Down

0 comments on commit 14d5e02

Please sign in to comment.