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; }
#define max_houses 100
new Iterator:fHouses<max_houses>;
CMD:createhouse(playerid, params[])
{
new price, s[300];
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]");
//gets free slot in array
new id=Iter_Free(fHouses);
if(id==INVALID_ITERATOR_SLOT)return SendClientMessage(playerid, COLOR_GREY, "No valid house slot!");
//signs slot id
Iter_Add(fHouses,id);
GetPlayerPos(playerid, HouseInfo[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(s, sizeof(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(s, sizeof(s), "You created a house at X: %f, Y: %f, Z: %f, for price of: %d: %d", x, y, z, price);
SendClientMessage(playerid, COLOR_GREY, s);
HouseInfo[id][hForSell] = 1;
return 1;
}
forward LoadHouses();
public LoadHouses()
{
new rows = cache_get_row_count(dbhandle);
printf("====================LOADING HOUSES====================");
for(new i = 1; i < rows && i < MAX_HOUSES; i ++)
{
cache_get_field_content(i, "Owner", HouseInfo[i][hOwner], dbhandle, MAX_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(s, sizeof(s), "This house is for sell!\nPrice: %d\nType /buyhouse to buy it.\nType /enter to go inside.", HouseInfo[i][hPrice]);
}else{
format(s, sizeof(s), "House\nOwner: %s\nTo enter inside type /enter.", HouseInfo[i][hOwner]);
}
HouseInfo[i][hPickup] = CreatePickup(1273, 23, HouseInfo[i][hOutPos][0], HouseInfo[i][hOutPos][1], HouseInfo[i][hOutPos][2], -1);
HouseInfo[i][hLabel] = CreateDynamic3DTextLabel(s ,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);
return 1;
}
for(new i = 1; i < rows && i < MAX_HOUSES; i ++)
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");
}
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. |