Raised This Month: $ Target: $400
 0% 

[MySQL] Save / Laod problem


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Xalus
Veteran Member
Join Date: Dec 2009
Location: Belgium
Old 08-10-2011 , 18:06   [MySQL] Save / Laod problem
Reply With Quote #1

Hello,
for some reason sometimes players items gets removed,
sometimes it doesn't save a deagle level for example,
so I hope u guys can help me.

Save:
PHP Code:
public client_disconnectiPlayer )
{    
    
Save(iPlayer);
}

public 
Save(iPlayer) {
    new 
szSteamId[32], szName[32], szTemp[1200];
    
get_user_authid(iPlayerszSteamIdcharsmax(szSteamId));
    
get_user_name(iPlayerszNamecharsmax(szName));
    
    
replace_all(szNamecharsmax(szName), "'""")
    
replace_all(szNamecharsmax(szName), "`""")
    
replace_all(szNamecharsmax(szName), "´""")
    
    
format(MySQL_Querycharsmax(MySQL_Query), "%s `totalEuro` = '%i', `Euro` = '%i', `rollwins` = '%i', `name` = '%s' WHERE `EuroMod`.`steamid` = '%s';","UPDATE `EuroMod` SET"g_tEuro[iPlayer], g_iEuro[iPlayer], tRolled[iPlayer], szNameszSteamId);
    
SQL_ThreadQuery(MySQL_Tuple"SQL_TrashHandler"MySQL_Query)
    
    
format(szTemp,charsmax(szTemp),"UPDATE `EuroModItems` SET ");
    
    new 
a;
    for(
a=0g_iItemCounta++) {
        
format(szTempcharsmax(szTemp), "%s`%i` = '%i', "szTempag_iItemLevel[iPlayer][a]);
    }        
    for(new 
z=0g_iWeapCountz++) {
        if(
== g_iWeapCount-1)
            
format(szTempcharsmax(szTemp), "%s`%i` = '%i' "szTempz+ag_iWeapLevel[iPlayer][z]);
        else
            
format(szTempcharsmax(szTemp), "%s`%i` = '%i', "szTempz+ag_iWeapLevel[iPlayer][z]);
    }
    
format(MySQL_Querycharsmax(MySQL_Query), "%sWHERE `steamid` = '%s';",szTempszSteamId);
    
SQL_ThreadQuery(MySQL_Tuple"SQL_TrashHandler"MySQL_Query)


Load:
PHP Code:
public client_authorizediPlayer )
{
   
Load(iPlayer);
}

public 
Load(id) {
    new 
szSteamId[32]; get_user_authid(idszSteamIdcharsmax(szSteamId));
    
    new 
szTemp[1]
    
szTemp[0]=id
    
    format
(MySQL_Querycharsmax(MySQL_Query), "SELECT * FROM `EuroMod` WHERE (`EuroMod`.`steamid` = '%s')"szSteamId);
    
SQL_ThreadQuery(MySQL_Tuple"Load_PlayerEuro"MySQL_QueryszTemp1)
    
    return 
PLUGIN_CONTINUE;
}
public 
Load_PlayerEuro(FailStateHandle:QueryError[], ErrcodeData[], 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 Data[0]
    
    new 
szSteamId[32]; get_user_authid(idszSteamIdcharsmax(szSteamId));
    
    if(
SQL_NumResults(Query) < 1)  {
        new 
szName[32];     get_user_name(idszName31);
        
        if (
equal(szSteamId,"ID_PENDING"))
            return 
PLUGIN_HANDLED;
                    
        
g_tEuro[id] = 400;
        
g_iEuro[id] = 400;
        
        new 
iItem[33];
        
        for( 
iItem[id] = 0iItem[id] < g_iItemCountiItem[id]++ )
        {
            
g_iItemLevel[id][iItem[id]] = 0;
        }
        for( 
iItem[id] = 0iItem[id] < g_iWeapCountiItem[id]++ )
        {
            
g_iWeapLevel[id][iItem[id]] = 0;
        }
        
format(MySQL_Querycharsmax(MySQL_Query),"INSERT INTO `EuroMod` ( `steamid`, `totalEuro` , `Euro`, `name` ) VALUES ('%s','%i','%i','%s')",szSteamIdg_tEuro[id], g_iEuro[id], szName)
        
SQL_ThreadQuery(MySQL_Tuple"SQL_TrashHandler"MySQL_Query)
        
    } else  {
        
g_tEuro[id]         = SQL_ReadResult(Query1)
        
g_iEuro[id]         = SQL_ReadResult(Query2)
    }
    
    new 
szTemp[1];
    
szTemp[0] = id
    
    format
(MySQL_Querycharsmax(MySQL_Query), "SELECT * FROM `EuroModItems` WHERE (`EuroModItems`.`steamid` = '%s')"szSteamId);
    
SQL_ThreadQuery(MySQL_Tuple"Load_PlayerEuroItems"MySQL_QueryszTemp1)
    
    return 
PLUGIN_CONTINUE;
}
public 
Load_PlayerEuroItems(FailStateHandle:QueryError[], ErrcodeData[], 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 Data[0]
    new 
a;
    
    if(
SQL_NumResults(Query) < 1)  {    
        new 
szSteamId[32]; get_user_authid(idszSteamIdcharsmax(szSteamId));
        
        
format(MySQL_Querycharsmax(MySQL_Query), "INSERT INTO `EuroModItems` (`steamid`)VALUES ('%s');"szSteamId);
        
SQL_ThreadQuery(MySQL_Tuple"SQL_TrashHandler"MySQL_Query)
    } else {
        for(
a=1<= g_iItemCounta++) {
            
g_iItemLevel[id][a-1] = SQL_ReadResult(Querya);
        }
        for(new 
z=0g_iWeapCountz++) {
            
g_iWeapLevel[id][z] = SQL_ReadResult(Queryz+a);
        }
        
        if( 
g_iWeapLevel[id][WEAPON_AWP] == )
            
g_iWeapLevel[id][BULLET_AWP]=0
        
        
if( g_iWeapLevel[id][WEAPON_DEAGLE] == )
            
g_iWeapLevel[id][BULLET_DEAGLE]=0
            
        
if( g_iWeapLevel[id][WEAPON_FS] == )
            
g_iWeapLevel[id][BULLET_FS]=0
        
        
if( g_iWeapLevel[id][WEAPON_USP] == )
            
g_iWeapLevel[id][BULLET_USP]=0
    
}

TrashHandler:
PHP Code:
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"ErrcodeError)
    else if(
FailState == TQUERY_QUERY_FAILED)
        
log_amx("Load Query failed. [%d] %s"ErrcodeError)

__________________
Retired.
Xalus is offline
Exolent[jNr]
Veteran Member
Join Date: Feb 2007
Location: Tennessee
Old 08-10-2011 , 18:48   Re: [MySQL] Save / Laod problem
Reply With Quote #2

It would help to know the structure of the table(s) in question.
__________________
No private work or selling mods.
Quote:
Originally Posted by xPaw View Post
I love you exolent!
Exolent[jNr] is offline
Xalus
Veteran Member
Join Date: Dec 2009
Location: Belgium
Old 08-11-2011 , 14:33   Re: [MySQL] Save / Laod problem
Reply With Quote #3

Here:

PHP Code:
public plugin_precache() {
    
MySQL_Tuple SQL_MakeDbTuple(HostUserPassDb)
    
    
format(MySQL_Querycharsmax(MySQL_Query), "CREATE TABLE IF NOT EXISTS EuroMod (steamid varchar(32),totalEuro INT(11), Euro INT(11), name varchar(32), rollwins INT(11))")
    
SQL_ThreadQuery(MySQL_Tuple"SQL_TrashHandler"MySQL_Query)
    
    new 
szTemp[1900];
    new 
a;
    for(
a=0g_iItemCounta++) {
        
formatex(szTempcharsmax(szTemp), "%s`%i` INT(11), "szTempa);
    }
    
    for(new 
i=0g_iWeapCounti++) {    
        if( (
== g_iWeapCount-1) ) 
            
formatex(szTempcharsmax(szTemp), "%s`%i` INT(11)"szTempi+a);
            
        else
            
formatex(szTempcharsmax(szTemp), "%s`%i` INT(11), "szTempi+a);
    }
    
    
format(MySQL_Querycharsmax(MySQL_Query), "CREATE TABLE IF NOT EXISTS EuroModItems (steamid varchar(32), %s)"szTemp);
    
SQL_ThreadQuery(MySQL_Tuple"SQL_TrashHandler"MySQL_Query)
    

__________________
Retired.
Xalus is offline
Exolent[jNr]
Veteran Member
Join Date: Feb 2007
Location: Tennessee
Old 08-11-2011 , 14:49   Re: [MySQL] Save / Laod problem
Reply With Quote #4

You should either use SQL_FieldNameToNum() to know which columns you are getting, or properly set them in your SELECT statement.
Otherwise, you may be getting the wrong columns.
__________________
No private work or selling mods.
Quote:
Originally Posted by xPaw View Post
I love you exolent!
Exolent[jNr] is offline
Sylwester
Veteran Member
Join Date: Oct 2006
Location: Poland
Old 08-11-2011 , 17:40   Re: [MySQL] Save / Laod problem
Reply With Quote #5

PHP Code:
formatex(szTempcharsmax(szTemp), "%s`%i` INT(11), "szTempa); 
Quote:
Originally Posted by funcwiki
Same as format(), except does not perform a "copy back" check.
This means formatex() is faster, but DOES NOT ALLOW this type of call:
formatex(buffer, len, "%s", buffer)
formatex(buffer, len, buffer, buffer)
formatex(buffer, len, "%s", buffer[5])
This is because the output is directly stored into "buffer", rather than copied back at the end.
You should use it this way:
PHP Code:
new pos
pos 
+= formatex(szTemp[pos], charsmax(szTemp)-pos"`%i` INT(11), "a); 
__________________
Impossible is Nothing
Sylwester is offline
Old 08-13-2011, 16:23
lucas_7_94
This message has been deleted by lucas_7_94. Reason: nothing.avi
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 03:30.


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