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 i = 0; i < g_iTotalItems; i++)
{
ArrayGetArray(g_aItems, i, eItemData)
HasUserCreditWeapon(id, eItemData[ItemConst])
formatex(szItem, charsmax(szItem), "%s - \y%i %s", eItemData[ItemName], eItemData[ItemCost], CURRENCY_TAG)
num_to_str(i, szNum, charsmax(szNum))
if(g_iCredits[id] >= eItemData[ItemCost] && !g_iTempTrue[id])
menu_additem(menu, szItem, szNum, 0)
else
menu_additem(menu, szItem, szNum, 1<<31)
g_iTempTrue[id] = false
}
PHP Code:
public HasUserCreditWeapon(id, const szConst[])
{
new szSteamId[32], szTemp[512]
get_user_authid(id, szSteamId, charsmax(szSteamId))
new Data[1]
Data[0] = id
formatex(szTemp,charsmax(szTemp),"SELECT * FROM `%s` WHERE (`%s`.`steamid` = '%s') AND (`%s`.`weap` = '%s');", Table_WeapData, Table_WeapData, szSteamId, Table_WeapData, szConst)
console_print(id, szConst)
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", Errcode, Error)
}
else if(FailState == TQUERY_QUERY_FAILED)
{
log_amx("Load Query failed. [%d] %s", Errcode, Error)
}
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.
__________________