Hello,
Can you help with a little problem…
How would you use your function mycb in a loop ?
Lets say I want to start a bank robbery which take location, name from config files and put it in a loop :
Citizen.CreateThread(function()
while true do
Citizen.Wait(1)
local playerPos = GetEntityCoords(PlayerPedId(), true)
for k,v in pairs(Banks) do
local bankPos = v.position
local distance = Vdist(playerPos.x, playerPos.y, playerPos.z, bankPos.x, bankPos.y, bankPos.z)
if distance < Config.Marker.DrawDistance then
if not holdingUpBank then
DrawMarker(Config.Marker.Type, bankPos.x, bankPos.y, bankPos.z, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, Config.Marker.x, Config.Marker.y, Config.Marker.z, Config.Marker.r, Config.Marker.g, Config.Marker.b, Config.Marker.a, false, false, 2, true, false, false, false)
if distance < 2 then
Drawing.draw3DText(bankPos.x, bankPos.y, bankPos.z, _U('press_to_rob', v.nameOfBank), 1, 0.2, 0.1, 255, 255, 255, 215)
if IsControlJustReleased(0, Keys['E']) then
if IsPedArmed(PlayerPedId(), 4) then
TriggerEvent("mhacking:show")
TriggerEvent("mhacking:start",7,20,mycb)
else
ESX.ShowNotification(_U('no_threat'))
end
end
end
end
end
end
if holdingUpBank then
local bankPos = Banks[bank].position
if Vdist(playerPos.x, playerPos.y, playerPos.z, bankPos.x, bankPos.y, bankPos.z) > Config.MaxDistance then
TriggerServerEvent('esx_holdupbank:tooFar', bank)
end
end
end
end)
Then after that in mycb function is successfull it start the robby :
function mycb(success, timeremaining)
if success then
print('Success with '..timeremaining..'s remaining.')
TriggerEvent('mhacking:hide')
TriggerServerEvent('esx_holdupbank:robberyStarted', k)
else
print('Failure')
TriggerEvent('mhacking:hide')
end
end
It doesn’t seem to work this way because in mycb the value “k” for the bank is not in the loop anymore so it will select a random bank in the config files even though you are at a different location so it will cancel the bank robbery because of the distance.
Thanks for your time.