How to create a command to bring everyone
#1

Hello, You read the title.
Reply
#2

let playerid represent the player you're bringing people to
get playerid's position
loop through all players
exclude playerid from the loop
set all player's position to playerid's XYZ coordinates

Done.
Reply
#3

Quote:
Originally Posted by RealCop228
Посмотреть сообщение
let playerid represent the player you're bringing people to
get playerid's position
loop through all players
exclude playerid from the loop
set all player's position to playerid's XYZ coordinates

Done.
And how I do it. I don't know.
Reply
#4

like this bro ?

pawn Код:
if(!strcmp("/tpall", cmdtext, true))
        {
        for(new i=1;i<=MAX_PLAYERS;i++)
        {
        new Float:x, Float:y, Float:z;
        GetPlayerPos(playerid,x,y,z);
        SetPlayerPos(i,x,y+1,z); // . is all player
        return 1;
    }
    return 0;
}
Reply
#5

Quote:
Originally Posted by Guest123
Посмотреть сообщение
like this bro ?

pawn Код:
if(!strcmp("/tpall", cmdtext, true))
        {
        for(new i=1;i<=MAX_PLAYERS;i++)
        {
        new Float:x, Float:y, Float:z;
        GetPlayerPos(playerid,x,y,z);
        SetPlayerPos(i,x,y+1,z); // . is all player
        return 1;
    }
    return 0;
}
You don't have to get the playerid's player position in every loop and also you dont have to take as many coordinates sets as the slots of the server are.


Here is the most timesaving (without foreach) command:
pawn Код:
if(!strcmp("/getall", cmdtext, true))
{
    new Float:x, Float:y, Float:z;
    GetPlayerPos(playerid, x, y, z);
    for(new i=0; i<MAX_PLAYERS; i++)
    {
        if (IsPlayerConnected(i))
        {
            SetPlayerPos(i,x,y,z);
        }
    }
    return 1;
}
Reply
#6

oh,, my bad :3
Reply
#7

Quote:
Originally Posted by HurtLocker
Посмотреть сообщение
You don't have to get the playerid's player position in every loop and also you dont have to take as many coordinates sets as the slots of the server are.


Here is the most timesaving (without foreach) command:
pawn Код:
if(!strcmp("/getall", cmdtext, true))
{
    new Float:x, Float:y, Float:z;
    GetPlayerPos(playerid, x, y, z);
    for(new i=0; i<MAX_PLAYERS; i++)
    {
        if (IsPlayerConnected(i))
        {
            SetPlayerPos(i,x,y,z);
        }
    }
    return 1;
}
I got errors with this so i tried the code from Guest123 and i didn't get any errors. I''ll try in-game now. Thanks.
Reply
#8

So that the players don't get gathered on a single spot and get stuck:
pawn Код:
if(!strcmp("/getall", cmdtext, true))
{
    new Float:x, Float:y, Float:z, Float:c=0.0;
    GetPlayerPos(playerid, x, y, z);
    for(new i=0; i<MAX_PLAYERS; i++)
    {
        if (IsPlayerConnected(i))
        {
            SetPlayerPos(i,x+c,y+c,z);
            c=c+0.4;
        }
    }
    return 1;
}
Reply
#9

Quote:
Originally Posted by HurtLocker
Посмотреть сообщение
So that the players don't get gathered on a single spot and get stuck:
pawn Код:
if(!strcmp("/getall", cmdtext, true))
{
    new Float:x, Float:y, Float:z, Float:c=0.0;
    GetPlayerPos(playerid, x, y, z);
    for(new i=0; i<MAX_PLAYERS; i++)
    {
        if (IsPlayerConnected(i))
        {
            SetPlayerPos(i,x+c,y+c,z);
            c=c+0.4;
        }
    }
    return 1;
}
Ok now I didn'' get any errors. I''ll get the best working one. THANKSSSSS!!!
Reply
#10

Also add this to the code above the SetPlayerPos(i,x+c,y+c,z); line:

pawn Код:
new interior;
GetPlayerInterior(playerid,interior);
SetPlayerInterior(i,interior);
This will help prevent any problems with players in different interiors (like the Police Station).






A +1 Rep means alot
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)