SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Filterscripts > Includes

Reply
 
Thread Tools Display Modes
Old 22/07/2011, 12:17 AM   #1
[HiC]TheKiller
High-roller
 
Join Date: Mar 2008
Location: New Zealand
Posts: 3,075
Reputation: 406
Default Tksave - Easy SQLite saving for players

TKsave

Introduction
This is a really basic include just to show you how useful SQLite can be. Information saves into a database and can be used easier for web files . I'm not going to make one of those "This is very efficient topic" because it's probably not as fast as most file saving systems.

How do I install this?
1. Put the include in your server directory -> Pawno -> includes
2. Add this to the top of your script
pawn Code:
#include <tksave>

Functions

pawn Code:
/*
native sql_setplayerdata(playerid, field[], data[]); -  Sets a player's data (string)
native sql_isplayerindb(playerid); - Checks if a player is in the database
native sql_getplayerdata(playerid, field[]); - Gets a player's data (string)
native sql_getplayerint(playerid, field[]); - Gets a player int from the database
native sql_getplayerfloat(playerid, field[]); // Gets a player's float from the database
native sql_setplayerfloat(playerid, field[], Float:data); - Set's a players float (could be used for a position)
native sql_setplayerint(playerid, field[], data); // Sets a players int (Could be used for money or admin lvl)
native sql_addfield(field[], type, MAXSIZE); - Add a table field such as password (Type 0 = Number, Type 1 = String, Type 2 = Float)
native sql_getusercount(); // Get the amount of users registered
native sql_inittable(); // Set's up the database / table (Only need to use this once but it won't make a difference if you leave it there)
native sql_open(sql[]); //Opens a SQL database (Chose a name for your database). This must be above everything on OnGameModeInit or OnFilterScriptInit. You must add .db on the end!
native sql_close(sql[]); //Closes the database, this is to be used on OnGameModeInit or OnFilterScriptInit. You must add .db on the end!
*/

Example

Saving a players position on Disconnect then loading it on OnPlayerSpawn.
pawn Code:
public OnFilterScriptInit()
{
    sql_open("database.db");
    sql_inittable();
    sql_addfield("X", 2, 50);
    sql_addfield("Y", 2, 50);
    sql_addfield("Z", 2, 50);
    return 1;
}

public OnFilterScriptExit()
{
    sql_close("database.db");
    return 1;
}

public OnPlayerDisconnect(playerid, reason)
{
    new Float:X, Float:Y, Float:Z;
    sql_setplayerfloat(playerid, "X", X);
    sql_setplayerfloat(playerid, "Y", Y);
    sql_setplayerfloat(playerid, "Z", Z);
    return 1;
}

public OnPlayerSpawn(playerid)
{
    if(sql_isplayerindb(playerid))
    {
        SetPlayerPos(playerid, sql_getplayerfloat(playerid, "X"), sql_getplayerfloat(playerid, "Y"), sql_getplayerfloat(playerid, "Z"));
    }
    return 1;
}

Download
HERE

Any bugs, post them here .
__________________
People seem to enjoy negitive repping me for topics that I made in 2009.
Therefore, if you want to view my releases, you can go here.

Skype: TheKiller@dr.com
I do NOT script for cash. Add me on MSN if you need help with small issues.
[HiC]TheKiller is offline   Reply With Quote
Old 22/07/2011, 12:21 AM   #2
willsuckformoney
High-roller
 
willsuckformoney's Avatar
 
Join Date: Dec 2009
Posts: 1,505
Reputation: 65
Default Re: Tksave - Easy SQLite saving for players

Nice, I could use it when I start to learn SQlite * MySQL.
__________________
Fuck the system.
willsuckformoney is offline   Reply With Quote
Old 22/07/2011, 12:25 AM   #3
The_$
Little Clucker
 
Join Date: Feb 2011
Posts: 20
Reputation: 0
Default Re: Tksave - Easy SQLite saving for players

Again very nice work TheKiller...
I love your scripts . It very usefull for SQL beginner's like me.

// Edit - Can someone make a example i get to many error's
The_$ is offline   Reply With Quote
Old 22/07/2011, 12:36 AM   #4
[HiC]TheKiller
High-roller
 
Join Date: Mar 2008
Location: New Zealand
Posts: 3,075
Reputation: 406
Default Re: Tksave - Easy SQLite saving for players

Quote:
Originally Posted by The_$ View Post
Again very nice work TheKiller...
I love your scripts . It very usefull for SQL beginner's like me.

// Edit - Can someone make a example i get to many error's
Updated with a example!

EDIT: Found a little typo, fixed it though.
__________________
People seem to enjoy negitive repping me for topics that I made in 2009.
Therefore, if you want to view my releases, you can go here.

Skype: TheKiller@dr.com
I do NOT script for cash. Add me on MSN if you need help with small issues.
[HiC]TheKiller is offline   Reply With Quote
Old 22/07/2011, 03:17 AM   #5
RealCop228
Godfather
 
Join Date: Feb 2010
Location: Springboro, OH
Posts: 8,268
Reputation: 670
Default Re: Tksave - Easy SQLite saving for players

I just noticed this. It looks pretty good man! I'm glad to see you active again.
__________________
Putting [URGENT] in the thread title stops me from opening the thread. Nobody else's problem on this forum is more important that another person's. Try not to be self-centered!
RealCop228 is offline   Reply With Quote
Old 22/07/2011, 03:44 AM   #6
PCheriyan007
Huge Clucker
 
Join Date: May 2010
Location: in hiding
Posts: 305
Reputation: 6
Default Re: Tksave - Easy SQLite saving for players

I'm not sure but is there something like this for MySQL? I'm thinking about doing a dynamic player stats signature and AFAIK, SQLite only works if the server and the website are on the same box.
__________________

Code:
[Filterscripts]
Nothing So Far
[Tutorials]
How to use SQLite (by Zh3r0)
How to stream Shoutcast to your server
[Current Project]
[DR]Drifting Roaches (Server)
PCheriyan007 is offline   Reply With Quote
Old 22/07/2011, 03:49 AM   #7
RealCop228
Godfather
 
Join Date: Feb 2010
Location: Springboro, OH
Posts: 8,268
Reputation: 670
Default Re: Tksave - Easy SQLite saving for players

Quote:
Originally Posted by PCheriyan007 View Post
I'm not sure but is there something like this for MySQL? I'm thinking about doing a dynamic player stats signature and AFAIK, SQLite only works if the server and the website are on the same box.
You can always set up an FTP connection to update the SQLite database whenever changes are made.
__________________
Putting [URGENT] in the thread title stops me from opening the thread. Nobody else's problem on this forum is more important that another person's. Try not to be self-centered!
RealCop228 is offline   Reply With Quote
Old 22/07/2011, 04:20 AM   #8
[HiC]TheKiller
High-roller
 
Join Date: Mar 2008
Location: New Zealand
Posts: 3,075
Reputation: 406
Default Re: Tksave - Easy SQLite saving for players

Quote:
Originally Posted by PCheriyan007 View Post
I'm not sure but is there something like this for MySQL? I'm thinking about doing a dynamic player stats signature and AFAIK, SQLite only works if the server and the website are on the same box.
It's really easy to just change it. All you really need to do is add a few params + the function name. I'll make that later :P.
__________________
People seem to enjoy negitive repping me for topics that I made in 2009.
Therefore, if you want to view my releases, you can go here.

Skype: TheKiller@dr.com
I do NOT script for cash. Add me on MSN if you need help with small issues.
[HiC]TheKiller is offline   Reply With Quote
Old 22/07/2011, 04:20 AM   #9
Igorek
Big Clucker
 
Igorek's Avatar
 
Join Date: Oct 2010
Posts: 105
Reputation: 41
Default Re: Tksave - Easy SQLite saving for players

good work...
Thanks.
Igorek is offline   Reply With Quote
Old 22/07/2011, 10:55 AM   #10
xkirill
High-roller
 
xkirill's Avatar
 
Join Date: May 2011
Location: In a box infront of your house stealing your WiFi
Posts: 2,513
Reputation: 289
Default Re: Tksave - Easy SQLite saving for players

like it
i will use it 100%
thanks!
__________________
KrustyGames.com
Above The Earth - Fatty Boom Boom [Metal]
"by rating your skills, you're limiting yourself." - Kaperstone
xkirill is online now   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
[Tutorial] Top x players using sqlite cessil Tutorials 11 06/10/2013 09:43 AM
[FilterScript] Temporary banning (SQLite) - Easy to use and it works! __ Filterscripts 17 27/03/2013 07:35 PM
Help with Saving/Loading Player Positions. EASY ricardo178 Help Archive 21 21/06/2011 05:38 PM
[HELP] sqlite saving in FS bugs other FS's? <Weponz> Help Archive 0 31/12/2010 04:34 PM
[EASY] Check Players leaving an area Trooper[Y] Help Archive 1 21/04/2009 03:23 PM


All times are GMT. The time now is 07:16 PM.


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