help survivor
#6

I personally never use a global variable to count players in events.


Код:
new bool:inEvent[MAX_PLAYERS];

//example usage of the function
public OnPlayerConnect(playerid)
{
playerEventState(playerid, false);
return 1;
}

public OnPlayerDeath(playerid, killerid, reason)
{
playerEventState(playerid, false);
return 1;
}

//you can use this to place player in an event or take him out. 
stock playerEventState(player, bool: st)
{
inEvent[player] = st;

//player is disqualified.
if(!st)
{
if(pOfEvent() == 1)
{
new lastPlayerID = eventLastPlayer(), str[50];
//do what you wish with the last player, example
format(str, sizeof str, "INFO: ID %d is the last alive ", lastPlayerID);
SendClientMessageToAll(str, 0xFF0000AA);
}
}
return st;
}

stock eventLastPlayer()
{
//this function is used only if we know that there is one player 
for(new i = 0; i < MAX_PLAYERS; ++i)
if(IsPlayerConnected(i) && inEvent[i])return i;
}

stock pOfEvent()
{
new playersEvent = 0;
for(new i = 0; i < MAX_PLAYERS; ++i)
if(IsPlayerConnected(i) && inEvent[i])playersEvent++;
return playersEvent;
}
Reply


Messages In This Thread
help survivor - by Freak@ - 22.06.2014, 00:22
Re: help survivor - by Cypress - 22.06.2014, 00:25
Re: help survivor - by BleverCastard - 22.06.2014, 00:28
Re: help survivor - by Cypress - 22.06.2014, 00:33
Re: help survivor - by Freak@ - 22.06.2014, 00:52
Re: help survivor - by Dr.Einstein - 22.06.2014, 02:32

Forum Jump:


Users browsing this thread: 1 Guest(s)