12.12.2011, 23:21
I am looking for an efficient way to save a player's weapon data (for all 13 slots) into a MySQL database. Is it possible by doing an array, that doesn't query the server 13 times?
new weapondata[2], savestr[250], pname[24];
GetPlayerName(playerid, pname, 24);
for(new x; x<13; x++)
{
GetPlayerWeaponData(playerid, x, weapondata[0], weapondata[1]);
format(savestr, sizeof(savestr), "%s%d||%d||", savestr, weapondata[0], weapondata[1]);
}
new query[320];
format(query, sizeof(query), "UPDATE users SET weapondata = '%s' WHERE username = '%s', savestr, pname);
mysql_query(query);
new wd[2][13], pname[24], query[150], wdataline[250];
GetPlayerName(playerid, pname, 24);
format(query, sizeof(query), "SELECT weapondata from users WHERE username = '%s'", pname);
mysql_query(query);
mysql_store_result();
mysql_fetch_field_row(wdataline, "weapondata");
mysql_free_result();
sscanf(wdataline, "p<||>ddddddddddddddddddddddddddd", wd[0][0], wd[1][0], wd[0][1], wd[1][1], wd[0][2], wd[1][2], wd[0][3], wd[1][3], wd[0][4], wd[1][4], wd[0][5], wd[1][5], wd[0][6], wd[1][6], wd[0][7], wd[1][7], wd[0][8], wd[1][8], wd[0][9], wd[1][9], wd[0][10], wd[1][10], wd[0][11], wd[1][11], wd[0][12], wd[1][12]);
for(new x; x<13; x++)
{
if(wd[x][0] != 0) GivePlayerWeapon(playerid, wd[x][0], wd[x][1]);
}
You could make one big query or you could make it a string. Making it a string was a method I used a while ago to save all vehicle mods, weapons etc in one line in the database. Later, I would split it with sscanf into separate categories.
pawn Код:
pawn Код:
![]() //You can probably do this some other way, but I'm not that great with sscanf |