[Include] C-MySQL. (Advanced MySQL Account Configuration)
#1

Information

Hi, i've been thinking about scripting this for the last few weeks, and finally had time to do so. This is pretty much, dini in MySQL. This is easy to use as long as you understand the parameters and have basic knowledge of creating and setting up a MySQL database.

Compatibility

This can be use with G-StyleZzZ's (C-MySQL.inc) and StrickenKid's (C-MySQL-S.inc) MySQL plugin.
These two plugins can be found at the plugin board. Direct links are below:

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

Example Script - Account System

http://forum.sa-mp.com/showthread.ph...127#post783127

Example Script (StrickenKid's plugin)

The example script comes with the download, but you can view it below:
pawn Код:
#include <a_samp>
#include <zcmd>
#include <sscanf2>
#include <C-MySQL-S>

#define MySQL_HOST ""
#define MySQL_USER ""
#define MySQL_DB ""
#define MySQL_PASSWORD ""
#define ACCOUNT_TABLE ""

public OnGameModeInit() {
    mysql_connect(MySQL_HOST, MySQL_USER, MySQL_PASSWORD, MySQL_DB, 1);
}

CMD:Register(playerid, params[]) {
    new
        Password[55],
        string[138];
    if(sscanf(params, "z[55]", Password)) return SendClientMessage(playerid, 0xFFFFFFF, "<> /register <password>");
    GetPlayerName(playerid, string, 24);
    format(string, 138, "SELECT * FROM %s WHERE Username = '%s'", ACCOUNT_TABLE, string);
    mysql_query(string);
    mysql_store_result();
    if(mysql_num_rows() >= 1) {
        SendClientMessage(playerid, 0xFFFFFFF, "<> You already have a account!");
        mysql_free_result();
                return 1;
    }
    mysql_free_result();
    GetPlayerName(playerid, string, 24);
    CMySQL_Create(string, ACCOUNT_TABLE, "Username");
    CMySQL_Password(string, ACCOUNT_TABLE, "Password", Password);
    CMySQL_SetInt(string, ACCOUNT_TABLE, "Username", "Money", 5000);
    return 1;
}
CMD:Login(playerid, params[]) {
    new
        Password[55],
        string[138];
    if(sscanf(params, "z[55]", Password)) return SendClientMessage(playerid, 0xFFFFFFF, "<> /login <password>");
    if(GetPVarInt(playerid, "Logged") == 1) return SendClientMessage(playerid, 0xFFFFFFF, "<> You're logged already");
    GetPlayerName(playerid, string, 24);
    if(!CMySQL_GetPassword(string, ACCOUNT_TABLE, "Password", Password)) return SendClientMessage(playerid, 0xFFFFFFF, "<> Invalid Password.");
    GivePlayerMoney(playerid, CMySQL_Int(string, ACCOUNT_TABLE, "Username", "Money"));
    SetPVarInt(playerid, "Logged", 1);
    return 1;
}
Why use this?

- Speed.
I'm pretty sure scripters would rather use made functions instead of writing a whole query, and doing all the necessary work.

- Easy
The script is very easy to use, so it shouldn't be a huge problem.

- Password
The passwords, are encrypted, so, don't worry about that security.

Functions (List)

pawn Код:
native CMySQL_Create(Username[], Table[], Field[]);
native CMySQL_Delete(Username[], Table[], Field[]);
native CMySQL_SetInt(Username[], Table[], Field[], FieldValue[], Value);
native CMySQL_Set(Username[], Table[], Field[], FieldValue[], Value[]);
native CMySQL_Int(Username[], Table[], Field[], FieldValue[]);
native CMySQL_Get(Username[], Table[], Field[], FieldValue[]);
native CMySQL_SetFloat(Username[], Table[], Field[], FieldValue[], Float:Value);
native CMySQL_Float(Username[], Table[], Field[], FieldValue[]);
native CMySQL_Password(Username[], Table[], Field[], Value[]);
native CMySQL_GetPassword(Username[], Table[], Field[], Value[]);
native CMySQL_SetUserName(name[], AccountTable[], UserFieldName[], Value[]);
native CMySQL_SetBool(Username[], Table[], Field[], FieldValue[], bool:Value);
native CMySQL_LoadAccount(Username[], Table[], Field[], ThreadID, extraid);
Functions (Explanation)

CMySQL_Create(Username[], Table[], Field[]);
Username - The account username.
Table - The table that stores the account.
Field - The field name you'd like to store the username inside. (Ex:
PHP код:
CMySQL_Create(GetPlayerNameEx(playerid), "Accounts""PUserName"); 
).

MySQL_Delete(Username[], Table[], Field[]);
Username - The account username.
Table - The table that stores the account.
Field - The field name you'd like to get the username from, so it doesn't delete a invalid field.

CMySQL_SetInt(Username[], Table[], Field[], FieldValue[], Value);
Username - The account username.
Table - The table that stores the account.
Field - The name storing field name, so it doesn't confuse for a invalid field.
FieldValue - The field you'd like to change.
Value - The value of the field (integer).
( Check the example for information how to use this, and other similar functions! ).

CMySQL_Set(Username[], Table[], Field[], FieldValue[], Value[]);
Username - The account username.
Table - The table that stores the account.
Field - The name storing field name, so it doesn't confuse for a invalid field.
FieldValue - The field you'd like to change.
Value - The value of the field (string).

CMySQL_Int(Username[], Table[], Field[], FieldValue[]);
Username - The account username.
Table - The table that stores the account.
Field - The name storing field name, so it doesn't confuse for a invalid field.
FieldValue - The field you'd like to get the value from (integer).

- Returns the value of the field (integer).

CMySQL_Get(Username[], Table[], Field[], FieldValue[]);
Username - The account username.
Table - The table that stores the account.
Field - The name storing field name, so it doesn't confuse for a invalid field.
FieldValue - The field you'd like to get the value from (string).

- Returns the value of the field (string).

CMySQL_SetFloat(Username[], Table[], Field[], FieldValue[], Float:Value);
Username - The account username.
Table - The table that stores the account.
Field - The name storing field name, so it doesn't confuse for a invalid field.
FieldValue - The field you'd like to set the value to (Float).
Value - The value of the field you'd like to set.

CMySQL_Float(Username[], Table[], Field[], FieldValue[]);
Username - The account username.
Table - The table that stores the account.
Field - The name storing field name, so it doesn't confuse for a invalid field.
FieldValue - The field you'd like to get the value from (float).

- Returns the value of the field (float).

CMySQL_Password(Username[], Table[], Field[], Value[]);
Username - The account username.
Table - The table that stores the account.
Field - The name storing field name, so it doesn't confuse for a invalid field.
Value- The value you'd like to set the field to.

- Stores in MD5

CMySQL_GetPassword(Username[], Table[], Field[], Value[]);
Username - The account username.
Table - The table that stores the account.
Field - The name storing field name, so it doesn't confuse for a invalid field.
Value- The value you'd like to get the password from.

- Receives from MD5

CMySQL_SetUserName(name[], AccountTable[], UserFieldName[], Value[]));
name- The account username (the current one, without changed).
AccountTable- The table that stores the account.
UserFieldName- The name storing field name, so it doesn't confuse for a invalid field.
Value- The new name you'd like to set.

CMySQL_SetBool(Username[], Table[], Field[], FieldValue[], bool:Value);
Username - The account username.
Table - The table that stores the account.
Field - The name storing field name, so it doesn't confuse for a invalid field.
FieldValue - The field you'd like to change.
Value - The value of the field (bool).

CMySQL_LoadAccount(Username[], Table[], Field[], ThreadID, extraid);
Username - The account username.
Table - The table that stores the account.
Field - The name storing field name, so it doesn't confuse for a invalid field.
ThreadID- The thread ID.
extraid - The extraid parameter for the thread callback.

Bugs

None found yet.

Thanks to

BlueG - Plugin.
Strickenkid - Plugin.

Download

C-MySQL 0.0
C-MySQL 0.1
C-MySQL 0.2
Reply
#2

Wow, really nice job. This looks great and very simple to use, could you give a quick explanation on "admin levels"? How you would set them and how you would check what a player has, I am a little fuzzy on doing that with MySQL...
Reply
#3

Quote:
Originally Posted by RealCop228
Посмотреть сообщение
Wow, really nice job. This looks great and very simple to use, could you give a quick explanation on "admin levels"? How you would set them and how you would check what a player has, I am a little fuzzy on doing that with MySQL...
pawn Код:
CMySQL_SetInt("MyUserName", "MyAccountTable", "MyUserName_Storing_Field", "AdminLevel", 5);
That made a username, level 5 administration. Make sure you created the field though in the MySQL database. :P
Reply
#4

Great! Thank you, that helped quite a lot!
Reply
#5

nice job.
Reply
#6

I F*****G LOVE YOU
Reply
#7

Thanks
Reply
#8

Nice work, but it's hardly "advanced."
Reply
#9

Quote:
Originally Posted by Calgon
Посмотреть сообщение
Nice work, but it's hardly "advanced."
Yep, it's more easy, then advanced :P
Reply
#10

I hate you. I literally started making this exact type of script this morning, and was finishing it up (am now at 80%) before seeing this post.

Nice work though.
Reply
#11

Dude that is awesome.
Reply
#12

Nice one, looks easy and simple to use
Reply
#13

But if you want to save 20 variables with CMySQL_SetInt();

the result is 20 querys... that's not so good...

(but i use also a method like this )
for speed-orientated scripters IS a query like:

"UPDATE `users` SET `this`="this",`That`="That" WHERE `Username`="papagei9"

better...
Reply
#14

papagei9, you have the correct idea, however it would be difficult to make that unless he had unlimited arguments used for CMySQL_SetInt(), which he would then have to count the arguments, see what they are, then format a query based on the number of arguments and their type, as well as the values.

In other words, it'd be a huge hassle trying to do that.
Reply
#15

Quote:
Originally Posted by Grim_
Посмотреть сообщение
papagei9, you have the correct idea, however it would be difficult to make that unless he had unlimited arguments used for CMySQL_SetInt(), which he would then have to count the arguments, see what they are, then format a query based on the number of arguments and their type, as well as the values.

In other words, it'd be a huge hassle trying to do that.
I can try that, but I doubt it'll work, try it out if you'd like:

Edit: Nevermind, the code will never work
Reply
#16

I have a few suggestions for the next version (if there's going to be one)

CMySQL_UpdateName
CMySQL_SetBool
CMySQL_Bool
Reply
#17

Quote:
Originally Posted by Grim_
Посмотреть сообщение
I have a few suggestions for the next version (if there's going to be one)

CMySQL_UpdateName
CMySQL_SetBool
CMySQL_Bool
What will UpdateName do?
Reply
#18

I'll be integrating this into my servers official GM, nice job!
Reply
#19

Nice one
Reply
#20

Simply changing the name for the player in the database, like in a /changename command.
Reply


Forum Jump:


Users browsing this thread: 3 Guest(s)