26.01.2013, 23:40
Problem is that i need to get some player data in other scripts, for example level.
So i am writing function as include with code below:
Problem is that i always get PlayerLevel[playerid]=0,
because while CheckPlayerLevel(playerid) finishes
PlayerLevel[playerid] is already returned and =0;
How to fix that?
So i am writing function as include with code below:
Код:
#if defined _PLevel_included
#endinput
#endif
#define _PLevel_included
#pragma library PLevel
#include <a_samp>
#include <a_mysql>
#define Table "Players"
#define SQL_HOST0 "localhost"
#define SQL_USER0 "root"
#define SQL_PASS0 "pass"
#define SQL_DB0 "sdata"
new LvlHandle;
new PlayerLevel[MAX_PLAYERS];
forward CheckPlayerLevel(playerid);
stock GetPlayerLevel(playerid)
{
LvlHandle = mysql_connect(SQL_HOST0, SQL_USER0, SQL_DB0, SQL_PASS0);
new LevelQ[100], EscPNameLvl[MAX_PLAYER_NAME];
mysql_real_escape_string(ppName(playerid),EscPNameLvl);
format(LevelQ,sizeof(LevelQ),"SELECT `Level` FROM `"Table"` WHERE `PlayerName` = '%s' LIMIT 0,1",EscPNameLvl);
mysql_function_query(LvlHandle, LevelQ, true, "CheckPlayerLevel", "i", playerid);
return PlayerLevel[playerid];
}
stock ppName(playerid)
{
new Name[MAX_PLAYER_NAME];
GetPlayerName(playerid, Name, sizeof(Name));
return Name;
}
public CheckPlayerLevel(playerid)
{
new Rows, Fields;
cache_get_data(Rows, Fields, LvlHandle);
if(Rows)
{
cache_get_row(0, 0, PlayerLevel[playerid], LvlHandle);
}
return 1;
}
because while CheckPlayerLevel(playerid) finishes
PlayerLevel[playerid] is already returned and =0;
How to fix that?

