Weapons MySQL loading
#1

Have problem with weapons loading in mysql, saving is very good but when i need to load it it's no use, script:

pawn Code:
GivePlayerWeapon( playerid, mysql_fetch_field_row( fetch, "Ginklas0" ), mysql_fetch_field_row( fetch, "Ammo0" ) );
    GivePlayerWeapon( playerid, mysql_fetch_field_row( fetch, "Ginklas1" ), mysql_fetch_field_row( fetch, "Ammo1" ) );
    GivePlayerWeapon( playerid, mysql_fetch_field_row( fetch, "Ginklas2" ), mysql_fetch_field_row( fetch, "Ammo2" ) );
    GivePlayerWeapon( playerid, mysql_fetch_field_row( fetch, "Ginklas3" ), mysql_fetch_field_row( fetch, "Ammo3" ) );
    GivePlayerWeapon( playerid, mysql_fetch_field_row( fetch, "Ginklas4" ), mysql_fetch_field_row( fetch, "Ammo4" ) );
    GivePlayerWeapon( playerid, mysql_fetch_field_row( fetch, "Ginklas5" ), mysql_fetch_field_row( fetch, "Ammo5" ) );
    GivePlayerWeapon( playerid, mysql_fetch_field_row( fetch, "Ginklas6" ), mysql_fetch_field_row( fetch, "Ammo6" ) );
    GivePlayerWeapon( playerid, mysql_fetch_field_row( fetch, "Ginklas7" ), mysql_fetch_field_row( fetch, "Ammo7" ) );
    GivePlayerWeapon( playerid, mysql_fetch_field_row( fetch, "Ginklas8" ), mysql_fetch_field_row( fetch, "Ammo8" ) );
    GivePlayerWeapon( playerid, mysql_fetch_field_row( fetch, "Ginklas9" ), mysql_fetch_field_row( fetch, "Ammo9" ) );
    GivePlayerWeapon( playerid, mysql_fetch_field_row( fetch, "Ginklas10" ), mysql_fetch_field_row( fetch, "Ammo10" ) );
    GivePlayerWeapon( playerid, mysql_fetch_field_row( fetch, "Ginklas11" ), mysql_fetch_field_row( fetch, "Ammo11" ) );
Reply
#2

Editing your code now.
Reply
#3

pawn Code:
for (new tmp=0; tmp<12; tmp++) GetPlayerWeaponData(playerid,tmp,weps[0][tmp],weps[1][tmp]);
       
        format( Query, sizeof(Query),"UPDATE `vartotojai` SET Ginklas0 = '%i', Ammo0 = '%i' WHERE Vardas = '%s'",\
        weps[ 0 ][ 0 ], weps[ 1 ][ 0 ], GetPlayerNameEx( playerid ));
        mysql_query( Query );
        format( Query, sizeof(Query),"UPDATE `vartotojai` SET Ginklas1 = '%i', Ammo1 = '%i' WHERE Vardas = '%s'",\
        weps[ 0 ][ 1 ], weps[ 1 ][ 1 ], GetPlayerNameEx( playerid ));
        mysql_query( Query );
        format( Query, sizeof(Query),"UPDATE `vartotojai` SET Ginklas2 = '%i', Ammo2 = '%i' WHERE Vardas = '%s'",\
        weps[ 0 ][ 2 ], weps[ 1 ][ 2 ], GetPlayerNameEx( playerid ));
        mysql_query( Query );
        format( Query, sizeof(Query),"UPDATE `vartotojai` SET Ginklas3 = '%i', Ammo3 = '%i' WHERE Vardas = '%s'",\
        weps[ 0 ][ 3 ], weps[ 1 ][ 3 ], GetPlayerNameEx( playerid ));
        mysql_query( Query );
        format( Query, sizeof(Query),"UPDATE `vartotojai` SET Ginklas4 = '%i', Ammo4 = '%i' WHERE Vardas = '%s'",\
        weps[ 0 ][ 4 ], weps[ 1 ][ 4 ], GetPlayerNameEx( playerid ));
        mysql_query( Query );
        format( Query, sizeof(Query),"UPDATE `vartotojai` SET Ginklas5 = '%i', Ammo5 = '%i' WHERE Vardas = '%s'",\
        weps[ 0 ][ 5 ], weps[ 1 ][ 5 ], GetPlayerNameEx( playerid ));
        mysql_query( Query );
        format( Query, sizeof(Query),"UPDATE `vartotojai` SET Ginklas6 = '%i', Ammo6 = '%i' WHERE Vardas = '%s'",\
        weps[ 0 ][ 6 ], weps[ 1 ][ 6 ], GetPlayerNameEx( playerid ));
        mysql_query( Query );
        format( Query, sizeof(Query),"UPDATE `vartotojai` SET Ginklas7 = '%i', Ammo7 = '%i' WHERE Vardas = '%s'",\
        weps[ 0 ][ 7 ], weps[ 1 ][ 7 ], GetPlayerNameEx( playerid ));
        mysql_query( Query );
        format( Query, sizeof(Query),"UPDATE `vartotojai` SET Ginklas8 = '%i', Ammo8 = '%i' WHERE Vardas = '%s'",\
        weps[ 0 ][ 8 ], weps[ 1 ][ 8 ], GetPlayerNameEx( playerid ));
        mysql_query( Query );
        format( Query, sizeof(Query),"UPDATE `vartotojai` SET Ginklas9 = '%i', Ammo9 = '%i' WHERE Vardas = '%s'",\
        weps[ 0 ][ 9 ], weps[ 1 ][ 9 ], GetPlayerNameEx( playerid ));
        mysql_query( Query );
        format( Query, sizeof(Query),"UPDATE `vartotojai` SET Ginklas10 = '%i', Ammo10 = '%i' WHERE Vardas = '%s'",\
        weps[ 0 ][ 10 ], weps[ 1 ][ 10 ], GetPlayerNameEx( playerid ));
        mysql_query( Query );
        format( Query, sizeof(Query),"UPDATE `vartotojai` SET Ginklas11 = '%i', Ammo11 = '%i' WHERE Vardas = '%s'",\
        weps[ 0 ][ 11 ], weps[ 1 ][ 11 ], GetPlayerNameEx( playerid ));
        mysql_query( Query );
Reply
#4

You have to understand how mysql_fetch_field_row works. Function itself doesn't return a value. The result is stored in string passed as first argument (by reference).

pawn Code:
new tmp[64];
mysql_fetch_field_row( fetch, "Ginklas0" ); //fetch is now equal value of field Ginklas0
mysql_fetch_field_row( tmp, "Ammo0" ); //tmp now has the value of field Ammo0
GivePlayerWeapon( playerid, strval(fetch), strval(tmp));
Strval changes type of variable from string to number - for computer string with value "1234" isn't the same as the value 1234.

#e: You have to completely rewrite your saving function - currently it can easily kill your server
Reply
#5

so is this code good now?
pawn Code:
new tmp[ 64 ];
    mysql_fetch_field_row( fetch, "Ginklas0" );
    mysql_fetch_field_row( tmp, "Ammo0" );
    GivePlayerWeapon( playerid, strval(fetch), strval(tmp));
    mysql_fetch_field_row( fetch, "Ginklas1" );
    mysql_fetch_field_row( tmp, "Ammo1" );
    GivePlayerWeapon( playerid, strval(fetch), strval(tmp));
    mysql_fetch_field_row( fetch, "Ginklas2" );
    mysql_fetch_field_row( tmp, "Ammo2" );
    GivePlayerWeapon( playerid, strval(fetch), strval(tmp));
    mysql_fetch_field_row( fetch, "Ginklas3" );
    mysql_fetch_field_row( tmp, "Ammo3" );
    GivePlayerWeapon( playerid, strval(fetch), strval(tmp));
    mysql_fetch_field_row( fetch, "Ginklas4" );
    mysql_fetch_field_row( tmp, "Ammo4" );
    GivePlayerWeapon( playerid, strval(fetch), strval(tmp));
    mysql_fetch_field_row( fetch, "Ginklas5" );
    mysql_fetch_field_row( tmp, "Ammo5" );
    GivePlayerWeapon( playerid, strval(fetch), strval(tmp));
    mysql_fetch_field_row( fetch, "Ginklas6" );
    mysql_fetch_field_row( tmp, "Ammo6" );
    GivePlayerWeapon( playerid, strval(fetch), strval(tmp));
    mysql_fetch_field_row( fetch, "Ginklas7" );
    mysql_fetch_field_row( tmp, "Ammo7" );
    GivePlayerWeapon( playerid, strval(fetch), strval(tmp));
    mysql_fetch_field_row( fetch, "Ginklas8" );
    mysql_fetch_field_row( tmp, "Ammo8" );
    GivePlayerWeapon( playerid, strval(fetch), strval(tmp));
    mysql_fetch_field_row( fetch, "Ginklas9" );
    mysql_fetch_field_row( tmp, "Ammo9" );
    GivePlayerWeapon( playerid, strval(fetch), strval(tmp));
    mysql_fetch_field_row( fetch, "Ginklas10" );
    mysql_fetch_field_row( tmp, "Ammo10" );
    GivePlayerWeapon( playerid, strval(fetch), strval(tmp));
    mysql_fetch_field_row( fetch, "Ginklas11" );
    mysql_fetch_field_row( tmp, "Ammo11" );
    GivePlayerWeapon( playerid, strval(fetch), strval(tmp));
Reply
#6

Yes. try that. if it works
EDIT
put it outside the mysql_free_result();
and try this. try only putting 1 GivePlayerWeapon( playerid, strval(fetch), strval(tmp)); instead of 11. try putting all of it outside mysql_free_result();
Reply
#7

Looks fine, but test it to be sure
Reply
#8

works thx
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)