SA-MP Forums Archive
A little question about function new and stock - 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: A little question about function new and stock (/showthread.php?tid=598072)



A little question about function new and stock - fuckingcruse - 08.01.2016

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.


Re: A little question about function new and stock - Jefff - 08.01.2016

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



Re: A little question about function new and stock - fuckingcruse - 09.01.2016

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


Re: A little question about function new and stock - SickAttack - 09.01.2016

"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.


Re: A little question about function new and stock - fuckingcruse - 09.01.2016

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


Re: A little question about function new and stock - SickAttack - 09.01.2016

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