18.08.2014, 03:18
Hi guys i found this useful gun saving tutorial, but it is not i MySQL R5. I dont understand very well the upper MySQL. Heres what im trying to, put in R5:
this is how my saving looks:
Can anyone help me with loading the weapons?
pawn Код:
public OnLoadPlayerWeapons(playerid)
{
new
weaponid,
ammo;
for(new i, j = cache_get_row_count(userDB); i < j; i++) // loop through all the rows that were found
{
weaponid = cache_get_row_int(i, 0, userDB);
ammo = cache_get_row_int(i, 1, userDB);
if(!(0 <= weaponid <= 46)) // check if weapon is valid (should be)
{
printf("[info] Warning: OnLoadPlayerWeapons - Unknown weaponid '%d'. Skipping.", weaponid);
continue;
}
GivePlayerWeapon(playerid, weaponid, ammo);
}
return;
}
pawn Код:
new
weaponid,
MySQLQuery[300],
ammo;
for(new i; i < 13; i++) // looping through all weapon slots (0 - 12)
{
GetPlayerWeaponData(playerid, i, weaponid, ammo); // get weaponid and ammo
if(!weaponid) continue; // don't insert if there's no weapon in this slot
format(MySQLQuery, sizeof(MySQLQuery), "INSERT INTO ginklai VALUES (%d, %d, %d) ON DUPLICATE KEY UPDATE ammo = %d;", GetPVarInt(playerid, "AccID"), weaponid, ammo, ammo);
printf("Query looks like: %s", MySQLQuery);
mysql_query(MySQLQuery);
new queryResult = mysql_query(MySQLQuery);
if (!queryResult) {
printf("Query failed, errno %d", mysql_errno());
} else {
print("Apparently query succeeded");
}
}

