· 6 years ago · Aug 14, 2019, 11:12 AM
1/*
2
3
4
5 FilterScript House System C-HOUSE.
6 Create by Cleyson Stein - StNN
7
8 Do not withdraw credits.
9 All rights reserved. 05/02/2018 *
10
11
12
13*/
14
15
16#include <a_samp>
17#include <pawn.cmd>
18#include <sscanf2>
19#include <streamer>
20
21enum
22{
23 MAX_HOUSE = 100, // Max house
24
25 RED = 0xFF000FFF,
26 CINZA = 0xCECECEFF,
27 ORANGE = 0xF97804FF,
28};
29
30enum pInfo
31{
32 Name[24],
33 HasHouse,
34 EnterHouse,
35};
36new p[MAX_PLAYERS][pInfo];
37
38enum cInfo
39{
40 cOwner[24],
41 Float:cX,
42 Float:cY,
43 Float:cZ,
44 cOccupied,
45 cLocked,
46 cIcon,
47 cPickup,
48 cInt,
49 Text3D:cText,
50 cPrice
51};
52new c[MAX_HOUSE][cInfo], TotalHouse;
53
54
55// interior houses
56enum inter
57{
58 Float:iX,
59 Float:iY,
60 Float:iZ,
61 Float:iA,
62 iID
63}
64
65new interior[][inter] =
66{
67 {2196.84, -1204.36, 1049.02, 94.0010, 6},
68 {2259.38, -1135.89, 1050.64, 275.3992, 10},
69 {2282.99, -1140.28, 1050.89, 358.4660, 11},
70 {2233.69, -1115.26, 1050.88, 358.4660, 5},
71 {2218.39, -1076.21, 1050.48, 95.2635, 1},
72 {2496.00, -1692.08, 1014.74, 177.8159, 3},
73 {2365.25, -1135.58, 1050.88, 359.0367, 8},
74 {2317.77, -1026.76, 1050.21, 359.0367, 9},
75 {2324.41, -1149.54, 1050.71, 359.0367, 12},
76 {1260.6603, -785.4005, 1091.9063, 270.9891, 5},
77 {140.28, 1365.92, 1083.85, 9.6901, 5}
78};
79
80// sqlite
81new DB:Database;
82
83
84
85public OnFilterScriptInit()
86{
87 print("\n-------------------------------------");
88 print(" System C-HOUSE successfully loaded.");
89 print(" Created by Cleyson Stein - StNN.");
90 print(" All rights reserved - 02/05/2018");
91 print("-------------------------------------\n");
92
93 ConnectDB();
94 LoadHouse();
95 EnableStuntBonusForAll(0);
96 DisableInteriorEnterExits();
97 return 1;
98}
99
100public OnFilterScriptExit()
101{
102 db_close(Database);
103
104 for(new i = 0; i < MAX_HOUSE; ++i)
105 {
106 DestroyDynamicPickup(c[i][cPickup]);
107 DestroyDynamicMapIcon(c[i][cIcon]);
108 DestroyDynamic3DTextLabel(c[i][cText]);
109 }
110 return 1;
111}
112
113public OnPlayerConnect(playerid)
114{
115 GetPlayerName(playerid, p[playerid][Name], 24);
116 LoadPlayer(playerid);
117 return 1;
118}
119
120public OnPlayerDisconnect(playerid, reason)
121{
122 if(p[playerid][HasHouse] > 0) SavePlayer(playerid);
123 return 1;
124}
125
126
127
128
129
130// ============= COMMANDS ADMIN
131CMD:ahouse(playerid)
132{
133 if(!IsPlayerAdmin(playerid)) return SendClientMessage(playerid, RED, "Command restricted to administrators.");
134
135 new String_COMANDOS[220]; //
136 format(String_COMANDOS, sizeof String_COMANDOS, "");
137
138 strcat(String_COMANDOS, "{009900}ADMIN C-HOUSE\n\n");
139 strcat(String_COMANDOS, "{CECECE}/createhouse {FFFFFF}- Create a house.\n");
140 strcat(String_COMANDOS, "{CECECE}/edithouse {FFFFFF}- Edit house.\n");
141 strcat(String_COMANDOS, "{CECECE}/deletehouse {FFFFFF}- Delete house.\n");
142 strcat(String_COMANDOS, "{CECECE}/gohouse {FFFFFF}- Go to house.\n");
143
144 ShowPlayerDialog(playerid, 9545, DIALOG_STYLE_MSGBOX, "Commands Admin C-HOUSE", String_COMANDOS, "Ok", "");
145 return 1;
146}
147
148CMD:createhouse(playerid, params[])
149{
150 if(!IsPlayerAdmin(playerid)) return SendClientMessage(playerid, RED, "Command restricted to administrators.");
151 if(sscanf(params, "ii", params[0], params[1])) return SendClientMessage(playerid, CINZA, "Use /createhouse [price] [int 0a10]");
152
153 Create_House(playerid, TotalHouse+1, params[0], params[1]);
154 return 1;
155}
156
157CMD:gohouse(playerid, params[])
158{
159 if(!IsPlayerAdmin(playerid)) return SendClientMessage(playerid, RED, "Command restricted to administrators.");
160 if(sscanf(params, "i", params[0])) return SendClientMessage(playerid, CINZA, "Use /gohouse [id]");
161
162 Go_House(playerid, params[0]);
163 return 1;
164}
165
166CMD:edithouse(playerid, params[])
167{
168 if(!IsPlayerAdmin(playerid)) return SendClientMessage(playerid, RED, "Command restricted to administrators.");
169 if(sscanf(params, "iii", params[0], params[1], params[2])) return SendClientMessage(playerid, CINZA, "Use /edithouse [id] [price] [int 0a10]");
170
171 Edit_House(playerid, params[0], params[1], params[2]);
172 return 1;
173}
174
175CMD:deletehouse(playerid, params[])
176{
177 if(!IsPlayerAdmin(playerid)) return SendClientMessage(playerid, RED, "Command restricted to administrators.");
178 if(sscanf(params, "i", params[0])) return SendClientMessage(playerid, CINZA, "Use /deletehouse [id]");
179
180 Delete_House(playerid, params[0]);
181 return 1;
182}
183
184
185
186
187
188
189// ================= COMMANDS PLAYERS
190
191/*CMD:money(playerid)
192{
193 GivePlayerMoney(playerid, 500000);
194 return 1;
195}
196*/
197
198CMD:buyhouse(playerid)
199{
200 for(new i = 0; i < MAX_HOUSE; i++)
201 {
202 if(IsPlayerInRangeOfPoint(playerid, 1, c[i][cX], c[i][cY], c[i][cZ]))
203 {
204 if(p[playerid][HasHouse] > 0) return SendClientMessage(playerid, RED, "You already own a house..");
205 if(c[i][cOccupied] == 1) return SendClientMessage(playerid, RED, "This house already owns.");
206 if(GetPlayerMoney(playerid) < c[i][cPrice]) return SendClientMessage(playerid, RED, "Insufficient moneye.");
207
208 format(c[i][cOwner], 24, p[playerid][Name]);
209 c[i][cOccupied] = 1;
210 p[playerid][HasHouse] = i;
211 SendClientMessage(playerid, ORANGE, "House successfully acquired.");
212 GivePlayerMoney(playerid, -c[i][cPrice]);
213
214 DestroyDynamicPickup(c[i][cPickup]);
215 DestroyDynamicMapIcon(c[i][cIcon]);
216 DestroyDynamic3DTextLabel(c[i][cText]);
217
218 new texto[200];
219 c[i][cIcon] = CreateDynamicMapIcon(c[i][cX], c[i][cY], c[i][cZ], 32, -1);
220 c[i][cPickup] = CreateDynamicPickup(19522, 21, c[i][cX], c[i][cY], c[i][cZ]);//1272
221
222 format(texto, sizeof(texto), "{B22222}HOUSE ID: {FFFFFF}%d\n{CD5C5C}Owner: {FFFFFF}%s\n{CD5C5C}Price: {FFFFFF}$ %d{CD5C5C}\n/helphouse", i, c[i][cOwner], c[i][cPrice]);
223 c[i][cText] = CreateDynamic3DTextLabel(texto, 0xFFFFFFAA, c[i][cX], c[i][cY], c[i][cZ]+1, 20);
224
225 new Query[80];
226 format(Query, sizeof(Query), "UPDATE HOUSES SET OWNER ='%s', OCCUPIED = 1 WHERE ID =%d", c[i][cOwner], i);
227 db_query(Database, Query);
228 break;
229 }
230 }
231 return 1;
232}
233
234CMD:sellhouse(playerid)
235{
236 for(new i = 0; i < MAX_HOUSE; i++)
237 {
238 if(IsPlayerInRangeOfPoint(playerid, 1, c[i][cX], c[i][cY], c[i][cZ]))
239 {
240 if(p[playerid][HasHouse] == 0) return SendClientMessage(playerid, RED, "You do not own a house.");
241 if(c[i][cOccupied] == 0) return SendClientMessage(playerid, RED, "This house does not have an owner.");
242 if(p[playerid][HasHouse] == i)
243 {
244 SendClientMessage(playerid, ORANGE, "House sold successfully.");
245 GivePlayerMoney(playerid, c[i][cPrice]/2);
246 format(c[i][cOwner], 24, "None");
247 c[i][cOccupied] = 0;
248 p[playerid][HasHouse] = 0;
249
250 DestroyDynamicPickup(c[i][cPickup]);
251 DestroyDynamicMapIcon(c[i][cIcon]);
252 DestroyDynamic3DTextLabel(c[i][cText]);
253
254 new texto[200];
255 c[i][cIcon] = CreateDynamicMapIcon(c[i][cX], c[i][cY], c[i][cZ], 31, -1);
256 c[i][cPickup] = CreateDynamicPickup(1273, 21, c[i][cX], c[i][cY], c[i][cZ]);
257
258 format(texto, sizeof(texto), "{2E8B57}HOUSE ID: {FFFFFF}%d\n{3CB371}Owner: {FFFFFF}%s\n{3CB371}Price: {FFFFFF}$ %d\n{3CB371}Press 'F' to enter\n/helphouse", i, c[i][cOwner], c[i][cPrice]);
259 c[i][cText] = CreateDynamic3DTextLabel(texto, 0xFFFFFFAA, c[i][cX], c[i][cY], c[i][cZ]+1, 20);
260
261 new Query[80];
262 format(Query, sizeof(Query), "UPDATE HOUSES SET OWNER ='%s', OCCUPIED = 0 WHERE ID =%d", c[i][cOwner], i);
263 db_query(Database, Query);
264 break;
265
266 } else {
267
268 SendClientMessage(playerid, RED, "This house is not yours.");
269 return 1;
270 }
271 }
272 }
273 return 1;
274}
275
276CMD:lock(playerid)
277{
278 for(new i = 0; i < MAX_HOUSE; i++)
279 {
280 if(IsPlayerInRangeOfPoint(playerid, 1, c[i][cX], c[i][cY], c[i][cZ]))
281 {
282 if(p[playerid][HasHouse] == 0) return SendClientMessage(playerid, RED, "You do not own a house.");
283 if(c[i][cOccupied] == 0) return SendClientMessage(playerid, RED, "This house does not have an owner.");
284 if(p[playerid][HasHouse] == i)
285 {
286 new Query[80];
287 if(c[i][cLocked] == 0)
288 {
289 SendClientMessage(playerid, ORANGE, "Locked house.");
290 c[i][cLocked] = 1;
291
292 format(Query, sizeof(Query), "UPDATE HOUSES SET LOCKED = 1 WHERE ID =%d", i);
293 db_query(Database, Query);
294 break;
295
296 } else {
297
298 SendClientMessage(playerid, ORANGE, "Unlocked house.");
299 c[i][cLocked] = 0;
300
301 format(Query, sizeof(Query), "UPDATE HOUSES SET LOCKED = 0 WHERE ID =%d", i);
302 db_query(Database, Query);
303 break;
304 }
305 } else {
306
307 SendClientMessage(playerid, RED, "This house is not yours.");
308 return 1;
309 }
310 }
311 }
312 return 1;
313}
314
315CMD:helphouse(playerid)
316{
317 ShowPlayerDialog(playerid, 9595, DIALOG_STYLE_MSGBOX, "Help C-House","{009900}HOUSES\n\n{CECECE}/buyhouse {FFFFFF}- Buy a house.\n{CECECE}/sellhouse {FFFFFF}- Sell your house.\n{CECECE}/lock {FFFFFF}- lock | unlock house.\n", "Ok", "");
318 return 1;
319}
320
321
322
323
324
325
326public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
327{
328 if(newkeys == KEY_SECONDARY_ATTACK) // KEY F
329 {
330 for(new x = 0; x < MAX_HOUSE; x++)
331 {
332 if(IsPlayerInRangeOfPoint(playerid, 1, c[x][cX], c[x][cY], c[x][cZ]))
333 {
334 if(c[x][cOccupied] == 0)
335 {
336 SetPlayerPos(playerid, interior[c[x][cInt]][iX], interior[c[x][cInt]][iY], interior[c[x][cInt]][iZ]);
337 SetPlayerFacingAngle(playerid, interior[c[x][cInt]][iA]);
338 SetPlayerInterior(playerid, interior[c[x][cInt]][iID]);
339 p[playerid][EnterHouse] = x;
340
341 SendClientMessage(playerid, ORANGE, "House for sale! To buy use /buyhouse in the pickup from outside. Use 'N' to exit.");
342 break;
343
344 }
345
346 if(c[x][cOccupied] == 1)
347 {
348 if(c[x][cLocked] == 1 && p[playerid][HasHouse] != x) return SendClientMessage(playerid, RED, "Locked house.");
349
350 if(p[playerid][HasHouse] == x)
351 {
352 SetPlayerPos(playerid, interior[c[x][cInt]][iX], interior[c[x][cInt]][iY], interior[c[x][cInt]][iZ]);
353 SetPlayerFacingAngle(playerid, interior[c[x][cInt]][iA]);
354 SetPlayerInterior(playerid, interior[c[x][cInt]][iID]);
355 p[playerid][EnterHouse] = x;
356
357 SendClientMessage(playerid, ORANGE, "Welcome to your home. Use 'N' to exit.");
358 break;
359
360 } else {
361
362 SendClientMessage(playerid, RED, "This house is not yours.");
363 return 1;
364 }
365 }
366 }
367 }
368 }
369
370 if(newkeys == 131072) // KEY N
371 {
372 if(p[playerid][EnterHouse] > 0)
373 {
374 SetPlayerPos(playerid, c[p[playerid][EnterHouse]][cX], c[p[playerid][EnterHouse]][cY], c[p[playerid][EnterHouse]][cZ]);
375 SetPlayerInterior(playerid, 0);
376 p[playerid][EnterHouse] = 0;
377 }
378 }
379 return 1;
380}
381
382
383
384
385
386
387// ============== DATA
388ConnectDB()
389{
390 if((Database = db_open("C-House.db")) == DB:0)
391 {
392 SendRconCommand("exit");
393 print("Failed to connect to SQlite DataBase"); // DEBUG
394
395 } else {
396
397 print("Successfully Connected to DataBase SQlite."); // DEBUG
398 }
399 //criar a db esta em db.txt
400
401 new Query[280];
402 format(Query, sizeof(Query), "CREATE TABLE IF NOT EXISTS HOUSES(ID INTEGER PRIMARY KEY AUTOINCREMENT,\
403 OWNER TEXT DEFAULT '',\
404 X FLOAT DEFAULT 0.0,\
405 Y FLOAT DEFAULT 0.0,\
406 Z FLOAT DEFAULT 0.0,\
407 INTERIOR INTEGER DEFAULT 0,\
408 LOCKED INTEGER DEFAULT 0,\
409 OCCUPIED INTEGER DEFAULT 0,\
410 PRICE INTEGER DEFAULT 0)");
411 db_query(Database, Query);
412
413 format(Query, sizeof(Query), "CREATE TABLE IF NOT EXISTS OWNERS(ID INTEGER PRIMARY KEY AUTOINCREMENT, NOME TEXT DEFAULT '', CASAID INTEGER DEFAULT 0)");
414 db_query(Database, Query);
415
416 return 1;
417}
418
419LoadPlayer(playerid)
420{
421 new DBResult:Result, Query[65];
422 format(Query, sizeof(Query), "SELECT * FROM OWNERS WHERE NOME = '%s'", p[playerid][Name]);
423 Result = db_query(Database, Query);
424
425 if(db_num_rows(Result))
426 {
427 p[playerid][HasHouse] = db_get_field_assoc_int(Result, "CASAID");
428
429 } else {
430
431 new Query2[75];
432 format(Query2, sizeof(Query2), "INSERT INTO OWNERS (NOME, CASAID) VALUES ('%s', 0)", p[playerid][Name]);
433 db_query(Database, Query2);
434
435 p[playerid][HasHouse] = 0;
436 }
437 db_free_result(Result);
438 return 1;
439}
440
441SavePlayer(playerid)
442{
443 new Query[75];
444 format(Query, sizeof(Query), "UPDATE OWNERS SET CASAID =%d WHERE NOME ='%s'", p[playerid][HasHouse], p[playerid][Name]);
445 db_query(Database, Query);
446 return 1;
447}
448
449
450
451
452// ============== INIT
453LoadHouse()
454{
455 new DBResult:Result, Query[50];
456 for(new i = 0; i < MAX_HOUSE; i++)
457 {
458 format(Query, sizeof(Query), "SELECT * FROM HOUSES WHERE ID = %d", i);
459 Result = db_query(Database, Query);
460
461 if(db_num_rows(Result))
462 {
463 db_get_field_assoc(Result, "OWNER", c[i][cOwner], 24);
464
465 c[i][cX] = db_get_field_assoc_float(Result, "X");
466 c[i][cY] = db_get_field_assoc_float(Result, "Y");
467 c[i][cZ] = db_get_field_assoc_float(Result, "Z");
468
469 c[i][cOccupied] = db_get_field_assoc_int(Result, "OCCUPIED");
470 c[i][cPrice] = db_get_field_assoc_int(Result, "PRICE");
471 c[i][cInt] = db_get_field_assoc_int(Result, "INTERIOR");
472 c[i][cLocked] = db_get_field_assoc_int(Result, "LOCKED");
473 TotalHouse ++;
474
475 CreateHouse(i);
476 }
477 db_free_result(Result);
478 }
479
480 printf("\nHouse loaded: %d", TotalHouse);
481 return 1;
482}
483
484CreateHouse(i)
485{
486 new texto[200];
487 if(c[i][cOccupied] == 0)
488 {
489 c[i][cIcon] = CreateDynamicMapIcon(c[i][cX], c[i][cY], c[i][cZ], 31, -1);
490 c[i][cPickup] = CreateDynamicPickup(1273, 21, c[i][cX], c[i][cY], c[i][cZ]);
491
492 format(texto, sizeof(texto), "{2E8B57}HOUSE ID: {FFFFFF}%d\n{3CB371}Owner: {FFFFFF}%s\n{3CB371}Price: {FFFFFF}$ %d\n{3CB371}Press 'F' to enter\n/helphouse", i, c[i][cOwner], c[i][cPrice]);
493 c[i][cText] = CreateDynamic3DTextLabel(texto, 0xFFFFFFAA, c[i][cX], c[i][cY], c[i][cZ]+1, 20);
494 }
495 else if(c[i][cOccupied] == 1)
496 {
497 c[i][cIcon] = CreateDynamicMapIcon(c[i][cX], c[i][cY], c[i][cZ], 32, -1);
498 c[i][cPickup] = CreateDynamicPickup(19522, 21, c[i][cX], c[i][cY], c[i][cZ]);//1272
499
500 format(texto, sizeof(texto), "{B22222}HOUSE ID: {FFFFFF}%d\n{CD5C5C}Owner: {FFFFFF}%s\n{CD5C5C}Price: {FFFFFF}$ %d{CD5C5C}\n/helphouse", i, c[i][cOwner], c[i][cPrice]);
501 c[i][cText] = CreateDynamic3DTextLabel(texto, 0xFFFFFFAA, c[i][cX], c[i][cY], c[i][cZ]+1, 20);
502 }
503 return 1;
504}
505
506
507
508
509
510
511// ============== ADMIN
512Create_House(playerid, id, preco, inte)
513{
514 new DBResult:Result, Query[160];
515 format(Query, sizeof(Query), "SELECT * FROM HOUSES WHERE ID = %d", id);
516 Result = db_query(Database, Query);
517
518 if(db_num_rows(Result))
519 {
520 SendClientMessage(playerid, RED, "Error.");
521
522 } else {
523
524 new Float:Pos[3];
525 GetPlayerPos(playerid, Pos[0], Pos[1], Pos[2]);
526
527 format(c[id][cOwner], 24, "None");
528 c[id][cX] = Pos[0];
529 c[id][cY] = Pos[1];
530 c[id][cZ] = Pos[2];
531 c[id][cOccupied] = 0;
532 c[id][cPrice] = preco;
533 c[id][cInt] = inte;
534
535 SendClientMessage(playerid, ORANGE, "House created successfully.");
536 CreateHouse(id);
537
538 format(Query, sizeof(Query), "INSERT INTO HOUSES(OWNER, X, Y, Z, PRICE, INTERIOR) VALUES ('%s', %f, %f, %f, %d, %d)", c[id][cOwner], c[id][cX], c[id][cY], c[id][cZ], c[id][cPrice], c[id][cInt]);
539 db_query(Database, Query);
540
541 TotalHouse ++;
542 }
543 db_free_result(Result);
544 return 1;
545}
546
547Edit_House(playerid, id, preco, interi)
548{
549 new DBResult:Result, Query[50];
550 format(Query, sizeof(Query), "SELECT * FROM HOUSES WHERE ID = %d", id);
551 Result = db_query(Database, Query);
552
553 if(db_num_rows(Result))
554 {
555 new string[60];
556 format(string, sizeof(string), "You have successfully edited the house id %d", id);
557 SendClientMessage(playerid, ORANGE, string);
558
559 c[id][cPrice] = preco;
560 c[id][cInt] = interi;
561
562 DestroyDynamicPickup(c[id][cPickup]);
563 DestroyDynamicMapIcon(c[id][cIcon]);
564 DestroyDynamic3DTextLabel(c[id][cText]);
565
566 CreateHouse(id);
567
568 } else {
569
570 SendClientMessage(playerid, RED, "Error.");
571 }
572 db_free_result(Result);
573 return 1;
574}
575
576Go_House(playerid, id)
577{
578 new DBResult:Result, Query[50];
579 format(Query, sizeof(Query), "SELECT * FROM HOUSES WHERE ID = %d", id);
580 Result = db_query(Database, Query);
581
582 if(db_num_rows(Result))
583 {
584 new string[60];
585 format(string, sizeof(string), "You went home id %d.", id);
586 SendClientMessage(playerid, ORANGE, string);
587
588 SetPlayerPos(playerid, c[id][cX], c[id][cY], c[id][cZ]);
589 SetPlayerInterior(playerid, 0);
590
591 } else {
592
593 SendClientMessage(playerid, RED, "Error.");
594 }
595 db_free_result(Result);
596 return 1;
597}
598
599Delete_House(playerid, id)
600{
601 new DBResult:Result, Query[50];
602 format(Query, sizeof(Query), "SELECT * FROM HOUSES WHERE ID = %d", id);
603 Result = db_query(Database, Query);
604
605 if(db_num_rows(Result))
606 {
607 format(Query, sizeof(Query), "DELETE FROM HOUSES WHERE ID = %d", id);
608 db_query(Database, Query);
609
610 new string[60];
611 format(string, sizeof(string), "You have successfully deleted the house id %d", id);
612 SendClientMessage(playerid, ORANGE, string);
613
614 format(c[id][cOwner], 24, "None");
615 c[id][cX] = -1;
616 c[id][cY] = -1;
617 c[id][cZ] = -1;
618
619 c[id][cOccupied] = -1;
620 c[id][cPrice] = -1;
621 c[id][cInt] = -1;
622 c[id][cLocked] = -1;
623
624 DestroyDynamicPickup(c[id][cPickup]);
625 DestroyDynamicMapIcon(c[id][cIcon]);
626 DestroyDynamic3DTextLabel(c[id][cText]);
627
628 TotalHouse --;
629
630 } else {
631
632 SendClientMessage(playerid, RED, "Error.");
633 }
634 db_free_result(Result);
635 return 1;
636}