Posts: 553
Threads: 41
Joined: Aug 2010
Reputation:
0
Hi, I'm learning to script and I'm trying to make a simple gamemode with a focus on Rustler air combats. The thing is that I have declared a global boolean array named pilot[playerid], that would be true whenever the player gets in the driver seat of an airplane or helicopter, and false one minute after he leaves it (well, it would be set as false also in other situations, but that's not the topic of this thread). Now comes the time to detect whenever the player enters or leaves his air vehicle as driver to set the boolean as true or to start the timer that will set it as false, and I have seen as my main options the combination of OnPlayerEnterVehicle and OnPlayerExitVehicle, or just using OnPlayerStateChange alone. The most logical option seems to be the first one, but what if once ingame I use an admin command to slap or teleport the player while he's flying a plane or heli, or to put him in one while he's on foot? maybe I'm wrong, but I think that OnPlayerExitVehicle and OnPlayerEnterVehicle are called only when the player leaves or enters his vehicle on his own will, and not when you use SetPlayerPos or PutPlayerInVehicle on him. So I'm wondering if all these situations could be detected by OnPlayerStateChange.
Posts: 2,524
Threads: 109
Joined: Sep 2009
Reputation:
0
taking that I count I suppose OnPlayerStateChange is not used only in vehicles remember that there are many states... however if you are slapped/removed by administrator will it is still called (I presume) because your actual state is changed from driver to on-foot, no matter how.
Posts: 966
Threads: 5
Joined: Jul 2011
Reputation:
0
OnPlayerEnterVehicle is called whenever a player presses ENTER near a vehicle. So for entering detection, it is better to use OnPlayerStateChange (newstate will be PLAYER_STATE_DRIVER or PLAYER_STATE_PASSENGER).
OnPlayerExitVehicle is called when the player fully exits the vehicle by their own free will - this does not include occasions like SetPlayerPos, RemovePlayerFromVehicle. So once again, you should refer to OnPlayerStateChange.
To understand it better, take an example of how bike anti-falls work. If OnPlayerStateChange is called when the player was on a bike, but OnPlayerExitVehicle was not called prior to it, the player will be put back onto the bike. However, if the player presses whatever key they use for vehicle entering/exiting, OnPlayerExitVehicle will be called first and that will trigger a variable of some sort and the player won't be restored to their vehicle in OnPlayerStateChange.
Posts: 553
Threads: 41
Joined: Aug 2010
Reputation:
0
Ok, thanks a lot to both of you.
Posts: 553
Threads: 41
Joined: Aug 2010
Reputation:
0
Hmm so yeah we can say that OnPlayerStateChange is more versatile, like more multipurpose and more accurate, whereas OnPlayerEnterVehicle and OnPlayerExitVehicle are more specific and more limited, right?
But one thing: are you sure that OnPlayerExitVehicle is not called when the player presses the exiting key, and that it's called only when the player has fully got out of his vehicle? I have used SetPlayerPos in this callback to remove the exiting animation and it has worked from the very first moment, ejecting me from the vehicle in the right instant of pressing the key.