Raised This Month: $51 Target: $400
 12% 

[Tut] MySql - Save/Load/Usefull Things (Xp Mod)


Post New Thread Reply   
 
Thread Tools Display Modes
frOOgy
Senior Member
Join Date: Jul 2014
Old 01-31-2015 , 06:01   Re: [Tut] MySql - Save/Load/Usefull Things (Xp Mod)
Reply With Quote #101

Can anyone make me an example plugin for rank using MySQL. Save Rank, kills, deaths. When player say /rank then show message: "Your rank is %d with %d kills and %d deaths". THXX
__________________
Help me in other requests

Change Map System [PLUGIN]

GaG System [PLUGIN] [PLUGIN]
frOOgy is offline
Send a message via Skype™ to frOOgy
Old 02-05-2015, 17:30
frOOgy
This message has been deleted by frOOgy.
skz
Senior Member
Join Date: Jul 2014
Location: Portugal
Old 02-05-2015 , 21:02   Re: [Tut] MySql - Save/Load/Usefull Things (Xp Mod)
Reply With Quote #102

Grim, In this tutorial, you should save the steam ID when a player join the server and save it as a global variable, because it isn't safe to detected the steam id of someone when they disconnect (as you do on this tutorial)
__________________
skz is offline
frOOgy
Senior Member
Join Date: Jul 2014
Old 02-06-2015 , 03:52   Re: [Tut] MySql - Save/Load/Usefull Things (Xp Mod)
Reply With Quote #103

Bro, I want to know how to save rank position, kills, deaths using mysql to name, not steam id. thxx
__________________
Help me in other requests

Change Map System [PLUGIN]

GaG System [PLUGIN] [PLUGIN]
frOOgy is offline
Send a message via Skype™ to frOOgy
skz
Senior Member
Join Date: Jul 2014
Location: Portugal
Old 02-06-2015 , 14:03   Re: [Tut] MySql - Save/Load/Usefull Things (Xp Mod)
Reply With Quote #104

I didn't answer to your request frosty, but btw, why don't you use steam id for saving instead of the name?
__________________
skz is offline
Jhob94
AMX Mod X Donor
Join Date: Jul 2012
Location: Siiiiiiiiuu
Old 02-06-2015 , 14:07   Re: [Tut] MySql - Save/Load/Usefull Things (Xp Mod)
Reply With Quote #105

Quote:
Originally Posted by skz View Post
I didn't answer to your request frosty, but btw, why don't you use steam id for saving instead of the name?
Guess why. Everyone that requests to save by name instead of steam id, requests it for only one single reason: They want to be banned
__________________
Jhob94 is offline
frOOgy
Senior Member
Join Date: Jul 2014
Old 02-07-2015 , 05:45   Re: [Tut] MySql - Save/Load/Usefull Things (Xp Mod)
Reply With Quote #106

nvm... I just want to save using MySQL. Can anyone make me an example plugin plzz ???
__________________
Help me in other requests

Change Map System [PLUGIN]

GaG System [PLUGIN] [PLUGIN]
frOOgy is offline
Send a message via Skype™ to frOOgy
skz
Senior Member
Join Date: Jul 2014
Location: Portugal
Old 02-07-2015 , 09:08   Re: [Tut] MySql - Save/Load/Usefull Things (Xp Mod)
Reply With Quote #107

froogy, you have an example of a plugin that saves data in this thread
__________________

Last edited by skz; 02-07-2015 at 09:09.
skz is offline
frOOgy
Senior Member
Join Date: Jul 2014
Old 02-07-2015 , 15:00   Re: [Tut] MySql - Save/Load/Usefull Things (Xp Mod)
Reply With Quote #108

So, can anyone edit BaD CopY's plugin and change nVault to MySQL ?

PHP Code:
#include <amxmodx>
#include <amxmisc>
#include <colorchat>
#include <csstats>
#include <nvault>
#include <csx>

#define PLUGIN "Rank System"
#define VERSION "1.0"
#define AUTHOR "BaD CopY"

new gTime[33]
new 
gVault


public plugin_init() {
    
register_plugin(PLUGINVERSIONAUTHOR)
    
    
register_clcmd("say /rank""cmd_rank")
    
register_clcmd("say rank""cmd_rank")
    
    
register_clcmd("team_say /rank""cmd_rank")
    
register_clcmd("team_say rank""cmd_rank")
    
    
gVault nvault_open("TIME")
}

public 
cmd_rank(id)
{
    new 
stats[8], body[8], szName[33];
    
    
get_user_name(idszName32)
    
    new 
rank_pos get_user_stats(idstatsbody)
    new 
rank_max get_statsnum()
    
    new 
iTimeMins gTime[id] / 60
    
    
static Deaths 0Kills 0Float:Ratio 0.0
    
    Deaths 
stats[1], Kills stats[0], Ratio Deaths == ? (float(Kills)) : (float(Kills) / float(Deaths))
    
    
ColorChat(0GREEN"^4[Rank]^3 %s^1's rank is ^4%d^1 of ^4%d ^3-- ^1KpD: ^4%.2f^1 [Online: %i m]"szNamerank_posrank_maxRatioiTimeMins)
    
    return 
PLUGIN_CONTINUE;
}

public 
client_authorized(id)
{
    
loaddata(id)
}

public 
client_disconnect(id)
{
    
gTime[id] += get_user_time(id)
    
savedata(id)
}

stock savedata(id)
{
    new 
AuthId[65]
    
get_user_authid(idAuthIdcharsmax(AuthId))
    
    new 
VaultKey[64], VaultData[256]
    
format(VaultKey63"%s-TIME"AuthId)
    
format(VaultData254"%i"gTime[id])
    
    
nvault_set(gVaultVaultKeyVaultData)
    
    return 
PLUGIN_CONTINUE
}

stock loaddata(id)
{
    new 
AuthID[35
    
get_user_authid(id,AuthID,charsmax(AuthID ))
    new 
vaultkey[64],vaultdata[256]
    
    
format(vaultkey,63,"%s-TIME" ,AuthID
    
format(vaultdata,255,"%i",gTime[id]) 
    
    
nvault_get(gVault,vaultkey,vaultdata,charsmax (vaultdata))
    
    new 
Time[33]
    
parse(vaultdataTimecharsmax(Time))
    
    
gTime[id] = str_to_num(Time)

__________________
Help me in other requests

Change Map System [PLUGIN]

GaG System [PLUGIN] [PLUGIN]

Last edited by frOOgy; 02-07-2015 at 15:00.
frOOgy is offline
Send a message via Skype™ to frOOgy
Eagle07
Veteran Member
Join Date: May 2014
Location: Morocco :D
Old 02-07-2015 , 16:46   Re: [Tut] MySql - Save/Load/Usefull Things (Xp Mod)
Reply With Quote #109

Quote:
Originally Posted by frOOgy View Post
So, can anyone edit BaD CopY's plugin and change nVault to MySQL ?

PHP Code:
#include <amxmodx>
#include <amxmisc>
#include <colorchat>
#include <csstats>
#include <nvault>
#include <csx>

#define PLUGIN "Rank System"
#define VERSION "1.0"
#define AUTHOR "BaD CopY"

new gTime[33]
new 
gVault


public plugin_init() {
    
register_plugin(PLUGINVERSIONAUTHOR)
    
    
register_clcmd("say /rank""cmd_rank")
    
register_clcmd("say rank""cmd_rank")
    
    
register_clcmd("team_say /rank""cmd_rank")
    
register_clcmd("team_say rank""cmd_rank")
    
    
gVault nvault_open("TIME")
}

public 
cmd_rank(id)
{
    new 
stats[8], body[8], szName[33];
    
    
get_user_name(idszName32)
    
    new 
rank_pos get_user_stats(idstatsbody)
    new 
rank_max get_statsnum()
    
    new 
iTimeMins gTime[id] / 60
    
    
static Deaths 0Kills 0Float:Ratio 0.0
    
    Deaths 
stats[1], Kills stats[0], Ratio Deaths == ? (float(Kills)) : (float(Kills) / float(Deaths))
    
    
ColorChat(0GREEN"^4[Rank]^3 %s^1's rank is ^4%d^1 of ^4%d ^3-- ^1KpD: ^4%.2f^1 [Online: %i m]"szNamerank_posrank_maxRatioiTimeMins)
    
    return 
PLUGIN_CONTINUE;
}

public 
client_authorized(id)
{
    
loaddata(id)
}

public 
client_disconnect(id)
{
    
gTime[id] += get_user_time(id)
    
savedata(id)
}

stock savedata(id)
{
    new 
AuthId[65]
    
get_user_authid(idAuthIdcharsmax(AuthId))
    
    new 
VaultKey[64], VaultData[256]
    
format(VaultKey63"%s-TIME"AuthId)
    
format(VaultData254"%i"gTime[id])
    
    
nvault_set(gVaultVaultKeyVaultData)
    
    return 
PLUGIN_CONTINUE
}

stock loaddata(id)
{
    new 
AuthID[35
    
get_user_authid(id,AuthID,charsmax(AuthID ))
    new 
vaultkey[64],vaultdata[256]
    
    
format(vaultkey,63,"%s-TIME" ,AuthID
    
format(vaultdata,255,"%i",gTime[id]) 
    
    
nvault_get(gVault,vaultkey,vaultdata,charsmax (vaultdata))
    
    new 
Time[33]
    
parse(vaultdataTimecharsmax(Time))
    
    
gTime[id] = str_to_num(Time)

try

PHP Code:
#include <amxmodx>
#include <amxmisc>
#include <colorchat>
#include <csstats>
#include <csx>
#include <sqlx>  

#define PLUGIN "Rank System"
#define VERSION "1.0"
#define AUTHOR "BaD CopY"

// Ur Mysql Information
new Host[]     = "hostname"
new User[]    = "username"
new Pass[]     = "password"
new Db[]     = "database"

new gTime[33]
new 
Handle:g_SqlTuple
new g_Error[512]

public 
plugin_init() {
    
register_plugin(PLUGINVERSIONAUTHOR)
    
    
register_clcmd("say /rank""cmd_rank")
    
register_clcmd("say rank""cmd_rank")
    
    
register_clcmd("team_say /rank""cmd_rank")
    
register_clcmd("team_say rank""cmd_rank")
    
}

public 
MySql_Init()
{
    
g_SqlTuple SQL_MakeDbTuple(Host,User,Pass,Db)
    
    new 
ErrorCode,Handle:SqlConnection SQL_Connect(g_SqlTuple,ErrorCode,g_Error,charsmax(g_Error))
    if(
SqlConnection == Empty_Handle)
        
set_fail_state(g_Error)
    
    new 
Handle:Queries
    Queries 
SQL_PrepareQuery(SqlConnection,"CREATE TABLE IF NOT EXISTS tutorial (steamid varchar(32),time INT(11))")
    
    if(!
SQL_Execute(Queries))
    {
        
SQL_QueryError(Queries,g_Error,charsmax(g_Error))
        
set_fail_state(g_Error)
        
    }
    
    
SQL_FreeHandle(Queries)
    
    
SQL_FreeHandle(SqlConnection)   
}  

public 
cmd_rank(id)
{
    new 
stats[8], body[8], szName[33];
    
    
get_user_name(idszName32)
    
    new 
rank_pos get_user_stats(idstatsbody)
    new 
rank_max get_statsnum()
    
    new 
iTimeMins gTime[id] / 60
    
    
static Deaths 0Kills 0Float:Ratio 0.0
    
    Deaths 
stats[1], Kills stats[0], Ratio Deaths == ? (float(Kills)) : (float(Kills) / float(Deaths))
    
    
ColorChat(0GREEN"^4[Rank]^3 %s^1's rank is ^4%d^1 of ^4%d ^3-- ^1KpD: ^4%.2f^1 [Online: %i m]"szNamerank_posrank_maxRatioiTimeMins)
    
    return 
PLUGIN_CONTINUE;
}

public 
client_authorized(id)
{
    
Load_MySql(id)
}

public 
client_disconnect(id)
{
    
gTime[id] += get_user_time(id)
    
Save_MySql(id)
}


public 
Load_MySql(id)
{
    new 
szSteamId[32], szTemp[512]
    
get_user_authid(idszSteamIdcharsmax(szSteamId))
    
    new 
Data[1]
    
Data[0] = id
    
    format
(szTemp,charsmax(szTemp),"SELECT * FROM `tutorial` WHERE (`tutorial`.`steamid` = '%s')"szSteamId)
    
SQL_ThreadQuery(g_SqlTuple,"register_client",szTemp,Data,1)
}

public 
Save_MySql(id)
{
    new 
szSteamId[32], szTemp[512]
    
get_user_authid(idszSteamIdcharsmax(szSteamId))
    
    
format(szTemp,charsmax(szTemp),"UPDATE `tutorial` SET `time` = '%i' WHERE `tutorial`.`steamid` = '%s';",gTime[id], szSteamId)
    
SQL_ThreadQuery(g_SqlTuple,"IgnoreHandle",szTemp)
}  

public 
register_client(FailState,Handle:Query,Error[],Errcode,Data[],DataSize)
{
    if(
FailState == TQUERY_CONNECT_FAILED)
    {
        
log_amx("Load - Could not connect to SQL database.  [%d] %s"ErrcodeError)
    }
    else if(
FailState == TQUERY_QUERY_FAILED)
    {
        
log_amx("Load Query failed. [%d] %s"ErrcodeError)
    }
    
    new 
id
    id 
Data[0]
    
    if(
SQL_NumResults(Query) < 1
    {
        
        new 
szSteamId[32]
        
get_user_authid(idszSteamIdcharsmax(szSteamId)) 
        
        if (
equal(szSteamId,"ID_PENDING"))
            return 
PLUGIN_HANDLED
        
        
new szTemp[512]
        
        
format(szTemp,charsmax(szTemp),"INSERT INTO `tutorial` ( `steamid` , `timef`)VALUES ('%s','0');",szSteamId)
        
SQL_ThreadQuery(g_SqlTuple,"IgnoreHandle",szTemp)
    } 
    else 
    {
        
gTime[id]         = SQL_ReadResult(Query1)
    }
    
    return 
PLUGIN_HANDLED
}  




public 
plugin_end()
{
    
    
SQL_FreeHandle(g_SqlTuple)

__________________
Eagle07 is offline
frOOgy
Senior Member
Join Date: Jul 2014
Old 02-07-2015 , 17:59   Re: [Tut] MySql - Save/Load/Usefull Things (Xp Mod)
Reply With Quote #110

Can you fix the code and make to show hours and minuts online, not just minutes ?

And can you say me for what we need this part of the code:

PHP Code:
new Host[]     = "hostname" 
new User[]    = "username" 
new Pass[]     = "password" 
new Db[]     = "database" 
thxx for replay bro
__________________
Help me in other requests

Change Map System [PLUGIN]

GaG System [PLUGIN] [PLUGIN]

Last edited by frOOgy; 02-08-2015 at 05:55.
frOOgy is offline
Send a message via Skype™ to frOOgy
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 07:20.


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