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



Death system help - silverms - 31.12.2016

so I made a death system that when you die you get injured and stay on ground 60 sec if no one helped you or admin /revive he get teleported to hospital its working fine when he die he freaze on the ground and apply the animation and when die teleport to the hospital but when I do /revive the player get revived but get teleported back to the hospital why?.

Код:
#define col_grey 0xADADADFF
new pDied[MAX_PLAYERS];
new detht;

that on player spawn:
	if(pDied[playerid] == 1)
	{
		// Spawning at ASGH in Los Santos...
		pDied[playerid] = 0;
   		SetPlayerPos(playerid, 1177.8596, -1324.0876, 14.0915);
  		// Message and money removal (using -400 at GivePlayerMoney to fine 500 as you automaticly lose $100 when you die).
		SendClientMessage(playerid, col_grey, "{639E4D}INFO:{ADADAD} You have just respawned and you lost $300!");
		GivePlayerMoney(playerid, -200);
	}
that on playerdeath: 
    {
	new Float:x, Float:y, Float:z;
	// Resetting their position:
 	GetPlayerPos(playerid, x, y, z);
 	SetPlayerPos(playerid, x, y, z);
	// Freezing them in death, aka not allowing them to respawn:
 	TogglePlayerControllable(playerid, 0);
 	ApplyAnimation(playerid, "CRACK", "crckdeth1", 4.1, 0, 1, 1, 1, 1, 1);
	// Informing them and activating timer:
 	SendClientMessage(playerid, col_grey, "{639E4D}INFO:{ADADAD} You have been brutally Injured,If someone doesn't revive you soon, you will die!");
 	detht = SetTimerEx("DeathTimer", 70000, false, "i", playerid);
 	return 1;
	}[Note]: there isn't return cause there is more coding underneath it
that the cmd:
if(strcmp(cmd, "/revive", true) == 0)
	{
	    if(!(PlayerInfo[playerid][pAdmin] >= 1))
	        return SendClientMessage(playerid, COLOR_GRAD2, "You are not authorized to use this command.");
	    // process command
	    tmp = strtok(cmdtext, idx);
	    if(!strlen(tmp))
	    {
	        SendClientMessage(playerid, COLOR_WHITE,"USAGE: /revive [playerid] - to revive a player");
	        return 1;
		}
		new
		    p=1,
		    ID[64] = " ",
			lookupid = ReturnUser(tmp);

		if(GetPlayerState(playerid) == PLAYER_STATE_PASSENGER) p=0;
		if(lookupid != INVALID_PLAYER_ID)
		{
	    	if(lookupid != playerid)
	    	{
	    		if(!gPlayerLogged[lookupid])
					return SendClientMessage(playerid, COLOR_GRAD2,"That player hasn't spawned yet.");
			}
		}
		ID = PlayerName(lookupid);
		// format string and send to player
		TogglePlayerControllable(lookupid, 1);
		KillTimer(detht);
		pDied[lookupid] = 0;
  		ClearAnimations(lookupid);
  		SetPlayerHealth(lookupid, 50.0);
		SendClientMessage(playerid, COLOR_YELLOW, "You have been revived by an admin");
  		format(string, sizeof(string),"Reviving %s",ID);
		SendClientMessage(playerid, COLOR_GRAD2,string);
		return 1;
	}
forward DeathTimer(playerid);
public DeathTimer(playerid)
{
    // As seen here: informing them and enabling variable:
    SendClientMessage(playerid, COLOR_RED, "{639E4D}INFO:{ADADAD} Nobody managed to save you in time, you died!");
    SetPlayerHealth(playerid, 0.0);
    pDied[playerid] = 1;
	// Spawning at ASGH in Los Santos...
	pDied[playerid] = 0;
	SetPlayerPos(playerid, 1177.8596, -1324.0876, 14.0915);
	// Message and money removal (using -400 at GivePlayerMoney to fine 500 as you automaticly lose $100 when you die).
	SendClientMessage(playerid, col_grey, "{639E4D}INFO:{ADADAD} You have just respawned and you lost $300!");
	GivePlayerMoney(playerid, -200);
	TogglePlayerControllable(playerid, 1);
	return 1;
}
I hop you help me fix it fast


Re: Death system help - dakata994 - 31.12.2016

Add this on the revive cmd:
Код:
KillTimer(DeathTimer(playerid));



Re: Death system help - silverms - 31.12.2016

Quote:
Originally Posted by dakata994
Посмотреть сообщение
Add this on the revive cmd:
Код:
KillTimer(DeathTimer(playerid));
do I remove the killtime(detht); and remove [detht =] settimer..


Re: Death system help - dakata994 - 31.12.2016

Just add
Код:
KillTimer(DeathTimer(playerid));
On the place of the other timer at /revive cmd.


Re: Death system help - silverms - 31.12.2016

now it is spawning me where I spawned when I joined my server the server set me where I last was when I left and when I do /revive it turn me back to my last position where I spawned


Re: Death system help - silverms - 31.12.2016

plz help fast +rep for who will help me


Re: Death system help - silverms - 31.12.2016

now it spawning me where I spawned when I loged in


Re: Death system help - silverms - 31.12.2016

any one?


Re: Death system help - lackmail - 31.12.2016

because the player already dead you are just stopping the player from respawning with TogglePlayerControllable(playerid, 0); thats why when you use /revive command and set it back to normal player spawn to another position if you want the player to spawn in same position you need to create global variables to store player injured position and another variable to check if the player has been revived:

Код:
new Revived[MAX_PLAYERS];
new Float:InjurLastX[MAX_PLAYERS];
new Float:InjurLastY[MAX_PLAYERS];
new Float:InjurLastZ[MAX_PLAYERS];

//under oonplayerdeath replace these lines
new Float:x, Float:y, Float:z;
GetPlayerPos(playerid, x, y, z);
SetPlayerPos(playerid, x, y, z);

//to these
GetPlayerPos(playerid, InjurLastX[playerid], InjurLastY[playerid], InjurLastZ[playerid]);
SetPlayerPos(playerid, InjurLastX[playerid], InjurLastY[playerid], InjurLastZ[playerid]);


//under onplayerspawn put this code
if(Revived[playerid]== 1) //checks if the player has been revived
{
 	SetPlayerPos(playerid, InjurLastX[playerid], InjurLastY[playerid], InjurLastZ[playerid]); //if yes then sets player position to the last injured position
}

//in /revive command put add this line it confirms that the player has been revived
Revived[playerid] = 1;



Re: Death system help - silverms - 31.12.2016

same