A little question about function new and stock
#1

Hey, there like i am making few location spawns.
Код:
new Spawns[][4] =
{
	{posX1,posY1,posZ1},
	{posX2,posY2,posZ2},
	{posX3,posY3,posZ3},
	{posX4,posY4,posZ4},
	{posX5,posY5,posZ5},
	{posX6,posY6,posZ6}
};

stock SetPos(playerid)
{
	SetPlayerPos(playerid,HIS ENUM VALUE});
}
I am making 1 enum,if his enum is 1 he must be teleported at posX1,posY1,posZ1 .. I am asking if it's possible to set the value of the POS in the new Spawns before.. And after an command execution he will be teleported as per his enum value. if its possible let me know.
Reply
#2

pawn Код:
new PlayerPos[MAX_PLAYERS];

somwhere
PlayerPos[playerid] = number_here_from_Spawns; // if you set 1 tp will be posx1

stock SetPos(playerid)
{
    new ID = PlayerPos[playerid] - 1;
    SetPlayerPos(playerid, Spawns[ID][0], Spawns[ID][1], Spawns[ID][2]);
}
Reply
#3

Can you explain jn a more better way? I didn't got you. Thank you.
Reply
#4

"PlayerPos[playerid]" is being used as the index on your array (it's not an enumerator | Spawns[index][0]), so if a player has their variable "PlayerPos[playerid]" set to 2, the selected index will then be 1 as "ID" is being subtracted 1 at the end of its declaration.

Meaning, the player's spawn would be set to "{posX2,posY2,posZ2}" because array indexes start at 0. If they have 6 assigned to their variable "PlayerPos[playerid]", then their spawn will be set to "{posX5,posY5,posZ5}" and so on.
Reply
#5

So, i must type new PlayerPos[MAX_PLAYERS]; at any part of my script above the new Spawns{ } ; right?
Reply
#6

Quote:
Originally Posted by fuckingcruse
Посмотреть сообщение
So, i must type new PlayerPos[MAX_PLAYERS]; at any part of my script above the new Spawns{ } ; right?
....

Quote:
Originally Posted by Jefff
Посмотреть сообщение
pawn Код:
new PlayerPos[MAX_PLAYERS];

somwhere
PlayerPos[playerid] = number_here_from_Spawns; // if you set 1 tp will be posx1

stock SetPos(playerid)
{
    new ID = PlayerPos[playerid] - 1;
    SetPlayerPos(playerid, Spawns[ID][0], Spawns[ID][1], Spawns[ID][2]);
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)