Advertisement
Guest User

House Version 2 - JonathanW

a guest
Jun 28th, 2014
4,381
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 27.95 KB | None | 0 0
  1. /*
  2. | Walker's Dynamic Housing System - ENG - 0.3Z |
  3. | Copyright |
  4. */
  5. #include <a_samp>
  6. #include <sscanf2>
  7. #include <YSI\y_ini>
  8. #include <zcmd>
  9. #include <streamer>
  10. // ===============[COLORS]===================
  11. #define COLOR_GREEN 0x008000FF
  12. #define COLOR_YELLOW 0xECD400F6
  13. #define COLOR_WHITE 0xFFFFFFFF
  14.  
  15. //===============[DEFINES]===================
  16. #define MAX_HOUSES 300
  17. #define SCM SendClientMessage // Just for easy,not too important.
  18. #define HOUSE_PATH "/Houses/House %d.ini"
  19. #define USER_PATH "/Users/%s.ini"
  20. #define DIALOG_HOUSE 1
  21. #define SELLPERCENT 50 // This is the Total Percent of Money that you will get back on selling the House.
  22. #define PRESSED(%0) \
  23. (((newkeys & (%0)) == (%0)) && ((oldkeys & (%0)) != (%0)))
  24. // ==============[TEXTDRAWS]==================
  25. new PlayerText:Statement[MAX_PLAYERS];
  26. new PlayerText:Box[MAX_PLAYERS];
  27. new PlayerText:boxtext[MAX_PLAYERS];
  28. // Player Info (We're using only 1 Variable right now)
  29. enum pInfo
  30. {
  31. HouseKey,
  32. HouseID
  33. }
  34. new PlayerInfo[MAX_PLAYERS][pInfo];
  35. // House Info (There are 19 Variables here)
  36. enum hInfo
  37. {
  38. Owner[32],
  39. Owned,
  40. Price,
  41. Float: EnterX,
  42. Float: EnterY,
  43. Float: EnterZ,
  44. Float: EnterA,
  45. Float: ExitX,
  46. Float: ExitY,
  47. Float: ExitZ,
  48. Float: ExitA,
  49. EnterInt,
  50. EnterVW,
  51. ExitInt,
  52. ExitVW,
  53. Money,
  54. Text3D: Label,
  55. PickupID,
  56. Locked
  57. }
  58. new HouseInfo[MAX_HOUSES][hInfo];
  59. new HouseTaken[MAX_HOUSES];
  60.  
  61. public OnFilterScriptExit()
  62. {
  63. return 1;
  64. }
  65.  
  66. public OnFilterScriptInit()
  67. {
  68. print("\n-----------------------------------------");
  69. print("-Dynamic Housing System - ENG - JonathanW-");
  70. print("------------------------------------------\n");
  71. // Loading Houses
  72. for(new i = 1; i < MAX_HOUSES; i++)
  73. {
  74. new gFile[35];
  75. format(gFile, 35, HOUSE_PATH ,i);
  76. if(fexist(gFile))
  77. {
  78. INI_ParseFile(gFile, "LoadHouse", .bExtra = true, .extra = i);
  79. ReadHouse(i);
  80. }
  81. }
  82. return 1;
  83. }
  84. //=============================[HOUSE FUNCTIONS]=============================
  85. // This is for Setting a House's Information
  86. stock ReadHouse(houseid)
  87. {
  88. new string[512];
  89. if(HouseInfo[houseid][Owned]) format(string, sizeof(string), "[House] {2F70D0}%d\n{FFFFFF}Owner: {2F70D0}%s\n{FFFFFF}Status: {2F70D0}%s", houseid,HouseInfo[houseid][Owner],HL(houseid));
  90. else format(string, sizeof(string), "House {2F70D0}%d\n{FFFFFF}Status: {2F70D0}For sale\n{FFFFFF}Price: {2F70D0}%d", houseid,HouseInfo[houseid][Price]);
  91. HouseInfo[houseid][Label] = CreateDynamic3DTextLabel(string, COLOR_WHITE, HouseInfo[houseid][ExitX], HouseInfo[houseid][ExitY], HouseInfo[houseid][ExitZ], 15);
  92. HouseInfo[houseid][PickupID] = CreateDynamicPickup(1273, 23, HouseInfo[houseid][ExitX], HouseInfo[houseid][ExitY], HouseInfo[houseid][ExitZ], 0, 0, -1, 40.0);
  93. }
  94. stock GetAvailableID()
  95. {
  96. for(new i = 1; i<MAX_HOUSES; i++)
  97. {
  98. if(HouseTaken[i] == 0) return i;
  99. }
  100. return -1;
  101. }
  102. stock Showlock(playerid)
  103. {
  104. PlayerTextDrawSetString(playerid, boxtext[playerid], "Locked");
  105. PlayerTextDrawShow(playerid, Box[playerid]);
  106. PlayerTextDrawShow(playerid, boxtext[playerid]);
  107. SetTimerEx("HideTextdraws", 4000, false, "i", playerid);
  108. return 1;
  109. }
  110. stock HL(houseid)
  111. {
  112. new string[16];
  113. if(HouseInfo[houseid][Locked] == 1) format(string, sizeof(string), "Locked");
  114. else if(HouseInfo[houseid][Locked] == 0) format(string, sizeof(string), "Unlocked");
  115. return string;
  116. }
  117. stock GetName(playerid)
  118. {
  119. new name[MAX_PLAYER_NAME];
  120. GetPlayerName(playerid,name,sizeof(name));
  121. for(new i = 0; i < MAX_PLAYER_NAME; i++)
  122. {
  123. if(name[i] == '_') name[i] = ' ';
  124. }
  125. return name;
  126. }
  127. stock CreateTextdraws(playerid)
  128. {
  129. Statement[playerid] = CreatePlayerTextDraw(playerid, 172.000000, 398.125000, "You have successfully ~g~purchased~w~ a house");
  130. PlayerTextDrawLetterSize(playerid, Statement[playerid], 0.377500, 1.337500);
  131. PlayerTextDrawAlignment(playerid, Statement[playerid], 1);
  132. PlayerTextDrawColor(playerid, Statement[playerid], -1);
  133. PlayerTextDrawSetShadow(playerid, Statement[playerid], 0);
  134. PlayerTextDrawSetOutline(playerid, Statement[playerid], 1);
  135. PlayerTextDrawBackgroundColor(playerid, Statement[playerid], 51);
  136. PlayerTextDrawFont(playerid, Statement[playerid], 1);
  137. PlayerTextDrawSetProportional(playerid, Statement[playerid], 1);
  138.  
  139. Box[playerid] = CreatePlayerTextDraw(playerid, 100.500000, 210.187500, "usebox");
  140. PlayerTextDrawLetterSize(playerid, Box[playerid], 0.000000, 2.034723);
  141. PlayerTextDrawTextSize(playerid, Box[playerid], 19.000000, 0.000000);
  142. PlayerTextDrawAlignment(playerid, Box[playerid], 1);
  143. PlayerTextDrawColor(playerid, Box[playerid], 0);
  144. PlayerTextDrawUseBox(playerid, Box[playerid], true);
  145. PlayerTextDrawBoxColor(playerid, Box[playerid], -226);
  146. PlayerTextDrawSetShadow(playerid, Box[playerid], 0);
  147. PlayerTextDrawSetOutline(playerid, Box[playerid], 0);
  148. PlayerTextDrawFont(playerid, Box[playerid], 0);
  149.  
  150. boxtext[playerid] = CreatePlayerTextDraw(playerid, 35.500000, 212.625000, "~g~UNLOCKED");
  151. PlayerTextDrawLetterSize(playerid, boxtext[playerid], 0.285499, 1.250000);
  152. PlayerTextDrawAlignment(playerid, boxtext[playerid], 1);
  153. PlayerTextDrawColor(playerid, boxtext[playerid], -1523963137);
  154. PlayerTextDrawSetShadow(playerid, boxtext[playerid], 0);
  155. PlayerTextDrawSetOutline(playerid, boxtext[playerid], 1);
  156. PlayerTextDrawBackgroundColor(playerid, boxtext[playerid], 51);
  157. PlayerTextDrawFont(playerid, boxtext[playerid], 1);
  158. PlayerTextDrawSetProportional(playerid, boxtext[playerid], 1);
  159. return 1;
  160. }
  161. stock SaveHouses()
  162. {
  163. for(new i=1;i < MAX_HOUSES;i++)
  164. {
  165. if(HouseTaken[i] == 0) continue;
  166.  
  167. new hFile[35];
  168. format(hFile, 35, HOUSE_PATH, i);
  169. new INI:File = INI_Open(hFile);
  170. INI_SetTag(File, "House Data");
  171. INI_WriteString(File, "Owner", HouseInfo[i][Owner]);
  172. INI_WriteInt(File, "Owned", HouseInfo[i][Owned]);
  173. INI_WriteInt(File, "Price", HouseInfo[i][Price]);
  174. INI_WriteFloat(File, "EnterX", HouseInfo[i][EnterX]);
  175. INI_WriteFloat(File, "EnterY", HouseInfo[i][EnterY]);
  176. INI_WriteFloat(File, "EnterZ", HouseInfo[i][EnterZ]);
  177. INI_WriteFloat(File, "EnterA", HouseInfo[i][EnterA]);
  178. INI_WriteFloat(File, "ExitX", HouseInfo[i][ExitX]);
  179. INI_WriteFloat(File, "ExitY", HouseInfo[i][ExitY]);
  180. INI_WriteFloat(File, "ExitZ", HouseInfo[i][ExitZ]);
  181. INI_WriteFloat(File, "ExitA", HouseInfo[i][ExitA]);
  182. INI_WriteInt(File, "EnterInt", HouseInfo[i][EnterInt]);
  183. INI_WriteInt(File, "EnterVW", HouseInfo[i][EnterVW]);
  184. INI_WriteInt(File, "ExitInt", HouseInfo[i][ExitInt]);
  185. INI_WriteInt(File, "ExitVW", HouseInfo[i][ExitVW]);
  186. INI_WriteInt(File, "Money", HouseInfo[i][Money]);
  187. INI_WriteInt(File, "PickupID", HouseInfo[i][PickupID]);
  188. INI_WriteInt(File, "Locked", HouseInfo[i][Locked]);
  189. INI_Close(File);
  190. }
  191. }
  192. forward LoadHouse(id, name[], value[]);
  193. public LoadHouse(id, name[], value[])
  194. {
  195. INI_String("Owner", HouseInfo[id][Owner],32);
  196. INI_Int("Owned", HouseInfo[id][Owned]);
  197. INI_Int("Price", HouseInfo[id][Price]);
  198. INI_Float("EnterX", HouseInfo[id][EnterX]);
  199. INI_Float("EnterY", HouseInfo[id][EnterY]);
  200. INI_Float("EnterZ", HouseInfo[id][EnterZ]);
  201. INI_Float("EnterA", HouseInfo[id][EnterA]);
  202. INI_Float("ExitX", HouseInfo[id][ExitX]);
  203. INI_Float("ExitY", HouseInfo[id][ExitY]);
  204. INI_Float("ExitZ", HouseInfo[id][ExitZ]);
  205. INI_Float("ExitA", HouseInfo[id][ExitA]);
  206. INI_Int("EnterInt", HouseInfo[id][EnterInt]);
  207. INI_Int("EnterVW", HouseInfo[id][EnterVW]);
  208. INI_Int("ExitInt", HouseInfo[id][ExitInt]);
  209. INI_Int("ExitVW", HouseInfo[id][ExitVW]);
  210. INI_Int("Money", HouseInfo[id][Money]);
  211. INI_Int("PickupID", HouseInfo[id][PickupID]);
  212. INI_Int("Locked", HouseInfo[id][Locked]);
  213. HouseTaken[id] = 1;
  214. return 1;
  215. }
  216. stock SaveUser(playerid)
  217. {
  218. new File[35];
  219. format(File, 35, USER_PATH, GetName(playerid));
  220. new INI:f = INI_Open(File);
  221. INI_SetTag(f, "Player Data");
  222. INI_WriteInt(f, "HouseID", PlayerInfo[playerid][HouseID]);
  223. INI_WriteInt(f, "HouseKey", PlayerInfo[playerid][HouseKey]);
  224. INI_Close(f);
  225. }
  226. forward LoadUser(playerid, name[], value[]);
  227. public LoadUser(playerid, name[], value[])
  228. {
  229. INI_Int("HouseID",PlayerInfo[playerid][HouseID]);
  230. INI_Int("HouseKey",PlayerInfo[playerid][HouseKey]);
  231. return 1;
  232. }
  233. // ====================================[COMMANDS]=================================
  234. CMD:hhelp(playerid, params[]) return cmd_househelp(playerid, params);
  235. CMD:help(playerid, params[]) return cmd_househelp(playerid, params);
  236. CMD:househelp(playerid, params[])
  237. {
  238. SendClientMessage(playerid, COLOR_WHITE, "{2F70D0}==================[HOUSE COMMANDS]===============");
  239. SendClientMessage(playerid, COLOR_WHITE, "{2F70D0}[ADMIN]: {FFFFFF}/createhouse /deletehouse /edithloc /edithprice");
  240. SendClientMessage(playerid, COLOR_WHITE, "{2F70D0}[PLAYER] {FFFFFF}/buy /sell /lock /putmoney /takemoney");
  241. SendClientMessage(playerid, COLOR_WHITE, "{2F70D0}[EXTRA]: {FFFFFF}/saveme /loadme");
  242. return 1;
  243. }
  244. CMD:createhouse(playerid, params[])
  245. {
  246. new type[128], string[256];
  247. new id = GetAvailableID();
  248. if(sscanf(params, "s[128]",type))
  249. {
  250. SendClientMessage(playerid, COLOR_WHITE, "{2F70D0}[SYNTAX] {FFFFFF}/createhouse [Level]");
  251. SendClientMessage(playerid, COLOR_WHITE, "{2F70D0}[OPTIONS]{FFFFFF}|| L1 - L2 - L3 - L4 ||");
  252. return 1;
  253. }
  254. if(!strcmp(type, "l1", true, 2))
  255. {
  256. HouseInfo[id][EnterX] = 2308.8;
  257. HouseInfo[id][EnterY] = -1212.8;
  258. HouseInfo[id][EnterZ] = 1049.0;
  259. HouseInfo[id][EnterInt] = 6;
  260. }
  261. if(!strcmp(type, "l2", true, 2))
  262. {
  263. HouseInfo[id][EnterX] = 260.7;
  264. HouseInfo[id][EnterY] = 1237.5;
  265. HouseInfo[id][EnterZ] = 1084.2;
  266. HouseInfo[id][EnterInt] = 9;
  267. }
  268. if(!strcmp(type, "l3", true, 2))
  269. {
  270. HouseInfo[id][EnterX] = 2365.2;
  271. HouseInfo[id][EnterY] = -1135.4;
  272. HouseInfo[id][EnterZ] = 1050.8;
  273. HouseInfo[id][EnterInt] = 8;
  274. }
  275. if(!strcmp(type, "l4", true, 2))
  276. {
  277. HouseInfo[id][EnterX] = 2270.1;
  278. HouseInfo[id][EnterY] = -1210.4;
  279. HouseInfo[id][EnterZ] = 1047.5;
  280. HouseInfo[id][EnterInt] = 10;
  281. }
  282. // Setting House Information
  283. new Float: Pos[3];
  284. GetPlayerPos(playerid, Pos[0], Pos[1], Pos[2]);
  285. HouseTaken[id] = 1;
  286. HouseInfo[id][Owned] = 0;
  287. HouseInfo[id][ExitX] = Pos[0];
  288. HouseInfo[id][ExitY] = Pos[1];
  289. HouseInfo[id][ExitZ] = Pos[2];
  290. HouseInfo[id][ExitInt] = GetPlayerInterior(playerid);
  291. HouseInfo[id][ExitVW] = GetPlayerVirtualWorld(playerid);
  292. HouseInfo[id][EnterVW] = GetPlayerVirtualWorld(playerid)+250;
  293. HouseInfo[id][Price] = 9999999;
  294. // Visually,creating the House
  295. format(string, sizeof(string), "House {2F70D0}%d\n{FFFFFF}Status: {2F70D0}For sale\n{FFFFFF}Price: {2F70D0}%d", id,HouseInfo[id][Price]);
  296. HouseInfo[id][Label] = CreateDynamic3DTextLabel(string, COLOR_WHITE, HouseInfo[id][ExitX], HouseInfo[id][ExitY], HouseInfo[id][ExitZ], 15);
  297. HouseInfo[id][PickupID] = CreateDynamicPickup(1273, 23, HouseInfo[id][ExitX], HouseInfo[id][ExitY], HouseInfo[id][ExitZ], 0, 0, -1, 40.0);
  298.  
  299. // Saving
  300. SaveHouses();
  301. return 1;
  302. }
  303. CMD:deletehouse(playerid, params[])
  304. {
  305. new houseid,string[128];
  306. if(sscanf(params, "d", houseid))
  307. {
  308. SendClientMessage(playerid, COLOR_WHITE, "{2F70D0}[SYNTAX] {FFFFFF}/deletehouse [houseid]");
  309. return 1;
  310. }
  311. if(houseid < 1 || houseid > MAX_HOUSES)
  312. {
  313. format(string, sizeof(string), "{2F70D0}[ERROR]:{FFFFFF}House ID cannot be below 0 and above %d.", MAX_HOUSES);
  314. SendClientMessage(playerid, COLOR_WHITE, string);
  315. return 1;
  316. }
  317. DestroyDynamic3DTextLabel(HouseInfo[houseid][Label]);
  318. DestroyDynamicPickup(HouseInfo[houseid][PickupID]);
  319. new file[128];
  320. // House Information
  321. HouseInfo[houseid][Owned] = 0;
  322. HouseInfo[houseid][Price] = 0;
  323. HouseInfo[houseid][EnterX] = 0.0;
  324. HouseInfo[houseid][EnterY] = 0.0;
  325. HouseInfo[houseid][EnterZ] = 0.0;
  326. HouseInfo[houseid][EnterA] = 0.0;
  327. HouseInfo[houseid][ExitX] = 0.0;
  328. HouseInfo[houseid][ExitY] = 0.0;
  329. HouseInfo[houseid][ExitZ] = 0.0;
  330. HouseInfo[houseid][ExitA] = 0.0;
  331. HouseInfo[houseid][PickupID] = 0;
  332. HouseInfo[houseid][Locked] = 0;
  333. HouseTaken[houseid] = 0;
  334. // Deleting the House From ScriptFiles.
  335. format(file, sizeof(file), HOUSE_PATH, houseid);
  336. if(fexist(file)) fremove(file);
  337. return 1;
  338. }
  339. CMD:edithloc(playerid, params[])
  340. {
  341. new string[128],houseid;
  342. if(sscanf(params, "d", houseid)) return SendClientMessage(playerid, COLOR_WHITE, "{2F70D0}[SYNTAX] {FFFFFF}/edithloc [houseid]");
  343. // Setting House Information
  344. new Float:X, Float:Y, Float:Z;
  345. GetPlayerPos(playerid, X, Y, Z);
  346. HouseInfo[houseid][ExitX] = X;
  347. HouseInfo[houseid][ExitY] = Y;
  348. HouseInfo[houseid][ExitZ] = Z;
  349. HouseInfo[houseid][ExitInt] = GetPlayerInterior(playerid);
  350. HouseInfo[houseid][ExitVW] = GetPlayerVirtualWorld(playerid);
  351. DestroyDynamicPickup(HouseInfo[houseid][PickupID]);
  352. DestroyDynamic3DTextLabel(HouseInfo[houseid][Label]);
  353. HouseInfo[houseid][PickupID] = 0;
  354. // Updating the Pickup
  355. if(HouseInfo[houseid][Owned])
  356. {
  357. format(string, sizeof(string), "House {2F70D0}%d\n{FFFFFF}Owner: {2F70D0}%s\n{FFFFFF}Status: {2F70D0}%s", houseid,HouseInfo[houseid][Owner],HL(houseid));
  358. }
  359. else
  360. {
  361. format(string, sizeof(string), "House {2F70D0}%d\n{FFFFFF}Status: {2F70D0}For sale\n{FFFFFF}Price: {2F70D0}%d", houseid,HouseInfo[houseid][Price]);
  362. }
  363. HouseInfo[houseid][Label] = CreateDynamic3DTextLabel(string, COLOR_WHITE, HouseInfo[houseid][ExitX], HouseInfo[houseid][ExitY], HouseInfo[houseid][ExitZ], 15);
  364. HouseInfo[houseid][PickupID] = CreateDynamicPickup(1273, 23, HouseInfo[houseid][ExitX], HouseInfo[houseid][ExitY], HouseInfo[houseid][ExitZ], 0, 0, -1, 40.0);
  365. // Saving
  366. SaveHouses();
  367. return 1;
  368. }
  369. CMD:edithprice(playerid, params[])
  370. {
  371. new string[128],houseid,price;
  372. if(sscanf(params, "dd", houseid,price)) return SendClientMessage(playerid, COLOR_WHITE, "{2F70D0}[SYNTAX] {FFFFFF}/edithprice [houseid] [price]");
  373. // Setting House Information
  374. HouseInfo[houseid][Price] = price;
  375. DestroyDynamicPickup(HouseInfo[houseid][PickupID]);
  376. HouseInfo[houseid][PickupID] = 0;
  377. DestroyDynamic3DTextLabel(HouseInfo[houseid][Label]);
  378. // Updating the Pickup
  379. format(string, sizeof(string), "House {2F70D0}%d\n{FFFFFF}Status: {2F70D0}For sale\n{FFFFFF}Price: {2F70D0}%d", houseid,HouseInfo[houseid][Price]);
  380. HouseInfo[houseid][Label] = CreateDynamic3DTextLabel(string, COLOR_WHITE, HouseInfo[houseid][ExitX], HouseInfo[houseid][ExitY], HouseInfo[houseid][ExitZ], 15);
  381. HouseInfo[houseid][PickupID] = CreateDynamicPickup(1273, 23, HouseInfo[houseid][ExitX], HouseInfo[houseid][ExitY], HouseInfo[houseid][ExitZ], 0, 0, -1, 40.0);
  382. // Saving
  383. SaveHouses();
  384. return 1;
  385. }
  386. CMD:lock(playerid, params[])
  387. {
  388. new id;
  389. new txdstring[128];
  390. if(!PlayerInfo[playerid][HouseKey]) return SendClientMessage(playerid, COLOR_WHITE, "{2F70D0}[ERROR]: {FFFFFF}You don't own a House that you can lock.");
  391. // Getting the House ID
  392. if(PlayerInfo[playerid][HouseID])
  393. {
  394. id = PlayerInfo[playerid][HouseID];
  395. }
  396. // Locking/Unlocking
  397. if(IsPlayerInRangeOfPoint(playerid, 3.0, HouseInfo[id][ExitX],HouseInfo[id][ExitY],HouseInfo[id][ExitZ]) || IsPlayerInRangeOfPoint(playerid, 3.0, HouseInfo[id][EnterX],HouseInfo[id][EnterY],HouseInfo[id][EnterY]))
  398. {
  399. if(HouseInfo[id][Locked] == 0)
  400. {
  401. new string[128];
  402. HouseInfo[id][Locked] = 1;
  403. // Textdraw
  404. format(txdstring, sizeof(txdstring), "Locked");
  405. PlayerTextDrawSetString(playerid, boxtext[playerid], txdstring);
  406. PlayerTextDrawShow(playerid, Box[playerid]);
  407. PlayerTextDrawShow(playerid, boxtext[playerid]);
  408. SetTimerEx("HideTextdraws", 4000, false, "i", playerid);
  409. // Pickup
  410. DestroyDynamic3DTextLabel(HouseInfo[id][Label]);
  411. format(string, sizeof(string), "House {2F70D0}%d\n{FFFFFF}Owner: {2F70D0}%s\n{FFFFFF}Status: {2F70D0}%s", id,HouseInfo[id][Owner],HL(id));
  412. HouseInfo[id][Label] = CreateDynamic3DTextLabel(string, COLOR_WHITE, HouseInfo[id][ExitX], HouseInfo[id][ExitY], HouseInfo[id][ExitZ], 15);
  413. return 1;
  414. }
  415. else
  416. {
  417. new string[128];
  418. HouseInfo[id][Locked] = 0;
  419. // Textdraw
  420. format(txdstring, sizeof(txdstring), "Unlocked");
  421. PlayerTextDrawSetString(playerid, boxtext[playerid], txdstring);
  422. PlayerTextDrawShow(playerid, Box[playerid]);
  423. PlayerTextDrawShow(playerid, boxtext[playerid]);
  424. SetTimerEx("HideTextdraws", 4000, false, "i", playerid);
  425. // Pickup
  426. DestroyDynamic3DTextLabel(HouseInfo[id][Label]);
  427. format(string, sizeof(string), "House {2F70D0}%d\n{FFFFFF}Owner: {2F70D0}%s\n{FFFFFF}Status: {2F70D0}%s", id,HouseInfo[id][Owner],HL(id));
  428. HouseInfo[id][Label] = CreateDynamic3DTextLabel(string, COLOR_WHITE, HouseInfo[id][ExitX], HouseInfo[id][ExitY], HouseInfo[id][ExitZ], 15);
  429. return 1;
  430. }
  431. }
  432. return 1;
  433. }
  434. CMD:buy(playerid, params[])
  435. {
  436. new string[256],buy;
  437. if(PlayerInfo[playerid][HouseKey]) return SendClientMessage(playerid, COLOR_WHITE, "{2F70D0}[ERROR]:{FFFFFF}You already own a House.");
  438. for(new idx=1; idx < MAX_HOUSES; idx++)
  439. {
  440. if(IsPlayerInRangeOfPoint(playerid, 3.0, HouseInfo[idx][ExitX], HouseInfo[idx][ExitY], HouseInfo[idx][ExitZ]))
  441. {
  442. if(!HouseInfo[idx][Owned])
  443. {
  444. if(GetPlayerMoney(playerid) < HouseInfo[idx][Price]) return SendClientMessage(playerid, COLOR_WHITE, "{2F70D0}[ERROR]:{FFFFFF} You cannot afford to purchase this house.");
  445. GivePlayerMoney(playerid, -HouseInfo[idx][Price]);
  446. PlayerInfo[playerid][HouseKey] = 1;
  447. PlayerInfo[playerid][HouseID] = idx;
  448. HouseInfo[idx][Owned] = 1;
  449. format(HouseInfo[idx][Owner], 32, "%s", GetName(playerid));
  450. SendClientMessage(playerid, COLOR_GREEN, "{2F70D0}[INFO]:{FFFFFF} Welcome to your new Home.For more Information,use /househelp.");
  451. // Textdraw
  452. PlayerTextDrawSetString(playerid, Statement[playerid], "You have successfully ~g~purchased~w~ a house");
  453. PlayerTextDrawShow(playerid, Statement[playerid]);
  454. SetTimerEx("HideTextdraws", 4000, false, "i", playerid);
  455. // Pickup
  456. DestroyDynamic3DTextLabel(HouseInfo[idx][Label]);
  457. HouseInfo[idx][PickupID] = 0;
  458. format(string, sizeof(string), "House {2F70D0}%d\n{FFFFFF}Owner: {2F70D0}%s\n{FFFFFF}Status: {2F70D0}%s", idx,HouseInfo[idx][Owner],HL(idx));
  459. HouseInfo[idx][Label] = CreateDynamic3DTextLabel(string, COLOR_WHITE, HouseInfo[idx][ExitX], HouseInfo[idx][ExitY], HouseInfo[idx][ExitZ], 15);
  460. HouseInfo[idx][PickupID] = CreateDynamicPickup(1273, 23, HouseInfo[idx][ExitX], HouseInfo[idx][ExitY], HouseInfo[idx][ExitZ], 0, 0, -1, 40.0);
  461. idx = MAX_HOUSES;
  462. // Saving
  463. SaveHouses();
  464. buy = 1;
  465. }
  466. if(idx == MAX_HOUSES-1 && !buy)
  467. {
  468. SendClientMessage(playerid, COLOR_WHITE, "{2F70D0}[ERROR]:{FFFFFF} This house is owned by someone else.");
  469. }
  470. }
  471. if(idx == MAX_HOUSES-1 && !buy)
  472. {
  473. SendClientMessage(playerid, COLOR_WHITE, "{2F70D0}[ERROR]:{FFFFFF} You are not near a House you can buy.");
  474. return 1;
  475. }
  476. }
  477. return 1;
  478. }
  479. CMD:sell(playerid, params[])
  480. {
  481. new string[128],txdstring[128];
  482. if(!PlayerInfo[playerid][HouseKey]) return SendClientMessage(playerid, COLOR_WHITE, "{2F70D0}[ERROR]:{FFFFFF}You do not own a House that you can sell.");
  483. {
  484. new id = PlayerInfo[playerid][HouseID];
  485. if(!IsPlayerInRangeOfPoint(playerid, 3, HouseInfo[PlayerInfo[playerid][HouseID]][ExitX], HouseInfo[PlayerInfo[playerid][HouseID]][ExitY], HouseInfo[PlayerInfo[playerid][HouseID]][ExitZ])) return SendClientMessage(playerid, COLOR_WHITE, "{2F70D0}[ERROR]:{FFFFFF}You are not near your House.");
  486. new string2[128];
  487. new price = HouseInfo[id][Price];
  488. new percent = SELLPERCENT*price/100;
  489. GivePlayerMoney(playerid, percent);
  490. // Textdraw
  491. format(txdstring, sizeof(txdstring), "You have successfully ~g~sold~w~ your house for $%d.",percent);
  492. PlayerTextDrawSetString(playerid, Statement[playerid], txdstring);
  493. PlayerTextDrawShow(playerid, Statement[playerid]);
  494. SetTimerEx("HideTextdraws", 4000, false, "i", playerid);
  495. // Setting the Information
  496. HouseInfo[id][Owned] = 0;
  497. HouseInfo[id][Locked] = 0;
  498. format(HouseInfo[PlayerInfo[playerid][HouseID]][Owner], 32, "Government");
  499. format(string, sizeof(string), "{2F70D0}[INFO]: {FFFFFF}You have sold your House for $%d.", percent);
  500. SendClientMessage(playerid, COLOR_WHITE, string);
  501. DestroyDynamic3DTextLabel(HouseInfo[id][Label]);
  502.  
  503. format(string2, sizeof(string2), "House {2F70D0}%d\n{FFFFFF}Status: {2F70D0}For sale\n{FFFFFF}Price: {2F70D0}%d", id,HouseInfo[id][Price]);
  504. HouseInfo[id][Label] = CreateDynamic3DTextLabel(string2, COLOR_WHITE, HouseInfo[id][ExitX], HouseInfo[id][ExitY], HouseInfo[id][ExitZ], 15);
  505.  
  506. PlayerInfo[playerid][HouseKey] = 0;
  507. PlayerInfo[playerid][HouseID] = 0;
  508. }
  509. return 1;
  510. }
  511. CMD:putmoney(playerid, params[])
  512. {
  513. new txdstring[128];
  514. new amount;
  515. new i = PlayerInfo[playerid][HouseID];
  516. if(!PlayerInfo[playerid][HouseKey]) return SendClientMessage(playerid, COLOR_WHITE, "{2F70D0}[ERROR]:{FFFFFF}You do not own a House.");
  517. {
  518. if(sscanf(params, "i", amount)) return SendClientMessage(playerid, COLOR_WHITE, "{2F70D0}[SYNTAX]:{FFFFFF} /putmoney [amount]");
  519. if(GetPlayerMoney(playerid) < amount) return SendClientMessage(playerid, COLOR_WHITE, "{2F70D0}[ERROR]:{FFFFFF} You don't have that much money on you right now.");
  520. // Adding the money to the House's Vault.
  521. HouseInfo[i][Money] += amount;
  522. // Deducting the Money from the Player
  523. GivePlayerMoney(playerid, -amount);
  524. // Textdraw
  525. format(txdstring, sizeof(txdstring), "You have ~g~deposited~w~ $%d in your house's vault",amount);
  526. PlayerTextDrawSetString(playerid, Statement[playerid], txdstring);
  527. PlayerTextDrawShow(playerid, Statement[playerid]);
  528. SetTimerEx("HideTextdraws", 4000, false, "i", playerid);
  529. }
  530. return 1;
  531. }
  532. CMD:takemoney(playerid, params[])
  533. {
  534. new txdstring[128];
  535. new amount;
  536. new i = PlayerInfo[playerid][HouseID];
  537. if(!PlayerInfo[playerid][HouseKey]) return SendClientMessage(playerid, COLOR_WHITE, "{2F70D0}[ERROR]:{FFFFFF}You do not own a House.");
  538. {
  539. if(sscanf(params, "i", amount)) return SendClientMessage(playerid, COLOR_WHITE, "{2F70D0}[SYNTAX]:{FFFFFF} /takemoney [amount]");
  540. if(HouseInfo[i][Money] < amount) return SendClientMessage(playerid, COLOR_WHITE, "{2F70D0}[ERROR]:{FFFFFF} You don't have that much money in your House's Vault right now.");
  541. // Adding the money to the House's Vault.
  542. HouseInfo[i][Money] -= amount;
  543. // Deducting the Money from the Player
  544. GivePlayerMoney(playerid, amount);
  545. // Textdraw
  546. format(txdstring, sizeof(txdstring), "You have ~g~taken~w~ $%d from your house's vault",amount);
  547. PlayerTextDrawSetString(playerid, Statement[playerid], txdstring);
  548. PlayerTextDrawShow(playerid, Statement[playerid]);
  549. SetTimerEx("HideTextdraws", 4000, false, "i", playerid);
  550. }
  551. return 1;
  552. }
  553. CMD:sethmoney(playerid, params[])
  554. {
  555. new amount,houseid;
  556. new txdstring[128];
  557. if(sscanf(params, "ii", houseid,amount)) return SendClientMessage(playerid, COLOR_WHITE, "{2F70D0}[SYNTAX]:{FFFFFF} /sethmoney [houseid] [amount]");
  558. HouseInfo[houseid][Money] = amount;
  559. // Textdraw
  560. format(txdstring, sizeof(txdstring), "You have set ~g~House(%d)'s money~w~ to $%d.",houseid,amount);
  561. PlayerTextDrawSetString(playerid, Statement[playerid], txdstring);
  562. PlayerTextDrawShow(playerid, Statement[playerid]);
  563. SetTimerEx("HideTextdraws", 4000, false, "i", playerid);
  564. return 1;
  565. }
  566. // VERSION 2
  567. CMD:knock(playerid, params[])
  568. {
  569. for(new i=1; i < (MAX_HOUSES); i++) if(IsPlayerInRangeOfPoint(playerid, 3.0, HouseInfo[i][ExitX], HouseInfo[i][ExitY], HouseInfo[i][ExitZ]))
  570. {
  571. for(new id = 0; id < MAX_PLAYERS; id++)
  572. {
  573. if(IsPlayerInRangeOfPoint(id, 8.0, HouseInfo[i][EnterX], HouseInfo[i][EnterY], HouseInfo[i][EnterZ]))
  574. {
  575. SendClientMessage(id, COLOR_WHITE, "(INFO): {FFFFFF}Someone has knocked the Door.");
  576. }
  577. }
  578. PlayerTextDrawSetString(playerid, Statement[playerid], "You have ~g~knocked~w~ the house door");
  579. PlayerTextDrawShow(playerid, Statement[playerid]);
  580. SetTimerEx("HideTextdraws", 4000, false, "i", playerid);
  581. }
  582. return 1;
  583. }
  584. CMD:shout(playerid, params[])
  585. {
  586. new string[1300];
  587. new msg[128];
  588. if(sscanf(params, "s[128]", msg)) return SendClientMessage(playerid, COLOR_WHITE, "(INFO): /shout [text]");
  589. for(new i=1; i < (MAX_HOUSES); i++)
  590. {
  591. if(IsPlayerInRangeOfPoint(playerid, 3.0, HouseInfo[i][ExitX], HouseInfo[i][ExitY], HouseInfo[i][ExitZ]))
  592. for(new id = 0; id < MAX_PLAYERS; id++)
  593. {
  594. if(IsPlayerInRangeOfPoint(id, 8.0, HouseInfo[i][EnterX], HouseInfo[i][EnterY], HouseInfo[i][EnterZ]))
  595. {
  596. format(string, sizeof(string), "~g~(Outside)~w~: %s", msg);
  597. PlayerTextDrawSetString(id, Statement[playerid], string);
  598. PlayerTextDrawShow(id, Statement[playerid]);
  599. SetTimerEx("HideTextdraws", 4000, false, "i", id);
  600. }
  601. }
  602. if(IsPlayerInRangeOfPoint(playerid, 3.0, HouseInfo[i][EnterX], HouseInfo[i][EnterY], HouseInfo[i][EnterZ]))
  603. for(new p = 0; p < MAX_PLAYERS; p++)
  604. {
  605. if(IsPlayerInRangeOfPoint(p, 8.0, HouseInfo[i][ExitX], HouseInfo[i][ExitY], HouseInfo[i][ExitZ]))
  606. {
  607. format(string, sizeof(string), "~g~(Inside)~w~: %s", msg);
  608. PlayerTextDrawSetString(p, Statement[playerid], string);
  609. PlayerTextDrawShow(p, Statement[playerid]);
  610. SetTimerEx("HideTextdraws", 4000, false, "i",p);
  611. }
  612. }
  613. }
  614. return 1;
  615. }
  616. CMD:house(playerid, params[])
  617. {
  618. SetPlayerPos(playerid, 10.0, 10.0, 10.0);
  619. return 1;
  620. }
  621. //
  622. // Extra
  623. CMD:saveme(playerid, params[])
  624. {
  625. SaveUser(playerid);
  626. SaveHouses();
  627. return 1;
  628. }
  629. CMD:loadme(playerid, params[])
  630. {
  631. new File[35];
  632. format(File, 35, USER_PATH, GetName(playerid));
  633. {
  634. INI_ParseFile(File, "LoadUser", .bExtra = true, .extra = playerid);
  635. }
  636. CreateTextdraws(playerid);
  637. return 1;
  638. }
  639. // ====================================[END OF COMMANDS]=================================
  640. forward HideTextdraws(playerid);
  641. public HideTextdraws(playerid)
  642. {
  643. PlayerTextDrawHide(playerid, Statement[playerid]);
  644. PlayerTextDrawHide(playerid, Box[playerid]);
  645. PlayerTextDrawHide(playerid, boxtext[playerid]);
  646. return 1;
  647. }
  648. public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
  649. {
  650. if (PRESSED( KEY_SECONDARY_ATTACK ))
  651. {
  652. for(new i = 1; i < sizeof(HouseInfo); i++)
  653. {
  654. if(IsPlayerInRangeOfPoint(playerid,4.0,HouseInfo[i][ExitX],HouseInfo[i][ExitY],HouseInfo[i][ExitZ]))
  655. {
  656. if(HouseInfo[i][Locked] == 1) return Showlock(playerid);
  657. if(HouseInfo[i][EnterX] == 0) return SendClientMessage(playerid, COLOR_WHITE, "[WARNING] This house has no Interior set up yet.");
  658. SetPlayerPos(playerid, HouseInfo[i][EnterX],HouseInfo[i][EnterY],HouseInfo[i][EnterZ]);
  659. SetPlayerInterior(playerid, HouseInfo[i][EnterInt]);
  660. SetPlayerVirtualWorld(playerid, HouseInfo[i][EnterVW]);
  661. }
  662. else if(IsPlayerInRangeOfPoint(playerid,4.0,HouseInfo[i][EnterX],HouseInfo[i][EnterY],HouseInfo[i][EnterZ]))
  663. {
  664. SetPlayerPos(playerid, HouseInfo[i][ExitX],HouseInfo[i][ExitY],HouseInfo[i][ExitZ]);
  665. SetPlayerInterior(playerid, HouseInfo[i][ExitInt]);
  666. SetPlayerVirtualWorld(playerid, HouseInfo[i][ExitVW]);
  667. }
  668. }
  669. }
  670. return 1;
  671. }
  672.  
  673. public OnPlayerConnect(playerid)
  674. {
  675. new File[35];
  676. format(File, 35, USER_PATH, GetName(playerid));
  677. {
  678. INI_ParseFile(File, "LoadUser", .bExtra = true, .extra = playerid);
  679. }
  680. CreateTextdraws(playerid);
  681. return 1;
  682. }
  683. public OnPlayerDisconnect(playerid, reason)
  684. {
  685. SaveUser(playerid);
  686. return 1;
  687. }
  688.  
  689. public OnPlayerSpawn(playerid)
  690. {
  691. return 1;
  692. }
  693.  
  694. public OnPlayerText(playerid, text[])
  695. {
  696. return 1;
  697. }
  698. public OnPlayerEnterVehicle(playerid, vehicleid, ispassenger)
  699. {
  700. return 1;
  701. }
  702.  
  703. public OnPlayerExitVehicle(playerid, vehicleid)
  704. {
  705. return 1;
  706. }
  707.  
  708. public OnPlayerStateChange(playerid, newstate, oldstate)
  709. {
  710. return 1;
  711. }
  712.  
  713. public OnRconCommand(cmd[])
  714. {
  715. return 1;
  716. }
  717.  
  718. public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
  719. {
  720. return 1;
  721. }
  722.  
  723. public OnPlayerClickPlayer(playerid, clickedplayerid, source)
  724. {
  725. return 1;
  726. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement