Mysql R7 Data Retrieval in multiple scripts
#1

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?
Reply


Messages In This Thread
Mysql R7 Data Retrieval in multiple scripts - by Liustas - 26.01.2013, 23:40
Re: Mysql R7 Data Retrieval in multiple scripts - by ReneG - 27.01.2013, 03:39
Re: Mysql R7 Data Retrieval in multiple scripts - by Liustas - 27.01.2013, 10:26

Forum Jump:


Users browsing this thread: 2 Guest(s)