23.01.2019, 20:38
made a example of a dynamic house system
PHP Code:
#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;
}
