Checking if players are still alive on a team
#1

I started coding a new game mode this weekend and it's almost finished. I just need to figure out how to check if all players on one team are dead, and then return a value if they are. How would one do this?
Reply
#2

Bump
Reply
#3

Well, explaing wont help alot.
But something like this:

pawn Код:
new TeamA[MAX_PLAYERS];
new TeamB[MAX_PLAYERS];
new TeamAalive;
new TeamBalive;
OnPlayerDeath
pawn Код:
if(TeamA[playerid]==1) TeamAalive--;
if(TeamB[playerid]==1) TeamBalive--;
And then put it in a timer, that checks how many are alive, and like this:

pawn Код:
if(TeamAalive<=0)
{
// whatever you do here
}

if(TeamBalive<=0)
{
// whatever you do here
}
If you need more help, just say.
Reply
#4

Also, somethink like this should work:
Код:
new PlayerDead[MAX_PLAYERS];//Global Variable
------------------------------------------------
//Somewhere in OnPlayerSpawn
PlayerDead[playerid] = 0;
------------------------------------------------------
//Somewhere in OnPlayerDeath
PlayerDead[playerid] = 1;
------------------------------------------------------
//Function
public IsTeamDead(teamid)//Will return true if all members of this team is dead
{
  for(new i = 0; i < MAX_PLAYERS; i++)
  {
    if(IsPlayerConnected(i))
    {
       if(GetPlayerTeam(i) == teamid)
       {
         if(PlayerDead[playerid] == 0)//if player alive
         return 0;
       }
    }
  }
  return 1;
}
Reply
#5

or just PLAYER_STATE_WASTED

https://sampwiki.blast.hk/wiki/Playerstates
Reply
#6

Quote:
Originally Posted by Sinyavski
Also, somethink like this should work:
Код:
new PlayerDead[MAX_PLAYERS];//Global Variable
------------------------------------------------
//Somewhere in OnPlayerSpawn
PlayerDead[playerid] = 0;
------------------------------------------------------
//Somewhere in OnPlayerDeath
PlayerDead[playerid] = 1;
------------------------------------------------------
//Function
public IsTeamDead(teamid)//Will return true if all members of this team is dead
{
  for(new i = 0; i < MAX_PLAYERS; i++)
  {
    if(IsPlayerConnected(i))
    {
       if(GetPlayerTeam(i) == teamid)
       {
         if(PlayerDead[playerid] == 0)//if player alive
         return 0;
       }
    }
  }
  return 1;
}
I have IsPlayerDead[MAX_PLAYERS] in my script already. All I needed was the function :P thanks guys

EDIT: It should be if(PlayerDead[i] == 0)

Also, I'm having trouble integrating this into my script. I want to make the current round end early and skip straight to the next one. If I posted it on pastebin or something would you guys help me fix it?
Reply
#7

How long is your script?


EDIT: Cool that your countdown works now.
Reply
#8

+- 700 lines. Not very long.
Reply
#9

PM me the pastebin code. I will check it.
Reply
#10

You got PM
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)