A long time ago, I used to program in PAWN (the language used in SAMP (GTA San Andreas Online)), and now that I’m learning LUA/FiveM, it’s been quite an experience for me. The way the threading system works is something I’ve never seen before—it’s impressive!
My question is: In PAWN, everything had Callbacks, like OnPlayerConnect, OnPlayerEnterVehicle, OnPlayerSpawn, OnPlayerKillOtherPlayer, etc.
Maybe I misspelled some Callbacks lol, but you get the idea. When I searched to see if there was an OnPlayerEnterVehicle callback here in FiveM, I realized it didn’t exist. So I went to check how many callbacks there are, and to my surprise, there are very few. Then I looked into how FiveM programmers identify client actions, and I saw they use checks (like IsPedInAnyVehicle) combined with Citizen.Wait(0). From what I understand, this means it constantly checks if the player is in a vehicle, while all the other codes (resources) are also executing AT THE SAME TIME…
So basically, while this check is constantly running, other checks are also running tick by tick (all the time), and it literally blows my mind lol.
Having multiple checks running tick by tick (Citizen.Wait(0))—doesn’t that risk crashing the client-side if done on the client-side, or crashing the server-side if done on the server-side?
How do you deal with this here? It scares me to think that one resource could overwrite the actions of another resource. For example:
[resource1]
client.lua:
some random codes....
Citizen.Wait(0)
IsPedShooting if yes SetPedMoney - 1
[resource2]
client.lua:
some random codes....
Citizen.Wait(0)
IsPedShooting if yes SetPedMoney + 1000
Just two examples of resources running tick by tick, with the imminent risk of one overwriting the actions of the other and causing a huge mess in the players’ economy. Of course, in the example above, it would be possible to create fixes and work around the problem, but I imagine that in more complex cases, this could become a disaster!
Don’t get me wrong—I know that PAWN/SAMP is prehistoric compared to LUA/FiveM. I’m using these examples because I genuinely want to learn how to deal with this using good practices and prevent my code from turning into an almost impossible mess to fix in the future.