This site is a testing version, but all data is shared with the live forum.


Raised This Month: $ Target: $400
 0% 

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


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
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 #1

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 #2

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 #3

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
Jhob94
AMX Mod X Donor
Join Date: Jul 2012
Old 02-11-2015 , 05:24   Re: [Tut] MySql - Save/Load/Usefull Things (Xp Mod)
Reply With Quote #4

Quote:
Originally Posted by frOOgy View Post
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
Are you sure that you want a sql and not nvault/fvault plugin?


Anyway, i need help about two thing. How do i get a string?
Also, lets say that i have in db the same steam id 2 times, but different values. How do i get those variables?
__________________
Jhob94 is offline
skz
Senior Member
Join Date: Jul 2014
Location: Portugal
Old 02-11-2015 , 13:23   Re: [Tut] MySql - Save/Load/Usefull Things (Xp Mod)
Reply With Quote #5

Quote:
Originally Posted by Jhob94 View Post
Anyway, i need help about two thing. How do i get a string?
Also, lets say that i have in db the same steam id 2 times, but different values. How do i get those variables?
Which string?
Why would you have the same steam id twice on your database?
__________________
skz is offline
frOOgy
Senior Member
Join Date: Jul 2014
Old 02-11-2015 , 11:53   Re: [Tut] MySql - Save/Load/Usefull Things (Xp Mod)
Reply With Quote #6

Because MySQL is most popular vault system and I want to learn how to use it
__________________
Help me in other requests

Change Map System [PLUGIN]

GaG System [PLUGIN] [PLUGIN]
frOOgy is offline
Send a message via Skype™ to frOOgy
Jhob94
AMX Mod X Donor
Join Date: Jul 2012
Old 02-11-2015 , 11:56   Re: [Tut] MySql - Save/Load/Usefull Things (Xp Mod)
Reply With Quote #7

Quote:
Originally Posted by frOOgy View Post
Because MySQL is most popular vault system and I want to learn how to use it
Then, first get a database before request the plugin...
__________________
Jhob94 is offline
frOOgy
Senior Member
Join Date: Jul 2014
Old 02-12-2015 , 14:57   Re: [Tut] MySql - Save/Load/Usefull Things (Xp Mod)
Reply With Quote #8

nevermind. did I need this part of the code:

[php]new Host[] = "hostname"
new User[] = "username"
new Pass[] = "password"
new Db[] = "database" [/pph]
__________________
Help me in other requests

Change Map System [PLUGIN]

GaG System [PLUGIN] [PLUGIN]
frOOgy is offline
Send a message via Skype™ to frOOgy
Jhob94
AMX Mod X Donor
Join Date: Jul 2012
Old 02-12-2015 , 15:19   Re: [Tut] MySql - Save/Load/Usefull Things (Xp Mod)
Reply With Quote #9

Quote:
Originally Posted by frOOgy View Post
nevermind. did I need this part of the code:

[php]new Host[] = "hostname"
new User[] = "username"
new Pass[] = "password"
new Db[] = "database" [/pph]
yes you need it. you need a database and put the information about database.
Anyway, sql isnt the best. It has advantages but also has disadvantages. The biggest advantage is that you will be able to make php scripts and show saved stuff in a website. If you dont need that, go use nvault or fvault because they are better.
__________________
Jhob94 is offline
frOOgy
Senior Member
Join Date: Jul 2014
Old 02-12-2015 , 17:37   Re: [Tut] MySql - Save/Load/Usefull Things (Xp Mod)
Reply With Quote #10

ok, thxx for help...

t/c
__________________
Help me in other requests

Change Map System [PLUGIN]

GaG System [PLUGIN] [PLUGIN]
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 02:49.


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