Help translating this to MySQL R5
#1

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:

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;
}
this is how my saving looks:

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");
                }
            }
Can anyone help me with loading the weapons?
Reply
#2

bump
Reply
#3

Yeah well, no one's going to help you with that. It'd be like saying: "Hey, I have a Lamborghini, how to convert it to a Toyota, because I only know how to drive Toyota!". The right answer would be: learn to drive a Lamborghini. The same principle applies here.
Reply
#4

I understand you, but its just my hobby this and R5 MySQL seems enough for me. Ill change my question, is it possible to loop through the tables in R5, and get same or similar results? If it is i will try my best to do it myself.
Reply


Forum Jump:


Users browsing this thread: