How can I list all enum data in dialog box
#1

Hello, i am trying to create GPS system, how can i show all locations in dialog.

Ex:
we can loop and show all data in sendclientmessage but i want to add each data in dialog box
PHP код:
------------------------------
Available Locations
------------------------------
1. Casino
2. Pizza Stacks
------------------------------
Select        |        Cancel
------------------------------ 
Reply
#2

You can use a string and concat all lines you want on the dialog. For example:
PHP код:
//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"); 
You can also use on OnDialogResponse the listitem as a position:
PHP код:
printf("%s marked on GPS", Locations[listitem][Name]); 
Reply
#3

It's just showing 1 item, here is my full code of /addgpslocation
PHP код:
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;
} 
Maybe having some problem on loop :/
Reply
#4

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 код:
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??? 
Reply
#5

Quote:
Originally Posted by AmigaBlizzard
Посмотреть сообщение
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 код:
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??? 
How i can find free spot?
Reply
#6

Fixed
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)