Help - 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: Help (
/showthread.php?tid=625331)
Help -
MarkNelson - 31.12.2016
How to make death animation with Timer. i mean.. When the player has a lower health like -5 percent he will do an animation for 5 seconds with the timer then when the timer ended the player health will be 0 then he dies.
Can anyone show me Code to do this?
Re: Help -
RyderX - 31.12.2016
Try this:
PHP код:
public OnPlayerDeath(playerid, killerid, reason)
{
ApplyAnimation(playerid,"ANIMATION_KIND", "ANIMATIONNAME",4.0,1,1,1,1,1);
return 1;
}
Re: Help -
SoLetsGO - 31.12.2016
I think the lowest health you can have is 0.0.
If you mean 5.0 rather than -5 then you should first create a global timer which loops through all the players and checks their health. You also need to have a variable for all players to check if the animation already started.
That variable needs to be set to false when a player connects.
PHP код:
new bool:AnimationBegan[MAX_PLAYERS];
public OnGameModeInit(){
SetTimer("globalTimer",1000,true);
}
public OnPlayerConnected(playerid){
AnimationBegan[playerid] = false;
}
forward animationDeathTimer(playerid);
public animationDeathTimer(playerid){
//clear animations
ClearAnimations(playerid);
//and put player's health to 0
SetPlayerHealth(playerid,0.0);
//Also clear AnimationBegan variable
AnimationBegan[playerid] = false;
return 1;
}
forward globalTimer();
public globalTimer(){
for(new i = 0;i<MAX_PLAYERS;i++){
if(!IsPlayerConnected(i))continue;
new Float:cHealth;
GetPlayerHealth(i,cHealth);
if(AnimationBegan[i] == false && cHealth <= 5.0){
AnimationBegan[i] = true;
//I guess thats the proper animation:
ApplyAnimation(i, "CRACK", "crckdeth2", 4.0, 1, 0, 0, 0, 0);
//and set the timer to stop the animation
SetTimerEx("animationDeathTimer",5*1000,false);
}
}
return 1;
}