Teleporting ALL players from a certain team with a command.
#1

I am working on a capture the flag DM, and if a player from blue team captures the red team flag, he will be teleported to the blue team spawn, BUT all the other blue team members will not be teleported then :S.

Is there a command to teleport all player with "if(GetPlayerTeam(playerid) == 1)" ?
So what I want is to only teleport the players from the winning team back to their spawn, and not the players that are outside the DM zone.

heres my code:

Код:
if(pickupid == redflag)
	{
 		if(GetPlayerTeam(playerid) == 0)
		{
		    SendClientMessage(playerid, COLOR_WHITE, "You have captured the flag, Your team wins");
    		SendClientMessageToAll(COLOR_WHITE, "Blue team has won!");
     		SetPlayerPos(playerid, -608.4156, 1830.7487, 7.0000);
     		return 1;
		}
	}
Thanks in advance
Reply
#2

pawn Код:
stock TeleportTeam(teamid, Float: X, Float: Z, Float: Y, Interior, VW)
{
    for(new i = 0; i < MAX_PLAYERS; i++)
    {
        if(GetPlayerTeam(i) == teamid)
        {
            SetPlayerPos(i, X, Y, Z);
            SetPlayerInterior(i, Interior);
            SetPlayerVirtualWorld(i, VW);
        }
    }
    return 1;
}
Use this.
Reply
#3

Quote:
Originally Posted by ******
Посмотреть сообщение
You need a loop, for example:

pawn Код:
foreach (Player, i)
{
    if (GetPlayerTeam(i) == THE_TEAM_TO_TELEPORT)
    {
    }
}
Warning, he used Foreach which request the include before using it and it's much better than a normal loop but you also can do.

pawn Код:
for(new i=0; i<MAX_PLAYERS+1; i++) // looping 500 players.
    if (GetPlayerTeam(i) == THE_TEAM_TO_TELEPORT)
    {
    }
Reply
#4

Could someone perhaps put it in the code I already have? I am a beginner scripter :/
Reply
#5

Quote:
Originally Posted by Soumi
Посмотреть сообщение
pawn Код:
stock TeleportTeam(teamid, Float: X, Float: Z, Float: Y, Interior, VW)
{
    for(new i = 0; i < MAX_PLAYERS; i++)
    {
        if(GetPlayerTeam(playerid) == teamid)
        {
            SetPlayerPos(i, X, Y, Z);
            SetPlayerInterior(Interior);
            SetPlayerVirtualWorld(VW);
        }
    }
    return 1;
}
Use this.
i dont understand of using playerid on the loop.
Reply
#6

Quote:
Originally Posted by TheArcher
Посмотреть сообщение
i dont understand of using playerid on the loop.
Fixed.

pawn Код:
//Put this somewhere in your gamemode (ANYWHERE :D)
stock TeleportTeam(teamid, Float: X, Float: Z, Float: Y, Interior, VW)
{
    for(new i = 0; i < MAX_PLAYERS; i++)
    {
        if(GetPlayerTeam(i) == teamid)
        {
            SetPlayerPos(i, X, Y, Z);
            SetPlayerInterior(i, Interior);
            SetPlayerVirtualWorld(i, VW);
        }
    }
    return 1;
}
//And this is your code:
if(pickupid == redflag)
    {
        if(GetPlayerTeam(playerid) == 0)
        {
            SendClientMessage(playerid, COLOR_WHITE, "You have captured the flag, Your team wins");
                SendClientMessageToAll(COLOR_WHITE, "Blue team has won!");
                    TeleportTeam(teamid, -608.4156, 1830.7487, 7.0000, 0, 0)
            return 1;
        }
    }
Reply
#7

@Soumi

A little warning:

pawn Код:
for(new i = 0; i < MAX_PLAYERS; i++)
It will loop 499 times. I'm not saying that the server will have 500 players but who knows for better reasons do.

pawn Код:
for(new i = 0; i < MAX_PLAYERS+1; i++)
Reply
#8

Quote:
Originally Posted by TheArcher
Посмотреть сообщение
@Soumi

A little warning:

pawn Код:
for(new i = 0; i < MAX_PLAYERS; i++)
It will loop 499 times. I'm not saying that the server will have 500 players but who knows for better reasons do.

pawn Код:
for(new i = 0; i < MAX_PLAYERS+1; i++)
pawn Код:
for(new i = 0; i <= MAX_PLAYERS; i++)
A loop of all 500 players. (< Is UNDER, = IS max_players(500))
Reply
#9

Thanks Soumi your code works but now if a player wants to leave this DM, he still will be teleported every time a flag is captured :S How does a player leaves a team?
Reply
#10

If player wants to leave the the team
pawn Код:
SetPlayerTeam(playerid, 9999); //Or use any other team ID (But players who aren't in the DM area will not be able to kill each other)
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)