· 8 years ago · Feb 20, 2018, 06:26 AM
1//SPECIAL THANKS To [HiC]TheKiller for doing the base Tutorial for HouseSystem, base is his but everything else is my work :)
2
3#include <a_samp>
4#include <zcmd>
5#include <streamer>
6
7#define MAX_HOUSES 300
8#define MAX_HOUSES_PER_PLAYER 1 //1 - Player can own only 1 house, change it to 2 if you want that Player can own 2 houses or else like 99 or 3
9#define databasename "houses.cfg"
10#define COLOR_SUPERGREEN 0xFF01FF
11#define COLOR_RED 0xFF0000AA
12
13enum hinfo
14{
15 owner[24],
16 Hname[100],
17 costprice,
18 Float:EnterPos[3],
19 Float:TelePos[3],
20 sellprice,
21 interiors,
22 Text3D:textid,
23 checkpointidx[2]
24};
25
26new DB:database, DBResult:queryresult, fquery[300];
27new HouseInformation[MAX_HOUSES][hinfo], houseid;
28new InHouse[MAX_PLAYERS], InHouseCP[MAX_PLAYERS];
29
30public OnFilterScriptInit()
31{
32 database = db_open(databasename);
33 db_query(database, "CREATE TABLE IF NOT EXISTS `HOUSEINFO` (housename varchar(51), houseowner varchar(25))");
34 //USAGE: CreateHouse(HouseName, Price, Float:EnterX, Float:EnterY, Float:EnterZ, Float:ExitX, Float:ExitY, Float:ExitZ, SellPrice, Interiorx)
35 CreateHouse("TESTING HOUSE", 100, 1765.9399,-1364.8022,15.7578, 266.857757, 305.001586, 999.148437, 2, 1);
36 return 1;
37}
38
39public OnPlayerConnect(playerid)
40{
41 InHouse[playerid] = -1;
42 InHouseCP[playerid] = -1;
43 return 1;
44}
45
46stock CreateHouse(HouseName[], CostP, Float:EnterX, Float:EnterY, Float:EnterZ, Float:TeleX, Float:TeleY, Float:TeleZ, Interiorx, SellP)
47{
48 format(HouseInformation[houseid][Hname], 100, "%s", HouseName);
49 HouseInformation[houseid][costprice] = CostP;
50 HouseInformation[houseid][EnterPos][0] = EnterX;
51 HouseInformation[houseid][EnterPos][1] = EnterY;
52 HouseInformation[houseid][EnterPos][2] = EnterZ;
53 HouseInformation[houseid][TelePos][0] = TeleX;
54 HouseInformation[houseid][TelePos][1] = TeleY;
55 HouseInformation[houseid][TelePos][2] = TeleZ;
56 HouseInformation[houseid][sellprice] = SellP;
57 HouseInformation[houseid][interiors] = Interiorx;
58 format(fquery, sizeof(fquery), "SELECT houseowner FROM HOUSEINFO WHERE housename = '%s'", HouseName);
59 queryresult = db_query(database, fquery);
60 if(db_num_rows(queryresult) != 0) db_get_field_assoc(queryresult, "houseowner", HouseInformation[houseid][owner], 24);
61 HouseInformation[houseid][checkpointidx][0] = CreateDynamicCP(EnterX, EnterY, EnterZ, 2.0);
62 HouseInformation[houseid][checkpointidx][1] = CreateDynamicCP(TeleX, TeleY, TeleZ, 2.0, 15500000+houseid, Interiorx); CreateDynamicPickup(1277,1,TeleX, TeleY, TeleZ,-1); CreateDynamic3DTextLabel("[ {FFFFFF}CONFIGURATION {FF0000}]", 0xFF0000FF, TeleX, TeleY, TeleZ + 0.5, 50.0);
63 if(!HouseInformation[houseid][owner][0]) format(fquery, sizeof(fquery), "[ {FFFFFF}House {00FF00}] \n %s \n Price: {FFFFFF}%d {00FF00}$", HouseName, CostP);
64 else if(HouseInformation[houseid][owner][0] != 0) format(fquery, sizeof(fquery), "[ {FFFFFF}House {00FF00}] \n %s \n Owner: {FFFFFF}%s", HouseName, HouseInformation[houseid][owner]);
65 HouseInformation[houseid][textid] = CreateDynamic3DTextLabel(fquery, COLOR_SUPERGREEN, EnterX, EnterY, EnterZ + 0.5, 50.0); CreateDynamicMapIcon(EnterX, EnterY, EnterZ, 31, 0, 0, 0, -1, 150.0); CreateDynamicPickup(1273,1,EnterX, EnterY, EnterZ,-1);
66 houseid ++;
67 return 1;
68}
69
70stock SetOwner(HouseName[], ownername[], houseids)
71{
72 format(fquery, sizeof(fquery), "INSERT INTO `HOUSEINFO` (`housename`, `houseowner`) VALUES('%s', '%s')", HouseName, ownername);
73 db_query(database, fquery);
74 format(HouseInformation[houseids][owner], 24, "%s", ownername);
75 format(fquery, sizeof(fquery), "[ {FFFFFF}House {00FF00}] \n %s \n Owner: {FFFFFF}%s", HouseName, HouseInformation[houseids][owner]);
76 UpdateDynamic3DTextLabelText(HouseInformation[houseids][textid], COLOR_SUPERGREEN, fquery);
77 return 1;
78}
79
80stock DeleteOwner(HouseName[], houseids)
81{
82 format(HouseInformation[houseids][owner], 24, "%s", "\0");
83 format(fquery, sizeof(fquery), "DELETE FROM `HOUSEINFO` WHERE `housename` = '%s'", HouseName);
84 db_query(database, fquery);
85 format(fquery, sizeof(fquery), "[ {FFFFFF}House {00FF00}] \n %s \n Price: {FFFFFF}%d {00FF00}$", HouseName, HouseInformation[houseids][costprice], HouseInformation[houseids][sellprice]);
86 UpdateDynamic3DTextLabelText(HouseInformation[houseids][textid], COLOR_SUPERGREEN, fquery);
87 return 1;
88}
89
90public OnPlayerEnterDynamicCP(playerid, checkpointid)
91{
92 for(new x; x<houseid; x++)
93 {
94 if(HouseInformation[x][checkpointidx][0] == checkpointid)
95 {
96 if(InHouse[playerid] != -1)
97 {
98 InHouse[playerid] = -1;
99 return 1;
100 }
101 InHouseCP[playerid] = x;
102 new Pname[24];
103 GetPlayerName(playerid, Pname, 24);
104 if(HouseInformation[x][owner][0] != 0 && !strcmp(Pname, HouseInformation[x][owner][0]))
105 {
106 ShowPlayerDialog(playerid,1162,DIALOG_STYLE_LIST,"{00FF00}House","{00FF00}Enter House","OK","Cancel");
107 }
108 if(!HouseInformation[x][owner][0]) ShowPlayerDialog(playerid,1161,DIALOG_STYLE_MSGBOX,"{00FF00}House","{FFFFFF}This House is {00FF00}Free {FFFFFF}to buy. Would you like to {00FF00}Buy it {FFFFFF}?","Buy","Cancel");
109 return 1;
110 }
111 if(HouseInformation[x][checkpointidx][1] == checkpointid)
112 {
113 if(InHouse[playerid] == -1)
114 {
115 InHouse[playerid] = x;
116 return 1;
117 }
118 ShowPlayerDialog(playerid,1163,DIALOG_STYLE_LIST,"{00FF00}House","{00FF00}Exit House\n{FF0000}Sell House","OK","Cancel");
119 return 1;
120 }
121 }
122 return 1;
123}
124
125public OnPlayerLeaveDynamicCP(playerid, checkpointid)
126{
127 if(InHouseCP[playerid] != - 1) InHouseCP[playerid] = -1;
128 return 1;
129}
130
131public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
132{
133if(dialogid == 1163)
134{
135if(response == 1)
136{
137if(listitem == 0)
138{
139for(new x; x<houseid; x++)
140{
141SetPlayerPos(playerid, HouseInformation[x][EnterPos][0], HouseInformation[x][EnterPos][1], HouseInformation[x][EnterPos][2]);
142SetPlayerInterior(playerid, 0);
143SetPlayerVirtualWorld(playerid, 0);
144}
145}
146}
147}
148if(dialogid == 1161)
149{
150if(response == 1)
151{
152if(InHouseCP[playerid] == -1) return SendClientMessage(playerid,COLOR_RED, "[!] You're not in your House !");
153if(HouseInformation[InHouseCP[playerid]][owner][0] != 0) return SendClientMessage(playerid,COLOR_RED, "[!] This House someone already owns !");
154if(GetPlayerMoney(playerid) < HouseInformation[InHouseCP[playerid]][costprice]) return SendClientMessage(playerid,COLOR_RED, "[!] You don't have enough money to buy this House !");
155new PlayerName[24];
156GetPlayerName(playerid, PlayerName, 24);
157format(fquery, sizeof(fquery), "SELECT `houseowner` FROM `HOUSEINFO` WHERE `houseowner` = '%s'", PlayerName);
158queryresult = db_query(database, fquery);
159if(db_num_rows(queryresult) == MAX_HOUSES_PER_PLAYER) return SendClientMessage(playerid,COLOR_RED, "[!] You have reached the maximum amount of Houses !");
160db_free_result(queryresult);
161SetOwner(HouseInformation[InHouseCP[playerid]][Hname], PlayerName, InHouseCP[playerid]);
162GivePlayerMoney(playerid, - HouseInformation[InHouseCP[playerid]][costprice]);
163SendClientMessage(playerid, COLOR_SUPERGREEN, "[*] You have successfully {FFFFFF}bought {00FF00}a {FFFFFF}new House {00FF00}!");
164}
165}
166if(dialogid == 1162)
167{
168if(response == 1)
169{
170if(listitem == 0)
171{
172for(new x; x<houseid; x++)
173{
174InHouseCP[playerid] = x;
175new Pname[24];
176GetPlayerName(playerid, Pname, 24);
177if(HouseInformation[x][owner][0] != 0 && !strcmp(Pname, HouseInformation[x][owner][0]))
178SetPlayerPos(playerid, HouseInformation[x][TelePos][0], HouseInformation[x][TelePos][1], HouseInformation[x][TelePos][2]);
179SetPlayerInterior(playerid, HouseInformation[x][interiors]);
180SetPlayerVirtualWorld(playerid, 15500000 + x);
181SendClientMessage(playerid, COLOR_SUPERGREEN, "[*] You have entered your {FFFFFF}House {00FF00}!");
182}
183}
184}
185}
186if(listitem == 1)
187{
188if(InHouse[playerid] == -1) return SendClientMessage(playerid,COLOR_RED, "[!] You're not in your house !");
189new Pname[24];
190GetPlayerName(playerid, Pname, 24);
191if(strcmp(HouseInformation[InHouse[playerid]][owner], Pname) != 0) return SendClientMessage(playerid,COLOR_RED, "[!] This is not your house !");
192DeleteOwner(HouseInformation[InHouse[playerid]][Hname], InHouse[playerid]);
193GivePlayerMoney(playerid, HouseInformation[InHouse[playerid]][sellprice]);
194SetPlayerPos(playerid, HouseInformation[InHouse[playerid]][EnterPos][0], HouseInformation[InHouse[playerid]][EnterPos][1], HouseInformation[InHouse[playerid]][EnterPos][2]);
195SetPlayerInterior(playerid, 0);
196SetPlayerVirtualWorld(playerid, 0);
197InHouseCP[playerid] = InHouse[playerid];
198SendClientMessage(playerid, COLOR_RED, "[*] You have successfully {FFFFFF}sold {FF0000}your {FFFFFF}house {FF0000}!");
199}
200return 1;
201}