13.12.2011, 00:49
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.
That would just save as a bunch of numbers that you could split with sscanf later on. I'm not sure if it's really efficient but it works well.
You kinda get the idea there. Anyway, you can also just have a bunch of variables in an update query
.
//You can probably do this some other way, but I'm not that great with sscanf
pawn Код:
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);
pawn Код:
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 can probably do this some other way, but I'm not that great with sscanf