Mysql R7 Data Retrieval in multiple scripts - Printable Version
+- SA-MP Forums Archive (
https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (
https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (
https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Mysql R7 Data Retrieval in multiple scripts (
/showthread.php?tid=410847)
Mysql R7 Data Retrieval in multiple scripts -
Liustas - 26.01.2013
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:
Код:
#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;
}
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?
Re: Mysql R7 Data Retrieval in multiple scripts -
ReneG - 27.01.2013
You don't, that's the whole point of having threaded queries. You send the query, and the code is called accordingly in a separate thread from the server (main pawn script).
Re: Mysql R7 Data Retrieval in multiple scripts -
Liustas - 27.01.2013
So there is no way to get data from Mysql R7 in other scripts using include function ?