Guest User

Untitled

a guest
Apr 25th, 2018
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.41 KB | None | 0 0
  1. #include <a_samp>
  2. #include <Dini>
  3. #include <streamer>
  4.  
  5. #define MAX_HOUSES 200
  6.  
  7. #define COLOR_WHITE 0xFFFFFFAA //White color
  8. #define COLOR_RED 0xFF0000AA //Red Color
  9. #define COLOR_GREEN 0x00FF00AA //Green color
  10.  
  11. enum hInfo
  12. {
  13. Float:hEnterX, //Entrance X. It's an float! example: 0.0000000. I'm gonna use the same with the other entrances/exits
  14. Float:hEnterY,
  15. Float:hEnterZ,
  16. Float:hExitX,
  17. Float:hExitY,
  18. Float:hExitZ,
  19. InsideInt, //The inside interior.. DUH!
  20. InsideVir, //Already subscribed above
  21. OutsideInt,
  22. OutsideVir,
  23. bool:hOwned, //boolean! Is house owned? NO = False, YES = True
  24. hOwner[MAX_PLAYER_NAME], //The house owner! I'm gonna use MAX_PLAYER_NAME, because a player can't have a longer name :')
  25. hPrice, //Will store the price
  26. hPickup, //The pickup. This is used to remove/move the pickup icon!
  27. hIcon, //The map icon. Also used to remove/move it! We are going to need an ID. Without an ID we can't do NOTHING!
  28. };
  29. new HouseInfo[MAX_HOUSES][hInfo];
  30.  
  31. stock LoadHouse(houseid)
  32. {
  33. new fstring[10]; //The string for the file [format]
  34. format(fstring, 10, "Houses/%d", houseid); //Format the filename
  35. if(!dini_Exists(fstring)) return 0; //"If Houses/{houseid} not exists then return False (0)"
  36. HouseInfo[houseid][hEnterX] = dini_Float(fstring, "EnterX");
  37. HouseInfo[houseid][hEnterY] = dini_Float(fstring, "EnterY");
  38. HouseInfo[houseid][hEnterZ] = dini_Float(fstring, "EnterZ");
  39. HouseInfo[houseid][hExitX] = dini_Float(fstring, "ExitX");
  40. HouseInfo[houseid][hExitY] = dini_Float(fstring, "ExitY");
  41. HouseInfo[houseid][hExitZ] = dini_Float(fstring, "ExitZ");
  42. HouseInfo[houseid][hInsideInt] = dini_Int(fstring, "InsideInt");
  43. HouseInfo[houseid][hInsideVir] = dini_Int(fstring, "InsideVir");
  44. HouseInfo[houseid][hOutsideInt] = dini_Int(fstring, "OutsideInt");
  45. HouseInfo[houseid][hOUtsideVir] = dini_Int(fstring, "OutsideVir");
  46. HouseInfo[houseid][hOwned] = dini_Bool(fstring, "Owned") ? true : false; //Because it is an boolean: ? true : false;
  47. strmid(HouseInfo[houseid][hOwner], dini_Get(fstring, "Owner"), 0, false, strlen(dini_Get("Owner"))); //Used this one instead of {string} = {string}. I've ever read that this is faster
  48. HouseInfo[houseid][hPrice] = dini_Int(fstring, "Price");
  49. return 1;
  50. }
  51. stock LoadHouseVisual(houseid, bool:reload = false)
  52. {
  53. if(reload)
  54. {
  55. DestroyDynamicMapIcon(HouseInfo[houseid][hIcon]);
  56. DestroyDynamicPickup(HouseInfo[houseid][hPickup]);
  57. }
  58. if(!HouseInfo[houseid][hOwned]) //Also known as 'if(HouseInfo[houseid][hOwned] == false)' - With aan boolean you can use '!{option}' and "{option}"! (!IsPlayerAdmin())) (IsPlayerAdmin())
  59. {
  60. //So the house is not owned. Let's make an green mapicon and en green house pickup!
  61. HouseInfo[houseid][hIcon] = CreateDynamicMapIcon(HouseInfo[houseid][hEnterX], HouseInfo[houseid][hEnterY], HouseInfo[houseid][hEnterZ], 31, 0, HouseInfo[houseid][hOutsideVir], HouseInfo[houseid][hOutsideInt]);
  62. HouseInfo[houseid][hPickup] = CreateDynamicPickup(1273, 1, HouseInfo[houseid][hEnterX], HouseInfo[houseid][hEnterY], HouseInfo[houseid][hEnterZ], HouseInfo[houseid][hOutsideVir], HouseInfo[houseid][hOutsideInt]);
  63. }
  64. else
  65. {
  66. //House is already owned. Blue pickup and red icon!
  67. HouseInfo[houseid][hIcon] = CreateDynamicMapIcon(HouseInfo[houseid][hEnterX], HouseInfo[houseid][hEnterY], HouseInfo[houseid][hEnterZ], 31, 0, HouseInfo[houseid][hOutsideVir], HouseInfo[houseid][hOutsideInt]);
  68. HouseInfo[houseid][hPickup] = CreateDynamicPickup(1273, 1, HouseInfo[houseid][hEnterX], HouseInfo[houseid][hEnterY], HouseInfo[houseid][hEnterZ], HouseInfo[houseid][hOutsideVir], HouseInfo[houseid][hOutsideInt]);
  69. }
  70. return 1;
  71. }
  72. stock SaveHouse(houseid)
  73. {
  74. dini_FloatSet(fstring, "EnterX", HouseInfo[houseid][hEnterX]);
  75. dini_FloatSet(fstring, "EnterY", HouseInfo[houseid][hEnterY]);
  76. dini_FloatSet(fstring, "EnterZ", HouseInfo[houseid][hEnterZ]);
  77. dini_FloatSet(fstring, "ExitX", HouseInfo[houseid][hExitX]);
  78. dini_FloatSet(fstring, "ExitY", HouseInfo[houseid][hExitY]);
  79. dini_FloatSet(fstring, "ExitZ", HouseInfo[houseid][hExitZ]);
  80. dini_IntSet(fstring, "InsideInt", HouseInfo[houseid][hInsideInt]);
  81. dini_IntSet(fstring, "InsideVir", HouseInfo[houseid][hInsideVir]);
  82. dini_IntSet(fstring, "OutsideInt", HouseInfo[houseid][hOutsideInt]);
  83. dini_IntSet(fstring, "OutsideVir", HouseInfo[houseid][hOUtsideVir]);
  84. dini_BoolSet(fstring, "Owned", HouseInfo[houseid][hOwned]);
  85. dini_Get(fstring, "Owner", HouseInfo[houseid][hOwner]); //No, not "GetSet"! :P
  86. dini_IntSet(fstring, "Price", HouseInfo[houseid][hPrice]);
  87. return 1;
  88. }
  89. public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
  90. {
  91. if(newkeys & 16 && !IsPlayerInAnyVehicle(playerid)) //If player pressed ENTER_VEHICLe and if he's not in an vehicle
  92. {
  93. for(new i = 0; i < MAX_HOUSES; i++) //Loop through all the houses
  94. {
  95. if(IsPlayerInRangeOfPoint(playerid, 1.5, HouseInfo[i][hEnterX], HouseInfo[i][hEnterY], HouseInfo[i][hEnterZ]) && GetPlayerInterior(playerid) == HouseInfo[i][hOutsideInt] && GetPlayerVirtualWorld(playerid) == HouseInfo[i][hOutsideVir]) //Is player near house entrance, and if player is in interior of that house + virtual world
  96. {
  97. SetPlayerPos(playerid, HouseInfo[i][hExitX], HouseInfo[i][hExitY], HouseInfo[i][hExitZ]);
  98. SetPlayerInterior(playerid, HouseInfo[i][hInsideInt]);
  99. SetPlayerVirtualWorld(playerid, HouseInfo[i][hInsideVir]);
  100. //This will put the player IN the house
  101. }
  102. else if(IsPlayerInRangeOfPoint(playerid, 1.5, HouseInfo[i][hExitX], HouseInfo[i][hExitY], HouseInfo[i][hExitZ]) && GetPlayerInterior(playerid) == HouseInfo[i][hInsideInt] && GetPlayerVirtualWorld(playerid) == HouseInfo[i][hInsideVir]) //Same as the previous IsPlayerInRangeOfPoint, but now if the player is near the house exit+int+vir
  103. {
  104. SetPlayerPos(playerid, HouseInfo[i][hEnterX], HouseInfo[i][hEnterY], HouseInfo[i][hEnterZ]);
  105. SetPlayerInterior(playerid, HouseInfo[i][hOutsideInt]);
  106. SetPlayerVirtualWorld(playerid, HouseInfo[i][hOutsideVir]);
  107. }
  108. }
  109. }
  110. return 1;
  111. }
  112. public OnGameModeInit()
  113. {
  114. SetTimer("UpdatePlayersHouseInfo", 1000, true); //Every 1000 milli seconds (1 sec.) it will be used again
  115. return 1;
  116. }
  117. public UpdatePlayersHouseInfo()
  118. {
  119. new str[100]; //The string we are gonna format
  120. for(new i = 0; i < MAX_PLAYERS; i++) //Loop through all the players
  121. {
  122. for(new j = 0; j < MAX_HOUSES; j++) //Loop through all the houses
  123. {
  124. if(IsPlayerInRangeOfPoint(j, HouseInfo[j][hEnterX], HouseInfo[j][hEnterY], HouseInfo[j][hEnterZ]) && GetPlayerInterior(i) == HouseInfo[j][hOutsideInt] && GetPlayerVirtualWorld(i) == HouseInfo[j][hOutsideVir]) //You already know this! If you don't know it, do step 3 again!
  125. {
  126. if(HouseInfo[j][hOwned]) //Is house owned?
  127. format(str, 100, "~w~House owned by ~r~%s", HouseInfo[j][hOwner]); //Will give: {white_color}House owned by {yellow_color}OWNER
  128. else //House isn't owned
  129. format(str, 100, "~w~House for sale!~n~Price: ~g~$%d,-", HouseInfo[j][hPrice]); //Will give: {white_color}House for sale!{new line}Price: {green_color}$PRICE
  130. GameTextForPlayer(i, str, 2000, 3); //Show the text 2 seconds!
  131. }
  132. }
  133. }
  134. return 1;
  135. }
  136. public OnPlayerCommandText(playerid, cmdtext[])
  137. {
  138. if(!strcmp(cmdtext, "/buyhouse", true))
  139. {
  140. new pName[MAX_PLAYER_NAME]; //For the player's name - For the house
  141. GetPlayerName(playerid, pName, MAX_PLAYER_NAME); //Get the name of the player and store it in [u]pName[/u]
  142. for(new i = 0; i < MAX_HOUSES; i++) //Last time I'm gonna say it: Loop through all the houses
  143. {
  144. if(IsPlayerInRangeOfPoint(playerid, 1.5, HouseInfo[i][hEnterX], HouseInfo[i][hEnterY], HouseInfo[i][hEnterZ]) && GetPlayerInterior(playerid) == HouseInfo[i][hOutsideInt] && GetPlayerVirtualWorld(playerid) == HouseInfo[i][hOutsideVir]) //Is player near house entrance, and if player is in interior of that house + virtual world (Last time I said this too!)
  145. {
  146. if(HouseInfo[i][hOwned]) return SendClientMessage(playerid, COLOR_RED, "This house is already owned!"); //Is the house owned? Then send message that it's owned and stop.
  147. if(GetPlayerMoney(playerid) < HouseInfo[i][hPrice]) return SendClientMessage(playerid, COLOR_RED, "You don't have enough money for this!"); //Has player too less money? Send him a message!
  148.  
  149. HouseInfo[i][hOwned] = true; //The house is owned, where the player used /buyhouse
  150. strmid(HouseInfo[i][hOwner], pName, 0, false, strlen(pName)); //Put the players name into the "hOwner" of the house
  151. GivePlayerMoney(playerid, -HouseInfo[i][hPrice]); //Remove some money of the player.. The value of the house
  152. SendClientMessage(playerid, COLOR_GREEN, "House bought!"); //Send the player an message.
  153. SaveHouse(i);
  154. LoadHouseVisual(i, true); //Load House Visual. Now, I've added ', true': It will RELOAD now!
  155. return 1;
  156. }
  157. }
  158. return 1;
  159. }
  160. if(!strcmp(cmdtext, "/sellhouse", true))
  161. {
  162. new pName[MAX_PLAYER_NAME]; //See /buyhouse
  163. GetPlayerName(playerid, pName, MAX_PLAYER_NAME); //See new pName[MAX_PLAYER_NAME];
  164. for(new i = 0; i < MAX_HOUSES; i++)
  165. {
  166. if(IsPlayerInRangeOfPoint(playerid, 1.5, HouseInfo[i][hEnterX], HouseInfo[i][hEnterY], HouseInfo[i][hEnterZ]) && GetPlayerInterior(playerid) == HouseInfo[i][hOutsideInt] && GetPlayerVirtualWorld(playerid) == HouseInfo[i][hOutsideVir])
  167. {
  168. if(!strcmp(HouseInfo[i][hOwner], pName, false)) //Is the owner of the house the same as the players name (is the player the owner?? !)
  169. {
  170. strmid(HouseInfo[i][hOwner], "For Sale", 0, false, 8); //Set the owner of the house to "For Sale"
  171. HouseInfo[i][hOwned] = false; //House is not owner anymore!
  172. GivePlayerMoney(playerid, HouseInfo[i][hPrice]/2); //Give the player 50% of the house value back!
  173. SendClientMessage(playerid, COLOR_GREEN, "House sold!");
  174. SaveHouse(i);
  175. LoadHouseVisual(i, true); //Load House Visual. Now, I've added ', true': It will RELOAD now!
  176. return 1;
  177. }
  178. }
  179. }
  180. return 1;
  181. }
  182. return 0;
  183. }
Add Comment
Please, Sign In to add comment