That's a handy function, however the problem is it would only put them in a line on the X axis, that is East to West. Sure if you wanted North to South you could change it to the Y axis but what if you wanted it at a 47.6 degree angle?
To do that, you use the trigonometric functions Sine and Cosine (Or in Pawn: floatsin and floatcos)
You simply add the sine of the angle to the X, and the cosine of the angle to the Y, like this:
(Don't forget to use 'degrees' in the functions!)
pawn Код:
SetPlayerPos(playerid, x + floatsin(angle, degrees), y + floatcos(angle, degrees), z);
We're not done yet though, you can probably work out that this will just put all the players in one spot as we haven't used 'count' or 'distance'.
Well, fortunately, if you multiply the Sine and Cosine functions by a distance, the "projected" position (Projected from the origin point) will be that distance from the origin. You can simply use your "count * distance" equasion:
pawn Код:
SetPlayerPos(playerid, x + ((count * p2pdistance) * floatsin(angle, degrees)), y + ((count * p2pdistance) * floatcos(angle, degrees)), z);
And you will need to add the 'angle' parameter to the function header, the final result is:
pawn Код:
TeleportAllToALine(Float: x, Float: y, Float: z, Float: p2pdistance, Float:angle, interior = 0, virtualworld = 0)
{
new
count = 0;
for(new playerid = 0; playerid < MAX_PLAYERS; playerid ++)
{
if(IsPlayerConnected(playerid))
{
SetPlayerPos(playerid, x + ((count * p2pdistance) * floatsin(angle, degrees)), y + ((count * p2pdistance) * floatcos(angle, degrees)), z);
SetPlayerFacingAngle(playerid, angle+90.0); // Set the players to face forwards, can't remember if it's + or - ...
SetPlayerInterior(playerid, interior);
SetPlayerVirtualWorld(playerid, virtualworld);
count ++;
}
}
}
I haven't tested this, but I hope you get the idea!
![Tongue](images/smilies/razz.gif)
You could also add a player angle parameter that changes the direction of the players, in case you want them to all face back or forward or at each other's backs!