SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Scripting Help

Reply
 
Thread Tools Display Modes
Old 20/03/2013, 04:16 PM   #1
ancezas
Huge Clucker
 
ancezas's Avatar
 
Join Date: Aug 2011
Location: Lithuania
Posts: 261
Reputation: 1
Default Weapons MySQL loading

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" ) );
__________________
MiniMissions www.vvp.sarp.lt IP: 94.23.54.150:7777
ancezas is offline   Reply With Quote
Old 20/03/2013, 04:18 PM   #2
Patrick
Guest
 
Posts: n/a
Default Re: Weapons MySQL loading

Editing your code now.
  Reply With Quote
Old 20/03/2013, 04:24 PM   #3
ancezas
Huge Clucker
 
ancezas's Avatar
 
Join Date: Aug 2011
Location: Lithuania
Posts: 261
Reputation: 1
Default Re: Weapons MySQL loading

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 );
__________________
MiniMissions www.vvp.sarp.lt IP: 94.23.54.150:7777
ancezas is offline   Reply With Quote
Old 20/03/2013, 04:24 PM   #4
Misiur
High-roller
 
Misiur's Avatar
 
Join Date: Jul 2009
Location: Poland
Posts: 2,528
Reputation: 556
Default Re: Weapons MySQL loading

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
Misiur is offline   Reply With Quote
Old 20/03/2013, 04:40 PM   #5
ancezas
Huge Clucker
 
ancezas's Avatar
 
Join Date: Aug 2011
Location: Lithuania
Posts: 261
Reputation: 1
Default Re: Weapons MySQL loading

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));
__________________
MiniMissions www.vvp.sarp.lt IP: 94.23.54.150:7777
ancezas is offline   Reply With Quote
Old 20/03/2013, 04:46 PM   #6
Patrick
Guest
 
Posts: n/a
Default Re: Weapons MySQL loading

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 With Quote
Old 20/03/2013, 04:46 PM   #7
Misiur
High-roller
 
Misiur's Avatar
 
Join Date: Jul 2009
Location: Poland
Posts: 2,528
Reputation: 556
Default Re: Weapons MySQL loading

Looks fine, but test it to be sure
Misiur is offline   Reply With Quote
Old 20/03/2013, 04:51 PM   #8
ancezas
Huge Clucker
 
ancezas's Avatar
 
Join Date: Aug 2011
Location: Lithuania
Posts: 261
Reputation: 1
Default Re: Weapons MySQL loading

works thx
__________________
MiniMissions www.vvp.sarp.lt IP: 94.23.54.150:7777
ancezas is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Loading players weapons Snowman12 Scripting Help 1 09/01/2012 12:21 AM
MySQL Loading Weapons, Not working.... Dokins Scripting Help 2 01/10/2011 08:50 PM
Crashing after loading weapons. borba Help Archive 8 27/04/2011 08:45 AM
Making weapons loading short ||123|| Help Archive 5 04/09/2010 07:03 PM
-1 Ammo bug when loading players weapons. Johndaone Help Archive 2 15/06/2010 05:35 AM


All times are GMT. The time now is 08:52 PM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.