Out/ref parameter in lua?

Hey there,

I’m trying to use the GetClosestPed function like this :

local coords = GetEntityCoords(GetPlayerPed(-1))
local ped

if GetClosestPed(coords["x"], coords["y"], coords["z"], 5.0, true, false, ped, true, true, -1) then
	Citizen.Trace("There is a ped !")
	Citizen.Trace(DumpTable(ped))
else
	Citizen.Trace("No ped")
end

But ped doesn’t seem to change, it’s a nil anyway. Is there a way to have an out/ref parameter in lua ?

No, there isn’t. Instead the method should just return the variable that is normally “outed” (I think).

Try the following:

ped = GetClosestPed(coords["x"], coords["y"], coords["z"], 5.0)

Edit: Turns out that the method does require more arguments, if the above doesn’t work try:

ped = GetClosestPed(coords["x"], coords["y"], coords["z"], 5.0, BOOLEAN, BOOLEAN, BOOLEAN, BOOLEAN, INT)

--[[
function GetClosestPed(x, y, z, radius, p4, p5, p7, p8, pedType)
	return _in(0xC33AB876A77F8164, x, y, z, radius, p4, p5, _i, p7, p8, pedType, _r)
end
]]

Note: You don’t need to provide a “ped” argument.

1 Like

Thanks, cheers mate !

Edit : Where did you get the function documentation ? I’m using http://www.dev-c.com/nativedb/ but it doesn’t say which parameter is what, it only says “Any” if it’s not void

I use a combination of nativedb and the natives.lua file that comes with CitizenMP (located at <GameInstall>/citizen/scripting/lua)

Sorry but I try the two functions but everything return false :cry: