Hi, I’m using the Vdist2 native between two values; my pickup that appears when you kill a specific NPC and all the players in the world. What I’m trying to do is whichever player was closest to the pickup when it was picked up is theoretically the player carrying the pickup. This player will have a marker drawn on top of them and they need to deliver the pickup to a specific location. This is all fine except that the vdist2 native returns a stupidly high number for two coords that are so close together.
while true do
Citizen.Wait(0)
MissionText("Collect the ~g~package.", 1000000)
local minimum, maximum = GetModelDimensions(GetEntityModel(GetPickupObject(pickup1)))
pickuppos = GetEntityCoords(GetPickupObject(pickup1))
DrawMarker(20, pickuppos.x, pickuppos.y, pickuppos.z+maximum.z+0.5, 0.0, 0.0, 0.0, 0.0, 180.0, 0.0, 0.5, 0.5, 0.5, 0, 128, 0, 50, 1, 1, 2, 0, 0)
if HasPickupBeenCollected(pickup1) then
for _, ped in ipairs(GetGamePool('CPed')) do -- Enumerate all peds
if IsPedAPlayer(ped) and DoesEntityExist(ped) and not IsEntityDead(ped) then
local pedpos = GetEntityCoords(ped)
local distanceCheck = Vdist2(pickuppos.x, pickuppos.y, pickuppos.z, pedpos.x, pedpos.y, pedpos.z)
Citizen.Trace(distanceCheck)
if distanceCheck <= 5.0 then -- Check if this player is closest when the pickup was collected
Citizen.Trace("Found Player") --
playerpickup = ped
break -- end for loop once player found
end
end
end
RemoveBlip(blippickup)
PlaySoundFrontend(a_0, "CHECKPOINT_NORMAL", "HUD_MINI_GAME_SOUNDSET", 1)
ClearPrints()
break
end
end
Video showcasing the problem (near the end)
Streamable