SA-MP Forums Archive
Death system. - 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: Death system. (/showthread.php?tid=519549)



Death system. - BleverCastard - 14.06.2014

I made a basic death system, however, it seems to set you to when you logged in. I've also preloaded the anim library and it doesn't seem to put you in the Crack anim, no matter how many times you set it in the OPD callback.

pawn Код:
public OnPlayerDeath(playerid, killerid, reason)
{
    TogglePlayerSpectating(playerid, true);
    new Float:X, Float:Y, Float:Z;
    GetPlayerPos(playerid, X, Y, Z);
    SetPlayerPos(playerid, X, Y, Z);
    SetPlayerHealth(playerid, 30);
    TogglePlayerSpectating(playerid, false);
    ApplyAnimation(playerid,"CRACK","crckdeth2",4.1,1,1,1,1,1);
    TogglePlayerControllable(playerid, false);
    SendClientMessage(playerid, COLOR_RED, "You've been killed.");
    return true;
}



Re: Death system. - Firewire - 14.06.2014

You should call a separate function on a timer after the death, this will allow a time gap in-between to pass the default death screen by SAMP and allow you to enable an anim after.


Re: Death system. - BleverCastard - 14.06.2014

Quote:
Originally Posted by Firewire
Посмотреть сообщение
You should call a separate function on a timer after the death, this will allow a time gap in-between to pass the default death screen by SAMP and allow you to enable an anim after.
I've done that, however still sets me in the samp position as I did when I logged in and doesn't set you in the animation.


Re: Death system. - Threshold - 15.06.2014

pawn Код:
TogglePlayerSpectating(playerid, false);
This calls OnPlayerSpawn, so you're instantly going to have issues with that.
pawn Код:
public OnPlayerDeath(playerid, killerid, reason)
{
    SetPlayerHealth(playerid, 30); //Dunno why, but okay..
    ApplyAnimation(playerid, "CRACK", "crckdeth2", 4.1, 1, 1, 1, 1, 1);
    TogglePlayerControllable(playerid, false);
    SendClientMessage(playerid, COLOR_RED, "You've been killed.");
    return true;
}
If that doesn't work, then I dunno. I haven't really done animations in OnPlayerDeath.


Re: Death system. - BleverCastard - 15.06.2014

I tried doing it a different way, but it still sets them to their spawn position, and animations aren't loading, even after preloading them.
pawn Код:
public OnPlayerDeath(playerid, killerid, reason)
{
    SavePlayerPosition(playerid);
    TogglePlayerSpectating(playerid, true);
    return true;
}

forward CheckPlayerDeath(playerid);
public CheckPlayerDeath(playerid)
{
    ApplyAnimation(playerid,"CRACK","crckdeth2",4.1,1,1,1,1,1);
    SetPlayerPos(playerid, PlayerInfo[playerid][pPosX], PlayerInfo[playerid][pPosY], PlayerInfo[playerid][pPosZ]);
    return true;
}

stock SavePlayerPosition(playerid)
{
    new Float:X, Float:Y, Float:Z;
    GetPlayerPos(playerid, X, Y, Z);
    PlayerInfo[playerid][pPosX] = X;
    PlayerInfo[playerid][pPosY] = Y;
    PlayerInfo[playerid][pPosZ] = Z;
   
    SpawnPlayer(playerid);
    TogglePlayerControllable(playerid, false);
    SendClientMessage(playerid, COLOR_RED, "You've been killed.");
    return 1;
}
//

public OnPlayerSpawn(playerid)
{
    TogglePlayerSpectating(playerid, false);
    SetTimerEx("CheckPlayerDeath", 500, false, "i", playerid);
    return 1;
}



Re: Death system. - Threshold - 15.06.2014

Because you're setting the player's position after playing the animation... I'm not sure why would would want to spawn the player to play an animation on death.

And remove this for god sakes!:
pawn Код:
TogglePlayerSpectating(playerid, false);