Raised This Month: $ Target: $400
 0% 

[REQ/HELP]Please Transform To MYSQL


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
soumyadip77
Senior Member
Join Date: Jul 2017
Location: INDIA,KOLKATA
Old 02-27-2018 , 22:10   [REQ/HELP]Please Transform To MYSQL
Reply With Quote #1

Any please transform it to MYSQL with top15 (Bugsy Please help me )

I need Only this for MYSQL

One more thing me already useing amxbans SQL plugin this xp mod will work in same server ??

PHP Code:
#include <amxmodx> 
#include <amxmisc> 
#include <nvault> 

#define MAXCLASSES 5  

new PlayerXP[33],PlayerLevel[33],PlayerClass[33
//These are for your special kills 
new XP_Kill,XP_Knife,XP_Hs 
//This is for the vault, so your EXP saves to the server 
new g_vault 
//This is for the SaveXP command 
new SaveXP 

new const CLASSES[MAXCLASSES][] = { 
    
"None"
    
"Rifle Specialist"
    
"Sniper Specialist"
    
"Pistol Specialist"
    
"Machine Gun Specialist" 


new const 
LEVELS[10] = { 
    
100
    
200
    
400
    
800
    
1600
    
3200
    
6400
    
12800
    
25600
    
51200 


public 
plugin_init() 

    
register_plugin("Simple EXP Mod""1.0""Thelius"// Registers the Plugin to the ModName, Version, and Creator 
    
register_event("DeathMsg""eDeath""a"// This is the death event 
    
SaveXP register_cvar("SaveXP""1"// This is to make sure that Saving XP is enabled 
    
XP_Kill register_cvar("XP_per_kill""40"// This defines the amount of EXP you gain per kill 
    
XP_Hs register_cvar("XP_hs_bonus""50"// This defines the amount of exp gained per headshot 
    
XP_Knife register_cvar("XP_knife_bonus""20"// This defines the amount of Exp gained per Knife Kill 
    
g_vault nvault_open("XPMod"// This opens the nvault so it can save the exp 
     
    
register_clcmd("say /class""ChangeClass"// Saying /class will open the class menu 
    
register_clcmd("say_team /class""ChangeClass"// Team saying /class will open the class menu 
    
register_clcmd("say /xp""ShowHud"// Saying /xp will show your EXP 
    
register_clcmd("say_team /xp""ShowHud"// Team Saying /xp will show your EXP 


public 
eDeath( ) 

    new 
headshot,attacker read_data
    new 
weapon get_user_weapon(attacker,headshot,headshot
    
headshot read_data
     
    
PlayerXP[attacker] += get_pcvar_num(XP_Kill
     
    if(
PlayerClass[attacker] == 0
         
    if(
headshot
        
PlayerXP[attacker] += get_pcvar_num(XP_Hs
     
    if(
weapon == CSW_KNIFE
        
PlayerXP[attacker] += get_pcvar_num(XP_Knife
     
    while(
PlayerXP[attacker] >= LEVELS[PlayerLevel[attacker]]) 
    { 
    
client_print(attackerprint_chat"[XP Mod] Congratulations you are now level %i %s!"PlayerLevel[attacker], CLASSES[PlayerClass[attacker]]); 
        
PlayerLevel[attacker] += 
    

    
ShowHud(attacker
    
SaveData(attacker


public 
ShowHud(id

    
set_hudmessage(025500.280.8806.012.0
    
show_hudmessage(id"Level: %i^nXP: %i^nClass: %s"PlayerLevel[id],PlayerXP[id],CLASSES[PlayerClass[id]]) 


public 
ChangeClass(id

    new 
menu menu_create("Class Menu""Class_Handle"); 
     
    
menu_additem(menu ,"Rifle Specialist""1" 0); 
    
menu_additem(menu ,"Sniper Specialist""2" 0); 
    
menu_additem(menu ,"Pistol Specialist""3" 0); 
    
menu_additem(menu ,"Machine Gun Specialist""4" 0); 
     
    
menu_setprop(menu MPROP_EXIT MEXIT_ALL); 
     
    
menu_display(id menu 0); 
     
    return 
PLUGIN_CONTINUE


public 
Class_Handle(id menu item

    if(
item == MENU_EXIT
    { 
         
        
menu_destroy(menu); 
    } 
     
    new 
szCommand[6], szName[64]; 
    new 
access callback
     
    
menu_item_getinfo(menu item access szCommand szName 63 callback); 
     
    new 
str_to_num(szCommand
    if(
PlayerClass[id] != i
    { 
        
PlayerClass[id] = 
        client_print
(id,print_chat"[XP Mod] You are now a %s"CLASSES[i]) 
    } 
    else 
    { 
        
client_print(id,print_chat"[XP Mod] You are already a %s",CLASSES[i]) 
    } 
     
    
menu_destroy(menu); 
    return 
PLUGIN_CONTINUE 


public 
client_connect(id

    if(
get_pcvar_num(SaveXP) == 1
    { 
         
        
LoadData(id
    } 


public 
client_disconnect(id

    if(
get_pcvar_num(SaveXP) == 1
    { 
         
        
SaveData(id
    } 
    
PlayerXP[id] = 
    PlayerLevel
[id] = 
    PlayerClass
[id] = 


public 
SaveData(id

    new 
AuthID[35
    
get_user_authid(id,AuthID,34
     
    new 
vaultkey[64],vaultdata[256
    
format(vaultkey,63,"%s-Mod"AuthID
    
format(vaultdata,255,"%i#%i#",PlayerXP[id],PlayerLevel[id]) 
    
nvault_set(g_vault,vaultkey,vaultdata
    return 
PLUGIN_CONTINUE 
}  

public 
LoadData(id

    new 
AuthID[35
    
get_user_authid(id,AuthID,34
     
    new 
vaultkey[64],vaultdata[256
    
format(vaultkey,63,"%s-Mod",AuthID
    
format(vaultdata,255,"%i#%i#",PlayerXP[id],PlayerLevel[id]) 
    
nvault_get(g_vault,vaultkey,vaultdata,255
     
    
replace_all(vaultdata255"#"" "
     
    new 
playerxp[32], playerlevel[32
     
    
parse(vaultdataplayerxp31playerlevel31
     
    
PlayerXP[id] = str_to_num(playerxp
    
PlayerLevel[id] = str_to_num(playerlevel
     
    return 
PLUGIN_CONTINUE 

PLEASE HELP ME

THANK YOU
soumyadip77 is offline
Send a message via Skype™ to soumyadip77
Paltimus
Junior Member
Join Date: Feb 2018
Location: German - Bomb site A
Old 02-28-2018 , 20:18   Re: [REQ/HELP]Please Transform To MYSQL
Reply With Quote #2

you have save with vault system why you need mysql ?

and if you atr forced to work with it ! i think this could help you to solve your problem !

http://forums.alliedmods.net/showthread.php?t=7024

Last edited by Paltimus; 02-28-2018 at 20:19. Reason: grammar
Paltimus is offline
soumyadip77
Senior Member
Join Date: Jul 2017
Location: INDIA,KOLKATA
Old 03-01-2018 , 21:59   Re: [REQ/HELP]Please Transform To MYSQL
Reply With Quote #3

Please make it any one
soumyadip77 is offline
Send a message via Skype™ to soumyadip77
Clauu
Senior Member
Join Date: Feb 2008
Location: RO
Old 03-04-2018 , 13:59   Re: [REQ/HELP]Please Transform To MYSQL
Reply With Quote #4

PHP Code:
#include <amxmodx> 
#include <amxmisc> 
#include <nvault>
#include <sqlx> 

// edit here
new const useSql 1// 0/1 to disable/enable mysql
#define DB_HOST "127.0.0.1"
#define DB_USER "root"
#define DB_PASS "password"
#define DB_NAME "database"
#define DB_TABLE "exp"
//


enum dataStruct sqlModule[6], Handle:sqlTupleHandle:sqlConnection }
new 
gData[dataStruct];
#define MAXCLASSES 5  

new PlayerXP[33],PlayerLevel[33],PlayerClass[33
//These are for your special kills 
new XP_Kill,XP_Knife,XP_Hs 
//This is for the vault, so your EXP saves to the server 
new g_vault 
//This is for the SaveXP command 
new SaveXP 

new const CLASSES[MAXCLASSES][] = { 
    
"None"
    
"Rifle Specialist"
    
"Sniper Specialist"
    
"Pistol Specialist"
    
"Machine Gun Specialist" 


new const 
LEVELS[10] = { 
    
100
    
200
    
400
    
800
    
1600
    
3200
    
6400
    
12800
    
25600
    
51200 


public 
plugin_init() 

    
register_plugin("Simple EXP Mod""1.0""Thelius"// Registers the Plugin to the ModName, Version, and Creator 
    
register_event("DeathMsg""eDeath""a"// This is the death event 
    
SaveXP register_cvar("SaveXP""1"// This is to make sure that Saving XP is enabled 
    
XP_Kill register_cvar("XP_per_kill""40"// This defines the amount of EXP you gain per kill 
    
XP_Hs register_cvar("XP_hs_bonus""50"// This defines the amount of exp gained per headshot 
    
XP_Knife register_cvar("XP_knife_bonus""20"// This defines the amount of Exp gained per Knife Kill
    
if(useSql)
        
db_connect();
    else
        
g_vault nvault_open("XPMod"// This opens the nvault so it can save the exp
     
    
register_clcmd("say /class""ChangeClass"// Saying /class will open the class menu 
    
register_clcmd("say_team /class""ChangeClass"// Team saying /class will open the class menu 
    
register_clcmd("say /xp""ShowHud"// Saying /xp will show your EXP 
    
register_clcmd("say_team /xp""ShowHud"// Team Saying /xp will show your EXP 


stock db_connect() {

    
gData[sqlModule]="mysql";
    
    new 
buffer[128];
    if(
is_module_loaded(gData[sqlModule])<0) {
        
formatex(buffer,charsmax(buffer),"^r^n[SQL] Error: module ^"%s^" not loaded.^r^n"gData[sqlModule]);
        
log_amx(buffer);
        
set_fail_state(buffer);
        return;
    }
    
    
SQL_GetAffinity(buffercharsmax(buffer));
    
    if(!
equali(buffergData[sqlModule]))
        if(!
SQL_SetAffinity(gData[sqlModule])) {
            
formatex(buffer,charsmax(buffer),"%s Failed to set ^"%s^" affinity!"gData[sqlModule]);
            
log_amx(buffer);
            
set_fail_state(buffer);
            return;
        }
    
    new 
err[256],errNum;
    
gData[sqlTuple] = _:SQL_MakeDbTuple(DB_HOSTDB_USERDB_PASSDB_NAME);
    
gData[sqlConnection] = _:SQL_Connect(gData[sqlTuple], errNumerrcharsmax(err));
    
    if(
gData[sqlTuple]==Empty_Handle || gData[sqlConnection]==Empty_Handle) {
    
        
formatex(buffer,charsmax(buffer),"[SQL] MySQL Error #%d - %s.."errNumerr);
        
log_amx(buffer);
        
set_fail_state(buffer);
    }
    
    
    
SQL_ThreadQuery(gData[sqlTuple],"QueryHandler","SET NAMES utf8","charset",10);
    
    
server_print("[SQL] connected to: '%s://%s:****@%s/%s/%s'"gData[sqlModule], DB_USERDB_HOSTDB_NAMEDB_TABLE);
    
    new 
query[512];
    
formatex(query,charsmax(query),"CREATE TABLE IF NOT EXISTS %s (id BIGINT NOT NULL %s PRIMARY KEY, name VARCHAR(64) NOT NULL, authid VARCHAR(32) NOT NULL UNIQUE, ip VARCHAR(20) NOT NULL, level INT NOT NULL DEFAULT 0, xp INT NOT NULL DEFAULT 0 )%s",DB_TABLE,(equali(gData[sqlModule], "mysql"))?"AUTO_INCREMENT":"DEFAULT 0",(equali(gData[sqlModule], "mysql"))?" ENGINE=MyISAM DEFAULT CHARSET=utf8;":"");
    
SQL_ThreadQuery(gData[sqlTuple],"QueryHandler",query,"create",10);
}

public 
eDeath( ) 

    new 
headshot,attacker read_data
    new 
weapon get_user_weapon(attacker,headshot,headshot
    
headshot read_data
     
    
PlayerXP[attacker] += get_pcvar_num(XP_Kill
     
    if(
PlayerClass[attacker] == 0
         
    if(
headshot
        
PlayerXP[attacker] += get_pcvar_num(XP_Hs
     
    if(
weapon == CSW_KNIFE
        
PlayerXP[attacker] += get_pcvar_num(XP_Knife
     
    while(
PlayerXP[attacker] >= LEVELS[PlayerLevel[attacker]]) 
    { 
        
client_print(attackerprint_chat"[XP Mod] Congratulations you are now level %i %s!"PlayerLevel[attacker], CLASSES[PlayerClass[attacker]]); 
        
PlayerLevel[attacker] += 
    

    
ShowHud(attacker


public 
ShowHud(id

    
set_hudmessage(025500.280.8806.012.0
    
show_hudmessage(id"Level: %i^nXP: %i^nClass: %s"PlayerLevel[id],PlayerXP[id],CLASSES[PlayerClass[id]]) 


public 
ChangeClass(id

    new 
menu menu_create("Class Menu""Class_Handle"); 
     
    
menu_additem(menu ,"Rifle Specialist""1" 0); 
    
menu_additem(menu ,"Sniper Specialist""2" 0); 
    
menu_additem(menu ,"Pistol Specialist""3" 0); 
    
menu_additem(menu ,"Machine Gun Specialist""4" 0); 
     
    
menu_setprop(menu MPROP_EXIT MEXIT_ALL); 
     
    
menu_display(id menu 0); 
     
    return 
PLUGIN_CONTINUE


public 
Class_Handle(id menu item

    if(
item == MENU_EXIT
    { 
         
        
menu_destroy(menu); 
    } 
     
    new 
szCommand[6], szName[64]; 
    new 
access callback
     
    
menu_item_getinfo(menu item access szCommand szName 63 callback); 
     
    new 
str_to_num(szCommand
    if(
PlayerClass[id] != i
    { 
        
PlayerClass[id] = 
        client_print
(id,print_chat"[XP Mod] You are now a %s"CLASSES[i]) 
    } 
    else 
    { 
        
client_print(id,print_chat"[XP Mod] You are already a %s",CLASSES[i]) 
    } 
     
    
menu_destroy(menu); 
    return 
PLUGIN_CONTINUE 


public 
client_putinserver(id

    if(
get_pcvar_num(SaveXP) == 1
    { 
         
        
LoadData(id
    } 


public 
client_disconnect(id

    if(
get_pcvar_num(SaveXP) == 1
    { 
         
        
SaveData(id
    } 
    
PlayerXP[id] = 
    PlayerLevel
[id] = 
    PlayerClass
[id] = 


public 
SaveData(id

    static 
AuthID[32
    
get_user_authid(id,AuthID,31
    
    if(
useSql)
        
SaveSqlData(id,AuthID);
    else
        
SaveNvaultData(id,AuthID);
}  

stock SaveSqlData(id, const AuthID[]) {

    static 
query[256], name[64];
    if(
PlayerXP[id] || PlayerLevel[id]) {
        
get_user_name(id,name,charsmax(name));
        
formatex(query,charsmax(query),"UPDATE %s SET name='%s', xp='%d', level='%d' WHERE authid='%s'",DB_TABLE,name,PlayerXP[id],PlayerLevel[id],AuthID);
        
SQL_ThreadQuery(gData[sqlTuple],"QueryHandler",query,"update",10);
    }
}

stock SaveNvaultData(id, const AuthID[]) {

    static 
vaultkey[64],vaultdata[256
    
format(vaultkey,63,"%s-Mod"AuthID
    
format(vaultdata,255,"%i#%i#",PlayerXP[id],PlayerLevel[id]) 
    
nvault_set(g_vault,vaultkey,vaultdata
}

public 
LoadData(id
{
    static 
AuthID[32
    
get_user_authid(id,AuthID,31
    
    if(
useSql)
        
LoadSqlData(id,AuthID);
    else
        
LoadNvaultData(id,AuthID);
}

stock LoadNvaultData(id, const AuthID[]) {
     
    static 
vaultkey[64],vaultdata[256
    
format(vaultkey,63,"%s-Mod",AuthID
    
format(vaultdata,255,"%i#%i#",PlayerXP[id],PlayerLevel[id]) 
    
nvault_get(g_vault,vaultkey,vaultdata,255
     
    
replace_all(vaultdata255"#"" "
     
    static 
playerxp[32], playerlevel[32
     
    
parse(vaultdataplayerxp31playerlevel31
     
    
PlayerXP[id] = str_to_num(playerxp
    
PlayerLevel[id] = str_to_num(playerlevel)
}

stock LoadSqlData(id, const AuthID[]) {

    static 
data[32], query[128];
    
data[0]=id;
    
copy(data[1],30,AuthID);
    
    
formatex(query,charsmax(query),"SELECT * FROM %s WHERE authid = '%s'",DB_TABLEAuthID); 
    
SQL_ThreadQuery(gData[sqlTuple],"QueryHandler",query,data,sizeof(data));
}

public 
QueryHandler(failStateHandle:queryHerr[], errNumdata[], data_size) {
    
    if(
failState==TQUERY_CONNECT_FAILED || failState==TQUERY_QUERY_FAILED || errNum) {
        
log_amx("[SQL] MySQL Error #%d - %s"errNumerr);
        return;
    }
    
    if(
equali(data,"update")||equali(data,"insert")||equali(data,"charset")||equali(data,"create"))
        return;
    
    new 
id data[0];
    new 
rows SQL_NumResults(queryH);
    if(!
rows) {
        static 
query[512], name[64], ip[20];
        
get_user_name(id,name,charsmax(name));
        
clear(name);
        
get_user_ip(id,ip,charsmax(ip),1);
        
formatex(query,charsmax(query),"REPLACE INTO %s (name,authid,ip,xp,level) VALUES('%s','%s','%s','%d','%d')",DB_TABLE,name,data[1],ip,PlayerXP[id],PlayerLevel[id]);
        
SQL_ThreadQuery(gData[sqlTuple],"QueryHandler",query,"insert",10);
        return;
    }

    
PlayerXP[id] = SQL_ReadResult(queryH,SQL_FieldNameToNum(queryH"xp"));
    
PlayerLevel[id] = SQL_ReadResult(queryH,SQL_FieldNameToNum(queryH"level"));
}

public 
plugin_end()
    
sql_close();

stock sql_close() {

    if(
gData[sqlTuple] != Empty_Handle
        
SQL_FreeHandle(gData[sqlTuple] );
        
    if(
gData[sqlConnection] != Empty_Handle
        
SQL_FreeHandle(gData[sqlConnection]);
}

stock clear(src[]) {
    
    new 
len=strlen(src);
    
replace_all(srclen"\", "\\");
    replace_all(src, len, "'", "\'");
    replace_all(src, len, "^"", "\^"");
    replace_all(src, len, "^n", "\^n");
    replace_all(src, len, "^r", "\^n");
    replace_all(src, len, "^x1A", "\^x1A");
    replace_all(src, len, "^x00", "\^x00");

Edit only where it says with your db credentials. Table and columns will be auto created

Last edited by Clauu; 03-04-2018 at 14:03.
Clauu is offline
soumyadip77
Senior Member
Join Date: Jul 2017
Location: INDIA,KOLKATA
Old 03-05-2018 , 06:59   Re: [REQ/HELP]Please Transform To MYSQL
Reply With Quote #5

Anyone can add top 15 for this xp mod
soumyadip77 is offline
Send a message via Skype™ to soumyadip77
Old 03-05-2018, 07:22
ish12321
This message has been deleted by ish12321.
Reply



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

Forum Jump


All times are GMT -4. The time now is 20:53.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode