Raised This Month: $32 Target: $400
 8% 

Save Points On mysql


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
oxygen935
Veteran Member
Join Date: Jun 2012
Location: Athens, Greece
Old 04-30-2013 , 09:59   Save Points On mysql
Reply With Quote #1

Hello everybody,
As the title says i have a points system on my server and i want to save the player points on a mysql database. I really need help... I found some xp mods that saves the xp on a mysql database but i want some help on how to save points and not xp...
btw i found this tutorial: http://forums.alliedmods.net/showthread.php?t=132686

PS:I really know that vault is faster and easier, so if you want to suggest me to use vault, better not reply. I want to learn how to save them on MySql DataBase...
__________________
Quote:
Originally Posted by quark View Post
You're a genius
Stopped any pawn work cause of university for computer science
oxygen935 is offline
Send a message via Skype™ to oxygen935
Sylwester
Veteran Member
Join Date: Oct 2006
Location: Poland
Old 04-30-2013 , 21:47   Re: Save Points On mysql
Reply With Quote #2

Asking us to help you learn how to save points and not xp makes no sense, because in both cases you save some integer value in database and there is no difference. If you need more examples, then take a look at my sql rank mod.
__________________
Impossible is Nothing
Sylwester is offline
oxygen935
Veteran Member
Join Date: Jun 2012
Location: Athens, Greece
Old 05-01-2013 , 01:54   Re: Save Points On mysql
Reply With Quote #3

Oh ok, i didn't know if it's the same. Thanks. I'll try it!
__________________
Quote:
Originally Posted by quark View Post
You're a genius
Stopped any pawn work cause of university for computer science
oxygen935 is offline
Send a message via Skype™ to oxygen935
oxygen935
Veteran Member
Join Date: Jun 2012
Location: Athens, Greece
Old 05-01-2013 , 15:15   Re: Save Points On mysql
Reply With Quote #4

I did something with mysql but i have some debug errors...
Code:
L 05/01/2013 - 21:01:40: Start of error session.
L 05/01/2013 - 21:01:40: Info (map "de_dust2") (file "addons/amxmodx/logs/error_20130501.log")
L 05/01/2013 - 21:01:40: [MySQL] Thread worker was unable to start.
L 05/01/2013 - 21:01:40: [AMXX] Displaying debug trace (plugin "points.amxx")
L 05/01/2013 - 21:01:40: [AMXX] Run time error 10: native error (native "SQL_ThreadQuery")
L 05/01/2013 - 21:01:40: [AMXX]    [0] points.sma::register_client (line 526)
Here is the part of mysql...
PHP Code:
#include <amxmodx>
#include <sqlx>

new points[33];

new 
Host[]     = "blahblah"
new User[]    = "blahblah"
new Pass[]     = "blahblah"
new Db[]     = "blahblah"

new Handle:g_SqlTuple
new g_Error[512]

public 
plugin_init() 
{
    
set_task(1.0"MySql_Init"
}

public 
MySql_Init()
{
    
// we tell the API that this is the information we want to connect to,
    // just not yet. basically it's like storing it in global variables
    
g_SqlTuple SQL_MakeDbTuple(Host,User,Pass,Db)
    
    
// ok, we're ready to connect
    
new ErrorCode,Handle:SqlConnection SQL_Connect(g_SqlTuple,ErrorCode,g_Error,charsmax(g_Error))
    if(
SqlConnection == Empty_Handle)
        
// stop the plugin with an error message
    
set_fail_state(g_Error)
    
    new 
Handle:Queries
    
// we must now prepare some random queries
    
Queries SQL_PrepareQuery(SqlConnection,"CREATE TABLE IF NOT EXISTS user_points (name varchar(32),points INT(11))")
    
    if(!
SQL_Execute(Queries))
    {
        
// if there were any problems
        
SQL_QueryError(Queries,g_Error,charsmax(g_Error))
        
set_fail_state(g_Error)
        
    }
    
    
// close the handle
    
SQL_FreeHandle(Queries)
    
    
// you free everything with SQL_FreeHandle
    
SQL_FreeHandle(SqlConnection)   
}

public 
plugin_end()
{
    
// free the tuple - note that this does not close the connection,
    // since it wasn't connected in the first place
    
SQL_FreeHandle(g_SqlTuple)
}

public 
Load_MySql(id)
{
    new 
szName[32], szTemp[512]
    
get_user_name(idszNamecharsmax(szName))
    
    new 
Data[1]
    
Data[0] = id
    
    format
(szTemp,charsmax(szTemp),"SELECT * FROM `user_points` WHERE (`user_points`.`name` = '%s')"szName)
    
SQL_ThreadQuery(g_SqlTuple,"register_client",szTemp,Data,1)
}

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
    {
        
//.if there are no results found
        
        
new szName[32]
        
get_user_name(idszNamecharsmax(szName))
        new 
szTemp[512]
        
        
// now we will insturt the values into our table.
        
format(szTemp,charsmax(szTemp),"INSERT INTO `user_points` ( `name` , `points`)VALUES ('%s','0');"szName)
        
SQL_ThreadQuery(g_SqlTuple,"IgnoreHandle",szTemp)
    } 
    else 
    {
        
// if there are results found
        
points[id]         = SQL_ReadResult(Query1)
    }
    
    return 
PLUGIN_HANDLED
}

public 
Save_MySql(id)
{
    new 
szName[32], szTemp[512]
    
get_user_name(idszNamecharsmax(szName))
    
    
format(szTemp,charsmax(szTemp),"UPDATE `user_points` SET `points` = '%i' WHERE `user_points`.`name` = '%s';",points[id], szName)
    
SQL_ThreadQuery(g_SqlTuple,"IgnoreHandle",szTemp)
}

public 
IgnoreHandle(FailState,Handle:Query,Error[],Errcode,Data[],DataSize)
{
    
SQL_FreeHandle(Query)
    
    return 
PLUGIN_HANDLED
}

public 
client_putinserver(id)
{
    
Load_MySql(id)
}

public 
client_disconnect(id)
{
    
Save_MySql(id)

__________________
Quote:
Originally Posted by quark View Post
You're a genius
Stopped any pawn work cause of university for computer science

Last edited by oxygen935; 05-01-2013 at 15:22.
oxygen935 is offline
Send a message via Skype™ to oxygen935
Old 05-01-2013, 16:16
claudiuhks
This message has been deleted by claudiuhks. Reason: Unwanted
YamiKaitou
Has a lovely bunch of coconuts
Join Date: Apr 2006
Location: Texas
Old 05-01-2013 , 18:13   Re: Save Points On mysql
Reply With Quote #5

Quote:
Originally Posted by oxygen935 View Post
I did something with mysql but i have some debug errors...
Code:
L 05/01/2013 - 21:01:40: Start of error session.
L 05/01/2013 - 21:01:40: Info (map "de_dust2") (file "addons/amxmodx/logs/error_20130501.log")
L 05/01/2013 - 21:01:40: [MySQL] Thread worker was unable to start.
L 05/01/2013 - 21:01:40: [AMXX] Displaying debug trace (plugin "points.amxx")
L 05/01/2013 - 21:01:40: [AMXX] Run time error 10: native error (native "SQL_ThreadQuery")
L 05/01/2013 - 21:01:40: [AMXX]    [0] points.sma::register_client (line 526)
I'm told that is because you are calling a Threaded Query when the map is changing. There is a thread in the Issues section that has a workaround, or you can ignore the error or bug the AMXX Devs to fix it
__________________
ProjectYami Laboratories

I do not browse the forums regularly anymore. If you need me for anything (asking questions or anything else), then PM me (be descriptive in your PM, message containing only a link to a thread will be ignored).
YamiKaitou is offline
Kia
AlliedModders Donor
Join Date: Apr 2010
Location: In a world of madness
Old 05-04-2013 , 06:20   Re: Save Points On mysql
Reply With Quote #6

Try this :

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

new PLUGIN[]  = "Points"
new AUTHOR[]  = "Kia Armani"
new VERSION[] = "1.0"

new Host[]        = ""
new User[]        = ""
new Pass[]        = ""
new Db[]       = ""

new Points[33];
new 
bool:iStart[33];

new 
Handle:g_SqlConnection
new Handle:g_SqlTuple
new g_Error[512]
new 
g_authed[33]
new 
g_sql_ready false
new bool:g_loaded[33]

new 
maxplayers;

public 
plugin_init()
{
    
register_plugin(PLUGINVERSIONAUTHOR)
    
    
maxplayers get_maxplayers()
    
set_task(0.1"MySql_Init")
}

public 
MySql_Init()
{
    
// we tell the API that this is the information we want to connect to,
    // just not yet. basically it's like storing it in global variables
    
g_SqlTuple SQL_MakeDbTuple(Host,User,Pass,Db)
    
    
// ok, we're ready to connect
    
new ErrorCode
    g_SqlConnection 
SQL_Connect(g_SqlTuple,ErrorCode,g_Error,charsmax(g_Error))
    if(
g_SqlConnection == Empty_Handle)
    {
        
// stop the plugin with an error message
        
set_fail_state(g_Error)
    }
    
    new 
Handle:Queries
    
// we must now prepare some random queries
    
Queries SQL_PrepareQuery(g_SqlConnection,"CREATE TABLE IF NOT EXISTS pts (steamid varchar(32), name varchar(64), money INT(11))")
    
    if(!
SQL_Execute(Queries))
    {
        
// if there were any problems
        
SQL_QueryError(Queries,g_Error,charsmax(g_Error))
        
set_fail_state(g_Error)
    }
    
    
// close the handle
    
SQL_FreeHandle(Queries)
    
    
g_sql_ready true
    
for(new i=1i<=maxplayersi++)
    {
        if(
g_authed[i])
        {
            
Load_MySql(i)
        }
    }
}

public 
Load_MySql(id)
{
    if(
g_sql_ready)
    {
        if(
g_SqlTuple == Empty_Handle)
        {
            
set_fail_state(g_Error)
        }
        
        new 
szSteamId[32], szTemp[512]
        
get_user_authid(idszSteamIdcharsmax(szSteamId))
        
        new 
Data[1]
        
Data[0] = id
        
        
//we will now select from the table `furienmoney` where the steamid match
        
format(szTemp,charsmax(szTemp),"SELECT * FROM `pts` WHERE (`pts`.`steamid` = '%s')"szSteamId)
        
SQL_ThreadQuery(g_SqlTuple,"register_client",szTemp,Data,1)
    }
}

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)
    {
        
//.if there are no results found
        
        
new szSteamId[32], szName[32], szQuotedName[64]
        
get_user_authid(idszSteamIdcharsmax(szSteamId)) // get user's steamid
        
get_user_name(idszName31// get user's name
        
SQL_QuoteString(g_SqlConnectionszQuotedName63szName)
        
        
//  if its still pending we can't do anything with it
        
if (equal(szSteamId,"ID_PENDING"))
        {
            return 
PLUGIN_HANDLED
        
}
        
        new 
szTemp[512]
        
        
// now we will insert the values into our table.
        
format(szTemp,charsmax(szTemp),"INSERT INTO `coins` ( `steamid` , `name` , `pts`) VALUES ('%s','%s','0');",szSteamIdszQuotedName)
        
SQL_ThreadQuery(g_SqlTuple,"IgnoreHandle",szTemp)
    }
    else
    {
        
// if there are results found
        
Points[id]        = SQL_ReadResult(Query2)
    }
    
g_loaded[id] = true
    
return PLUGIN_HANDLED
}

public 
Save_MySql(id)
{
    if(
g_loaded[id])
    {
        new 
szSteamId[32], szTemp[512], szName[32], szQuotedName[64]
        
get_user_authid(idszSteamIdcharsmax(szSteamId))
        
get_user_name(idszName31)
        
SQL_QuoteString(g_SqlConnectionszQuotedName63szName)
        
        
// Here we will update the user hes information in the database where the steamid matches.
        
format(szTemp,charsmax(szTemp),"UPDATE `coins` SET `name` = '%s', `pts` = '%i' WHERE `coins`.`steamid` = '%s';",szQuotedName,Points[id],szSteamId)
        
SQL_ThreadQuery(g_SqlTuple,"IgnoreHandle",szTemp)
    }
}

public 
IgnoreHandle(FailState,Handle:Query,Error[],Errcode,Data[],DataSize)
{
    
SQL_FreeHandle(Query)
    
    return 
PLUGIN_HANDLED
}

public 
plugin_end()
{
    if(
g_SqlConnection != Empty_Handle)
    {
        
SQL_FreeHandle(g_SqlConnection//free connection handle here
    
}
}

public 
client_disconnect(id)
{
    
    
Save_MySql(id)
    
Points[id] = 0
    iStart
[id] = false
}

public 
client_authorized(id)
{
    
g_authed[id] = true
    Load_MySql
(id)

__________________
Kia is offline
BaD CopY
Senior Member
Join Date: Oct 2014
Location: Home
Old 07-31-2016 , 17:39   Re: Save Points On mysql
Reply With Quote #7

How to make top15 functions using mysql ?
BaD CopY is offline
Send a message via Yahoo to BaD CopY Send a message via Skype™ to BaD CopY
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 08-01-2016 , 17:44   Re: Save Points On mysql
Reply With Quote #8

Code:
SELECT TOP 15 FieldValue
FROM YourTable
ORDER BY FieldValue ASC;
__________________
Bugsy is offline
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 01:31.


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