SA-MP Forums Archive
Teleporting ALL players from a certain team with a command. - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Teleporting ALL players from a certain team with a command. (/showthread.php?tid=282732)



Teleporting ALL players from a certain team with a command. - Gemini - 12.09.2011

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


Re : Teleporting ALL players from a certain team with a command. - Soumi - 12.09.2011

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.


Re: Teleporting ALL players from a certain team with a command. - TheArcher - 12.09.2011

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)
    {
    }



Re: Teleporting ALL players from a certain team with a command. - Gemini - 12.09.2011

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


Re: Re : Teleporting ALL players from a certain team with a command. - TheArcher - 12.09.2011

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.


Re : Teleporting ALL players from a certain team with a command. - Soumi - 12.09.2011

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;
        }
    }



Re: Re : Teleporting ALL players from a certain team with a command. - TheArcher - 12.09.2011

@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++)



Re: Re : Teleporting ALL players from a certain team with a command. - wouter0100 - 12.09.2011

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))


Re: Teleporting ALL players from a certain team with a command. - Gemini - 12.09.2011

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?


Re : Teleporting ALL players from a certain team with a command. - Soumi - 12.09.2011

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)