Spawn Player in House MYSQL
#1

Hello i have a probleme i try to create the spawn player in house but i does only teleports it to house id 0 if hes the owner but if het aint the owner it stil go search for id 0 and not the other id's


Her the code sorry for my english

Код:
stock SpawnPlayerAtHouse(playerid)
{
	new pname[24],QUERY[400],id;
    GetPlayerName(playerid, pname, 24);
 	format(QUERY, sizeof(QUERY), "SELECT * FROM House WHERE Owner = '%s' AND id = %i",pname,id);
    mysql_query(QUERY);
	mysql_store_result();
	while (mysql_retrieve_row())
	{
		SetPlayerPos(playerid, HouseInfo[id][hExitX], HouseInfo[id][hExitY], HouseInfo[id][hExitZ]);
		SetPlayerInterior(playerid, HouseInfo[id][hInterior]);
		SetPlayerVirtualWorld(playerid, id);
	}
	mysql_free_result();
}
Reply
#2

Does the MySQL have the correct table in it?
Reply
#3

The variable id is not set to anything so it's going to return 0 every time. If the houses actually correspond to the ids in the database, then you can do something like:

pawn Код:
stock SpawnPlayerAtHouse(playerid)
{
    new pname[24],QUERY[400],id;
        GetPlayerName(playerid, pname, 24);
    format(QUERY, sizeof(QUERY), "SELECT id FROM House WHERE Owner = '%s' LIMIT 1",pname);
        mysql_query(QUERY);
    mysql_store_result();
        id = mysql_fetch_int();
    SetPlayerPos(playerid, HouseInfo[id][hExitX], HouseInfo[id][hExitY], HouseInfo[id][hExitZ]);
    SetPlayerInterior(playerid, HouseInfo[id][hInterior]);
    SetPlayerVirtualWorld(playerid, id); //You may want to change this. If the house id is 0, then it will go into the normal world.
    mysql_free_result();
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)