[Tutorial] Simple SQL Commands/Features
#1

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:
https://sampforum.blast.hk/showthread.php?tid=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 Код:
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 Код:
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 Код:
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 Код:
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 Код:
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 Код:
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!
Reply
#2

Very Good
Reply
#3

Quote:
Originally Posted by TahaAsif12
Посмотреть сообщение
Very Good
Thank you!
Reply
#4

Thank you voxel very much
Reply
#5

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

This has nothing to do with SQL at all.
http://en.wikipedia.org/wiki/SQL
Reply
#7

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

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

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

Quote:
Originally Posted by Voxel
Посмотреть сообщение
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).
We are not making a big deal we are just pointing out the obvious here. If this is meant to be a sql tutorial why not add in some querys and such or use that fs that you linked to in the tutorial and show us how to use it with more detail.

And you saying it obviously has to do with SQLite is quite wrong just by looking at the code you have, could be anything from flat-file to mysql. That's why you need to add more info into the tutorial and show some sqlite examples.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)