MySQL threaded query how to get it's return?
#1

How can I get the return value of a MySQL tquery callback?

In non async query:

Код:
public OnPlayerRequestClass(playerid, classid)
{	
	// Check if the name is on our database
	// If it is -> Show login dialog
	// If not -> Tell client to register on site + kick
	if (!NameCheck(playerid)) return KickPlayer(playerid, "This name is not on our Database. Please register on our website: custom-roleplay.com");
	return 1;
}

public NameCheck(playerid) {
	new name[MAX_PLAYER_NAME + 1];
	GetPlayerName(playerid, name, sizeof(name));
	new query[128];
	mysql_format(Database, query, sizeof query, "SELECT * FROM users WHERE name = '%s'", name);
	mysql_query(Database, query);
	if (cache_num_rows() > 0) {
		return true;
	}
	return false;
}
How do I do this with the async version?
Thanks in advance!
Reply
#2

Just create a callback and do shit there rather than on player class selection. Waiting for the query to complete makes threading useless (tquery and waiting for the query to complete for the result)
Код:
public OnPlayerRequestClass(playerid, classid)
{
    new name[MAX_PLAYER_NAME + 1];
	GetPlayerName(playerid, name, sizeof(name));
	new query[128];
	mysql_format(Database, query, sizeof query, "SELECT * FROM users WHERE name = '%s'", name);
	mysql_tquery(Database, query, "OnPlayerNameCheck", "i", playerid);
	return 1;
}

forward public OnPlayerNameCheck(playerid);
public OnPlayerNameCheck(playerid)
{
	if(cache_num_rows() > 0)
	{
		ShowPlayerCharacterSleection or whatever();
		// name exist
	}
	else
	{
	    SendClientMessage(playerid, color_red, "this account doesnt exist....");
	    // name doesnt exist
  	}
	return 1;
}
Reply
#3

But aren't functions like SetSpawnInfo only supposed to be called inside callbacks like OnPlayerRequestClass.
Reply
#4

Quote:
Originally Posted by Seifspeed
Посмотреть сообщение
But aren't functions like SetSpawnInfo only supposed to be called inside callbacks like OnPlayerRequestClass.
You can call them where you want. Doesnt metter

Edit: Only functions that are needed to set things up before they can be used are tied to certain native public function like AddPlayerClass or RemoveBuildingForPlayer etc
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)