Creepy house system bug
#1

Code:
CMD:createhouse(playerid, params[])
{
	new price, Float:x, Float:y, Float:z, query[800], str[350];
	if(PlayerInfo[playerid][pAdmin] < 4) return SendClientMessage(playerid, COLOR_GREY, "Not authorized!");
	if(sscanf(params, "d", price)) return SendClientMessage(playerid, COLOR_GREY, "Usage:{FFFFFF} /createhouse [price]");
	new id=GetFreeHouseID();
	GetPlayerPos(playerid, x, y, z);
	HouseInfo[id][hOutInterior] = GetPlayerInterior(playerid);
	HouseInfo[id][hOutWorld] = GetPlayerVirtualWorld(playerid);
	HouseInfo[id][hOutPos][0] = x;
	HouseInfo[id][hOutPos][1] = y;
	HouseInfo[id][hOutPos][2] = z;
	HouseInfo[id][hPrice] = price;
	HouseInfo[id][hID] = id;
	format(query, sizeof(query), "INSERT INTO `houses` (`Out_X`, `Out_Y`, `Out_Z`, `OutInt`, `OutWorld`, `Price`, `ID`) VALUES ('%f', '%f', '%f', '%i', '%i', '%i', '%i')", HouseInfo[id][hOutPos][0], HouseInfo[id][hOutPos][1], HouseInfo[id][hOutPos][2], HouseInfo[id][hOutInterior], HouseInfo[id][hOutWorld], HouseInfo[id][hPrice], id);
	mysql_function_query(dbhandle, query, true, "", "");	
	HouseInfo[id][hPickup] = CreatePickup(1273, 23, HouseInfo[id][hOutPos][0], HouseInfo[id][hOutPos][1], HouseInfo[id][hOutPos][2], -1);
	format(str, sizeof(str), "This house is for sell!\nPrice: %d\nType /buyhouse to buy it.\nType /enter to go inside.", HouseInfo[id][hPrice]);
	HouseInfo[id][hLabel] = CreateDynamic3DTextLabel(str ,COLOR_ORANGE, HouseInfo[id][hOutPos][0], HouseInfo[id][hOutPos][1], HouseInfo[id][hOutPos][2],30.0, INVALID_PLAYER_ID, INVALID_VEHICLE_ID, 0, -1, -1, -1, 7.0);
	format(str, sizeof(str), "You created a house at X: %f, Y: %f, Z: %f, for price of: %d: %d", x, y, z, price);
	SendClientMessage(playerid, COLOR_GREY, str);
	HouseInfo[id][hForSell] = 1;
	return 1;
}
forward LoadHouses();
public LoadHouses()
{
	new str[250];
	new loadstr[850];
	new rows = cache_get_row_count(dbhandle);
	format(loadstr, sizeof(loadstr), "====================LOADING HOUSES====================");
	printf(loadstr);
	for(new i = 1; i < rows && i < MAX_HOUSES; i ++)
	{
		cache_get_field_content(i, "Owner", HouseInfo[i][hOwner], dbhandle, MAX_PLAYER_NAME);
		HouseInfo[i][hID] 		      = cache_get_field_content_int(i, "ID", dbhandle);
		HouseInfo[i][hOutPos][0]      = cache_get_field_content_float(i, "Out_X", dbhandle);
		HouseInfo[i][hOutPos][1]      = cache_get_field_content_float(i, "Out_Y", dbhandle);
		HouseInfo[i][hOutPos][2]      = cache_get_field_content_float(i, "Out_Z", dbhandle);
		HouseInfo[i][hIntPos][0]      = cache_get_field_content_float(i, "Int_X", dbhandle);
		HouseInfo[i][hIntPos][1]      = cache_get_field_content_float(i, "Int_Y", dbhandle);
		HouseInfo[i][hIntPos][2]      = cache_get_field_content_float(i, "Int_Z", dbhandle);
		HouseInfo[i][hOutInterior]    = cache_get_field_content_int(i, "OutInt", dbhandle);
		HouseInfo[i][hOutWorld]       = cache_get_field_content_int(i, "OutWorld", dbhandle);
		HouseInfo[i][hInsideInterior] = cache_get_field_content_int(i, "InsideInt", dbhandle);
		HouseInfo[i][hInsideWorld]    = cache_get_field_content_int(i, "InsideWorld", dbhandle);
		HouseInfo[i][hLocked]   	  = cache_get_field_content_int(i, "Locked", dbhandle);
		HouseInfo[i][hForSell]   	  = cache_get_field_content_int(i, "ForSell", dbhandle);
		HouseInfo[i][hPrice]   	  	  = cache_get_field_content_int(i, "Price", dbhandle);
		if(cache_get_field_content_int(i, "ForSell") == 0)
		{
			HouseInfo[i][hForSell] = 0;
		}
		if(cache_get_field_content_int(i, "Locked") == 1)
		{
			HouseInfo[i][hForSell] = 1;
		}
		if(HouseInfo[i][hForSell] == 1)
		{
			HouseInfo[i][hPickup] = CreatePickup(1273, 23, HouseInfo[i][hOutPos][0], HouseInfo[i][hOutPos][1], HouseInfo[i][hOutPos][2], -1);
	        format(str, sizeof(str), "This house is for sell!\nPrice: %d\nType /buyhouse to buy it.\nType /enter to go inside.", HouseInfo[i][hPrice]);
			HouseInfo[i][hLabel] = CreateDynamic3DTextLabel(str ,COLOR_ORANGE, HouseInfo[i][hOutPos][0], HouseInfo[i][hOutPos][1], HouseInfo[i][hOutPos][2],30.0, INVALID_PLAYER_ID, INVALID_VEHICLE_ID, 0, -1, -1, -1, 7.0);
		}
		else
		{
			HouseInfo[i][hPickup] = CreatePickup(1273, 23, HouseInfo[i][hOutPos][0], HouseInfo[i][hOutPos][1], HouseInfo[i][hOutPos][2], -1);
	        format(str, sizeof(str), "House\nOwner: %s\nTo enter inside type /enter.", HouseInfo[i][hOwner]);
			HouseInfo[i][hLabel] = CreateDynamic3DTextLabel(str ,COLOR_ORANGE, HouseInfo[i][hOutPos][0], HouseInfo[i][hOutPos][1], HouseInfo[i][hOutPos][2],30.0, INVALID_PLAYER_ID, INVALID_VEHICLE_ID, 0, -1, -1, -1, 7.0);
		}
		format(loadstr, sizeof(loadstr), "Loading house at %f %f %f[ID: %d]", HouseInfo[i][hOutPos][0], HouseInfo[i][hOutPos][1], HouseInfo[i][hOutPos][2], HouseInfo[i][hID]);
		printf(loadstr);
	}
	format(loadstr, sizeof(loadstr), "====================LOADED: %d HOUSES=================", rows);
	printf(loadstr);
	return 1;
}
My problem is:
I create 10 houses, the last house should be ID 10, and it is, last house I created is ID 10. After GMX, that last spawned house [ID: 10] is now ID 1, and all other houses are 2,3,4,5..
Second problem:

I create 10 houses, I delete houseid 9, after GMX everything is mixed, it spawns houses from id 1 to id 8.
When I /createhouse, after the GMX, it creates house ID 10. After GMX, that house id 10 is deleted, does not even spawn.

If you have any clue and could help me, it'd be appreciated.
If you don't understand what I mean, I will explain more, just reply if you're willing to help.
Reply
#2

made a example of a dynamic house system
PHP Code:
#define max_houses 100
new Iterator:fHouses<max_houses>;
CMD:createhouse(playeridparams[])
{
    new 
prices[300];
    if(
PlayerInfo[playerid][pAdmin] < 4) return SendClientMessage(playeridCOLOR_GREY"Not authorized!");
    if(
sscanf(params"d"price)) return SendClientMessage(playeridCOLOR_GREY"Usage:{FFFFFF} /createhouse [price]");
    
//gets free slot in array
    
new id=Iter_Free(fHouses);
    if(
id==INVALID_ITERATOR_SLOT)return SendClientMessage(playeridCOLOR_GREY"No valid house slot!");
    
//signs slot id
    
Iter_Add(fHouses,id);
    
GetPlayerPos(playeridHouseInfo[id][hOutPos][0], HouseInfo[id][hOutPos][1], HouseInfo[id][hOutPos][2]);
    
HouseInfo[id][hOutInterior] = GetPlayerInterior(playerid);
    
HouseInfo[id][hOutWorld] = GetPlayerVirtualWorld(playerid);
    
HouseInfo[id][hPrice] = price;
    
CreateHouse(i);
    
format(ssizeof(s), "INSERT INTO `houses` (`Out_X`, `Out_Y`, `Out_Z`, `OutInt`, `OutWorld`, `Price`) VALUES ('%f', '%f', '%f', '%i', '%i', '%i')"
    
HouseInfo[id][hOutPos][0], HouseInfo[id][hOutPos][1], HouseInfo[id][hOutPos][2], HouseInfo[id][hOutInterior], HouseInfo[id][hOutWorld], HouseInfo[id][hPrice]);
    new 
Cache:cq=mysql_query(dbhandle,s);
    
//gets auto increment id from db
    
HouseInfo[id][hID]=cache_inser_id();
    
cache_delete(cq);
    
//mysql_tquery(dbhandle,s);
    //dont use this old thing
    //mysql_function_query(dbhandle, query, true, "", "");    
    
format(ssizeof(s), "You created a house at X: %f, Y: %f, Z: %f, for price of: %d: %d"xyzprice);
    
SendClientMessage(playeridCOLOR_GREYs);
    
HouseInfo[id][hForSell] = 1;
    return 
1;
}
forward LoadHouses();
public 
LoadHouses()
{
    new 
rows cache_get_row_count(dbhandle);
    
printf("====================LOADING HOUSES====================");
    for(new 
1rows && MAX_HOUSES++)
    {
        
cache_get_field_content(i"Owner"HouseInfo[i][hOwner], dbhandleMAX_PLAYER_NAME);
        
//add auto increment to ID
        
HouseInfo[i][hID]               = cache_get_field_content_int(i"ID");
        
HouseInfo[i][hOutPos][0]      = cache_get_field_content_float(i"Out_X");
        
HouseInfo[i][hOutPos][1]      = cache_get_field_content_float(i"Out_Y");
        
HouseInfo[i][hOutPos][2]      = cache_get_field_content_float(i"Out_Z");
        
HouseInfo[i][hIntPos][0]      = cache_get_field_content_float(i"Int_X");
        
HouseInfo[i][hIntPos][1]      = cache_get_field_content_float(i"Int_Y");
        
HouseInfo[i][hIntPos][2]      = cache_get_field_content_float(i"Int_Z");
        
HouseInfo[i][hOutInterior]    = cache_get_field_content_int(i"OutInt");
        
HouseInfo[i][hOutWorld]       = cache_get_field_content_int(i"OutWorld");
        
HouseInfo[i][hInsideInterior] = cache_get_field_content_int(i"InsideInt");
        
HouseInfo[i][hInsideWorld]    = cache_get_field_content_int(i"InsideWorld");
        
HouseInfo[i][hLocked]         = cache_get_field_content_int(i"Locked");
        
HouseInfo[i][hForSell]         = cache_get_field_content_int(i"ForSell");
        
HouseInfo[i][hPrice]               = cache_get_field_content_int(i"Price");
        if(
cache_get_field_content_int(i"ForSell") == 0)HouseInfo[i][hForSell] = 0;
        if(
cache_get_field_content_int(i"Locked") == 1)HouseInfo[i][hForSell] = 1;
        
Iter_Add(fHouses,i);
        
CreateHouse(i);
    }
    
printf("====================LOADED: %d HOUSES================="rows);
    return 
1;
}
CreateHouse(i){
    new 
s[300];
    if(
HouseInfo[i][hForSell] == 1){
        
format(ssizeof(s), "This house is for sell!\nPrice: %d\nType /buyhouse to buy it.\nType /enter to go inside."HouseInfo[i][hPrice]);
    }else{
        
format(ssizeof(s), "House\nOwner: %s\nTo enter inside type /enter."HouseInfo[i][hOwner]);
    }
    
HouseInfo[i][hPickup] = CreatePickup(127323HouseInfo[i][hOutPos][0], HouseInfo[i][hOutPos][1], HouseInfo[i][hOutPos][2], -1);
    
HouseInfo[i][hLabel] = CreateDynamic3DTextLabel(,COLOR_ORANGEHouseInfo[i][hOutPos][0], HouseInfo[i][hOutPos][1], HouseInfo[i][hOutPos][2],30.0INVALID_PLAYER_IDINVALID_VEHICLE_ID0, -1, -1, -17.0);
    return 
1;

Reply
#3

Thanks will try when I am at home
Reply
#4

This is your issue:
pawn Code:
for(new i = 1; i < rows && i < MAX_HOUSES; i ++)
Rows start at 0, your iteration starts at 1.

You could do something like this to achieve your goal:
pawn Code:
new G_HOUSES_SPAWNED = 0;

for(new i; i < rows && i < MAX_HOUSES; i++){
    G_HOUSES_SPAWNED++;
   
    HouseInfo[ G_HOUSES_SPAWNED ][ var_pppp ] = cache_get_field_content_int(i, "ID");


}
Reply
#5

NAH
It should start from 1
Reply
#6

Read my post more thoroughly.
Reply
#7

Quote:
Originally Posted by ShadowMortar
View Post
NAH
It should start from 1
LOL WTF. The row starts from 0, so from 0 to 9 is 10 rows. The ID from the auto increment starts from 1.

If you don't want to do what's right - then don't ask for help here.
Reply
#8

Quote:
Originally Posted by ShadowMortar
View Post
NAH
It should start from 1
I think this guy is trying to say that IDs should start from 1, not the array index (which is starting from 0).
Reply
#9

Quote:
Originally Posted by Logic_
View Post
LOL WTF. The row starts from 0, so from 0 to 9 is 10 rows. The ID from the auto increment starts from 1.

If you don't want to do what's right - then don't ask for help here.
Instead of show offing your attidute, you could tell me that peacefully.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)