mySQL loading houses (pretty close)
#1

Ok, I finally got /addhouse to work and stuff. And it saved in my mySQL database. But I'm having trouble to load it, when the server restarts.
I can't make it like some other things because it's connected to enum. (like PlayerInfo) So I tried the PlayerINfo way, but it didn't work, Here's the Code:

OnGameModeInIt()
Код:
LoadHouses();
Stock LoadHouses()
Код:
stock LoadHouses(houseid)
{
	new
		Query[700],
		Int,
		lTotal,
 		hMsg1[128],
        hMsg2[128],
        hMsg3[128];

	if(mysql_fetch_row(Query))
	{
			sscanf(Query, "e<p<|>ds[24]fffd", Houses[houseid][HouseID], Houses[houseid][HouseOwner], Houses[houseid][hX], Houses[houseid][hY], Houses[houseid][hZ], Houses[houseid], Houses[houseid][House_Price]); // Remember to update this if you add more info...
  			Loop(i, MAX_HOUSES)
	        HouseCPOut[i] = CreateDynamicCP(Houses[houseid][hX], Houses[houseid][hY], Houses[houseid][hZ], 1.5, Houses[houseid][hVirtual], Houses[houseid][hVVirtual], -1, 5);
			format(hMsg1, sizeof(hMsg1),"HouseOwner - '%s'", Houses[houseid][HouseOwner]);
			format(hMsg2, sizeof(hMsg2), "House ID - %d", houseid);
   			format(hMsg3, sizeof(hMsg3), "Interior - %d", Int);
			HouseInfoCP = TextDrawCreate(15.000000, 170.000000, hMsg1);
			TextDrawFont(HouseInfoCP, 1);
			TextDrawTextSize(HouseInfoCP,145.000000, 260.000000);
			TextDrawLetterSize(HouseInfoCP,0.299999,0.800000);
			TextDrawUseBox(HouseInfoCP, 1);
			TextDrawBoxColor(HouseInfoCP, 0x000000FF);
			HouseInfoCP2 = TextDrawCreate(15.000000, 160.000000, hMsg2);

			TextDrawFont(HouseInfoCP2, 1);
			TextDrawTextSize(HouseInfoCP2,145.000000, 260.000000);
			TextDrawLetterSize(HouseInfoCP2,0.299999,0.800000);
			TextDrawUseBox(HouseInfoCP2, 1);
			TextDrawBoxColor(HouseInfoCP2, 0x000000FF);
	        //pTotal++;
			mysql_free_result();
			print("=====================================================================\n");
			printf("** %i\t<->\tHouses Loaded From\t<->\tMySQL\t\t   **", lTotal);
			print("=====================================================================\n");
	}
	return 1;
}
2: Then I tried the way of some house FS I found from Mick88 and Watcha

On Top:
Код:
#define GET_INT(%1,%2) 					mysql_fetch_field_row(tmp, %2);%1 = strval(tmp)
#define GET_STR(%1,%2) 					mysql_fetch_field_row(%1, %2)
#define GET_FLOAT(%1,%2) 				mysql_fetch_field_row(tmp, %2);%1 = floatstr(tmp)
OnGameModeInIt()
Код:
    	//Loading houses from database
	new mysql_connection;
   	mysql_connection = mysql_connect(SQL_HOST, SQL_USER, SQL_DB, SQL_PASS);
	mysql_query("SELECT * FROM `houses` WHERE `id` < "#MAX_HOUSES);
	mysql_store_result(mysql_connection);
	new n;
	while (mysql_retrieve_row())
	{
	    new tmp[32];
	    new id;
		GET_INT(id, "id");//Loads houseid
		GET_INT(Houses[id][House_Price], "price");
		GET_INT(Houses[id][House_Interior], "interior");
		GET_STR(Houses[id][HouseOwner], "owner");

		new Float:x, Float:y, Float:z, Float:r;
		GET_FLOAT(x, "x");
		GET_FLOAT(y, "y");
		GET_FLOAT(z, "z");
		Houses[id][hX] = x;
		Houses[id][hY] = y;
		Houses[id][hZ] = z;
                SpawnHouse();
	    n++;
	}
forward SpawnHouse();
public SpawnHouse()
Код:
	new houseid;
	houseid = Houses[houseid][HouseID];
	Loop(i, MAX_HOUSES)
	
	HouseCPOut[i] = CreateDynamicCP(Houses[houseid][hX], Houses[houseid][hY], Houses[houseid][hZ], 1.5, Houses[houseid][hVirtual], Houses[houseid][hVVirtual], -1, 5.0);
// yeah left the textdraws out this time, since it was just a test.
I know it's all wrong in the function. shouldn't do: new houseid; and stuff, but just to give you an idea. Can somebody help me out, in how I still can load the ID of the house, so I can load all the other parts aswell (like hX, hY, hZ)?

Or please help me out with the other example I gave...
Thanks in advance!
Reply
#2

BUMP. Still no one who can help me out with this ?
Reply
#3

Ok booked a lil bit more progress with the 2nd option:

OnGamemodeInIt:
Код:
//Loading houses from database
	new mysql_connection;
   	mysql_connection = mysql_connect(SQL_HOST, SQL_USER, SQL_DB, SQL_PASS);
	mysql_query("SELECT * FROM `houses` WHERE `id` < "#MAX_HOUSES);
	mysql_store_result(mysql_connection);
	new n;
	while (mysql_retrieve_row())
	{
	    new tmp[32];
	    new id;
		GET_INT(id, "id");//Loads houseid
		GET_INT(Houses[id][House_Price], "price");
		GET_INT(Houses[id][House_Interior], "interior");
		GET_STR(Houses[id][HouseOwner], "owner");

		new Float:x, Float:y, Float:z;
		GET_FLOAT(x, "x");
		GET_FLOAT(y, "y");
		GET_FLOAT(z, "z");
		Houses[id][hX] = x;
		Houses[id][hY] = y;
		Houses[id][hZ] = z;
        for(new i = 0; i < MAX_PLAYERS; i++)
        {
			HouseCPOut[i] = CreateDynamicCP(x, y, z, 1.5, 0, 0, -1, 5.0);
		}
        SpawnHouse();
	    n++;
	}
That actually works and creates a checkpoint.
But I want to know why it works like that, and not like this:
Код:
        for(new i = 0; i < MAX_PLAYERS; i++)
        {
			HouseCPOut[i] = CreateDynamicCPHouses[id][hX],Houses[id][hY],Houses[id][hZ], 1.5, 0, 0, -1, 5.0);
		}
Is there something wrong? Or is it right and could it be that somehow the enum isn't right?

also could somebody give me a little bit explanation at things like:
Код:
for(new i = 0; i < MAX_PLAYERS; i++)
which I believe is the same as Loop(i, MAX_PLAYERS) with this on the top of my script:
Код:
#define Loop(%0,%1) for(new %0 = 0; %0 < %1; %0++)
and why sometimes this doesn't work:
Код:
for(new i = 0; i < MAX_PLAYERS; i++)
And this does:
Код:
new i; for(i = 0; i < MAX_PLAYERS; i++)
Reply
#4

Maybe my LoadPlayer snippit will help you

pawn Код:
stock LoadPlayer(playerid)
{
    new tmp[200];
    format(tmp, sizeof(tmp), "SELECT * FROM players WHERE username = '%s'", p_data[playerid][name]);
    mysql_query(tmp);
    mysql_store_result();
    if(mysql_num_rows() == 0) return printf("Failed to load data for %s he isn't registered!", p_data[playerid][name]);
    while(mysql_fetch_row_format(tmp,"|"))
    {
        sscanf(tmp, "p<|>i{s[24]s[24]}ii",
        p_data[playerid][SQLID],
        p_data[playerid][admin],
        p_data[playerid][kills]);
    }
    return printf("Player %s loaded, values admin = %d | kills = %d", p_data[playerid][name] ,p_data[playerid][admin], p_data[playerid][kills]);
}
Reply
#5

Yeah that one is pretty similiar to my first option of the house loading code. (first post)
and pretty similair to my loadplayer code (the one I'm using)
Код:
stock LoadPlayerInfo(iPlayer)
{
	new
		Query[700];

	if(mysql_fetch_row(Query))
	{
		sscanf(Query, "e<p<|>s[24]s[35]ddddfffds[24]>", PVar[iPlayer]); // Remember to update this if you add more info...
		mysql_free_result();
		SpawnPlayer(iPlayer);
		SetPlayerSkin(iPlayer, PVar[iPlayer][pSkin]);
	}
	return 1;
}
That works for me and stuff, just the loading house stuff doesn't But I'm start to think it it because of the Enum. Since using (see post 3) works, just not when I use Houses[i][...]

Thanks for replying though!
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)