SA-MP Forums Archive
Detect if player is alive or dead? - 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)
+---- Forum: Help Archive (https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: Detect if player is alive or dead? (/showthread.php?tid=139970)



Detect if player is alive or dead? - -Rebel Son- - 07.04.2010

Ok, Some of you may have noticed my topic in the "everything" board, about me making my clans server mode, well in the process of building it, i've come to a slight problem, I need a way to detect witch players are alive after the Minigame is over, so they can be rewarded. anyone got a clue?




Re: Detect if player is alive or dead? - cessil - 07.04.2010

do a loop and check everyones hp, location or state


Re: Detect if player is alive or dead? - -Rebel Son- - 07.04.2010

Not to be rude and ask for codes, but can i get a example?


Re: Detect if player is alive or dead? - deather - 07.04.2010

Код:
forward Check(playerid); - // At the top

SetTimerEx("Check", 1000, 0, "d", playerid); - // Where you want to check for the player's death - Remember '0' will check only once.

public Check(playerid)
{
new Float:health;
GetPlayerHealth(playerid, health);
if(health == 0.0) // Dead
{
// Do something here
}
return 1;
}
Didn't check but should work.


Re: Detect if player is alive or dead? - GTA_Rules - 07.04.2010

Or just use a global variable.

Код:
new isDeath[MAX_PLAYERS];

OnPlayerConnect( playerid )
{
  isDeath[playerid] = false;
  return 1;
}

OnPlayerDeath( playerid )
{
  isDeath[playerid] = true;
  return 1;
}

OnPlayerSpawn( playerid )
{
  isDeath[playerid] = false;
  return 1;
}
Now you can do something like:
Код:
if(isDeath[playerid])
{
  // He's dead, put code here.
}
else
{
  // He's not dead.
}
At least you don't have to use another timer that way.


Re: Detect if player is alive or dead? - -Rebel Son- - 07.04.2010

Ok and for my minigame what goes where? i got somewhat lost trying to install it.



here is where i put the codes when the player accepts the Random DM notice.
Код:
if(dialogid == 3)
{
if(response)
{
new rand = random(sizeof(DDM));
MiniGame[playerid] = 1;
SetTimer("END",60000,3);
GivePlayerWeapon(playerid,24,500);
GivePlayerWeapon(playerid,27,500);
GivePlayerWeapon(playerid,30,500);
SetPlayerPos(playerid,DDM[rand][0],DDM[rand][1],DDM[rand][2]);
SetPlayerDrunkLevel(playerid,50000);
}
else
{
SendClientMessage(playerid,COLOR_RED,"Fine be that way ...");
}
return 1;
}
and here is the fuction "END" Witch is called when the minigame is over.
Код:
public END()
{
for(new i=0; i<MAX_PLAYERS; i++) KillTimer(3);
for(new i=0; i<MAX_PLAYERS; i++) SetPlayerPos(i,2087.1794,1448.4274,10.8203);
for(new i=0; i<MAX_PLAYERS; i++) MiniGame[i] = 0;
for(new i=0; i<MAX_PLAYERS; i++) RPW(i);
for(new i=0; i<MAX_PLAYERS; i++) SetPlayerDrunkLevel(i,0);
for(new i=0; i<MAX_PLAYERS; i++) GivePlayerMoney(i,5000);
}



Re: Detect if player is alive or dead? - Joe_ - 07.04.2010

OUCH! so many loops!11!11eleven

Lagg much, use "public END(playerid)" and replace the timer with "SetTimerEx("END", 60000, 0, "d", playerid);"

Then delete all of your loops etc, you know what to do.



Re: Detect if player is alive or dead? - -Rebel Son- - 07.04.2010

Cool thanks.




Re: Detect if player is alive or dead? - dice7 - 07.04.2010

That will cause even more lag if you have >50 players at once. Use just one loop in your timer called function


Re: Detect if player is alive or dead? - -Rebel Son- - 10.04.2010

Thanks, works now