warning 213: tag mismatch warning 213: tag mismatch warning 213: tag mismatch
forward OnLoadPlayerWeapons(playerid); public OnLoadPlayerWeapons(playerid) { new weaponid, ammo; for(new i, j = cache_get_row_count(g_SQL); i < j; i++) // loop through all the rows that were found { weaponid = cache_get_value_int(i, 0, g_SQL); ammo = cache_get_value_int(i, 1, g_SQL); 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; }
cache_get_value_int(i, "field_name", weaponid); cache_get_value_int(i, "field_name", ammo);
cache_get_value_index_int(i, 0, weaponid); cache_get_value_index_int(i, 1, ammo);
Second parameter for cache_get_value_int function is field name. If you want to get value by its index, use cache_get_value_index_int instead.
|
Second parameter for cache_get_value_int function is field name, and third parameter is for reference variable.
Example: Код:
cache_get_value_int(i, "field_name", weaponid); cache_get_value_int(i, "field_name", ammo); Example: Код:
cache_get_value_index_int(i, 0, weaponid); cache_get_value_index_int(i, 1, ammo); |
for(new i, j = cache_get_row_count(g_SQL); i < j; i++)
for(new i, j = cache_num_rows(); i < j; i++)
https://sampwiki.blast.hk/wiki/MySQL/R40..._get_row_count
The function does not return the number of rows but it stores it to a variable (passed-by-reference) in version R40+. You can also use: Код:
for(new i, j = cache_num_rows(); i < j; i++) |
UpdatePlayerData(playerid, reason) { if (pInfo[playerid][IsLoggedIn] == false) return 0; // if the client crashed, it's not possible to get the player's position in OnPlayerDisconnect callback // so we will use the last saved position (in case of a player who registered and crashed/kicked, the position will be the default spawn point) if (reason == 1) { GetPlayerPos(playerid, pInfo[playerid][X_Pos], pInfo[playerid][Y_Pos], pInfo[playerid][Z_Pos]); GetPlayerFacingAngle(playerid, pInfo[playerid][A_Pos]); GetPlayerHealth(playerid, pInfo[playerid][pSalud]); GetPlayerArmour(playerid, pInfo[playerid][pChaleco]); GetPlayerMoney(playerid); } new query[145]; mysql_format(g_SQL, query, sizeof query, "UPDATE `jugadores` SET `PosX` = %f, `PosY` = %f, `PosZ` = %f, `PosA` = %f, `interior` = %d WHERE `id` = %d LIMIT 1", pInfo[playerid][X_Pos], pInfo[playerid][Y_Pos], pInfo[playerid][Z_Pos], pInfo[playerid][A_Pos], GetPlayerInterior(playerid), pInfo[playerid][ID]); mysql_tquery(g_SQL, query); new query2[145]; mysql_format(g_SQL, query2, sizeof query2, "UPDATE `jugadores` SET `pSalud` = %f, `pChaleco` = %f, `pDinero` = %d WHERE `id` = %d LIMIT 1", pInfo[playerid][pSalud], pInfo[playerid][pChaleco], GetPlayerMoney(playerid), pInfo[playerid][ID]); mysql_tquery(g_SQL, query2); SavePlayerWeapons(playerid); return 1; } SavePlayerWeapons(playerid) { new armaID, municion; for(new i; i < 13; i++) // looping through all weapon slots (0 - 12) { GetPlayerWeaponData(playerid, i, armaID, municion); // get weaponid and ammo if(!armaID) continue; // don't insert if there's no weapon in this slot new query3[145]; mysql_format(g_SQL, query3, sizeof(query3), "INSERT INTO armas_usuarios (`userID`, `armaID`, `municion`) VALUES (%d, %d, %d) ON DUPLICATE KEY UPDATE municion = %d;", pInfo[playerid][ID], armaID, municion, municion); mysql_tquery(g_SQL, query3); // parallel queries } } forward OnLoadPlayerWeapons(playerid); public OnLoadPlayerWeapons(playerid) { new weaponid, ammo; new query2[145]; mysql_format(g_SQL, query2, sizeof(query2), "SELECT armaID, municion FROM armas_usuarios WHERE id = %d; ", pInfo[playerid][ID]); mysql_tquery(g_SQL, query2); // parallel queries for(new i, j = cache_num_rows(); i < j; i++) // loop through all the rows that were found { weaponid = cache_get_value_index_int(i, 0, weaponid); ammo = cache_get_value_index_int(i, 1, ammo); 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; }