SA-MP Forums Archive
Is it bad to use alot of OnPlayerKeyStateChange's? - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Is it bad to use alot of OnPlayerKeyStateChange's? (/showthread.php?tid=471737)



Is it bad to use alot of OnPlayerKeyStateChange's? - Unri - 25.10.2013

The title is my question. I have noticed, that alot of scripts, on the forums, are keeping from using OnPlayerKeyStateChange.


Re: Is it bad to use alot of OnPlayerKeyStateChange's? - JonnyDeadly - 25.10.2013

The only issue I can see with this is that a lot of checking would be taking place when a player presses a key affected by the callback in some way. Don't refrain from using this callback however, if your coding plan demands it necessary.


Re: Is it bad to use alot of OnPlayerKeyStateChange's? - Babul - 25.10.2013

a) imagine you have a stunt server with 200 players online, and each player wants to have a nitro + jump +flip key assigned. using timers (or better: 1 timer only) at a certain interval, will need to check all keystates each 200*(1000/interval in ms) times per second. multiply that with 3 for the amout of keys, and you have an excellent lagging script (at least a script which reacts too slowly).

b) imagine the OnPlayerKeyStateChange() callback used, taking advantage of the playerid and KeyValues already provided... not a single timer required, and it reacts instantly (assuming the ping could be 0 lol).

save CPU time whenever its possible, and USE the callbacks provided, they are there for a reason. (tip: B)