SA-MP Forums Archive
How to create a command to bring everyone - 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: How to create a command to bring everyone (/showthread.php?tid=431569)



How to create a command to bring everyone - RiChArD_A - 18.04.2013

Hello, You read the title.


Re: How to create a command to bring everyone - Scenario - 18.04.2013

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.


Re: How to create a command to bring everyone - RiChArD_A - 18.04.2013

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.


Re: How to create a command to bring everyone - Guest123 - 18.04.2013

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



Re: How to create a command to bring everyone - HurtLocker - 18.04.2013

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



Re: How to create a command to bring everyone - Guest123 - 18.04.2013

oh,, my bad :3


Re: How to create a command to bring everyone - RiChArD_A - 18.04.2013

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.


Re: How to create a command to bring everyone - HurtLocker - 19.04.2013

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



Re: How to create a command to bring everyone - RiChArD_A - 19.04.2013

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


Re: How to create a command to bring everyone - jakejohnsonusa - 19.04.2013

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