SA-MP Forums Archive
Character List - 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: Character List (/showthread.php?tid=647847)



Character List - JaKe Elite - 12.01.2018

PHP код:
stock ListCharacters(playerid)
{
    new 
sz_Query[128], DBResult:resultname[MAX_PLAYER_NAME], count;
    
format(sz_Querysizeof(sz_Query), "SELECT * FROM `chars` WHERE `userid` = %d"PlayerInfo[playerid][pUserID]);
    
result db_query(Databasesz_Query);
    for (
count 0count db_num_rows(result); count ++)
    {
        
db_get_field_assoc(result"char_name"nameMAX_PLAYER_NAME);
        
format(sz_Querysizeof(sz_Query), "%s\n"name);
        
db_next_row(result);
    }
    
db_free_result(result);
    
    if(
count 0
        
SendClientMessage(playeridCOLOR_LIGHTRED"(( Choose a character. ))") &&
        
format(sz_Querysizeof(sz_Query), "Create Character\n%s"sz_Query) &&
        
Dialog_Show(playeridLoadCharacterDIALOG_STYLE_LIST""COL_GREEN"Characters List"sz_Query"Load""");
    else
        
SendClientMessage(playeridCOLOR_LIGHTRED"(( You have not created a character yet, Create one!") &&
        
Dialog_Show(playeridCreateCharacterDIALOG_STYLE_INPUT""COL_RED"Character Name""* You have not created a character yet, Create one!\nPlease input the name of your character:""Create""");
    return 
1;

For some reason the code above only lists one character even though the player owns two or more characters, What is with the code?


Re: Character List - Misiur - 12.01.2018

pawn Код:
format(sz_Query, sizeof(sz_Query), "%s\n", name);
You are overwriting sz_Query with each new row.
pawn Код:
format(sz_Query, sizeof(sz_Query), "%s%s\n", sz_Query, name);



Re: Character List - JaKe Elite - 12.01.2018

Ah, didn't noticed that. Thank you.