Posts: 716
	Threads: 92
	Joined: May 2018
	
	
 
	
	
		So, i have this array:
pawn Код:
new const g_LocationData[][e_LocData] =
{
    {"Bank", 2315.952880, -1.618174, 26.742187},
    {"LS Atrium", 1710.433715, -1669.379272, 20.225049}
};
 
Enum:
pawn Код:
enum e_LocData
{
    e_LocName[32],
    Float:e_LocX,
    Float:e_LocY,
    Float:e_LocZ
};
 
I want to select a random destionation and create a checkpoint if i type /destination, but i don't know how to loop the array i created, help?
And if possible, show the random name destionation, ex: "You teleported to Bank"
	
 
	
	
	
		
	
 
 
	
	
	
		
	Posts: 716
	Threads: 92
	Joined: May 2018
	
	
 
	
	
		Thank you, and how to store generated random destination name in a pvar to recall it in a second moment in another function? (not the command)
	
	
	
	
		
	
 
 
	
	
	
		
	Posts: 716
	Threads: 92
	Joined: May 2018
	
	
 
	
	
		Ok thanks, to retrieve it in show in a message, will work in this way?
pawn Код:
new string[80];
GetPVarString(playerid, "RandomLocation",g_LocationData[randomloc][e_LocName]);
format(string, sizeof(string), "Last teleport was to: %s" GetPVarString(playerid, "RandomLocation",g_LocationData[randomloc][e_LocName]));
 
	 
	
	
	
		
	
 
 
	
	
	
		
	Posts: 716
	Threads: 92
	Joined: May 2018
	
	
 
	
	
		Do u mind giving me an example?
	
	
	
	
		
	
 
 
	
	
	
		
	Posts: 6,242
	Threads: 8
	Joined: Jun 2008
	
	
 
	
	
		
Quote:
					Originally Posted by  KinderClans
 
 
Do u mind giving me an example? 
 | 
 Do you mind keeping this thread up? I've struggled with this sort of thing in the past, and it would be good to have it simply shown and remain for others.
	
 
	
	
	
		
	
 
 
	
	
	
		
	Posts: 716
	Threads: 92
	Joined: May 2018
	
	
 
	
	
		Did in this way:
pawn Код:
new const g_LocationData[][e_LocData] =
{
    {"Bank", 2315.952880, -1.618174, 26.742187},
    {"LS Atrium", 1710.433715, -1669.379272, 20.225049}
};
enum e_LocData
{
    e_LocName[32],
    Float:e_LocX,
    Float:e_LocY,
    Float:e_LocZ
};
CMD:tele(playerid, params[])
(
    new randomloc = random(sizeof(g_LocationData));
    new Msg[48];
    format(Msg, sizeof(Msg), "Teleported to: %s", g_LocationData[randomloc][e_LocName]);
    SetPlayerPos(playerid, g_LocationData[randomloc][e_LocX], g_LocationData[randomloc][e_LocY], g_LocationData[randomloc][e_LocZ]);
    SendClientMessage(playerid, -1, Msg);
    SetPVarString(playerid,"RandomLocation",g_LocationData[randomloc][e_LocName]);
    return 1;
)
CMD:last(playerid, params[])
{
    new string[80];
    GetPVarString(playerid, "RandomLocation",g_LocationData[randomloc][e_LocName]);
    format(string, sizeof(string), "Last teleport was to: %s" GetPVarString(playerid, "RandomLocation",g_LocationData[randomloc][e_LocName]));
    return 1
}
 
But i'm getting "undefinel symbol: randomloc" at /last command.
	
 
	
	
	
		
	
 
 
	
	
	
		
	Posts: 716
	Threads: 92
	Joined: May 2018
	
	
 
	
	
		Does SetPVarInt saves only integrers and not strings?
	
	
	
	
		
	
 
 
	
	
	
		
	Posts: 6,242
	Threads: 8
	Joined: Jun 2008
	
	
 
	
	
		What are you doing?
Do you guys even know what PVars and SVars are actually for?
The const, and random are all good... But using PVars for anything that is in the script itself, and not shared across any other scripts, is just a waste.
	
	
	
	
		
	
 
 
	
	
	
		
	Posts: 716
	Threads: 92
	Joined: May 2018
	
	
 
	
	
		It's not a waste if you want to retrirve a random array name (which is my case)..
	
	
	
	
		
	
 
 
	
	
	
		
	Posts: 428
	Threads: 4
	Joined: Feb 2017
	
Reputation: 
0
	 
 
	
	
		Dosen't matter whether its Pvar or normal variables, all you need to do is random(sizeof array) and save it in a pvar/normal variable and use if further wherever you want to and with having the index number, you have access to all the data members in that array.
	
	
	
	
		
	
 
 
	
	
	
		
	Posts: 716
	Threads: 92
	Joined: May 2018
	
	
 
	
	
		
Quote:
					Originally Posted by  Calisthenics
 
 
//code 
 | 
 Thank you it works perfectly.