When working with threaded functions you've got to smartly produce everything so it always keeps running on the thread you assign it to:
If you have a CMD which requieres data from the SQL to continue, you've got to continue the CMD in the function you've threaded the CMD into, you can never rely nor it will work if you call a threaded function to retrieve a value since threaded functions run in a different thread (hence the name) and may finish during or after the execution of the whole command.
This is an example of using threaded data with cmds, see how I continue the command in the function I thread it to?
pawn Код:
CMD:bans(playerid, params[])
{
if(GetPVarInt(playerid,"AccountLevel") < 5 && !IsPlayerAdmin(playerid))
return 0;
if(!isnull(params)) return Usage(playerid,"/bans");
mysql_format(dbHandle, query, 128, "SELECT * FROM `bans` WHERE `ban_status` = 1 ORDER BY `ban_id`");
mysql_tquery(dbHandle, query, "OnPlayerRequestListBans", "i", playerid);
SetPVarInt(playerid, "listviewingmax", 10);
SetPVarInt(playerid, "listviewingmin", 0);
return 1;
}
forward OnPlayerRequestListBans(playerid);
public OnPlayerRequestListBans(playerid)
{
new rows, fields, characterstr[1536], result[24];
cache_get_data(rows, fields);
if(rows)
{
new internal, type, title[64], temp;
new bans = GetPVarInt(playerid,"listviewingmin");
SetPVarInt(playerid, "listviewingtotal", rows);
for(new i = 0; i < 10; i ++)
listban[playerid][i] = -1;
while(bans < rows && bans < GetPVarInt(playerid,"listviewingmax"))
{
temp = cache_get_field_content_int(bans, "ban_id");
format(characterstr, 1536, "%s{FF6600}ID: {FFFFFF}%02d",characterstr,temp);
listban[playerid][internal] = temp;
type = cache_get_field_content_int(bans, "type");
format(characterstr, 1536, "%s\t{FF6600}Type: {FFFFFF}%s",characterstr, GetBanTypeForDialogStr(type));
if(type == 1) // char
{
cache_get_field_content(bans, "char_name", result);
format(characterstr, 1536, "%s\t{FF6600}Character: {FFFFFF}%s",characterstr, result);
}
else if(type == 2) // account
{
cache_get_field_content(bans, "account_name", result);
format(characterstr, 1536, "%s\t{FF6600}Account: {FFFFFF}%s",characterstr, result);
}
else if(type == 4) //route
{
cache_get_field_content(bans, "ip", result);
format(characterstr, 1536, "%s\t{FF6600}IP: {FFFFFF}%s\t",characterstr, result);
}
else //ip/full
{
cache_get_field_content(bans, "ip", result);
format(characterstr, 1536, "%s\t{FF6600}IP: {FFFFFF}%s",characterstr, result);
}
cache_get_field_content(bans, "admin", result);
format(characterstr, 1536, "%s\t{FF6600}Issuer: {FFFFFF}%s",characterstr, result);
format(characterstr, 1536, "%s\n",characterstr);
bans ++;
internal ++;
}
if(rows > 10)
{
new Float:totalpages;
new Float:currentpage;
totalpages = floatround(rows/10.0, floatround_ceil);
currentpage = floatround(GetPVarInt(playerid,"listviewingmax")/10.0, floatround_ceil);
format(title, sizeof(title),"{FFFFFF}Click the ban for more information. {BBBBBB}(%d/%d)", floatround(currentpage), floatround(totalpages));
ShowPlayerDialog(playerid, 900, DIALOG_STYLE_LIST, title,characterstr,"Expand","Next >");
}
else
{
ShowPlayerDialog(playerid, 900, DIALOG_STYLE_LIST, "Select the list item to view ban information",characterstr,"Expand","Exit");
}
}
else
{
TDInfo(playerid, "No active bans.");
return 1;
}
return 1;
}