Raised This Month: $ Target: $400
 0% 

Save load MYSQL


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
ironskillz1
AlliedModders Donor
Join Date: Jul 2012
Location: Sweden
Old 05-08-2013 , 12:40   Save load MYSQL
Reply With Quote #1

I got this vault save och load
and i need to make it to mySQL
Code:
public SaveData( id )
{
    new szData[ 64 ], szKey[ 32 ];
    get_user_authid( id, szKey, charsmax( szKey ) );
    format( szKey, charsmax( szKey ), "%s-BOUGHTSKINS", szKey );
    
    for( new i ; i < MAX_SKINS ; i ++ )
        if( g_bBoughtSkin[ id ][ i ] )
            format( szData, charsmax( szData ), "%s%i-", szData, i );
    
    set_vaultdata( szKey, szData );
}
public LoadData( id )
{
    new szData[ 64 ], szKey[ 32 ], szPiece[ 32 ];
    
    get_user_authid( id, szKey, charsmax( szKey ) );
    format( szKey, charsmax( szKey ), "%s-BOUGHTSKINS", szKey );
    
    get_vaultdata( szKey, szData, charsmax( szData ) );
    
    while( contain( szData, "-" ) >= 0 ) 
    {       
        strtok( szData, szPiece, charsmax( szPiece ), szData, charsmax( szData ), '-' );      
        
        g_bBoughtSkin[ id ][ str_to_num( szPiece ) ] = true;
    }
}
Here is the sql code i use
(i have tried but it didnt work)
Code:
#include <sqlx>
public plugin_precache() 
{ 
 MySQL_Tuple = SQL_MakeDbTuple(Host, User, Pass, Db) 
 SQL_ThreadQuery(MySQL_Tuple, "SQL_TrashHandler", "CREATE TABLE IF NOT EXISTS `Points_Shop`(`id` INT(1) NOT NULL AUTO_INCREMENT, `steamid` VARCHAR(32), `name` VARCHAR(32), `points` INT(1), `totalpoints` INT(1), `jumps` INT(1), `knife` INT(1), `player` INT(1), `bought` INT(1), PRIMARY KEY(`id`))")
}
public MySQL_Save(const id) {
 new szBugName[32], szName[32];
 get_user_name(id, szBugName, charsmax(szBugName))
 MakeStringSQLSafe(szBugName, szName, charsmax(szName))
 
 new szAuthid[32]
 get_user_authid(id, szAuthid, charsmax(szAuthid))
 for( new i ; i < MAX_SKINS ; i ++ ) 
 
 formatex(MySQL_Query, charsmax(MySQL_Query), "UPDATE `Points_Shop` SET `name` = '%s', `points` = '%i', `totalpoints` = '%i', `jumps` = '%i', `knife` = '%d', `player` = '%d', `bought` = '%i' WHERE `steamid`='%s'", szName, gKillerPoints[id], gTotalKillerPoints[id], vJump[id], knife_model[id], player_model[id], g_bBoughtSkin[id][i], szAuthid)
 SQL_ThreadQuery(MySQL_Tuple, "SQL_TrashHandler", MySQL_Query)
}
MakeStringSQLSafe(const input[], output[], len)
{
 copy(output, len, input);
 replace_all(output, len, "'", "*");
 replace_all(output, len, "^"", "*");
 replace_all(output, len, "`", "*");
}
public MySQL_Load(id) {
 new szAuthid[32]
 get_user_authid(id, szAuthid, charsmax(szAuthid))
 
 new Temp[1]
 Temp[0] = id
 
 formatex(MySQL_Query, charsmax(MySQL_Query), "SELECT * FROM `Points_Shop` WHERE `steamid` = '%s'", szAuthid)
 SQL_ThreadQuery(MySQL_Tuple, "Load_PlayerInfo", MySQL_Query, Temp, sizeof(Temp))
}
public Load_PlayerInfo(FailState, Handle:Query, Error[], Errcode, Data[], DataSize) {
 if(FailState == TQUERY_CONNECT_FAILED)
  log_amx("Load - Could not connect to SQL database.  [%d] %s", Errcode, Error)
 else if(FailState == TQUERY_QUERY_FAILED)
  log_amx("Load Query failed. [%d] %s", Errcode, Error)
 
 new id = Data[0]
 
 new szName[32], szBugName[32], szAuthid[32]; 
 get_user_name(id, szBugName, charsmax(szBugName));
 MakeStringSQLSafe(szBugName, szName, sizeof(szName) - 1);
 
 get_user_authid(id, szAuthid, charsmax(szAuthid))
 
 if(SQL_NumResults(Query) < 1) 
 {
 
 formatex(MySQL_Query, charsmax(MySQL_Query), "INSERT INTO `Points_Shop` (`steamid`, `name`) VALUES ('%s', '%s')", szAuthid, szName)
 SQL_ThreadQuery(MySQL_Tuple, "SQL_TrashHandler", MySQL_Query)
 }
 else 
 {
  gKillerPoints[id]         = SQL_ReadResult(Query, 3)
  gTotalKillerPoints[id]         = SQL_ReadResult(Query, 4)
  vJump[id]         = SQL_ReadResult(Query, 5)
  knife_model[id]         = SQL_ReadResult(Query, 6)
  player_model[id]         = SQL_ReadResult(Query, 7)
  for( new i ; i < MAX_SKINS ; i ++ ) 
  g_bBoughtSkin[id][i]         = SQL_ReadResult(Query, 8)
 }
}
public SQL_TrashHandler(FailState,Handle:Query,Error[],Errcode,Data[],DataSize) { 
 if(FailState == TQUERY_CONNECT_FAILED)
  log_amx("Load - Could not connect to SQL database.  [%d] %s", Errcode, Error)
 else if(FailState == TQUERY_QUERY_FAILED)
  log_amx("Load Query failed. [%d] %s", Errcode, Error)
 
 SQL_FreeHandle(Query)
}
__________________
I have many private and unique plugins for Jailbreak and Hide'N'Seek. PM me for more info.

Pm me.

Check out my roulette site.

Last edited by ironskillz1; 05-08-2013 at 13:01.
ironskillz1 is offline
Send a message via Skype™ to ironskillz1
Kia
AlliedModders Donor
Join Date: Apr 2010
Location: In a world of madness
Old 05-08-2013 , 16:35   AW: Save load MYSQL
Reply With Quote #2

If you're trying to make a shop which saves the items in SQL look at the SQL Version from hats, it has been released on Suggestions forum a while ago.
__________________
Kia is offline
ironskillz1
AlliedModders Donor
Join Date: Jul 2012
Location: Sweden
Old 05-08-2013 , 18:24   Re: AW: Save load MYSQL
Reply With Quote #3

Quote:
Originally Posted by Kia View Post
If you're trying to make a shop which saves the items in SQL look at the SQL Version from hats, it has been released on Suggestions forum a while ago.
I already got the save in vault that works
Code:
public SaveData( id )
{
    new szData[ 64 ], szKey[ 32 ];
    get_user_authid( id, szKey, charsmax( szKey ) );
    format( szKey, charsmax( szKey ), "%s-BOUGHTSKINS", szKey );
    
    for( new i ; i < MAX_SKINS ; i ++ )
        if( g_bBoughtSkin[ id ][ i ] )
            format( szData, charsmax( szData ), "%s%i-", szData, i );
    
    set_vaultdata( szKey, szData );
}
public LoadData( id )
{
    new szData[ 64 ], szKey[ 32 ], szPiece[ 32 ];
    
    get_user_authid( id, szKey, charsmax( szKey ) );
    format( szKey, charsmax( szKey ), "%s-BOUGHTSKINS", szKey );
    
    get_vaultdata( szKey, szData, charsmax( szData ) );
    
    while( contain( szData, "-" ) >= 0 ) 
    {       
        strtok( szData, szPiece, charsmax( szPiece ), szData, charsmax( szData ), '-' );      
        
        g_bBoughtSkin[ id ][ str_to_num( szPiece ) ] = true;
    }
}
But i need for sql to
__________________
I have many private and unique plugins for Jailbreak and Hide'N'Seek. PM me for more info.

Pm me.

Check out my roulette site.
ironskillz1 is offline
Send a message via Skype™ to ironskillz1
Kia
AlliedModders Donor
Join Date: Apr 2010
Location: In a world of madness
Old 05-09-2013 , 02:03   AW: Re: AW: Save load MYSQL
Reply With Quote #4

Quote:
Originally Posted by Kia View Post
If you're trying to make a shop which saves the items in SQL look at the SQL Version from hats, it has been released on Suggestions forum a while ago.
__________________
Kia is offline
ironskillz1
AlliedModders Donor
Join Date: Jul 2012
Location: Sweden
Old 05-09-2013 , 06:29   Re: AW: Re: AW: Save load MYSQL
Reply With Quote #5

Nope the only thing i need help with is to make this code
Code:
public SaveData( id )
{
    new szData[ 64 ], szKey[ 32 ];
    get_user_authid( id, szKey, charsmax( szKey ) );
    format( szKey, charsmax( szKey ), "%s-BOUGHTSKINS", szKey );
    
    for( new i ; i < MAX_SKINS ; i ++ )
        if( g_bBoughtSkin[ id ][ i ] )
            format( szData, charsmax( szData ), "%s%i-", szData, i );
    
    set_vaultdata( szKey, szData );
}
public LoadData( id )
{
    new szData[ 64 ], szKey[ 32 ], szPiece[ 32 ];
    
    get_user_authid( id, szKey, charsmax( szKey ) );
    format( szKey, charsmax( szKey ), "%s-BOUGHTSKINS", szKey );
    
    get_vaultdata( szKey, szData, charsmax( szData ) );
    
    while( contain( szData, "-" ) >= 0 ) 
    {       
        strtok( szData, szPiece, charsmax( szPiece ), szData, charsmax( szData ), '-' );      
        
        g_bBoughtSkin[ id ][ str_to_num( szPiece ) ] = true;
    }
}
save like SQL
__________________
I have many private and unique plugins for Jailbreak and Hide'N'Seek. PM me for more info.

Pm me.

Check out my roulette site.
ironskillz1 is offline
Send a message via Skype™ to ironskillz1
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 10:57.


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