Raised This Month: $51 Target: $400
 12% 

DataPacks & SQL_TQuery


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
DJ Data
SourceMod Donor
Join Date: Dec 2012
Location: Switzerland
Old 09-14-2015 , 15:41   DataPacks & SQL_TQuery
Reply With Quote #1

So here's my code:
PHP Code:
public Action:Command_Tip(clientargs)
{
    if(
args 2)
    {
        
CPrintToChat(client"{red}Arctek ★ System - ERROR: Usage: !tip <playername> <1-9>");
    }
    else if(
args == 2)
    {   
        new 
String:arg1[32], String:arg2[1], String:steamid[32];
        
GetCmdArg(1arg1sizeof(arg1));
        
GetCmdArg(2arg2sizeof(arg2));
        
GetClientAuthString(clientsteamidsizeof(steamid));
        new 
target FindTarget(clientarg1);
        
        
// Write DataPack
        
new Handle:pack CreateDataPack();
        
WritePackCell(packclient);
        
WritePackString(packsteamid);
        
WritePackCell(packtarget);
        
        
// Debug
        
PrintToServer("Arctek ★ SQL: Writing of DataPack fired");
        
        
TipQuery(pack);
    }
}

TipQuery(Handle:pack)
{
    
// Debug
    
PrintToServer("Arctek ★ SQL: TipQuery fired");
    
    
// Read DataPack
    
ResetPack(packfalse);
    new 
String:packSteamID[32];
    
ReadPackString(packpackSteamIDsizeof(packSteamID));
    
    new 
String:query[128];
    
FormatEx(querysizeof(query), "SELECT points FROM Users WHERE steamID2 = '%s'"packSteamID);

    
SQL_TQuery(g_hDBtipquerycallbackquerypack);
}

public 
tipquerycallback(Handle:ownerHandle:hndl, const String:error[], any:pack)
{
    
// Debug
    
PrintToServer("Arctek ★ SQL: tipquerycallback fired");
    
    
ResetPack(packfalse);
    new 
packClient ReadPackCell(pack);
    
ResetPack(packfalse);
    
    new 
tokensme[MAXPLAYERS 1];
    
    if (
hndl == INVALID_HANDLE)
    {
        
LogError("Arctek ★ SQL: - ERROR: %s"error);
        return;
    }
    
    while(
SQL_FetchRow(hndl))
    {
        
tokensme[packClient] = SQL_FetchInt(hndl0);
        if(
tokensme[packClient] < 1)
        {
            
CPrintToChat(packClient"{red}Arctek ★ System - ERROR: You have do have enough VIP Tokens! (You have {blue}%d{red} VIP Tokens.)"tokensme[packClient]);
        }
        else if(
tokensme[packClient] > 0)
        {
            
TipSendQuery(pack);
        }
        
    }
}

TipSendQuery(Handle:pack)
{
    
ResetPack(packfalse);
    new 
packClient ReadPackCell(pack);
    new 
String:packSteamID[32];
    
ReadPackString(packpackSteamIDsizeof(packSteamID));
    new 
packTarget ReadPackCell(pack);
    
ResetPack(packfalse);
    
    
CPrintToChatAll("%d %s %d"packClientpackSteamIDpackTarget);

Compiles fine, console says this when using the command:
Code:
L 09/14/2015 - 21:35:21: [SM] Native "ReadPackString" reported: DataPack operation is out of bounds.
L 09/14/2015 - 21:35:21: [SM]   [0]  Line 147, arctek/sql.sp::TipQuery()
L 09/14/2015 - 21:35:21: [SM]   [1]  Line 135, arctek/sql.sp::Command_Tip()
Line 147: ReadPackString(pack, packSteamID, sizeof(packSteamID));
Line 135: TipQuery(pack);

These 2 functions worked fine before i started calling "pack" in the TQuery call back and such. Am I calling it on multiple levels? dimensions?

Either way, im confused.

Any help is appreciated.
__________________
SourcePawn Coding Level: Novice
DJ Data is offline
Miu
Veteran Member
Join Date: Nov 2013
Old 09-14-2015 , 15:59   Re: DataPacks & SQL_TQuery
Reply With Quote #2

you're reading from the first position since you just reset it, but the first position is an integer, the client index, not a string

you don't need to be reading from the datapack at that point anyway, you can just pass the steamid to that function as an argument
Miu is offline
DJ Data
SourceMod Donor
Join Date: Dec 2012
Location: Switzerland
Old 09-14-2015 , 16:00   Re: DataPacks & SQL_TQuery
Reply With Quote #3

Quote:
Originally Posted by Miu View Post
you're reading from the first position since you just reset it, but the first position is an integer, the client index, not a string

you don't need to be reading from the datapack at that point anyway, you can just pass the steamid to that function as an argument
I tried:
PHP Code:
    ResetPack(packfalse);
    
SetPackPosition(pack2);
    new 
String:packSteamID[32];
    
ReadPackString(packpackSteamIDsizeof(packSteamID)); 
but that returns the same errors.
__________________
SourcePawn Coding Level: Novice

Last edited by DJ Data; 09-14-2015 at 16:01.
DJ Data is offline
Impact123
Veteran Member
Join Date: Oct 2011
Location: Germany
Old 09-14-2015 , 16:03   Re: DataPacks & SQL_TQuery
Reply With Quote #4

SetPackPosition doesn't work that way. This thread has some info about it. You also shouldn't send client index to asynchronous functions. Use a serial or userid instead.
__________________

Last edited by Impact123; 09-14-2015 at 16:10.
Impact123 is offline
DJ Data
SourceMod Donor
Join Date: Dec 2012
Location: Switzerland
Old 09-14-2015 , 16:04   Re: DataPacks & SQL_TQuery
Reply With Quote #5

Quote:
Originally Posted by Impact123 View Post
SetPackPosition doesn't work that way.
Then how does it work? Do I really have to calculate the bytes and increment from there?
__________________
SourcePawn Coding Level: Novice
DJ Data is offline
Miu
Veteran Member
Join Date: Nov 2013
Old 09-14-2015 , 16:09   Re: DataPacks & SQL_TQuery
Reply With Quote #6

the pack position thing is really awk, ReadPackCell(pack) is an easy way to increment it in that case
Miu is offline
DJ Data
SourceMod Donor
Join Date: Dec 2012
Location: Switzerland
Old 09-14-2015 , 16:11   Re: DataPacks & SQL_TQuery
Reply With Quote #7

Quote:
Originally Posted by Miu View Post
the pack position thing is really awk, ReadPackCell(pack) is an easy way to increment it in that case
I guess I'll just store empty variables?
Or can i read pack cell without having to store it?
__________________
SourcePawn Coding Level: Novice
DJ Data is offline
Miu
Veteran Member
Join Date: Nov 2013
Old 09-14-2015 , 16:12   Re: DataPacks & SQL_TQuery
Reply With Quote #8

reading will increment it properly, you don't need to store the result
Miu is offline
DJ Data
SourceMod Donor
Join Date: Dec 2012
Location: Switzerland
Old 09-14-2015 , 16:15   Re: DataPacks & SQL_TQuery
Reply With Quote #9

Quote:
Originally Posted by Miu View Post
reading will increment it properly, you don't need to store the result
Thanks, i'll try that ^^
__________________
SourcePawn Coding Level: Novice
DJ Data 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 16:18.


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