Detect if player is alive or dead?
#1

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?

Reply
#2

do a loop and check everyones hp, location or state
Reply
#3

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

Код:
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.
Reply
#5

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.
Reply
#6

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);
}
Reply
#7

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.
Reply
#8

Cool thanks.

Reply
#9

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

Thanks, works now
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)