SA-MP Forums

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

Reply
 
Thread Tools Display Modes
Old 08/04/2014, 12:25 PM   #11
iRaiDeN
Huge Clucker
 
iRaiDeN's Avatar
 
Join Date: Mar 2014
Location: Israel
Posts: 480
Reputation: 41
Default Re: Saving weapon data (MySQL)

good job
iRaiDeN is offline   Reply With Quote
Old 08/08/2014, 05:20 PM   #12
Type-R
Huge Clucker
 
Type-R's Avatar
 
Join Date: Feb 2011
Posts: 291
Reputation: 5
Default Re: Saving weapon data (MySQL)

how do i do this with old MySQL like R4? I put this on disconnect:

pawn Code:
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);
                mysql_query(MySQLQuery);
            }

I go to the server, give myself weapons then quit, and nothing appears in the database. and how could i redo, the loading for Queries? Thank you.
__________________
Type-R is offline   Reply With Quote
Old 14/08/2014, 12:17 PM   #13
iFarbod
Gangsta
 
Join Date: Jan 2014
Location: Los Santos (HD Universe)
Posts: 610
Reputation: 61
Default Re: Saving weapon data (MySQL)

Quote:
Originally Posted by Type-R View Post
how do i do this with old MySQL like R4? I put this on disconnect:

pawn Code:
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);
                mysql_query(MySQLQuery);
            }

I go to the server, give myself weapons then quit, and nothing appears in the database. and how could i redo, the loading for Queries? Thank you.
That's outdated, use R33+, (R39-2)
iFarbod is offline   Reply With Quote
Old 15/08/2014, 01:03 AM   #14
Type-R
Huge Clucker
 
Type-R's Avatar
 
Join Date: Feb 2011
Posts: 291
Reputation: 5
Default Re: Saving weapon data (MySQL)

1. I dont know R33+
2. I dont have time
3. Its just kind of a free time thing, so for my likings R5 is enough, sorry i put R4..
__________________
Type-R is offline   Reply With Quote
Old 08/02/2015, 09:34 PM   #15
Sime30
Huge Clucker
 
Join Date: Oct 2012
Location: Should I stay or should I go
Posts: 348
Reputation: 31
Default Re: Saving weapon data (MySQL)

Hey Vince.

First off, good job!

Second, I have a question. Why did you put a semicolon at the end of format ?
Code:
ammo = %d;
EDIT: Found an answer! If we put a semicolon that means the end of a query so we can put multiple queries that way, if anyone is wondering.

Last edited by Sime30; 08/02/2015 at 11:49 PM.
Sime30 is offline   Reply With Quote
Old 18/06/2015, 06:03 PM   #16
AndySedeyn
High-roller
 
AndySedeyn's Avatar
 
Join Date: Feb 2014
Location: Belgium
Posts: 1,207
Reputation: 681
Default Re: Saving weapon data (MySQL)

I thank you sincerely for the useful information in the database normalization series.
AndySedeyn is offline   Reply With Quote
Old 07/07/2015, 08:41 PM   #17
b3nz
Little Clucker
 
Join Date: Jun 2015
Posts: 47
Reputation: 17
Default Re: Saving weapon data (MySQL)

Sorry for bumping this, but I'm really interested in this. Anyway, I have a question:

Quote:
Purging obsolete data
Whenever a weapon is taken away, do not forget to delete it from the database otherwise it will be returned to the player when they next join. You could write a hook for ResetPlayerWeapons. It may also be possible that weapons that have no ammo are left behind in the table. This doesn't affect anything in-game and can be cleaned up with a query (delete where ammo = 0) when the server starts, or on a cron job.
Couldn't this be solved easily by deleting certain player's weapons info in the table before saving it again? This won't use much memory, as you obviously would save the player's weapons once per possesion (when the player disconnects).
b3nz is offline   Reply With Quote
Old 10/07/2015, 01:42 AM   #18
TenTen
Big Clucker
 
TenTen's Avatar
 
Join Date: Jul 2015
Posts: 196
Reputation: 4
Default Re: Saving weapon data (MySQL)

Nice
TenTen is offline   Reply With Quote
Old 18/07/2015, 12:29 AM   #19
2KY
Gangsta
 
2KY's Avatar
 
Join Date: Jan 2012
Location: United States
Posts: 949
Reputation: 166
Default Re: Saving weapon data (MySQL)

EDIT: Got it, thanks for the tutorial Vince. You saved me a lot of time and effort.
__________________
Check out my wiki page
2KY is offline   Reply With Quote
Old 23/07/2015, 01:37 AM   #20
TenTen
Big Clucker
 
TenTen's Avatar
 
Join Date: Jul 2015
Posts: 196
Reputation: 4
Default Re: Saving weapon data (MySQL)

Great job Vince
TenTen 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
The problem with saving data in mysql. MaySee Scripting Help 3 22/07/2013 11:10 AM
MySQL saving Data yanir3 Scripting Help 5 24/06/2013 07:27 PM
Mysql Saving Data Stefand Scripting Help 7 07/05/2013 10:42 AM
Problems with MySQL data saving sobolanux Help Archive 0 22/04/2011 02:54 PM
Not saving to ini file (Weapon Data) Robbin237 Help Archive 5 02/05/2009 10:02 AM


All times are GMT. The time now is 03:12 AM.


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