------------------------------
Available Locations
------------------------------
1. Casino
2. Pizza Stacks
------------------------------
Select | Cancel
------------------------------
//In this case I suppose you the array's name is Locations
new string[1024], str[128];
for(new i = 0; i < LocationSize; i++)
{
format(str, 128, "%d. %s\n", i+1, Locations[i][Name]);
strcat(string, str);
}
ShowPlayerDialog(playerid, 1, DIALOG_STYLE_LIST, "Available Locations", string, "Select", "Cancel");
printf("%s marked on GPS", Locations[listitem][Name]);
COMMAND:addgpslocation(playerid,params[])
{
if(!IsPlayerAdmin(playerid)) return SendClientMessage(playerid, -1, "Error: You are not authorized to use this command.");
new name[512];
if(sscanf(params, "s[512]", name)) return SendClientMessage(playerid, -1, "Usage: /addgpslocation [Name]");
for(new i=0;i<sizeof(GPS);i++)
{
new Float:x,Float:y,Float:z;
GetPlayerPos(playerid, x, y, z);
GPS[i][loc_name] = name;
GPS[i][loc_x] = x;
GPS[i][loc_y] = y;
GPS[i][loc_z] = z;
format(GPS[i][loc_name],512, "%s", name);
new query[256];
format(query, sizeof(query),"INSERT INTO gps (loc_x,loc_y,loc_z,loc_name) VALUES ('%f','%f','%f','%s')",GPS[i][loc_x],GPS[i][loc_y],GPS[i][loc_z],GPS[i][loc_z],GPS[i][loc_name]);
mysql_function_query(dbhandle,query,false,"","");
printf("%s || ID : %i", query,i);
printf("Pos : %f,%f,%f", x,y,z);
SendClientMessage(playerid, -1, "GPS: Location added successfully!");
return 1;
}
return 1;
}
GPS[i][loc_name] = name; // Store once
GPS[i][loc_x] = x;
GPS[i][loc_y] = y;
GPS[i][loc_z] = z;
format(GPS[i][loc_name],512, "%s", name); // Store again???
You're adding your entered location to every index of your GPS array, overwriting every previously added location.
You have to find a free spot and only add it to that free spot, then abort the loop. Also, why store the name first, then store it a second time using format at the exact same field of your enum? PHP код:
|