Raised This Month: $ Target: $400
 0% 

Return Boolean through multiple Functions


  
 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
Author Message
Kia
AlliedModders Donor
Join Date: Apr 2010
Location: In a world of madness
Old 06-07-2014 , 05:13   Return Boolean through multiple Functions
Reply With Quote #1

Hello everybody,

I have a problem which I can not solve.
When you type a command in the chat which opens a menu, I want to make a SQL Check for all Items I have in an Array.
Now, my problem is, I do not know how to return a value through multiple functions, since I only want to show items the player owns.
My current structure looks like this. The Problem is that the SQL is not fast enough so sometimes you can buy a weapon again even when you own it already.

Menu :
PHP Code:
for(new 0g_iTotalItemsi++)
{
        
ArrayGetArray(g_aItemsieItemData)
    
        
HasUserCreditWeapon(ideItemData[ItemConst])
        
        
formatex(szItemcharsmax(szItem), "%s - \y%i %s"eItemData[ItemName], eItemData[ItemCost], CURRENCY_TAG)
        
        
num_to_str(iszNumcharsmax(szNum))
        
        if(
g_iCredits[id] >= eItemData[ItemCost] && !g_iTempTrue[id])
            
menu_additem(menuszItemszNum0)
        else
            
menu_additem(menuszItemszNum1<<31)
            
        
g_iTempTrue[id] = false

PHP Code:
public HasUserCreditWeapon(id, const szConst[])
{
    new 
szSteamId[32], szTemp[512]
    
get_user_authid(idszSteamIdcharsmax(szSteamId))
    
    new 
Data[1]
    
Data[0] = id
    
    formatex
(szTemp,charsmax(szTemp),"SELECT * FROM `%s` WHERE (`%s`.`steamid` = '%s') AND (`%s`.`weap` = '%s');"Table_WeapDataTable_WeapDataszSteamIdTable_WeapDataszConst)
    
console_print(idszConst)
    
SQL_ThreadQuery(g_SqlTuple,"CheckCount",szTemp,Data,1)
}

public 
CheckCount(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)
    }
    
    new 
id
    id 
Data[0]
    
    if(
SQL_NumResults(Query) >= 1)
        
g_iTempTrue[id] = true
        
else
        
g_iTempTrue[id] = false
    
    
return PLUGIN_HANDLED

So, my question is, how do return a value through HasUserCreditWeapon and CheckCount back to the menu so it waits long enough that I get the actual state. Or is there any other way to do it?

Greetz,
Kia.
__________________
Kia is offline
 


Thread Tools
Display Modes

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 09:44.


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