SA-MP Forums Archive
Crash on loading houses - 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)
+---- Forum: Help Archive (https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: Crash on loading houses (/showthread.php?tid=264316)



Crash on loading houses - Willow - 25.06.2011

So, I'm using a mysql housing system, but I am not able to get it work correctly.

The houses are getting loaded with this function

Код:
LoadHouses()
{
	new query[1024];
	print("House loading started...(before fromat)");
	format(query,sizeof(query),"SELECT * FROM `houses`");
	print("House loading started...(before query)");
	mysql_query(query);
	print("House loading started...(store res)");
	mysql_store_result();
	new i;
	new rows = mysql_num_rows();
	if(rows)
	{
	    print("House loading started...(if(rows))");
		while(i < rows,i++)
		{
	    	print("in for new");
			new string[512];
			format(string, sizeof(string), "SELECT * FROM `houses` WHERE ID = '%d'", i);
			mysql_query(string);
			mysql_store_result();
		
			sscanf(string,"ds[24]dffffffddddd", \
			HD[i][ID], \
			HD[i][owner], \
 			HD[i][price], \
			HD[i][exteriorX], \
			HD[i][exteriorY], \
			HD[i][exteriorZ], \
			HD[i][interiorX], \
			HD[i][interiorY], \
			HD[i][interiorZ], \
			HD[i][interiorInt], \
			HD[i][locked], \
			HD[i][gunslot1], \
			HD[i][locklevel], \
			HD[i][safeamount]);

			if(strlen(HD[i][owner]) > 0) CreatePickup(1273, 1, HD[i][exteriorX], HD[i][exteriorY], HD[i][exteriorZ], -1);
			else CreatePickup(1272, 1, HD[i][exteriorX], HD[i][exteriorY], HD[i][exteriorZ], -1);
			printf("House %d created at x: %f, y: %f, z: %f, locklevel: %d", i, HD[i][exteriorX], HD[i][exteriorY], HD[i][exteriorZ], HD[i][locklevel]);
		}
	}
	else
	{
	    print("No houses to load!");
	}
	print("House loading finished.");
	mysql_free_result();
	return 1;
}
If checked the code you can see I've added print lines for debugging. The problem is when I run the server it crashers before mysql_query(query) is called.

What could be wrong?


Re: Crash on loading houses - Donya - 25.06.2011

pawn Код:
LoadHouses()
{
    new Query[156], i; //(156 looks fine, for now, if u ever add more vars, print it and count the text length.)
    format(Query, sizeof(Query),"SELECT * FROM houses");
    mysql_query(Query);
    mysql_store_result();
    if(mysql_num_rows())
    {
        while(mysql_fetch_row(Query))
        {
            sscanf(Query, "d", i,
            HD[i][ID] = i;
            sscanf(Query, "ds[24]dffffffddddd", i,
            HD[i][owner],
            HD[i][price],
            HD[i][exteriorX],
            HD[i][exteriorY],
            HD[i][exteriorZ],
            HD[i][interiorX],
            HD[i][interiorY],
            HD[i][interiorZ],
            HD[i][interiorInt],
            HD[i][locked],
            HD[i][gunslot1],
            HD[i][locklevel],
            HD[i][safeamount]);

            if(strlen(HD[i][owner]) > 0) CreatePickup(1273, 1, HD[i][exteriorX], HD[i][exteriorY], HD[i][exteriorZ], -1);
            else CreatePickup(1272, 1, HD[i][exteriorX], HD[i][exteriorY], HD[i][exteriorZ], -1);
            printf("House %d created at x: %f, y: %f, z: %f, locklevel: %d", i, HD[i][exteriorX], HD[i][exteriorY], HD[i][exteriorZ], HD[i][locklevel]);
        }
    }
    else print("No houses to load!");
    print("House loading finished.");
    mysql_free_result();
    return 1;
}
lets see. due to people who know nothing.. (below) i will count the length you will probably need.

id..hmm lets use 4 chars
owner - 24
price - 11
ex - 9
ey - 9
ez - 9
ix - 9
iy - 9
iz - 9
iint - 11
locked - 11
gunslot1 - 11
locklevel - 11
safeamount - 11

around 158. and i doubt int,locked,gunslot,locklevel, will reach 11 integers. so 156 is good for now.


Re: Crash on loading houses - Willow - 25.06.2011

still crashes


Re: Crash on loading houses - GangsTa_ - 25.06.2011

Isn't your query variable's length too long?


Re: Crash on loading houses - Willow - 25.06.2011

No, it's not


Re: Crash on loading houses - Donya - 25.06.2011

yes 1024, was quite big for nothing.

i shouldn't even be using 256, 156 should work fine.. also

SELECT * FROM houses

the query is crashing because of "SELECT * FROM houses" something is wrong with your houses table..

are u using BlueG's plugin? (G-Stylezzz)

i also suggest keeping the code i gave you.. you are looping for nothing.


Re: Crash on loading houses - Willow - 25.06.2011

no, I'm not using G-Stylezzz plugin (I am using StrickedKid's plugin) and I thing my houses table is ok, because INSERT INTO works fine. btw., thanks for your code!


Re: Crash on loading houses - Markx - 25.06.2011

https://sampforum.blast.hk/showthread.php?tid=55261


Re: Crash on loading houses - Willow - 25.06.2011

Tried using Query[190], still crash..


Re: Crash on loading houses - Donya - 25.06.2011

Quote:
Originally Posted by Markx
Посмотреть сообщение
don't post things you don't know about. if you wanted to know why i used that, ask. this is mysql. what if his string length gets so long in the query that it goes over 256?

this is not CHAT, the max input is NOT 128.

that topic is mostly explaining chat, onplayertext, samp chatbox. format's string length is NOT 128.

Ontopic: Willow, use BlueG's plugin, strickenkid's has bugs.

Edited my post, it was a bit hash.