Advertisement
Guest User

sass839

a guest
Feb 16th, 2010
172
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 24.71 KB | None | 0 0
  1. /*
  2. -------------------------------------------
  3. | _____ _ __ |
  4. | / ____| | / _| |
  5. | | (___ | |_ ___| |_ __ _ _ __ |
  6. | \___ \| __/ _ \ _/ _` | '_ \ |
  7. | ____) | || __/ || (_| | | | | |
  8. | |_____/ \__\___|_| \__,_|_| |_| |
  9. | |
  10. | ** House System v1.0 ** |
  11. | |
  12. -------------------------------------------
  13. .:: Do not remove Credits ::.
  14. */
  15.  
  16. #include <a_samp>
  17. #include <Dini>
  18. #include <dudb>
  19. #include <utils>
  20.  
  21. new FALSE = false;
  22. #define dcmd(%1,%2,%3) if ((strcmp((%3)[1], #%1, true, (%2)) == 0) && ((((%3)[(%2) + 1] == 0) && (dcmd_%1(playerid, "")))||(((%3)[(%2) + 1] == 32) && (dcmd_%1(playerid, (%3)[(%2) + 2]))))) return 1
  23. #define SendFormattedMessage(%0,%1,%2) do{new _str[128]; format(_str,128,%2); SendClientMessage(%0,%1,_str);}while(FALSE)
  24.  
  25. #define COLOR_WHITE 0xFFFFFFAA
  26. #define COLOR_LIME 0x80FF00AA
  27.  
  28. #define MAX_HOUSES 100 // Max houses allowed to be created
  29. #define PTP_RADIUS 2.0 // Radius of PlayerToPoint Function
  30.  
  31. forward SavePlayerHouse(houseid);
  32. forward ReadPlayerHouseData(playerid);
  33. forward PlayerToPoint(Float:radi, playerid, Float:x, Float:y, Float:z);
  34.  
  35. new Timer[1];
  36.  
  37. enum hInfo
  38. {
  39. hName[24],
  40. hSellable,
  41. hSell,
  42. hRent,
  43. hLevel,
  44. hPickup,
  45. Float:hExitX,
  46. Float:hExitY,
  47. Float:hExitZ,
  48. hVirtualWorld,
  49. hLocked
  50. };
  51. new HouseInfo[MAX_HOUSES][hInfo];
  52.  
  53. new Float:HousesCoords[13][3] = {
  54. {222.9534, 1287.7649, 1082.1406}, // Sml - 1 bedroom
  55. {261.0827, 1284.6899, 1080.2578}, // Sml - 1 bedroom
  56. {260.6734, 1237.7909, 1084.2578}, // Sml - 1 bedroom
  57. {376.7426, 1417.3226, 1081.3281}, // Sml - 1 bedroom
  58. {295.2874, 1473.2769, 1080.2578}, // Med - 2 bedroom
  59. {327.9431, 1478.3801, 1084.4375}, // Med - 2 bedroom
  60. {2270.1050, -1210.3917, 1047.5625}, // Med - 2 bedroom
  61. {447.1211, 1397.8444, 1084.3047}, // Med - 2 bedroom
  62. {2196.0063, -1204.6326, 1049.0234}, // Lrg - 3 bedroom
  63. {235.3416, 1187.2882, 1080.2578}, // Lrg - 3 bedroom
  64. {490.9987, 1399.4164, 1080.2578}, // Lrg - 3 bedroom
  65. {227.1212, 1114.1840, 1080.9972}, // Lrg - 4 bedroom
  66. {225.6624, 1022.5345, 1084.0145} // Xlrg - 4 bedrooms
  67. };
  68.  
  69. new HousesLevels[13][2] = {
  70. {1, 2000}, // Sml - 1 bedroom
  71. {4, 4500}, // Sml - 1 bedroom
  72. {9, 7000}, // Sml - 1 bedroom
  73. {15, 10000}, // Sml - 1 bedroom
  74. {15, 17000}, // Med - 2 bedroom
  75. {15, 23000}, // Med - 2 bedroom
  76. {10, 34000}, // Med - 2 bedroom
  77. {2, 62000}, // Med - 2 bedroom
  78. {6, 102000}, // Lrg - 3 bedroom
  79. {3, 156000}, // Lrg - 3 bedroom
  80. {2, 188000}, // Lrg - 3 bedroom
  81. {5, 235000}, // Lrg - 4 bedroom
  82. {7, 295000} // Xlrg - 4 bedrooms
  83. };
  84.  
  85. public OnFilterScriptInit()
  86. {
  87. print("\n--------------------------------------");
  88. print("Stefan's House System");
  89. print("--------------------------------------\n");
  90.  
  91. for(new i = 0; i <= MAX_PLAYERS; i++)
  92. {
  93. Timer[0] = SetTimerEx("ReadPlayerHouseData", 1000, true, "%i", i);
  94. }
  95. for(new h = 0; h <= MAX_HOUSES; h++) // Player Homes
  96. {
  97. LoadPlayerHouse(h);
  98. }
  99. return true;
  100. }
  101.  
  102. public OnFilterScriptExit()
  103. {
  104. KillTimer(Timer[0]);
  105. }
  106.  
  107. public OnPlayerCommandText(playerid, cmdtext[])
  108. {
  109. dcmd(househelp,9,cmdtext);
  110. dcmd(houseinfo,9,cmdtext);
  111. dcmd(enter,5,cmdtext);
  112. dcmd(exit,4,cmdtext);
  113. /*dcmd(evict,5,cmdtext);
  114. dcmd(renthouse,9,cmdtext);
  115. dcmd(unrenthouse,11,cmdtext);
  116. dcmd(tenants,7,cmdtext);*/
  117. dcmd(house,5,cmdtext);
  118. dcmd(lockhouse,9,cmdtext);
  119. dcmd(unlockhouse,11,cmdtext);
  120. dcmd(rentprice,9,cmdtext);
  121. dcmd(buyhouse,8,cmdtext);
  122. dcmd(sellhouse,9,cmdtext);
  123. dcmd(unsellhouse,11,cmdtext);
  124. dcmd(createhouse,11,cmdtext);
  125. dcmd(destroyhouse,12,cmdtext);
  126.  
  127. return false;
  128. }
  129.  
  130. ///////////////////////////////////////
  131. // Buisness + Homes Functions
  132. //////////////////////////////////////
  133.  
  134. stock CreatePlayerHouse(playerid, sellprice, HouseLvl)
  135. {
  136. if((ReturnNextUnusedHouseID()-1) >= MAX_HOUSES) return SendClientMessage(playerid, COLOR_WHITE, ".:: [HOUSE]: Maximum amount of houses on the server have been created.");
  137. new house[64], Float:X, Float:Y, Float:Z; GetPlayerPos(playerid, X, Y, Z);
  138. new NextHouseID = ReturnNextUnusedHouseID();
  139. new World = ReturnNextUnusedVirtualWorld();
  140.  
  141. format(house, sizeof(house), "/Houses/%d.dini.save", NextHouseID);
  142.  
  143. if(!dini_Exists(house)){
  144. dini_Create(house);
  145. dini_Set(house, "Name", "None");
  146. dini_IntSet(house, "For_Sell", 1);
  147. dini_IntSet(house, "Sell_Price", sellprice);
  148. dini_IntSet(house, "Rent_Price", 1000);
  149. dini_IntSet(house, "House_Level", HouseLvl);
  150. dini_FloatSet(house,"Exit_Coord:X", X);
  151. dini_FloatSet(house,"Exit_Coord:Y", Y);
  152. dini_FloatSet(house,"Exit_Coord:Z", Z);
  153. dini_IntSet(house, "VirtualWorld", World);
  154. dini_IntSet(house, "Status", 0);
  155. LoadPlayerHouse(NextHouseID);
  156. SendClientMessage(playerid, COLOR_WHITE, ".:: [HOUSE]: House has been Successfully created.");
  157. }
  158. return true;
  159. }
  160.  
  161. stock LoadPlayerHouse(houseid)
  162. {
  163. new house[64]; format(house, sizeof(house), "/Houses/%d.dini.save", houseid);
  164. if(dini_Exists(house)){
  165. format(HouseInfo[houseid][hName], MAX_PLAYER_NAME, "%s", dini_Get(house, "Name"));
  166. HouseInfo[houseid][hSellable] = dini_Int(house, "For_Sell");
  167. HouseInfo[houseid][hSell] = dini_Int(house, "Sell_Price");
  168. HouseInfo[houseid][hRent] = dini_Int(house, "Rent_Price");
  169. HouseInfo[houseid][hLevel] = dini_Int(house, "House_Level");
  170. HouseInfo[houseid][hExitX] = dini_Float(house, "Exit_Coord:X");
  171. HouseInfo[houseid][hExitY] = dini_Float(house, "Exit_Coord:Y");
  172. HouseInfo[houseid][hExitZ] = dini_Float(house, "Exit_Coord:Z");
  173. HouseInfo[houseid][hVirtualWorld] = dini_Int(house, "VirtualWorld");
  174. HouseInfo[houseid][hLocked] = dini_Int(house, "Status");
  175.  
  176. if(HouseInfo[houseid][hSellable] == 1){
  177. HouseInfo[houseid][hPickup] = CreatePickup(1273, 23, HouseInfo[houseid][hExitX], HouseInfo[houseid][hExitY], HouseInfo[houseid][hExitZ]); // not bought
  178. } else {
  179. HouseInfo[houseid][hPickup] = CreatePickup(1272,23, HouseInfo[houseid][hExitX], HouseInfo[houseid][hExitY], HouseInfo[houseid][hExitZ]); // bought
  180. }
  181. }
  182. return true;
  183. }
  184.  
  185. public SavePlayerHouse(houseid)
  186. {
  187. new house[64]; format(house, sizeof(house), "/Houses/%d.dini.save", houseid);
  188. if(dini_Exists(house)){
  189. dini_Set(house, "Name", HouseInfo[houseid][hName]);
  190. dini_IntSet(house, "For_Sell", HouseInfo[houseid][hSellable]);
  191. dini_IntSet(house, "Sell_Price", HouseInfo[houseid][hSell]);
  192. dini_IntSet(house, "Rent_Price", HouseInfo[houseid][hRent]);
  193. dini_IntSet(house, "House_Level", HouseInfo[houseid][hLevel]);
  194. dini_FloatSet(house, "Exit_Coord:X", HouseInfo[houseid][hExitX]);
  195. dini_FloatSet(house, "Exit_Coord:Y", HouseInfo[houseid][hExitY]);
  196. dini_FloatSet(house, "Exit_Coord:Z", HouseInfo[houseid][hExitZ]);
  197. dini_IntSet(house, "VirtualWorld", HouseInfo[houseid][hVirtualWorld]);
  198. dini_IntSet(house, "Status", HouseInfo[houseid][hLocked]);
  199. }
  200. return true;
  201. }
  202.  
  203. stock ReturnNextUnusedHouseID()
  204. {
  205. new house[64];
  206. for(new h = 0; h <= MAX_HOUSES; h++){
  207. format(house, sizeof(house), "/Houses/%d.dini.save", h);
  208. if(!dini_Exists(house)) return h; }
  209. return true;
  210. }
  211.  
  212. stock ReturnNextUnusedVirtualWorld()
  213. {
  214. new house[64]; // Please do not make more then 255 houses because that is the Maximum Virtual Worlds. Or use as many as you want in 0.3
  215. format(house, sizeof(house), "/Houses/%d.dini.save", ReturnNextUnusedHouseID()-1);
  216. return dini_Int(house, "VirtualWorld")+1;
  217. }
  218.  
  219. public ReadPlayerHouseData(playerid)
  220. {
  221. new string[256], house[64];
  222. for(new h = 0; h <= MAX_HOUSES; h++){
  223. format(house, sizeof(house), "/Houses/%d.dini.save", h);
  224. if(dini_Exists(house)){
  225. if(HouseInfo[h][hSellable] == 1){
  226. if(PlayerToPoint(PTP_RADIUS, playerid, HouseInfo[h][hExitX], HouseInfo[h][hExitY], HouseInfo[h][hExitZ])) {
  227. format(string, sizeof(string), "~g~] House for Sale ]~n~~w~Owner:~y~ %s~n~~w~Level:~r~ %d~n~~w~Sell Price:~r~ %d~n~~w~Rent Cost:~r~ %d", HouseInfo[h][hName], HouseInfo[h][hLevel], HouseInfo[h][hSell], HouseInfo[h][hRent]);
  228. GameTextForPlayer(playerid,string, 1500, 3);
  229. }
  230. } else if(HouseInfo[h][hSellable] == 0){
  231. if(PlayerToPoint(PTP_RADIUS, playerid, HouseInfo[h][hExitX], HouseInfo[h][hExitY], HouseInfo[h][hExitZ])) {
  232. format(string, sizeof(string), "~w~Owner:~y~ %s~n~~w~Level:~r~ %d~n~~w~Rent Cost:~r~ %d", HouseInfo[h][hName], HouseInfo[h][hLevel], HouseInfo[h][hRent]);
  233. GameTextForPlayer(playerid,string, 1500, 3);
  234. } } } }
  235. }
  236.  
  237. stock DestroyPlayerHouse(playerid, houseid)
  238. {
  239. new house[64];
  240. format(house, sizeof(house), "/Houses/%d.dini.save", houseid);
  241. if(dini_Exists(house)){
  242. dini_Remove(house);
  243. DestroyPickup(HouseInfo[houseid][hPickup]);
  244. SendClientMessage(playerid, COLOR_WHITE, ".:: [HOUSE]: The given house has been destroyed.");
  245. } else return SendClientMessage(playerid, COLOR_WHITE, ".:: [ERROR]: The given house id does not exsist so it cannot be destroyed.");
  246. return false;
  247. }
  248.  
  249. ///////////////////////////
  250. // Dcmd Commands
  251. //////////////////////////
  252.  
  253. dcmd_househelp(playerid,params[]) {
  254. #pragma unused params
  255. if(IsPlayerConnected(playerid)){
  256. SendClientMessage(playerid, COLOR_WHITE,"[HOUSE OWNER]: /(un)sellhouse, /(un)lockhouse, /rentprice, /tenants, /evict, /house (upgrade/downgrade)");
  257. SendClientMessage(playerid, COLOR_WHITE,"[HOUSE PLAYERS]: /houseinfo, /buyhouse, /(un)renthouse, /enter, /exit");
  258. }
  259. return true;
  260. }
  261.  
  262. dcmd_houseinfo(playerid,params[]) {
  263. #pragma unused params
  264. if(IsPlayerConnected(playerid)){
  265. for(new h = 0; h <= MAX_HOUSES; h++){
  266. if(PlayerToPoint(PTP_RADIUS, playerid, HouseInfo[h][hExitX], HouseInfo[h][hExitY], HouseInfo[h][hExitZ])){
  267. new IsLocked[24];
  268. if(HouseInfo[h][hLocked] == 1) { IsLocked = "True"; } else { IsLocked = "False"; }
  269. SendClientMessage(playerid, COLOR_LIME,"HOUSE STATS ----------------------------------------------------------");
  270. SendFormattedMessage(playerid, COLOR_WHITE, "Owner: %s - Level[%d] - RentCost[$%d] - SellPrice[$%d]", HouseInfo[h][hName], HouseInfo[h][hLevel], HouseInfo[h][hRent], HouseInfo[h][hSell]);
  271. SendFormattedMessage(playerid, COLOR_WHITE, "IsLocked[%s] - HouseID[%d] - ExitCoords[X:%.4f, Y:%.4f, Z:%.4f]", IsLocked, h, HouseInfo[h][hExitX], HouseInfo[h][hExitY], HouseInfo[h][hExitZ]);
  272. SendClientMessage(playerid, COLOR_LIME,"----------------------------------------------------------");
  273. } } }
  274. return true;
  275. }
  276.  
  277. dcmd_enter(playerid,params[]) {
  278. #pragma unused params
  279. if(IsPlayerConnected(playerid)){
  280. for(new h = 0; h <= MAX_HOUSES; h++){
  281. if(PlayerToPoint(PTP_RADIUS, playerid, HouseInfo[h][hExitX], HouseInfo[h][hExitY], HouseInfo[h][hExitZ])){
  282. new Level = HouseInfo[h][hLevel];
  283. if(HouseInfo[h][hLocked] == 1 && strcmp(HouseInfo[h][hName],GetName(playerid), false ) != 0) return SendClientMessage(playerid, COLOR_WHITE, ".:: [HOUSE]: This house has been locked by the owner.");
  284. SetPlayerPos(playerid, HousesCoords[Level][0], HousesCoords[Level][1], HousesCoords[Level][2]);
  285. SetPlayerInterior(playerid, HousesLevels[Level][0]); SetPlayerVirtualWorld(playerid, HouseInfo[h][hVirtualWorld]);
  286. } } }
  287. return true;
  288. }
  289.  
  290. dcmd_exit(playerid,params[]) {
  291. #pragma unused params
  292. if(IsPlayerConnected(playerid)){
  293. for(new h = 0; h <= MAX_HOUSES; h++){
  294. if(PlayerToPoint(PTP_RADIUS, playerid, HousesCoords[HouseInfo[h][hLevel]][0], HousesCoords[HouseInfo[h][hLevel]][1], HousesCoords[HouseInfo[h][hLevel]][2])){
  295. SetPlayerPos(playerid, HouseInfo[h][hExitX], HouseInfo[h][hExitY], HouseInfo[h][hExitZ]);
  296. SetPlayerInterior(playerid, 0); SetPlayerVirtualWorld(playerid, 0);
  297. } } }
  298. }
  299.  
  300. /*dcmd_evict(playerid,params[]) { // This needs to be intergrated with your players .ini account
  301. #pragma unused params
  302. if(IsPlayerConnected(playerid)){
  303. new giveplayerid;
  304. if(sscanf(params, "i", giveplayerid)) return SendClientMessage(playerid, COLOR_WHITE, "[USAGE]: /evict [id]");
  305. if(!IsPlayerConnected(giveplayerid)) return SendClientMessage(playerid, COLOR_WHITE, "The given player does not exist");
  306.  
  307. for(new h = 0; h <= MAX_HOUSES; h++){
  308. if(PlayerToPoint(PTP_RADIUS, playerid, HouseInfo[h][hExitX], HouseInfo[h][hExitY], HouseInfo[h][hExitZ])){
  309. if(strcmp(HouseInfo[h][hName],GetName(playerid), false ) == 0){
  310. if(PlayerInfo[giveplayerid][pHouse] != h) return SendClientMessage(playerid, COLOR_WHITE, ".:: [ERROR]: This player is not renting your house.");
  311. PlayerInfo[giveplayerid][pHouse] = -1; PlayerUpdate(giveplayerid);
  312. SendFormattedMessage(playerid, COLOR_WHITE, ".:: [HOUSE]: You have evicted %s[%d] from your house.", GetName(giveplayerid), giveplayerid);
  313. } else return SendClientMessage(playerid, COLOR_WHITE, ".:: [HOUSE]: You are not the owner of this house.");
  314. } } }
  315. return true;
  316. }
  317.  
  318. dcmd_tenants(playerid,params[]) { // This needs to be intergrated with your players .ini account
  319. #pragma unused params
  320. if(IsPlayerConnected(playerid)){
  321. for(new i = 0; i <= MAX_PLAYERS; i++){
  322. for(new h = 0; h <= MAX_HOUSES; h++){
  323. if(PlayerToPoint(PTP_RADIUS, playerid, HouseInfo[h][hExitX], HouseInfo[h][hExitY], HouseInfo[h][hExitZ])){
  324. if(PlayerInfo[i][pHouse] == h){
  325. if(strcmp(HouseInfo[h][hName],GetName(playerid), false ) == 0){
  326. PlayerInfo[giveplayerid][pHouse] = -1;
  327. SendClientMessage(playerid, COLOR_LIME, "_---- Tenants ----");
  328. SendFormattedMessage(playerid, COLOR_WHITE, "%s[%d]", GetName(i), i);
  329. } else return SendClientMessage(playerid, COLOR_WHITE, ".:: [HOUSE]: You are not the owner of this house.");
  330. } } } } }
  331. return true;
  332. }
  333.  
  334. dcmd_renthouse(playerid,params[]) { // This needs to be intergrated with your players .ini account
  335. #pragma unused params
  336. if(IsPlayerConnected(playerid)){
  337. for(new h = 0; h <= MAX_HOUSES; h++){
  338. if(PlayerToPoint(PTP_RADIUS, playerid, HouseInfo[h][hExitX], HouseInfo[h][hExitY], HouseInfo[h][hExitZ])){
  339. if(HouseInfo[h][hName] == "Name") return SendClientMessage(playerid, COLOR_WHITE, ".:: [ERROR]: No one has bought this house so you cannot rent from here.");
  340. if(PlayerInfo[playerid][pHouse] != -1) return SendClientMessage(playerid, COLOR_WHITE, ".:: [ERROR]: You are allready renting a house. Use /unrenthouse to stop renting there.");
  341. PlayerInfo[playerid][pHouse] = h; PlayerUpdate(giveplayerid);
  342. SendFormattedMessage(playerid, COLOR_WHITE, ".:: [HOUSE]: You are now renting from %s.", HouseInfo[h][hName]);
  343. } } }
  344. return true;
  345. }
  346.  
  347. dcmd_unrenthouse(playerid,params[]) { // This needs to be intergrated with your players .ini account
  348. #pragma unused params
  349. if(IsPlayerConnected(playerid)){
  350. if(PlayerInfo[playerid][pHouse] == -1) return SendClientMessage(playerid, COLOR_WHITE, ".:: [ERROR]: You are not renting a house.");
  351. PlayerInfo[playerid][pHouse] = -1; PlayerUpdate(giveplayerid);
  352. SendFormattedMessage(playerid, COLOR_WHITE, ".:: [HOUSE]: You are not renting from %s anymore.", HouseInfo[h][hName]);
  353. }
  354. return true;
  355. }
  356. */
  357.  
  358. dcmd_buyhouse(playerid,params[]) {
  359. #pragma unused params
  360. if(IsPlayerConnected(playerid)){
  361. for(new h = 0; h <= MAX_HOUSES; h++){
  362. if(PlayerToPoint(PTP_RADIUS, playerid, HouseInfo[h][hExitX], HouseInfo[h][hExitY], HouseInfo[h][hExitZ])){
  363. if(strcmp(HouseInfo[h][hName],GetName(playerid), false ) != 0){
  364. if(HouseInfo[h][hSellable] == 1){
  365. if(GetPlayerMoney(playerid) < HouseInfo[h][hSell]) return SendClientMessage(playerid, COLOR_WHITE, ".:: [HOUSE]: You do not have anough money to buy this house.");
  366. DestroyPickup(HouseInfo[h][hPickup]);
  367. HouseInfo[h][hPickup] = CreatePickup(1272,23, HouseInfo[h][hExitX], HouseInfo[h][hExitY], HouseInfo[h][hExitZ]); // bought
  368. HouseInfo[h][hSellable] = 0; GivePlayerMoney(playerid, -HouseInfo[h][hSell]);
  369. format(HouseInfo[h][hName], 24, "%s", GetName(playerid)); SavePlayerHouse(h);
  370. } else return SendClientMessage(playerid, COLOR_WHITE, ".:: [HOUSE]: This house is not for sale.");
  371. } else return SendClientMessage(playerid, COLOR_WHITE, ".:: [HOUSE]: You are cannot buy the house you are selling.");
  372. } } }
  373. return true;
  374. }
  375.  
  376. dcmd_rentprice(playerid,params[]) {
  377. #pragma unused params
  378. if(IsPlayerConnected(playerid)){
  379. new Price;
  380. if(sscanf(params, "i", Price)) return SendClientMessage(playerid, COLOR_WHITE, "[USAGE]: /rentprice [rentprice]");
  381. if(Price < 0 || Price > 10000) return SendClientMessage(playerid, COLOR_WHITE, "You cannot set the rent price below 0 or above 10k");
  382. for(new h = 0; h <= MAX_HOUSES; h++){
  383. if(PlayerToPoint(PTP_RADIUS, playerid, HouseInfo[h][hExitX], HouseInfo[h][hExitY], HouseInfo[h][hExitZ])){
  384. if(strcmp(HouseInfo[h][hName],GetName(playerid), false ) == 0){
  385. HouseInfo[h][hRent] = Price; SavePlayerHouse(h);
  386. } else return SendClientMessage(playerid, COLOR_WHITE, ".:: [HOUSE]: You are not the owner of this house.");
  387. } } }
  388. return true;
  389. }
  390.  
  391. dcmd_house(playerid,params[]) {
  392. #pragma unused params
  393. if(IsPlayerConnected(playerid)){
  394. new tmp[64];
  395. if(sscanf(params, "s", tmp)) return SendClientMessage(playerid, COLOR_WHITE, "[USAGE]: /house (upgrade/downgrade)");
  396. SendFormattedMessage(playerid, COLOR_WHITE, "Houses: 0[%d], 1[%d], 2[%d], 3[%d], 4[%d], 5[%d], 6[%d]", HousesLevels[0][1], HousesLevels[1][1], HousesLevels[2][1], HousesLevels[3][1], HousesLevels[4][1], HousesLevels[5][1], HousesLevels[6][1]);
  397. SendFormattedMessage(playerid, COLOR_WHITE, "7[%d], 8[%d], 9[%d], 10[%d], 11[%d], 12[%d]", HousesLevels[7][1], HousesLevels[8][1], HousesLevels[9][1], HousesLevels[10][1], HousesLevels[11][1], HousesLevels[12][1]);
  398. if(strlen(tmp) == strlen("upgrade")){
  399. for(new h = 0; h <= MAX_HOUSES; h++){
  400. if(PlayerToPoint(PTP_RADIUS, playerid, HouseInfo[h][hExitX], HouseInfo[h][hExitY], HouseInfo[h][hExitZ])){
  401. if(strcmp(HouseInfo[h][hName],GetName(playerid), false ) == 0){
  402. if(HouseInfo[h][hLevel]+1 > 12) return SendClientMessage(playerid, COLOR_WHITE, "You cannot set your house lvl above 12");
  403. new Level = HousesLevels[HouseInfo[h][hLevel]+1][1];
  404. SendFormattedMessage(playerid, COLOR_WHITE, "You have added improvments to your house that costs $%d", Level);
  405. HouseInfo[h][hLevel] = (HouseInfo[h][hLevel]+1); GivePlayerMoney(playerid, -Level);
  406. SavePlayerHouse(h);
  407. } else return SendClientMessage(playerid, COLOR_WHITE, ".:: [HOUSE]: You are not the owner of this house."); } }
  408. }
  409. if(strlen(tmp) == strlen("downgrade")){
  410. for(new h = 0; h <= MAX_HOUSES; h++){
  411. if(PlayerToPoint(PTP_RADIUS, playerid, HouseInfo[h][hExitX], HouseInfo[h][hExitY], HouseInfo[h][hExitZ])){
  412. if(strcmp(HouseInfo[h][hName],GetName(playerid), false ) == 0){
  413. if(HouseInfo[h][hLevel]-1 < 0) return SendClientMessage(playerid, COLOR_WHITE, "You cannot set your house lvl below 0");
  414. new Level = HousesLevels[HouseInfo[h][hLevel]-1][1];
  415. SendFormattedMessage(playerid, COLOR_WHITE, "You have removed improvments done to your house and have been refunded $%d", Level);
  416. HouseInfo[h][hLevel] = (HouseInfo[h][hLevel]-1); GivePlayerMoney(playerid, Level);
  417. SavePlayerHouse(h);
  418. } else return SendClientMessage(playerid, COLOR_WHITE, ".:: [HOUSE]: You are not the owner of this house."); } }
  419. }
  420. }
  421. return true;
  422. }
  423.  
  424. dcmd_lockhouse(playerid,params[]) {
  425. #pragma unused params
  426. if(IsPlayerConnected(playerid)){
  427. for(new h = 0; h <= MAX_HOUSES; h++){
  428. if(PlayerToPoint(PTP_RADIUS, playerid, HouseInfo[h][hExitX], HouseInfo[h][hExitY], HouseInfo[h][hExitZ])){
  429. if(strcmp(HouseInfo[h][hName],GetName(playerid), false ) == 0){
  430. if(HouseInfo[h][hLocked] == 1) return SendClientMessage(playerid, COLOR_WHITE, ".:: [ERROR]: This house is allready locked.");
  431. HouseInfo[h][hLocked] = 1; SavePlayerHouse(h);
  432. SendClientMessage(playerid, COLOR_WHITE, ".:: [HOUSE]: You house has been locked.");
  433. } else return SendClientMessage(playerid, COLOR_WHITE, ".:: [HOUSE]: You are not the owner of this house.");
  434. } } }
  435. return true;
  436. }
  437.  
  438. dcmd_unlockhouse(playerid,params[]) {
  439. #pragma unused params
  440. if(IsPlayerConnected(playerid)){
  441. for(new h = 0; h <= MAX_HOUSES; h++){
  442. if(PlayerToPoint(PTP_RADIUS, playerid, HouseInfo[h][hExitX], HouseInfo[h][hExitY], HouseInfo[h][hExitZ])){
  443. if(strcmp(HouseInfo[h][hName],GetName(playerid), false ) == 0){
  444. if(HouseInfo[h][hLocked] == 0) return SendClientMessage(playerid, COLOR_WHITE, ".:: [ERROR]: This house is allready unlocked.");
  445. HouseInfo[h][hLocked] = 0; SavePlayerHouse(h);
  446. SendClientMessage(playerid, COLOR_WHITE, ".:: [HOUSE]: You house has been unlocked.");
  447. } else return SendClientMessage(playerid, COLOR_WHITE, ".:: [HOUSE]: You are not the owner of this house.");
  448. } } }
  449. return true;
  450. }
  451.  
  452. dcmd_sellhouse(playerid,params[]) {
  453. #pragma unused params
  454. if(IsPlayerConnected(playerid)){
  455. new Sell;
  456. if(sscanf(params, "i", Sell)) return SendClientMessage(playerid, COLOR_WHITE, "[USAGE]: /sellhouse [sellprice]");
  457. if(Sell < 0 || Sell > 5000000) return SendClientMessage(playerid, COLOR_WHITE, "You cannot set the sell price below 0 or above 5 Mill");
  458. for(new h = 0; h <= MAX_HOUSES; h++){
  459. if(PlayerToPoint(PTP_RADIUS, playerid, HouseInfo[h][hExitX], HouseInfo[h][hExitY], HouseInfo[h][hExitZ])){
  460. if(strcmp(HouseInfo[h][hName],GetName(playerid), false ) == 0){
  461. DestroyPickup(HouseInfo[h][hPickup]);
  462. HouseInfo[h][hPickup] = CreatePickup(1273, 23, HouseInfo[h][hExitX], HouseInfo[h][hExitY], HouseInfo[h][hExitZ]); // not bought
  463. HouseInfo[h][hSellable] = 1; HouseInfo[h][hSell] = Sell; SavePlayerHouse(h);
  464. } else return SendClientMessage(playerid, COLOR_WHITE, ".:: [HOUSE]: You are not the owner of this house.");
  465. } } }
  466. return true;
  467. }
  468.  
  469. dcmd_unsellhouse(playerid,params[]) {
  470. #pragma unused params
  471. if(IsPlayerConnected(playerid)){
  472. for(new h = 0; h <= MAX_HOUSES; h++){
  473. if(PlayerToPoint(PTP_RADIUS, playerid, HouseInfo[h][hExitX], HouseInfo[h][hExitY], HouseInfo[h][hExitZ])){
  474. if(strcmp(HouseInfo[h][hName],GetName(playerid), false ) == 0){
  475. DestroyPickup(HouseInfo[h][hPickup]);
  476. HouseInfo[h][hPickup] = CreatePickup(1272,23, HouseInfo[h][hExitX], HouseInfo[h][hExitY], HouseInfo[h][hExitZ]); // bought
  477. HouseInfo[h][hSellable] = 0; SavePlayerHouse(h);
  478. } else return SendClientMessage(playerid, COLOR_WHITE, ".:: [HOUSE]: You are not the owner of this house.");
  479. } } }
  480. return true;
  481. }
  482.  
  483. dcmd_createhouse(playerid,params[]) {
  484. #pragma unused params
  485. if(IsPlayerConnected(playerid)){
  486. //if(PlayerInfo[playerid][pAdmin] < 10) return SendClientMessage(playerid,COLOR_WHITE,"SERVER: Unknown command.");
  487. if(!IsPlayerAdmin(playerid)) return SendClientMessage(playerid, COLOR_WHITE, "Only admins allowed to use this command");
  488. new Sell, lvl;
  489. if(sscanf(params, "ii", Sell, lvl)) return SendClientMessage(playerid, COLOR_WHITE, "[USAGE]: /createhouse [sellprice] [HouseLvl]");
  490. if(Sell < 0 || Sell > 5000000) return SendClientMessage(playerid, COLOR_WHITE, "You cannot set the sell price below 0 or above 5 Mill");
  491. if(lvl < 0 || lvl > 12) return SendClientMessage(playerid, COLOR_WHITE, "You cannot create a house lvl that is below 0 or above 12");
  492. CreatePlayerHouse(playerid, Sell, lvl); }
  493. return true;
  494. }
  495.  
  496. dcmd_destroyhouse(playerid,params[]) {
  497. #pragma unused params
  498. if(IsPlayerConnected(playerid)){
  499. //if(PlayerInfo[playerid][pAdmin] < 10) return SendClientMessage(playerid,COLOR_WHITE,"SERVER: Unknown command.");
  500. if(!IsPlayerAdmin(playerid)) return SendClientMessage(playerid, COLOR_WHITE, "Only admins allowed to use this command");
  501. new houseid;
  502. if(sscanf(params, "i", houseid)) return SendClientMessage(playerid, COLOR_WHITE, "[USAGE]: /destroyhouse [houseid]");
  503. DestroyPlayerHouse(playerid, houseid);}
  504. return true;
  505. }
  506.  
  507. ///////////////////////////
  508. // Standard Functions
  509. //////////////////////////
  510.  
  511. stock GetName(playerid)
  512. {
  513. new pname[MAX_PLAYER_NAME]; pname="Invalid PlayerID";
  514. if(IsPlayerConnected(playerid)) {
  515. GetPlayerName(playerid, pname, sizeof (pname));
  516. }
  517. return pname;
  518. }
  519.  
  520. public PlayerToPoint(Float:radi, playerid, Float:x, Float:y, Float:z)
  521. {
  522. new Float:oldposx, Float:oldposy, Float:oldposz;
  523. new Float:tempposx, Float:tempposy, Float:tempposz;
  524. GetPlayerPos(playerid, oldposx, oldposy, oldposz);
  525. tempposx = (oldposx -x); tempposy = (oldposy -y); tempposz = (oldposz -z);
  526. if(((tempposx < radi) && (tempposx > -radi)) && ((tempposy < radi) && (tempposy > -radi)) && ((tempposz < radi) && (tempposz > -radi)))
  527. { return true; }
  528. return false;
  529. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement