SA-MP Forums

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

Reply
 
Thread Tools Display Modes
Old 17/11/2013, 10:46 AM   #1
Voxel
Gangsta
 
Voxel's Avatar
 
Join Date: Sep 2013
Location: The Netherlands
Posts: 578
Reputation: 70
Default Simple SQLite Commands/Features

Simple SQLite Commands/Features
By Voxel

Info:
Hello fella's,

So in my previous topic i posted a SQL base starting script and you can view it here:
http://forum.sa-mp.com/showthread.php?t=476204

I decided to make a tutorial to explain how to make simple SQL commands such as /givemoney or /setscore, /setkills etc. This can be very helpfull to administrate your server.
Lets get started shall we?

Tutorial:

First things first, i reccomend you use my filterscript to follow this tutorial, or if you can convert it to your variables then thats fine aswell.

1. A cash test command
First we will make a command that tests if your money saving is working properly.
(note that i am using ZCMD)
pawn Code:
CMD:cashtest(playerid, params[]) //the command
{
    User[playerid][USER_MONEY] += 1000000;
    //User can also be pInfo and USER_MONEY can be pMoney (depends on what you set)
    GivePlayerMoney(playerid, 1000000);
    //gives the player the in-game money wich is then stored in the database (at USER_MONEY)
    return 1;
}
2. /setkills command
Second we will make a command that will change the kills value in your database.
pawn Code:
CMD:setkills(playerid, params[])
{
    if(User[playerid][USER_ADMIN] >= 5)
   //we check if the user is admin level 5 or higher
    {
        new targetid ,amount;
        if(sscanf(params, "ud", targetid, amount)) return  SendClientMessage(playerid, COL_WHITE, "/setkills [playerid] [kills]");
        if(!IsPlayerConnected(targetid)) return SendClientMessage(playerid, COL_WHITE, "Player is not online");

        User[playerid][USER_KILLS] = amount;
        //gets the variable amount and sets it to the entered value, so /setkills [id] [value = amount]
    }
    else
    {
        SendClientMessage(playerid, COL_RED, "You are not a administrator!");
    }
    return 1;
}
3. /setdeaths command
This is basicly the same as /setkills only we change the database info from USER_KILLS to USER_DEATHS and we change the command params to /setdeaths [playerid] [deaths]
pawn Code:
CMD:setdeaths(playerid, params[])
{
    if(User[playerid][USER_ADMIN] >= 5)
   //we check if the user is admin level 5 or higher
    {
        new targetid ,amount;
        if(sscanf(params, "ud", targetid, amount)) return  SendClientMessage(playerid, COL_WHITE, "/setdeaths [playerid] [deaths]");
        if(!IsPlayerConnected(targetid)) return SendClientMessage(playerid, COL_WHITE, "Player is not online");

        User[playerid][USER_DEATHS] = amount;
        //gets the variable amount and sets it to the entered value, so /setdeaths [id] [value = amount]
    }
    else
    {
        SendClientMessage(playerid, COL_RED, "You are not a administrator!");
    }
    return 1;
}
4. /setscore command
As fourth we make a /setscore command to set the players score to the desired value, again you use the same functions as you do with kills and deaths
pawn Code:
CMD:setscore(playerid, params[])
{
    if(User[playerid][USER_ADMIN] >= 5)
   //we check if the user is admin level 5 or higher
    {
        new targetid ,amount;
        if(sscanf(params, "ud", targetid, amount)) return  SendClientMessage(playerid, COL_WHITE, "/setscore [playerid] [score]");
        if(!IsPlayerConnected(targetid)) return SendClientMessage(playerid, COL_WHITE, "Player is not online");

        User[playerid][USER_SCORE] = amount;
        //gets the variable amount and sets it to the entered value, so /setscore [id] [value = amount]
    }
    else
    {
        SendClientMessage(playerid, COL_RED, "You are not a administrator!");
    }
    return 1;
}
5. /givemoney command
Now we will make a /givemoney command to give the player money on top of his already set value with a limit so it cannot be abused
pawn Code:
CMD:givemoney(playerid, params[])
{
    if(User[playerid][USER_ADMIN] >= 5)
    //we check if the user is admin level 5 or higher
    {
        new targetid, amount;
        if(sscanf(params, "ud", targetid, amount)) return  SendClientMessage(playerid, COL_WHITE, "/givemoney [playerid] [money]");
        if(!IsPlayerConnected(targetid)) return SendClientMessage(playerid, COL_WHITE, "Player is not online");
        if(amount < 0 || amount > 30000) return SendClientMessage(playerid, COL_WHITE, "You can only give a maximum amount of $30 000");
        //here we check if the user types a amount between 0 and 30000, if he exceeds this value he will recieve a message that he can only give a maximum of 300000

        User[playerid][USER_MONEY] += amount;
        //here we get the value of the givin amount again but this time we put: plus and equal
        GivePlayerMoney(playerid, amount);
        //and finally we give the player the amount (value) that we put in our params of the command!
    }
    else
    {
        SendClientMessage(playerid, COL_RED, "You are not a administrator!");
    }
    return 1;
}
6. /setadmin command
And finally we will need to set a players admin rank!
pawn Code:
CMD:setadmin(playerid,params[])
{
    if(User[playerid][USER_ADMIN] >= 6 || IsPlayerAdmin(playerid))
    //we check if he has the maximum admin rank or if he is a rcon admin
    {
        new targetid, level;
        if(sscanf(params, "ud", targetid, level)) return  SendClientMessage(playerid, COL_WHITE,"/setadmin [playerid] [level]");
        if(!IsPlayerConnected(targetid)) return SendClientMessage(playerid, COL_WHITE, "Player is not online");
        if(level < 0 || level > 6) return SendClientMessage(playerid, COL_WHITE, "You can only set admin levels from 1 to 6!");
        //we check if he enters a value between 0 and 6 otherwise he will get a error saying only admin levels between 1 and 6.

        User[targetid][USER_ADMIN] = level;
        //we set the variable level to the value we gave in the params and it saves it in the database
    }
    else
    {
        SendClientMessage(playerid, COL_RED, "You are not a administrator!");
    }
    return 1;
}
I hope you guys understand this and good luck with your SQLite database!
__________________
My Work:
[GameMode]The Nether Survival
[Filterscript]SQLite Database Start
[Tutorial]SQLite Commands
[Tutorial]Loot/ Inventory System
[Tutorial]Simple Hunger/Thirst System
[Tutorial]Converting Binary
[Map]Tropical Island + Pier
[Map]San Fierro Apocalypse

Last edited by Voxel; 07/12/2013 at 04:46 PM.
Voxel is offline   Reply With Quote
Old 07/12/2013, 10:02 AM   #2
TahaAsif12
Huge Clucker
 
Join Date: Nov 2013
Posts: 268
Reputation: 23
Default Re: Simple SQL Commands/Features

Very Good
__________________
TahaAsif12 is offline   Reply With Quote
Old 07/12/2013, 11:49 AM   #3
Voxel
Gangsta
 
Voxel's Avatar
 
Join Date: Sep 2013
Location: The Netherlands
Posts: 578
Reputation: 70
Default Re: Simple SQL Commands/Features

Quote:
Originally Posted by TahaAsif12 View Post
Very Good
Thank you!
__________________
My Work:
[GameMode]The Nether Survival
[Filterscript]SQLite Database Start
[Tutorial]SQLite Commands
[Tutorial]Loot/ Inventory System
[Tutorial]Simple Hunger/Thirst System
[Tutorial]Converting Binary
[Map]Tropical Island + Pier
[Map]San Fierro Apocalypse
Voxel is offline   Reply With Quote
Old 07/12/2013, 11:52 AM   #4
Tomix
Big Clucker
 
Join Date: Apr 2013
Posts: 128
Reputation: -3
Default Re: Simple SQL Commands/Features

Thank you voxel very much
Tomix is offline   Reply With Quote
Old 07/12/2013, 01:45 PM   #5
iJumbo
High-roller
 
iJumbo's Avatar
 
Join Date: Sep 2009
Location: HEX 69 74 61 6C 79
Posts: 2,175
Reputation: 136
Default Re: Simple SQL Commands/Features

Well you can't call them "SQL commands"(Commands with SQL) becouse you do not perform any query in that commands.. they are just script that change some variables..


EDIT: Anyway forgot to say.. good
__________________

Need a VPS? Get it here!
Website designer & developer php, html, css, html5, javascript
iJumbo is offline   Reply With Quote
Old 07/12/2013, 03:42 PM   #6
BigETI
Banned
 
Join Date: Mar 2010
Location: Germany
Posts: 1,046
Reputation: 359
Default AW: Simple SQL Commands/Features

This has nothing to do with SQL at all.
http://en.wikipedia.org/wiki/SQL
BigETI is offline   Reply With Quote
Old 07/12/2013, 04:44 PM   #7
Voxel
Gangsta
 
Voxel's Avatar
 
Join Date: Sep 2013
Location: The Netherlands
Posts: 578
Reputation: 70
Default Re: Simple SQL Commands/Features

Quote:
Originally Posted by iJumbo View Post
Well you can't call them "SQL commands"(Commands with SQL) becouse you do not perform any query in that commands.. they are just script that change some variables..


EDIT: Anyway forgot to say.. good
Thank you!
Quote:
Originally Posted by BigETI View Post
This has nothing to do with SQL at all.
http://en.wikipedia.org/wiki/SQL
Nothing to do with SQL at all? please... you obviously need a SQLite database to use these commands.
You dont always have to be such a wiseacre.

Anyway thanks for the replies!
__________________
My Work:
[GameMode]The Nether Survival
[Filterscript]SQLite Database Start
[Tutorial]SQLite Commands
[Tutorial]Loot/ Inventory System
[Tutorial]Simple Hunger/Thirst System
[Tutorial]Converting Binary
[Map]Tropical Island + Pier
[Map]San Fierro Apocalypse
Voxel is offline   Reply With Quote
Old 07/12/2013, 04:51 PM   #8
nickdodd25
Huge Clucker
 
nickdodd25's Avatar
 
Join Date: Jan 2012
Location: Unknown
Posts: 448
Reputation: 114
Default Re: Simple SQL Commands/Features

Quote:
Originally Posted by Voxel View Post
Thank you!

Nothing to do with SQL at all? please... you obviously need a SQLite database to use these commands.
You dont always have to be such wiseacre.

Anyway thanks for the replies!
You must be missing some code or something there is no query functions or anything related to SQLite in your tutorial....or did you confuse sscanf with SQLite?
__________________
Nick
nickdodd25 is offline   Reply With Quote
Old 07/12/2013, 04:52 PM   #9
Vince
Spam Machine
 
Vince's Avatar
 
Join Date: Sep 2007
Location: Belgium
Posts: 10,067
Reputation: 2660
Default Re: Simple SQL Commands/Features

Quote:
Originally Posted by Voxel View Post
you obviously need a SQLite database to use these commands.
There's nothing obvious about that. BigETI makes a valid point. There is no reference to any saving or loading anywhere in your tutorial whatsoever. Might as well work with plain text files.
__________________
Vince is offline   Reply With Quote
Old 07/12/2013, 04:57 PM   #10
Voxel
Gangsta
 
Voxel's Avatar
 
Join Date: Sep 2013
Location: The Netherlands
Posts: 578
Reputation: 70
Default Re: Simple SQL Commands/Features

Quote:
Originally Posted by nickdodd25 View Post
You must be missing some code or something there is no query functions or anything related to SQLite in your tutorial....or did you confuse sscanf with SQLite?
I'm not missing any code and I don't really understand why everyone is making such a big deal out of it.
I made a tutorial on how to manage and change you'r SQLite database using these commands.
As I said it obviously has to do with the SQLite since its detecting if you are a specific admin level and then change a specific value IN the SQLite database.

Yes I understand that i'm not changing any query's or anything like that but the fact that people say it has nothing to do with SQLite is just invalid (atleast in my opinion).

And if you guys would just think for a minut and read the info you would know why i made this tutorial and what for.
Quote:
Originally Posted by Vince View Post
There is no reference to any saving or loading anywhere in your tutorial whatsoever.
With these commands you change and save the set value to the sqlite database

This tutorial was made for my SQLite filterscript:
http://forum.sa-mp.com/showthread.ph...76#post2785276
__________________
My Work:
[GameMode]The Nether Survival
[Filterscript]SQLite Database Start
[Tutorial]SQLite Commands
[Tutorial]Loot/ Inventory System
[Tutorial]Simple Hunger/Thirst System
[Tutorial]Converting Binary
[Map]Tropical Island + Pier
[Map]San Fierro Apocalypse
Voxel 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
[FilterScript] Essentials [Standard server commands, new features] Sellize Filterscripts 8 28/03/2013 04:37 PM
[FilterScript] J_Admin V0.1 ~*more* UserFriendly~*more* Commands[y_ini, zcmd][Many features] Jarnu Filterscripts 14 06/12/2012 09:01 AM
[FilterScript] NRank V1.1 | 10+ Commands | 2nd Release | Full Of Features | Much More Nirzor Filterscripts 5 28/11/2012 06:59 AM


All times are GMT. The time now is 02:33 PM.


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