De-syncing Grenades
#1

Hello all. I've been away from samp/pawno for about a year. I have just come back and got my scripts sorted for 0.3b.

The only problem I have come across so far regards the use of grenades for parkour challenges. Before, you could throw a grenade (using it to jump higher and farther) and other players would not be able to see the grenade you have thrown. This limited disruption to other players when using grenades for parkour.

Now in 0.3b, the code I previously used no longer prevents other players from being able to see your thrown grenade. Can anybody offer me any suggestions?

Here is the code that I had successfully used in the past:

Код:
new weaponSync = 0; // global variable to control weapon sync

public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
	// DESYNCING WEAPONS
	if(newkeys == 4) {
	    if(GetPlayerState(playerid) == PLAYER_STATE_ONFOOT) {
	        if(!IsPlayerNPC(playerid)) {
			if(weaponSync == 0) {
		        	ApplyAnimation(playerid, "PED", "Fight2Idle", 4.1, 0, 0, 0, 0, 1);
	  		}
 		}
	    }
	}
}
Thanks in advance!
Reply
#2

Hm, do you use the weaponSync variable in OnPlayerUpdate? Not sure if it already existed a year ago. If not, rewrite your code for OnPlayerUpdate.
If you return 0 in OnPlayerUpdate, the sever does not synchronize the players' actions for the other players, so e.g. the grenade is only thrown for the throwing player.
You can either just return 0 in there if weaponSync is 0, but you will have to reset the variable after a certain time, and this would make the player move laggy for the other players.
Or you check if the fire key is pressed directly in OnPlayerUpdate with GetPlayerKeys, and return 0 if it is. This would decrease the "desync lag" for the other players.
Reply
#3

Thanks Mauzen. I think OnPlayerUpdate came in with 0.3a, but it's something I have not looked at with me being away and all. After checking the wiki, it looks like an incredibly useful callback that I will most likely now use for a multitude of things, including this weapon syncing. I'll have a play and let you know how it turns out.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)