help survivor
#1

Wanted a basis for identifying the only player to stay alive an event x1, can someone help thanks.
Reply
#2

You should count the players that take place in the even and when they die decrease the variable. Then you check if it equals to 1.

pawn Код:
new TotalEvenParticipants;

TotalEvenParticipants++;
// When someone joins

TotalEvenParticipants--;
//When someone dies

if (TotalEvenParticipants == 1)
//only one left
You should always mind about decreasing the variable during someone disconnects while participating in even.
Reply
#3

pawn Код:
new JoinedEvent[MAX_PLAYERS]; // Top of script

/joinevent
JoinedEvent[playerid] = 1;
new count;
count++;



OnPlayerDeath:
if(JoinedEvent[playerid] == 1)
{
    count--;
    You've been killed and you're now out of the event.
    if(count == 1)
    {
        Declare winner.
    }
}
EDIT: Just seen Cypress' edit.
Reply
#4

Quote:
Originally Posted by BleverCastard
Посмотреть сообщение
pawn Код:
new JoinedEvent[MAX_PLAYERS]; // Top of script

/joinevent
JoinedEvent[playerid] = 1;
new count;
count++;



OnPlayerDeath:
if(JoinedEvent[playerid] == 1)
{
    count--;
    You've been killed and you're now out of the event.
    if(count == 1)
    {
        Declare winner.
    }
}
EDIT: Just seen Cypress' edit.
That's not going to work because if someone quits while in the even it's not going to declare the winner. Plus you need the count variable to be on top along with the "JoinedEvent" one.
Reply
#5

Quote:
Originally Posted by Cypress
Посмотреть сообщение
That's not going to work because if someone quits while in the even it's not going to declare the winner. Plus you need the count variable to be on top along with the "JoinedEvent" one.
I like to do when they count so the event?
Reply
#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


Forum Jump:


Users browsing this thread: 1 Guest(s)