[Include] Useful Functions v1.0 (MySQL)
#1

Useful Functions v1.0
Based on MySQL
Introduction
Useful functions is based on MySQL, wich uses just functions, no queries. It gots 10 functions, based on a log that can be activated and dezactivated, with them you can set all what you need, by strings.
Theres nothing copied, all these fuctions are made from scratch. The author is PAWN++ Team (Romania), we usually make scripts for money, this is a free script.

Features
Using the following systems and plugins.
  • [REL] MySQL Plugin (R7 released) - Used for the DataBase (extracting/setting/deleting) *recommanded.
  • Wampp Server or Xampp - Used for edit the DataBase *recommanded.
Functions
  • MySQL_Log (bool:active = true)
    Код:
    bool active    - To activate choose true and to deactivate choose false.
  • MySQL_SetInt(char var[], int is, char where[], char condition[], char table[])
    Код:
    char var       - The table wich will be set.
    int is         - The number that will be set in the 'var'.
    char where     - Where it will be set.
    char condition - The condition to be set.
    char table     - The table with the information.
    Returns with 1.
  • MySQL_SetFloat(char var[], Float:is, char where[], char condition[], char table[])
    Код:
    char var       - The table wich will be set.
    float is       - The float that will be set in the 'var'.
    char where     - Where it will be set.
    char condition - The condition to be set.
    char table     - The table with the information.	
    Returns with 1.
  • MySQL_SetString(char var[], char is[], char where[], char condition[], char table[])
    Код:
    char var       - The table wich will be set.
    char is        - The float that will be set in the 'var'.
    char where     - Where it will be set.
    char condition - The condition to be set.
    char table     - The table with the information.	
    Returns with 1.
  • MySQL_GetFloat(char selected[], char var[], char condition[], char table[])
    Код:
    char selected  - The table from where it will be take.
    char var       - The row from where it will be take.
    char condition - The condition to be take
    char table     - The table with the information.
    Returns with the extracted float variable.
  • MySQL_GetInt(char selected[], char var[], char condition[], char table[])
    Код:
    char selected  - The table from where it will be take.
    char var       - The row from where it will be take.
    char condition - The condition to be take
    char table     - The table with the information.
    Returns with the extracted integer variable.
  • MySQL_GetString(char selected[], char var[], char condition[], char table[])
    Код:
    char selected  - The table from where it will be take.
    char var       - The row from where it will be take.
    char condition - The condition to be take
    char table     - The table with the information.
    Returns with the extracted string variable.
  • MySQL_Delete(char var[], char condition[], char table[])
    Код:
    char var       - The table from where it will be deleted.
    char condition - The condition to delete the row.
    char table     - The table with the information.
    Returns with 1.
  • MySQL_Count(char get[], char table[])
    Код:
    char get       - The table where the rows will be counted.
    char table     - The table with the information.
    Returns with number of rows
  • MySQL_If(char var[], char condition[], char table[])
    Код:
    char var       - The table wich will be rerified.
    char condition - The row will be take with a condition.
    char table     - The table with the information.
    Returns 0 if it exists or 1 if it doesen`t exists.
Install

1. Place it to the top of the script:

pawn Код:
#include <useful_functions>
2. Add these defines and fill them:

pawn Код:
#define PAWN_HOST "" // The IP of the server
#define PAWN_USER "" // The user of the server
#define PAWN_PASSWORD "" // The password of the server
#define PAWN_DATABASE "" // The name of the DataBase
2. Add the folder 'UF' with 'log.ini' in the directory scriptfiles.

Examples
  • MySQL_Log
    pawn Код:
    public OnGameModeInit()
    {
        MySQL_Log ( true );
        return 1;
    }
  • MySQL_SetInt
    pawn Код:
    YCMD:setint ( playerid, params[], help )
    {
        new
            giveplayerid,
            where [ 25 ],
            value;

        if ( sscanf ( params, "us[25]i", giveplayerid, where, value ) ) return SendClientMessage ( playerid, 0xFFFFFFAA, "{C8C8C8}USE: {FFFFFF}/setint (PartOfName/playerid) (where) (value)");

        MySQL_SetInt ( where, value, "username", GetName ( giveplayerid ), "players" );
        return 1;
    }
  • MySQL_SetFloat
    pawn Код:
    YCMD:setfloat ( playerid, params[], help )
    {
        new
            giveplayerid,
            where [ 25 ],
            Float:value;

        if ( sscanf ( params, "us[25]f", giveplayerid, where, value ) ) return SendClientMessage ( playerid, 0xFFFFFFAA, "{C8C8C8}USE: {FFFFFF}/setint (PartOfName/playerid) (where) (value)");

        MySQL_SetInt ( where, value, "username", GetName ( giveplayerid ), "players" );
        return 1;
    }
  • MySQL_SetString
    pawn Код:
    YCMD:setstring ( playerid, params[], help )
    {
        new
            giveplayerid,
            where [ 25 ],
            value [ 100 ];

        if ( sscanf ( params, "us[25]s[100]", giveplayerid, where, value ) ) return SendClientMessage ( playerid, 0xFFFFFFAA, "{C8C8C8}USE: {FFFFFF}/setint (PartOfName/playerid) (where) (value)");

        MySQL_SetInt ( where, value, "username", GetName ( giveplayerid ), "players" );
        return 1;
    }
  • MySQL_GetFloat
    pawn Код:
    YCMD:playerpos ( playerid, params[], help )
    {
        new
            name    [ 21 ],
            X,
            Y,
            Z;

        if ( sscanf ( params, "s[21]", name ) ) return SendClientMessage ( playerid, 0xFFFFFFAA, "{C8C8C8}USE: {FFFFFF}/playerpos (CompleteName)");

        X = MySQL_GetFloat( "cordX", name, "username", "players" );
        Y = MySQL_GetFloat( "cordY", name, "username", "players" );
        Z = MySQL_GetFloat( "cordZ", name, "username", "players" );
        printf ( "Name: %s, X: %f Y: %f Z:%f", name, x, y, z );
        return 1;
    }
  • MySQL_GetInt
    pawn Код:
    YCMD:adminlevel ( playerid, params[], help )
    {
        new
            name    [ 21 ],
            level;

        if ( sscanf ( params, "s[21]", name ) ) return SendClientMessage ( playerid, 0xFFFFFFAA, "{C8C8C8}USE: {FFFFFF}/playerpos (CompleteName)");

        level = MySQL_GetInt( "admin", name, "username", "players" );
        printf ( "Name: %s, Admin Level: %i, name, level );
        return 1;
    }
  • MySQL_GetString
    pawn Код:
    YCMD:playerpass ( playerid, params[], help )
    {
        new
            name    [ 21 ],
            password [ 50 ];

        if ( sscanf ( params, "s[21]", name ) ) return SendClientMessage ( playerid, 0xFFFFFFAA, "{C8C8C8}USE: {FFFFFF}/playerpos (CompleteName)");

        format ( password, 50, "%s", MySQL_GetString( "password", name, "username", "players" ) );
        printf ( "Name: %s, Password: %s, name, password );
        return 1;
    }
  • MySQL_Count
    pawn Код:
    public OnGameModeInit ( )
    {
        printf ( "There are %d accounts.", MySQL_Count ( "*", "players" ) );
        printf ( "There are %d bans.", MySQL_Count ( "*", "banlist" ) );
        return 1;
    }
  • MySQL_If
    pawn Код:
    public OnPlayerConnect ( playerid )
    {
        if ( MySQL_If ( "*", "username", GetName ( playerid ), "players" ) == 0 )
        {
            SendClientMessage ( playerid, 0xFFFFFFAA, "{C8C8C8}Welcome back.");
        } else return SendClientMessage ( playerid, 0xFFFFFFAA, "{C8C8C8}You don't have an account.");
        return 1;
    }
Bugs

We found no bug, if you find a bug, please contact us.

Author: PAWN++ Team
Credits: BlueG, Spookie
Download: Click
Password: pawnteam
Help: If you want to help us, send me a Private Message.

PAWN++
  • Armyw0w (Romania) - Founder
  • Alyn (Romania) - Founder
  • WaLLy (Romania) - Member
  • Spookie (Romania) - Member
* We are sorry for that we missed to place the File Password, thanks for understanding.
Thanks.
Reply
#2

Good job
Reply
#3

Great job!
Reply
#4

This is pointless and ruins the efficiency with MySQL.

Look at BUD and see how Slice does it - you can save multiple variables at once and you still maintain efficient code. This is like the DINI of MySQL.
Reply
#5

Calgon, theres no need for the INC to be advanced, a lot of people want to use MySQL but don`t know how. Maybe in the next version the it will be more advanced.
Reply
#6

There's always a need for efficiency, especially with SA-MP and MySQL. You're encouraging use of bad methods.
Reply
#7

Thanks.Useful for newbie:d
Reply
#8

This is extremely useful.
Reply
#9

Calgo, we don`t think that it is a Bad Method and about the Difficulty of the INC, we made this especally for newbies, we never wanted to say that BUD or any other INC is worse than our, we said that our INC is better for someone that doesen`t know what MySQL means, but wants to learn it.
Reply
#10

Quote:
Originally Posted by Spookie98
Посмотреть сообщение
Calgo, we don`t think that it is a Bad Method and about the Difficulty of the INC, we made this especally for newbies, we never wanted to say that BUD or any other INC is worse than our, we said that our INC is better for someone that doesen`t know what MySQL means, but wants to learn it.
I'm not saying the idea of the include is a bad idea - I'm sure it's very useful to newbies. But you don't use the most efficient methods to save data (or to load it), which you really should if you're encouraging newbies to use it. Those who base their scripts on this will have hell in the future.

Consider using caching, threading and functions with support for multiple parameters.

Take a look at BUD - https://sampforum.blast.hk/showthread.php?tid=187720 - there's multiSet and multiGet, for roleplay servers, there's on average probably around 100-200 fields for each player, that's 200 select queries just to login, then 200 to save everything. If you made a function like multiSet or multiGet, the code would be a lot more efficient, you could reduce those queries by much more than half.
Reply
#11

Dear Calgon, we`re sure that the INC can be much better, be sure that we`ll improve it in the future, if the newbies will use this include they should keep an eye on this Topic, there will be more updates in the future.


Pawn++ School Member,
Spookie
Reply
#12

Very nice release!

5/5!
Reply
#13

Thanks for all comments ! Waiting for more comments out here
Reply
#14

Password added. Sorry for that.
Reply
#15

Why is this called "useful functions"? Very misleading..
Reply
#16

Calgon was pointing out how he could make his script more efficient and then actually showed him how he could improve his code a little bit more so this isn't directed at him completely, but Slice comes along and posts a totally un-necessarily comment.

Didn't realize how cocky high-rollers were on this forum, forgetting the fact that most of the stuff posted in the filterscripts section of this forum is all noob created for noob use.

Besides, most here only think they know Pawn because they could script a "really efficient server", when in actuality if it came to it wouldn't be able to do anything else with the language.

Not to mention years ago, you were in the same exact shoes as this guy, because we all start somewhere.

Back to on-topic: Keep up the good work!
Reply
#17

@TheLazySloth thanks a lot ! We respect both, Slice and Calgo, and you too. Everyone can post his opinnion about our work. About Slice`s post, @Slice, its called Useful Functions because you are not using Queries anymore, so it makes MySql much easy for begginers. Thats the reason for Useful Functions title.

And one more time thanks @TheLazySloth for his pozitive comment. We`ll keep up the good work, I think that I`m going to release my first FS out here..Keep on eye on me too.
Reply
#18

Quote:
Originally Posted by TheLazySloth
Посмотреть сообщение
Calgon was pointing out how he could make his script more efficient and then actually showed him how he could improve his code a little bit more so this isn't directed at him completely, but Slice comes along and posts a totally un-necessarily comment.

Didn't realize how cocky high-rollers were on this forum, forgetting the fact that most of the stuff posted in the filterscripts section of this forum is all noob created for noob use.
His choice of name for this release was bad, and someone had to point that out. Being mildly critical isn't nearly the same as being cocky.

Quote:
Originally Posted by TheLazySloth
Посмотреть сообщение
Besides, most here only think they know Pawn because they could script a "really efficient server", when in actuality if it came to it wouldn't be able to do anything else with the language.
Who's that comment aimed at? I'm pretty sure both Calgon and I know how to "do anything else with the language".

Quote:
Originally Posted by TheLazySloth
Посмотреть сообщение
Not to mention years ago, you were in the same exact shoes as this guy, because we all start somewhere.
Yes, and I'm glad of all the mild/moderate criticism I was given. It made me improve.

More off-topic: Who pissed in your cereal this morning?

Back on-topic:

Quote:
Originally Posted by Spookie98
Посмотреть сообщение
About Slice`s post, @Slice, its called Useful Functions because you are not using Queries anymore, so it makes MySql much easy for begginers. Thats the reason for Useful Functions title.
Perhaps "Useful MySQL Functions" would be a better pick.

Also, you should use mysql_real_escape_string on all strings coming from outside the script. Your script currently has some very bad security flaws.
Reply
#19

Thanks for the mysql_real_escape_String suggestion, maybe in the next version. And now, be serios,where is the difference bettwen Useful Functions (MySQL) and Useful MySql Functions ? Theres just placement difference. Please think twice before posting.
Reply
#20

I assumed that the name of this release is what's big and orange on the first page.
Reply


Forum Jump:


Users browsing this thread: 4 Guest(s)