Actor animation desync
#3

For players, NPCs and now actors it's a well known bug "Animations desync".

We have a body death system (lying animation, using NPCs), we solved this by sending the RPC ApplyAnimation to each stream-in player, for example this is using the RAK plugin (also works in 0.3.7):
Code:
#define RPC_ApplyAnimation 86

enum AnimsSyncEnum {
	s_is_anim,
	s_animlib[50],
	s_animname[50],
	Float:s_fDelta,
	s_loop,
	s_lockx,
	s_locky,
	s_freeze,
	s_time,
	s_forcesync
};

new AnimsSync[MAX_PLAYERS][AnimsSyncEnum];

forward ApplyAnimationEx(playerid, animlib[], animname[], Float:fDelta, loop, lockx, locky, freeze, time, forcesync);
public ApplyAnimationEx(playerid, animlib[], animname[], Float:fDelta, loop, lockx, locky, freeze, time, forcesync) {
	
	AnimsSync[playerid][s_is_anim] = true;

	format(AnimsSync[playerid][s_animlib], 50, "%s", animlib);
	format(AnimsSync[playerid][s_animname], 50, "%s", animname);

	AnimsSync[playerid][s_fDelta]		= fDelta;
	AnimsSync[playerid][s_loop]			= loop;
	AnimsSync[playerid][s_lockx]		= lockx;
	AnimsSync[playerid][s_locky]		= locky;
	AnimsSync[playerid][s_freeze]		= freeze;
	AnimsSync[playerid][s_time]			= time;
	AnimsSync[playerid][s_forcesync]	= forcesync;

	//ApplyAnimation(playerid, animlib, "null", fDelta, loop, lockx, locky, freeze, time, forcesync); // Pre-load?
	ApplyAnimation(playerid, animlib, animname, fDelta, loop, lockx, locky, freeze, time, forcesync);
}


forward ClearAnimationsEx(playerid, forcesync);
public ClearAnimationsEx(playerid, forcesync) {
	AnimsSync[playerid][s_is_anim] = false;

	ClearAnimations( playerid, forcesync );
}

forward ApplyAnimationSync(playerid, toplayerid);
public ApplyAnimationSync(playerid, toplayerid) {

	if ( AnimsSync[playerid][s_is_anim] && ! IsPlayerInAnyVehicle(playerid) ) {
		new BitStream:bsAnim = InitBitStream();
		WriteToBitStream(bsAnim, BS_SHORT, 	playerid);
		WriteToBitStream(bsAnim, BS_CHAR, 	strlen(AnimsSync[playerid][s_animlib])); // anim lib len
		WriteToBitStream(bsAnim, BS_STRING, AnimsSync[playerid][s_animlib] ); // anim lib
		WriteToBitStream(bsAnim, BS_CHAR, 	strlen( AnimsSync[playerid][s_animname] )); // anim name len
		WriteToBitStream(bsAnim, BS_STRING, AnimsSync[playerid][s_animname] ); // anim name
		WriteToBitStream(bsAnim, BS_FLOAT, 	AnimsSync[playerid][s_fDelta] ); // fDelta
		WriteToBitStream(bsAnim, BS_BOOL, 	AnimsSync[playerid][s_loop] ); // loop
		WriteToBitStream(bsAnim, BS_BOOL, 	AnimsSync[playerid][s_lockx] ); // lockx
		WriteToBitStream(bsAnim, BS_BOOL, 	AnimsSync[playerid][s_locky] ); // locky
		WriteToBitStream(bsAnim, BS_BOOL, 	AnimsSync[playerid][s_freeze] ); // freeze
		WriteToBitStream(bsAnim, BS_UINT, 	AnimsSync[playerid][s_time] ); // time
		//WriteToBitStream(bsAnim, BS_CHAR, AnimsSync[playerid][s_forcesync] ); // forcesync // doesn't exists

		SendRPC(toplayerid, RPC_ApplyAnimation, bsAnim); // Pre-load?
		SendRPC(toplayerid, RPC_ApplyAnimation, bsAnim);
	}

}

// Sync
public OnPlayerStreamIn(playerid, forplayerid) {

	ApplyAnimationSync( playerid, forplayerid );
	ApplyAnimationSync( forplayerid, playerid );

	return 1;
}
NOTE: Remember to use ApplyAnimationEx() and ClearAnimationsEx() instead of ClearAnimations()

That you need is the new RPC for ApplyActorAnimation to make it work with Actors – or SA-MP team adds OnActorStreamIn, ApplyActorAnimationForPlayer and ApplyAnimationForPlayer to avoid plugins and network manipulation (and others workarounds).

Regards.
Reply


Messages In This Thread
Actor animation desync - by MP2 - 27.04.2015, 15:43
Re: Actor animation desync - by PeppeAC - 27.04.2015, 16:10
Re: Actor animation desync - by zo0r - 27.04.2015, 16:43
Re: Actor animation desync - by MP2 - 27.04.2015, 20:57
Re: Actor animation desync - by Crayder - 27.04.2015, 21:08
Re: Actor animation desync - by MP2 - 27.04.2015, 21:10
Re: Actor animation desync - by ATomas - 27.04.2015, 21:13
Re: Actor animation desync - by Crayder - 27.04.2015, 21:16
Re: Actor animation desync - by Kar - 27.04.2015, 22:25
Re: Actor animation desync - by Abagail - 27.04.2015, 23:58

Forum Jump:


Users browsing this thread: 1 Guest(s)