Raised This Month: $ Target: $400
 0% 

[CS:S] SQL_TQuery doesn't works ?


Post New Thread Reply   
 
Thread Tools Display Modes
delachambre
AlliedModders Donor
Join Date: Jan 2011
Location: France
Old 08-29-2012 , 13:46   Re: [CS:S] SQL_TQuery doesn't works ?
Reply With Quote #21

Yes it was a side SQL error on my part, but let the SQL is OK, but why does the loop does not? I do not understand what is happening ... Is recovery steam ID is too fast? that is the question ^ ^
__________________
♥ 𝕊ℙ𝕒𝕨𝕟 𝔻𝕖𝕧𝕖𝕝𝕠𝕡𝕖𝕣 [ℂ𝕊:𝕊] ♥

Clan-Nemesis
delachambre is offline
11530
Veteran Member
Join Date: Sep 2011
Location: Underworld
Old 08-29-2012 , 13:55   Re: [CS:S] SQL_TQuery doesn't works ?
Reply With Quote #22

You should be using IsClientAuthorized before you use GetClientAuthString.

Also in the loop why do:
Code:
new after = bank[i];
bank[i] = StringToInt(arg2) + after;
When you could do:
Code:
bank[i] = StringToInt(arg2) + bank[i];
Or, even better:
Code:
bank[i] += StringToInt(arg2);
And don't use the found bool, just return from the plugin if found.

Aside from the things above, and the error I gave you two posts ago, is everything working now? Or is it still broken? If it's broken, I'll try a version which includes some of my things, and some of your code.
__________________
11530 is offline
delachambre
AlliedModders Donor
Join Date: Jan 2011
Location: France
Old 08-29-2012 , 14:02   Re: [CS:S] SQL_TQuery doesn't works ?
Reply With Quote #23

I have try this :

Code:
public Action:Command_Givemoney(client, args)
{
	decl String:arg1[64];
	decl String:arg2[32];
	decl String:SteamID[64];
	
	new bool:found = false;
	
	GetCmdArg(1, arg1, sizeof(arg1));
	GetCmdArg(2, arg2, sizeof(arg2));
	
	for (new i = 1; i <= MaxClients; i++)
	{
		if (IsClientInGame(i) && IsClientAuthorized(i))
		{
			GetClientAuthString(i, SteamID, sizeof(SteamID));
			
			if (StrEqual(SteamID, arg1))
			{
				bank[i] = StringToInt(arg2) + bank[i];
				
				found = true;
				
				PrintToChat(i, "%s : Vous avez reçu %i$ pour votre achat en ligne.", LOGO, StringToInt(arg2));
			}
		}
	}
	
	if (!found)
	{
		decl String:query[256];
		
		new data = StringToInt(arg2);
		
		decl String:error[256];
		
		new Handle:db = SQL_Connect("roleplay", true, error, sizeof(error));
		
		Format(query, sizeof(query), "SELECT * FROM `Roleplay_Players` WHERE steam_id = '%s';", arg1);
		
		SQL_TQuery(db, GetBank, query, data);
		
		CloseHandle(db);
	}
}

public GetBank(Handle:owner, Handle:hndl, String:error[], any:data)
{
	decl String:query[256];
	decl String:Found_Steam[64];
	
	new totalbank;
	
	decl String:error2[256];
	new Handle:db = SQL_Connect("roleplay", true, error2, sizeof(error2));
	
	if (hndl)
	{
		while (SQL_FetchRow(hndl))
		{
			SQL_FetchString(hndl, 0, Found_Steam, sizeof(Found_Steam));
			
			totalbank = SQL_FetchInt(hndl, 2);
		}
		
		totalbank = data + totalbank;
		
		Format(query, sizeof(query), "UPDATE `Roleplay_Players` SET `bank` = %i WHERE `steam_id` = '%s';", totalbank, Found_Steam);
		SQL_FastQuery(db, query);
		
		LogMessage("[DONS-RP] : Le steam_id %s a reçu %i$ dans sa banque.", Found_Steam, data);
	}
	else
	{
		LogError("Query failed! %s", error);
	}
	
	CloseHandle(db);
}
Don't works.

I have this in logmessage :

Code:
19:59:33: [roleplay.smx] [DONS-RP] : Le steam_id  a reçu 0$ dans sa banque.
no error log, the steam ID is not displayed when it should, money is a 0 then I typed sm_givemoney STEAM_0:17722551 1000
__________________
♥ 𝕊ℙ𝕒𝕨𝕟 𝔻𝕖𝕧𝕖𝕝𝕠𝕡𝕖𝕣 [ℂ𝕊:𝕊] ♥

Clan-Nemesis

Last edited by delachambre; 08-29-2012 at 14:03.
delachambre is offline
11530
Veteran Member
Join Date: Sep 2011
Location: Underworld
Old 08-29-2012 , 14:11   Re: [CS:S] SQL_TQuery doesn't works ?
Reply With Quote #24

Quote:
Originally Posted by delachambre View Post
no error log, the steam ID is not displayed when it should, money is a 0 then I typed sm_givemoney STEAM_0:17722551 1000
Why should it? You only use LogMessage, not PrintToChat.
__________________

Last edited by 11530; 08-29-2012 at 14:12.
11530 is offline
delachambre
AlliedModders Donor
Join Date: Jan 2011
Location: France
Old 08-29-2012 , 14:13   Re: [CS:S] SQL_TQuery doesn't works ?
Reply With Quote #25

Quote:
Originally Posted by 11530 View Post
Why should it? You only use LogMessage, not PrintToChat.
i use this :

Code:
LogMessage("[DONS-RP] : Le steam_id %s a reçu %i$ dans sa banque.", Found_Steam, data);
i have this response :
Code:
[roleplay.smx] [DONS-RP] : Le steam_id  a reçu 0$ dans sa banque.
__________________
♥ 𝕊ℙ𝕒𝕨𝕟 𝔻𝕖𝕧𝕖𝕝𝕠𝕡𝕖𝕣 [ℂ𝕊:𝕊] ♥

Clan-Nemesis
delachambre is offline
11530
Veteran Member
Join Date: Sep 2011
Location: Underworld
Old 08-29-2012 , 14:15   Re: [CS:S] SQL_TQuery doesn't works ?
Reply With Quote #26

I'll just write one myself.
__________________

Last edited by 11530; 08-29-2012 at 14:16.
11530 is offline
delachambre
AlliedModders Donor
Join Date: Jan 2011
Location: France
Old 08-29-2012 , 14:16   Re: [CS:S] SQL_TQuery doesn't works ?
Reply With Quote #27

Quote:
Originally Posted by 11530 View Post
LogMessage writes to the Log, not to chat.
I know .... I mean there was a problem with the steam id and money compared to what I write with the command ...
__________________
♥ 𝕊ℙ𝕒𝕨𝕟 𝔻𝕖𝕧𝕖𝕝𝕠𝕡𝕖𝕣 [ℂ𝕊:𝕊] ♥

Clan-Nemesis
delachambre is offline
delachambre
AlliedModders Donor
Join Date: Jan 2011
Location: France
Old 08-29-2012 , 14:20   Re: [CS:S] SQL_TQuery doesn't works ?
Reply With Quote #28

Quote:
Originally Posted by 11530 View Post
I'll just write one myself.
Ok, thanks a lot :')
__________________
♥ 𝕊ℙ𝕒𝕨𝕟 𝔻𝕖𝕧𝕖𝕝𝕠𝕡𝕖𝕣 [ℂ𝕊:𝕊] ♥

Clan-Nemesis
delachambre is offline
11530
Veteran Member
Join Date: Sep 2011
Location: Underworld
Old 08-29-2012 , 14:51   Re: [CS:S] SQL_TQuery doesn't works ?
Reply With Quote #29

Try something like this:

Note: This only does what your code in post #1 is meant to do. It does not do anything else (like retrieve bank info). You need to add that yourself - I'm only putting you on the right path.

PHP Code:
#pragma semicolon 1
#include <sourcemod>

new Handle:g_hDatabase INVALID_HANDLE;
new 
String:g_sSteamID[MAXPLAYERS+1][21];
new 
g_iBank[MAXPLAYERS+1];

#define LOGO "[DONS-RP]"

public OnPluginStart()
{
    
RegAdminCmd("sm_givemoney"Command_GivemoneyADMFLAG_ROOT"Give money to a SteamID");
}

public 
OnMapStart()
{
    for (new 
1<= MaxClientsi++)
    {
        if (
IsClientInGame(i) && IsClientAuthorized(i) && !IsFakeClient(i))
        {
            
GetClientAuthString(ig_sSteamID[i], sizeof(g_sSteamID[]));
            
g_iBank[i] = 0;
        }
    }
    
    if (!
SQL_CheckConfig("roleplay"))
    {
        
SetFailState("%s: Cannot find database config \'roleplay\'. Check databases.cfg"LOGO);
        return;
    }
    
SQL_TConnect(ConnectCallback"roleplay");
}

public 
ConnectCallback(Handle:ownerHandle:hndl, const String:error[], any:data)
{
    if (
hndl == INVALID_HANDLE)
    {
        
SetFailState("Database failure: %s"error);
        return;
    }

    
g_hDatabase hndl;
    
decl String:sQuery[256];
    
    
FormatEx(sQuerysizeof(sQuery), "SET NAMES 'utf8'");
    
SQL_TQuery(g_hDatabaseCriticalQueryCallbacksQuery);
    
    
FormatEx(sQuerysizeof(sQuery), "CREATE TABLE IF NOT EXISTS `Roleplay_Players` (`PID` INT UNSIGNED NOT NULL AUTO_INCREMENT, `steam_id` VARCHAR(20) UNIQUE NOT NULL, `bank` INT UNSIGNED NOT NULL DEFAULT '0', PRIMARY KEY(`PID`)) ENGINE=MyISAM DEFAULT CHARSET=utf8");
    
SQL_TQuery(g_hDatabaseCriticalQueryCallbacksQuery);
    
}

public 
DefaultQueryCallback(Handle:ownerHandle:hndl, const String:error[], any:data)
{
    if(
hndl == INVALID_HANDLE)
    {
        
LogError("%s: Query failure: %s"LOGOerror);
    }
}

public 
CriticalQueryCallback(Handle:ownerHandle:hndl, const String:error[], any:data)
{
    if(
hndl == INVALID_HANDLE)
    {
        
SetFailState("Critical query failure: %s"error);
        return;
    }
}

public 
Action:Command_Givemoney(clientargs)
{
    if (
args == 2)
    {
        
decl String:arg1[128];
        
decl String:arg2[128];
        
        
GetCmdArg(1arg1sizeof(arg1));
        
GetCmdArg(2arg2sizeof(arg2));
        
        new 
iNum StringToInt(arg2);
        
        for (new 
1<= MaxClientsi++)
        {
            if (
strcmp(g_sSteamID[i], arg1) == 0)
            {
                
g_iBank[i] += iNum;
                
PrintToChat(i"%s : Vous avez reçu %d$ pour votre achat en ligne."LOGOiNum);
                return 
Plugin_Handled;
            }
        }
    
        if (
g_hDatabase != INVALID_HANDLE)
        {
            
decl String:sQuery[512];
            
FormatEx(sQuerysizeof(sQuery), "INSERT INTO `Roleplay_Players` (`steam_id`, `bank`) VALUES ('%s', '%d') ON DUPLICATE KEY UPDATE `bank` = `bank` + '%d'"arg1iNumiNum);
            
SQL_TQuery(g_hDatabaseDefaultQueryCallbacksQuery);
            
PrintToChat(client"%s: %s a reçu %i$ dans sa banque."LOGOarg1iNum);
            
LogMessage("%s: %s a reçu %i$ dans sa banque."LOGOarg1iNum);
        }
    }
    else
    {
        
ReplyToCommand(client"Usage: sm_givemoney [#userid|name] [amount]");
    }
    return 
Plugin_Handled;
}

public 
OnClientAuthorized(client, const String:auth[])
{
    
strcopy(g_sSteamID[client], sizeof(g_sSteamID[]), auth);
    
g_iBank[client] = 0;
}

public 
OnClientDisconnect_Post(client)
{
    
g_sSteamID[client][0] = '\0';
    
g_iBank[client] = 0;

Code:
/givemoney SOMEID 1000

Output from MySQL:
+-----+----------+------+
| PID | steam_id | bank |
+-----+----------+------+
|   1 | SOMEID   | 1000 |
+-----+----------+------+
Code:
/givemoney SOMEID 200

Output from MySQL:
+-----+----------+------+
| PID | steam_id | bank |
+-----+----------+------+
|   1 | SOMEID   | 1200 |
+-----+----------+------+
Note: As bl4nk said, quotes are needed when using a "real" SteamID, e.g. !givemoney "STEAM_0:17722551" 1000
__________________

Last edited by 11530; 08-29-2012 at 14:53.
11530 is offline
delachambre
AlliedModders Donor
Join Date: Jan 2011
Location: France
Old 08-29-2012 , 14:57   Re: [CS:S] SQL_TQuery doesn't works ?
Reply With Quote #30

I try this, thanks.
__________________
♥ 𝕊ℙ𝕒𝕨𝕟 𝔻𝕖𝕧𝕖𝕝𝕠𝕡𝕖𝕣 [ℂ𝕊:𝕊] ♥

Clan-Nemesis
delachambre 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 21:59.


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