AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Save load MYSQL (https://forums.alliedmods.net/showthread.php?t=215496)

ironskillz1 05-08-2013 12:40

Save load MYSQL
 
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)
}


Kia 05-08-2013 16:35

AW: Save load MYSQL
 
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.

ironskillz1 05-08-2013 18:24

Re: AW: Save load MYSQL
 
Quote:

Originally Posted by Kia (Post 1948345)
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

Kia 05-09-2013 02:03

AW: Re: AW: Save load MYSQL
 
Quote:

Originally Posted by Kia (Post 1948345)
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.


ironskillz1 05-09-2013 06:29

Re: AW: Re: AW: Save load MYSQL
 
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


All times are GMT -4. The time now is 10:57.

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