SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Filterscripts > Includes

Reply
 
Thread Tools Display Modes
Old 10/08/2010, 08:50 AM   #1
Carlton
Gangsta
 
Carlton's Avatar
 
Join Date: Mar 2010
Posts: 687
Reputation: 4
Default C-MYSQL (Remade) - Increased Speed & More Simple


C-MySQL

Information

Hi, I recently released a include called C-MySQL, the old include was:
  • Slow
  • Confusing
  • Little opportunity (Speed increasing wise)

Well, I decided to remake the script will some new functions and some functions removed. This time this can be useful.

Setup

There's a new way to set this up now. Instead of the useless parameters that made the include confusing, there are now defines that you can fill out. These defines are below:

pawn Code:
#define ACCOUNT_TABLE ""
#define USERNAME_FIELD ""
#define PASSWORD_FIELD ""

These defines should be filled in as below (This is an example):

pawn Code:
#define ACCOUNT_TABLE "Accounts"
#define USERNAME_FIELD "Username"
#define PASSWORD_FIELD "Password"

If you look inside the include you'll notice this:

pawn Code:
#if defined MYSQL_PLUGIN
    #include <a_mysql>
#else
    #include <mysql>
#endif

If you would like to use Strickenkid's MySQL plugin disable MYSQL_PLUGIN, like below:

pawn Code:
//#define MYSQL_PLUGIN // Defined = BlueG's plugin. | Undefined = Strickenkid's plugin.

These defines are found in the include ( C-MySQL.inc )

Functions (List)

Code:
native CMySQL_Create(Username[], Password[], bool:md5 = true, ThreadID = -1, extraID = -1);
native CMySQL_Delete(Username[], ThreadID = -1, extraID = -1);
native CMySQL_SetInt(Username[], Field[], Value, ThreadID = -1, extraID = -1);
native CMySQL_CustomDataSet(Username[], Custom[], ThreadID = -1, extraID = -1);
native CMySQL_Set(Username[], Field[], Value[], bool:md5 = false, ThreadID = -1, extraID = -1);
native CMySQL_SetFloat(Username[], Field[], Float:Value, ThreadID = -1, extraID = -1);
native CMySQL_SetBool(Username[], Field[], bool:Value, ThreadID = -1, extraID = -1);
native CMySQL_Load(Username[], ThreadID = -1, extraID = -1);
native CMySQL_Exists(Username[]);
native CMySQL_Int(Username[], Field[], ThreadID = -1, extraID = -1);
native CMySQL_Get(Username[], Field[], Storage[], ThreadID = -1, extraID = -1);
native Float:CMySQL_Float(Username[], Field[],ThreadID = -1, extraID = -1);
Functions (Explanation)

CMySQL_Create(Username[], Password[], bool:md5 = true, ThreadID = -1, extraID = -1)
Username - The account's username.
Password - The account's password.
bool:md5 - If true (default), then it md5 hashes the password, otherwise it doesn't.
ThreadID - For threading usages.
extraID - For threading usages.
returns 1 if the MySQL was successful.
Example:

pawn Code:
CMySQL_Create("Carlton", "MyPassword");

MySQL_Delete(Username[], ThreadID = -1, extraID = -1)
Username - The account's username.
ThreadID - For threading usages.
extraID - For threading usages.
returns 1 if the MySQL was successful.
Example:

pawn Code:
CMySQL_Delete("Carlton");

CMySQL_SetInt(Username[], Field[], Value, ThreadID = -1, extraID = -1)
Username - The account's username.
Field - The field you would like to set the value to.
ThreadID - For threading usages.
extraID - For threading usages.
returns 1 if the MySQL was successful.
Example:

pawn Code:
CMySQL_SetInt("Carlton", "AdminLevel", 1337);

CMySQL_CustomDataSet(Username[], Custom[], ThreadID = -1, extraID = -1)
Username - The account's username.
Custom - The custom saving query.
ThreadID - For threading usages.
extraID - For threading usages.
returns 1 if the MySQL was successful.
Example:

pawn Code:
CMySQL_CustomDataSet("Carlton", "AdminLevel = 1337, Money = 10000, SkinID = 17");

CMySQL_Set(Username[], Field[], Value[], bool:md5 = false, ThreadID = -1, extraID = -1)
Username - The account's username.
Field - The field you would like to set the value to.
bool:md5 - If false (default), then it md5 hashes the value, otherwise it doesn't.
ThreadID - For threading usages.
extraID - For threading usages.
returns 1 if the MySQL was successful.
Example:

pawn Code:
CMySQL_Set("Carlton", "Password", "MyNewPassword", true);

CMySQL_SetFloat(Username[], Field[], Float:Value, ThreadID = -1, extraID = -1)
Username - The account's username.
Field - The field you would like to set the value to.
ThreadID - For threading usages.
extraID - For threading usages.
returns 1 if the MySQL was successful.
Example:

pawn Code:
CMySQL_SetFloat("Carlton", "PosX", 1337.0);

CMySQL_SetBool(Username[], Field[], bool:Value, ThreadID = -1, extraID = -1)
Username - The account's username.
Field - The field you would like to set the value to.
ThreadID - For threading usages.
extraID - For threading usages.
returns 1 if the MySQL was successful.
Example:

pawn Code:
CMySQL_SetBool("Carlton", "IsHungry", true);

CMySQL_Load(Username[], ThreadID = -1, extraID = -1);
Username - The account's username.
ThreadID - For threading usages.
extraID - For threading usages.
returns 1 if the MySQL was successful.
Example:

pawn Code:
#define MYSQL_LOAD_ACCOUNT (0)
CMySQL_Load("Carlton", MYSQL_LOAD_ACCOUNT, playerid);

public OnQueryFinish(...) {
     mysql_store_result();
     ....
}

CMySQL_Exists(Username[])
Username - The account's username.
ThreadID - For threading usages.
extraID - For threading usages.
returns 1 if the account exists.
Example:

pawn Code:
if(CMySQL_Exists("Carlton")) return print("Your account exists!");

CMySQL_Int(Username[], Field[], ThreadID = -1, extraID = -1)
Username - The account's username.
Field - The field you would like to get the value from.
ThreadID - For threading usages.
extraID - For threading usages.
returns the value of the field.
Example:

pawn Code:
new MyMoney = CMySQL_Int("Carlton", "Money");

CMySQL_Get(Username[], Field[], Storage[], ThreadID = -1, extraID = -1)
Username - The account's username.
Field - The field you would like to get the value from.
Storage - The string you'd like to store the value to.
ThreadID - For threading usages.
extraID - For threading usages.
returns nothing.
Example:

pawn Code:
new MyEmail[16];
CMySQL_Get("Carlton", "Email", MyEmail);
print(MyEmail);

Float:CMySQL_Float(Username[], Field[],ThreadID = -1, extraID = -1)
Username - The account's username.
Field - The field you would like to get the value from.
ThreadID - For threading usages.
extraID - For threading usages.
returns the value of the field.
Example:

pawn Code:
SetPlayerPos(playerid, CMySQL_Float("Carlton", "CrashPosX"), CMySQL_Float("Carlton", "CrashPosY"), CMySQL_Float("Carlton", "CrashPosZ"),

Example Script

pawn Code:
#include <a_samp>
#include <a_mysql>
#include <zcmd>
#include <sscanf2>

new MyMoney[MAX_PLAYERS], MyKills[MAX_PLAYERS];

stock GetUserName(playerid) {
      new name[24];
      GetPlayerName(playerid, name, 24); return name;
}

CMD:register(playerid, params[]) {
      if(CMySQL_Exists(GetUserName(playerid))
           return SendClientMessage(playerid, 0xFFFFFFA, "<> Your account exists already!");

      new password[32];
      if(sscanf(params, "s[32]", password))
           return SendClientMessage(playerid, 0xFFFFFFA, "<> /register <password>");
 
      if(strlen(password) > 32)
           return SendClientMessage(playerid, 0xFFFFFFA, "<> Your password must be 32 characters or less.");
 
      CMySQL_Create(GetUserName(playerid), password);
}

CMD:login(playerid, params[]) {
       if(!CMySQL_Exists(GetUserName(playerid))
           return SendClientMessage(playerid, 0xFFFFFFA, "<> Your account doesn't exist!");
 
      new password[32];
      if(sscanf(params, "s[32]", password))
           return SendClientMessage(playerid, 0xFFFFFFA, "<> /login <password>");
 
      if(strlen(password) > 32)
           return SendClientMessage(playerid, 0xFFFFFFA, "<> Your password must be 32 characters or less.");

      new Passwordz[32];
      CMySQL_Get(GetUserName(playerid), "Password", Passwordz, true);
      if(!strcmp(Passwordz, password, true)) {
           SendClientMessage(playerid, 0xFFFFFFA, "<> You're now logged.");
           CMySQL_Load(GetUserName(playerid), 1, playerid);
      }
}

stock GetMyAdminLevel(Username[]) {
     return CMySQL_Int(Username, "AdminLevel");
}

public OnPlayerDisconnect(playerid, reason) {
       new string[128];
       format(string, 128, "Money = %i, MyKills = %i", GetPlayerMoney(playerid), GetPlayerScore(playerid));
       CMySQL_CustomDataSet(GetUserName(playerid), string);
}

public OnQueryFinish( query[], resultid, extraid, connectionHandle ) {
      mysql_store_result();
      new Data[128];
      mysql_fetch_row_format(Data, "|");
      sscanf(Data, "p<|>ii", MyMoney[extraid], MyKills[extraid]);
      GivePlayerMoney(playerid, MyMoney[extraid]);
}

Requirements

You will need either BlueG's or Strickenkids plugin, these can be found below:

http://forum.sa-mp.com/forumdisplay.php?f=18

Thanks to

Strickenkid - Plugin.
BlueG - Plugin.

Download

Click below.

Last edited by Carlton; 19/08/2010 at 06:00 PM.
Carlton is offline   Reply With Quote
Old 10/08/2010, 08:54 AM   #2
Grim_
High-roller
 
Grim_'s Avatar
 
Join Date: Sep 2008
Location: United States
Posts: 2,896
Reputation: 118
Default Re: C-MYSQL (Remade) - Increased Speed & More Simple

Nice to see the new version, great work as always

Btw, does this one now work with other versions of SMF than just 1.0?
Grim_ is offline   Reply With Quote
Old 10/08/2010, 08:58 AM   #3
DiddyBop
Gangsta
 
DiddyBop's Avatar
 
Join Date: Aug 2009
Posts: 666
Reputation: 10
Default Re: C-MYSQL (Remade) - Increased Speed & More Simple

FFS

i clicked epic missions to try and rip some stuff out of a game mode or filter script and it brings me to download link

im gunna sue you.




Anyways, i like the functions good job
DiddyBop is offline   Reply With Quote
Old 10/08/2010, 04:19 PM   #4
Carlton
Gangsta
 
Carlton's Avatar
 
Join Date: Mar 2010
Posts: 687
Reputation: 4
Default Re: C-MYSQL (Remade) - Increased Speed & More Simple

Quote:
Originally Posted by Grim_ View Post
Nice to see the new version, great work as always

Btw, does this one now work with other versions of SMF than just 1.0?
This is not C-SMF
Carlton is offline   Reply With Quote
Old 10/08/2010, 04:25 PM   #5
Grim_
High-roller
 
Grim_'s Avatar
 
Join Date: Sep 2008
Location: United States
Posts: 2,896
Reputation: 118
Default Re: C-MYSQL (Remade) - Increased Speed & More Simple

Wow... I feel stupid :P

Still nice work
Grim_ is offline   Reply With Quote
Old 10/08/2010, 04:51 PM   #6
Kar
Banned
 
Join Date: May 2010
Location: Black Asylum
Posts: 2,938
Reputation: 538
Default Re: C-MYSQL (Remade) - Increased Speed & More Simple

DDDDDDDDD yay ty!
Kar is offline   Reply With Quote
Old 10/08/2010, 11:53 PM   #8
Brian_Furious
Gangsta
 
Brian_Furious's Avatar
 
Join Date: May 2009
Location: C:\Windows\System32\brian_furious.dll
Posts: 710
Reputation: 40
Default Re: C-MYSQL (Remade) - Increased Speed & More Simple

Thats cool, but where is a_mysql.inc ? id ont find it in this topic...

Note: I find it and it works fine..thanks a lot!
__________________
I currently working on a NEW LA:RP (Los Angeles RolePlay) 3.0 R2

Last edited by Brian_Furious; 11/08/2010 at 12:03 AM.
Brian_Furious is offline   Reply With Quote
Old 14/08/2010, 11:23 PM   #10
[LoD]Hauke
Little Clucker
 
Join Date: Jan 2010
Posts: 45
Reputation: 42
Thumbs up Re: C-MYSQL (Remade) - Increased Speed & More Simple

A very nice inlcude !
but
CMySQL_Exists("Name")

Has a little Bug...
undefined symbol "ThreadID"
[LoD]Hauke 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
[Tutorial] Creating a MySQL account system (Simple) Carlton Tutorials 13 19/07/2014 06:45 AM
[FilterScript] [FS] Plant C4 - | Remade | Torran Filterscripts 16 20/05/2011 11:52 AM
[Help] Simple Speed Boost when you press KEY_FIRE Toni Help Archive 18 10/03/2011 06:52 AM
Simple MySQL reading crashes the Server virtualmarc Help Archive 4 20/09/2009 02:28 PM
My Remade songs (FL Studio) Mrkrabz Everything and Nothing 0 01/02/2009 01:11 PM


All times are GMT. The time now is 10:00 AM.


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