[Include] Tksave - Easy SQLite saving for players
#1

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 Код:
#include <tksave>
Functions

pawn Код:
/*
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 Код:
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 .
Reply
#2

Nice, I could use it when I start to learn SQlite * MySQL.
Reply
#3

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
Reply
#4

Quote:
Originally Posted by The_$
Посмотреть сообщение
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.
Reply
#5

I just noticed this. It looks pretty good man! I'm glad to see you active again.
Reply
#6

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.
Reply
#7

Quote:
Originally Posted by PCheriyan007
Посмотреть сообщение
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.
Reply
#8

Quote:
Originally Posted by PCheriyan007
Посмотреть сообщение
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.
Reply
#9

good work...
Thanks.
Reply
#10

like it
i will use it 100%
thanks!
Reply
#11

Slice made something like this, but more advanced. The BUD(Blazing User Database) system.

Gratz on it!
Reply
#12

Well done. I'm sure I'll use this.
Reply
#13

JIZZZZ

Nice job, looks really hot after I saw the functions <3
Reply
#14

Quote:
Originally Posted by [HiC]TheKiller
Посмотреть сообщение
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.
Well I'll be definitely waiting for that release
Reply
#15

Well done!!!!
Reply
#16

This is pretty cool. I think i'll be using this for the community project, since it's pretty straight forward and simple to use.
Reply
#17

This realy helps me out thanks!
one question;

if i try creating a vehicle from the database this way;
pawn Код:
CreateVehicle(sql_getplayerfloat(playerid,"model"),sql_getplayerfloat(playerid,"X"),sql_getplayerfloat(playerid,"Y"),sql_getplayerfloat(playerid,"Z"),sql_getplayerfloat(playerid,"A"),5, 5,500);
I get a warning: tag mismatch...however, if i replace de model with a vehicle number it does work so its just this part sql_getplayerfloat(playerid,"model") ..any ideas how to fix ?
Reply
#18

Dead link...i want it please...
Reply
#19

Quote:
Originally Posted by Adi007
Посмотреть сообщение
Dead link...i want it please...
This thread is from 2012!! How would you even find it. There are better systems these days. Not to mention this completely ignores normalisation. Why does everyone just use mysql/sql as a storage system without realizing it is a modular system with it's own language and should be considered just if not equally as important than the gamemode itself!

https://sampforum.blast.hk/showthread.php?tid=303682

https://sampforum.blast.hk/showthread.php?tid=187720

There, use those two systems. Remember it also ignores normalisation.. but I doubt most of you even care about proper usage anyway.
Reply
#20

Download link?
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)