Hello all,
I am still quite new to Lua programming and FiveM, and I was wondering if you can create a thread inside a client script inside a function. The reason i ask this is the following. Sometimes you’d like a thread to check something in a while loop, but not the entire time the client is connected. So far I’ve only seen scripts where the Citizen.CreateThread is called instantly when the client connects. The following example from the esx_indentity scripts seems a little ineffecient:
Citizen.CreateThread(function()
while true do
Citizen.Wait(0)
if guiEnabled then
DisableControlAction(0, 1, true) -- LookLeftRight
DisableControlAction(0, 2, true) -- LookUpDown
DisableControlAction(0, 106, true) -- VehicleMouseControlOverride
DisableControlAction(0, 142, true) -- MeleeAttackAlternate
DisableControlAction(0, 30, true) -- MoveLeftRight
DisableControlAction(0, 31, true) -- MoveUpDown
DisableControlAction(0, 21, true) -- disable sprint
DisableControlAction(0, 24, true) -- disable attack
DisableControlAction(0, 25, true) -- disable aim
DisableControlAction(0, 47, true) -- disable weapon
DisableControlAction(0, 58, true) -- disable weapon
DisableControlAction(0, 263, true) -- disable melee
DisableControlAction(0, 264, true) -- disable melee
DisableControlAction(0, 257, true) -- disable melee
DisableControlAction(0, 140, true) -- disable melee
DisableControlAction(0, 141, true) -- disable melee
DisableControlAction(0, 143, true) -- disable melee
DisableControlAction(0, 75, true) -- disable exit vehicle
DisableControlAction(27, 75, true) -- disable exit vehicle
else
Citizen.Wait(500)
end
end
end)
I would like this thread to just be killed once the player is not in a gui, and started again once the player opens the gui. Is this possible in Lua?