I don't see a point in loading all of the characters and storing the data. What if someone has 10 characters? Odds are, they aren't going to use them all! Just make it so it loads the data for the character they want to play on.
However, obviously, you need to load the username's so you can let the player pick one!
Some pseudo-type code I just now wrote up. It in no way works as is, but it should give you a head start!
pawn Код:
enum eCharactersEnum
{
cID,
cUsername,
cDOB,
cSkin,
cMoney
// etc, etc, etc
};
new
pCharacters[MAX_PLAYERS][eCharactersEnum]
;
mysql_function_query(connectionHandle, "SELECT `username` FROM `playerCharacters` WHERE `masteraccountID` = 1291", true, "loadAccounts", "d", playerid); // after master-account authentication or something
new
loadedCharUsernames[MAX_PLAYERS][MAX_CHARACTERS][MAX_PLAYER_NAME]
;
public loadAccounts(playerid)
{
new
rows,
fields
;
cache_get_data(rows, fields);
if(rows > 0)
{
new
szMainString[1000]
;
for(new i = 0; i < rows; i++)
{
cache_get_row(0, 0, szUsername);
strcat(szMainString, szUsername);
strcat(szMainString, "\n");
loadedCharUsernames[playerid][i] = szUsername; // obviously won't work, but you get the point: store the username in the var, the i corresponds with the "listitem" number on the dialog
}
ShowPlayerDialog(playerid, DIALOG_LIST_CHARACTERS, DIALOG_STYLE_LIST, "Select a character to play on...", szMainString, "Select", "");
}
return 1;
}
public OnDialogResponse(...)
{
if(dialogid == DIALOG_LIST_CHARACTERS)
{
mysql_function_query(connectionHandle, "SELECT * FROM `playerCharacters` WHERE `cID` = loadedCharUsernames[playerid][listitem]", true, "loadCharacter", "d", playerid);
}
return 0;
}
public loadCharacter(playerid)
{
new
rows,
fields
;
cache_get_data(rows, fields);
if(rows == 1)
{
new
temp[30]
;
// load the data, store it in the character enum
cache_get_row(0, 0, temp); pCharacters[playerid][cID] = strval(temp);
// .......
}
return 1;
}