pawn-lang / sa-mp-fixes

Includes and plugins to fix various issues in the SA:MP server that can be fixed externally, leaving the devs time for other things.
139 stars 57 forks source link

Add fixes for OnPlayerSpawn, OnPlayerKeyStateChange, OnPlayerStateChange #181

Open AmyrAhmady opened 8 months ago

AmyrAhmady commented 8 months ago

This amazing PR adds three new fixes to one of the most used libraries of SA-MP community.

1. OnPlayerSpawn

I noticed while OnPlayerConnect is called when a filterscript loads, fixes.inc doesn't call OnPlayerSpawn for all spawned players. So imagine this situation: What if players are already spawned and user is doing some sort of initialization like some sort of cheat detection or something, and when script is loaded mid-game, that type of code never runs for players who are already spawned! This is such an important and required fix! Also this fix internally is called FIX_OnPlayerSpawnCall since FIX_OnPlayerSpawn is taken. But I guess it shouldn't be a problem, if it is, let me know, I offer to quickly modify it based on your preferences.

2. OnPlayerKeyStateChange

Just like OnPlayerSpawn but this time for keys. What if a player is already holding a key and you load your filterscript? Then script's OnPlayerKeyStateChange would never get called, because there's no change yet! You may ask well why even call it then since there's no change? That's because players are already connected so why are you calling OnPlayerConnect? To fix it!

3. OnPlayerStateChange

This works just like both above, I need my filterscript to be aware when it's loaded and there are players in different states

Note:

This is my first time contributing to fixes.inc project, if there's any problem in my code and it goes against fixes.inc guidelines, let me know because I'm offering to fix my own mistakes for free. Thanks!

Cheaterman commented 8 months ago

I can't believe fixes.inc missed those cases for a decade! Thanks for your amazing contribution to the SA-MP community.

NexiusTailer commented 8 months ago

What about OnVehicleSirenStateChange? Should be very similar to KeyStateChange yet missed.

ziggi commented 8 months ago

What about this callbacks? I think they are should be in the list too.

Y-Less commented 8 months ago

Are these callbacks called in a gamemode when it starts?

AmyrAhmady commented 8 months ago

Of course not! I didn't know that's an important factor for this, because OnPlayerConnect isn't called in gamemode when it starts! It's called when "server" is restarted, not your gamemode, not your filterscript, the entire server therefore it has to emulate player disconnecting and reconnecting for all scripts on server restarts, because you want your players to join again when you stop and start again. I'm so sorry if samp client fakes server rejoin!

And if it's an important thing to consider, then my apologies, I forgot to add another fix to call OnGameModeInit when a filterscript starts at runtime, because that's the one and only callbacks that gets called when a gamemode is generally started.

So please, let me know if I should add this one too! because then we are missing it on filterscript reload!

AbdulOmarCR commented 8 months ago

This PR has been approved by me.