Guest User

Untitled

a guest
Apr 25th, 2018
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.45 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. hInsideInt, //The inside interior.. DUH!
  20. hInsideVir, //Already subscribed above
  21. hOutsideInt,
  22. hOutsideVir,
  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. new fstring[10]; //The string for the file [format]
  32.  
  33. stock LoadHouse(houseid)
  34. {
  35. format(fstring, 10, "Houses/%d", houseid); //Format the filename
  36. if(!dini_Exists(fstring)) return 0; //"If Houses/{houseid} not exists then return False (0)"
  37. HouseInfo[houseid][hEnterX] = dini_Float(fstring, "EnterX");
  38. HouseInfo[houseid][hEnterY] = dini_Float(fstring, "EnterY");
  39. HouseInfo[houseid][hEnterZ] = dini_Float(fstring, "EnterZ");
  40. HouseInfo[houseid][hExitX] = dini_Float(fstring, "ExitX");
  41. HouseInfo[houseid][hExitY] = dini_Float(fstring, "ExitY");
  42. HouseInfo[houseid][hExitZ] = dini_Float(fstring, "ExitZ");
  43. HouseInfo[houseid][hInsideInt] = dini_Int(fstring, "InsideInt");
  44. HouseInfo[houseid][hInsideVir] = dini_Int(fstring, "InsideVir");
  45. HouseInfo[houseid][hOutsideInt] = dini_Int(fstring, "OutsideInt");
  46. HouseInfo[houseid][hOutsideVir] = dini_Int(fstring, "OutsideVir");
  47. HouseInfo[houseid][hOwned] = dini_Bool(fstring, "Owned") ? true : false; //Because it is an boolean: ? true : false;
  48. 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
  49. HouseInfo[houseid][hPrice] = dini_Int(fstring, "Price");
  50. return 1;
  51. }
  52. stock LoadHouseVisual(houseid, bool:reload = false)
  53. {
  54. if(reload)
  55. {
  56. DestroyDynamicMapIcon(HouseInfo[houseid][hIcon]);
  57. DestroyDynamicPickup(HouseInfo[houseid][hPickup]);
  58. }
  59. if(!HouseInfo[houseid][hOwned]) //Also known as 'if(HouseInfo[houseid][hOwned] == false)' - With aan boolean you can use '!{option}' and "{option}"! (!IsPlayerAdmin())) (IsPlayerAdmin())
  60. {
  61. //So the house is not owned. Let's make an green mapicon and en green house pickup!
  62. HouseInfo[houseid][hIcon] = CreateDynamicMapIcon(HouseInfo[houseid][hEnterX], HouseInfo[houseid][hEnterY], HouseInfo[houseid][hEnterZ], 31, 0, HouseInfo[houseid][hOutsideVir], HouseInfo[houseid][hOutsideInt]);
  63. HouseInfo[houseid][hPickup] = CreateDynamicPickup(1273, 1, HouseInfo[houseid][hEnterX], HouseInfo[houseid][hEnterY], HouseInfo[houseid][hEnterZ], HouseInfo[houseid][hOutsideVir], HouseInfo[houseid][hOutsideInt]);
  64. }
  65. else
  66. {
  67. //House is already owned. Blue pickup and red icon!
  68. HouseInfo[houseid][hIcon] = CreateDynamicMapIcon(HouseInfo[houseid][hEnterX], HouseInfo[houseid][hEnterY], HouseInfo[houseid][hEnterZ], 31, 0, HouseInfo[houseid][hOutsideVir], HouseInfo[houseid][hOutsideInt]);
  69. HouseInfo[houseid][hPickup] = CreateDynamicPickup(1273, 1, HouseInfo[houseid][hEnterX], HouseInfo[houseid][hEnterY], HouseInfo[houseid][hEnterZ], HouseInfo[houseid][hOutsideVir], HouseInfo[houseid][hOutsideInt]);
  70. }
  71. return 1;
  72. }
  73. stock SaveHouse(houseid)
  74. {
  75. dini_FloatSet(fstring, "EnterX", HouseInfo[houseid][hEnterX]);
  76. dini_FloatSet(fstring, "EnterY", HouseInfo[houseid][hEnterY]);
  77. dini_FloatSet(fstring, "EnterZ", HouseInfo[houseid][hEnterZ]);
  78. dini_FloatSet(fstring, "ExitX", HouseInfo[houseid][hExitX]);
  79. dini_FloatSet(fstring, "ExitY", HouseInfo[houseid][hExitY]);
  80. dini_FloatSet(fstring, "ExitZ", HouseInfo[houseid][hExitZ]);
  81. dini_IntSet(fstring, "InsideInt", HouseInfo[houseid][hInsideInt]);
  82. dini_IntSet(fstring, "InsideVir", HouseInfo[houseid][hInsideVir]);
  83. dini_IntSet(fstring, "OutsideInt", HouseInfo[houseid][hOutsideInt]);
  84. dini_IntSet(fstring, "OutsideVir", HouseInfo[houseid][hOutsideVir]);
  85. dini_BoolSet(fstring, "Owned", HouseInfo[houseid][hOwned]);
  86. dini_Set(fstring, "Owner", HouseInfo[houseid][hOwner]); //No, not "GetSet"! :P
  87. dini_IntSet(fstring, "Price", HouseInfo[houseid][hPrice]);
  88. return 1;
  89. }
  90. public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
  91. {
  92. if(newkeys & 16 && !IsPlayerInAnyVehicle(playerid)) //If player pressed ENTER_VEHICLe and if he's not in an vehicle
  93. {
  94. for(new i = 0; i < MAX_HOUSES; i++) //Loop through all the houses
  95. {
  96. 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
  97. {
  98. SetPlayerPos(playerid, HouseInfo[i][hExitX], HouseInfo[i][hExitY], HouseInfo[i][hExitZ]);
  99. SetPlayerInterior(playerid, HouseInfo[i][hInsideInt]);
  100. SetPlayerVirtualWorld(playerid, HouseInfo[i][hInsideVir]);
  101. //This will put the player IN the house
  102. }
  103. 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
  104. {
  105. SetPlayerPos(playerid, HouseInfo[i][hEnterX], HouseInfo[i][hEnterY], HouseInfo[i][hEnterZ]);
  106. SetPlayerInterior(playerid, HouseInfo[i][hOutsideInt]);
  107. SetPlayerVirtualWorld(playerid, HouseInfo[i][hOutsideVir]);
  108. }
  109. }
  110. }
  111. return 1;
  112. }
  113. public OnGameModeInit()
  114. {
  115. SetTimer("UpdatePlayersHouseInfo", 1000, true); //Every 1000 milli seconds (1 sec.) it will be used again
  116. return 1;
  117. }
  118.  
  119. forward UpdatePlayersHouseInfo();
  120. public UpdatePlayersHouseInfo()
  121. {
  122. new str[100]; //The string we are gonna format
  123. for(new i = 0; i < MAX_PLAYERS; i++) //Loop through all the players
  124. {
  125. for(new j = 0; j < MAX_HOUSES; j++) //Loop through all the houses
  126. {
  127. if(IsPlayerInRangeOfPoint(j, 10, 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!
  128. {
  129. if(HouseInfo[j][hOwned]) //Is house owned?
  130. format(str, 100, "~w~House owned by ~r~%s", HouseInfo[j][hOwner]); //Will give: {white_color}House owned by {yellow_color}OWNER
  131. else //House isn't owned
  132. 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
  133. GameTextForPlayer(i, str, 2000, 3); //Show the text 2 seconds!
  134. }
  135. }
  136. }
  137. return 1;
  138. }
  139. public OnPlayerCommandText(playerid, cmdtext[])
  140. {
  141. if(!strcmp(cmdtext, "/buyhouse", true))
  142. {
  143. new pName[MAX_PLAYER_NAME]; //For the player's name - For the house
  144. GetPlayerName(playerid, pName, MAX_PLAYER_NAME); //Get the name of the player and store it in [u]pName[/u]
  145. for(new i = 0; i < MAX_HOUSES; i++) //Last time I'm gonna say it: Loop through all the houses
  146. {
  147. 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!)
  148. {
  149. 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.
  150. 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!
  151.  
  152. HouseInfo[i][hOwned] = true; //The house is owned, where the player used /buyhouse
  153. strmid(HouseInfo[i][hOwner], pName, 0, false, strlen(pName)); //Put the players name into the "hOwner" of the house
  154. GivePlayerMoney(playerid, -HouseInfo[i][hPrice]); //Remove some money of the player.. The value of the house
  155. SendClientMessage(playerid, COLOR_GREEN, "House bought!"); //Send the player an message.
  156. SaveHouse(i);
  157. LoadHouseVisual(i, true); //Load House Visual. Now, I've added ', true': It will RELOAD now!
  158. return 1;
  159. }
  160. }
  161. return 1;
  162. }
  163. if(!strcmp(cmdtext, "/sellhouse", true))
  164. {
  165. new pName[MAX_PLAYER_NAME]; //See /buyhouse
  166. GetPlayerName(playerid, pName, MAX_PLAYER_NAME); //See new pName[MAX_PLAYER_NAME];
  167. for(new i = 0; i < MAX_HOUSES; i++)
  168. {
  169. if(IsPlayerInRangeOfPoint(playerid, 1.5, HouseInfo[i][hEnterX], HouseInfo[i][hEnterY], HouseInfo[i][hEnterZ]) && GetPlayerInterior(playerid) == HouseInfo[i][hOutsideInt] && GetPlayerVirtualWorld(playerid) == HouseInfo[i][hOutsideVir])
  170. {
  171. if(!strcmp(HouseInfo[i][hOwner], pName, false)) //Is the owner of the house the same as the players name (is the player the owner?? !)
  172. {
  173. strmid(HouseInfo[i][hOwner], "For Sale", 0, false, 8); //Set the owner of the house to "For Sale"
  174. HouseInfo[i][hOwned] = false; //House is not owner anymore!
  175. GivePlayerMoney(playerid, HouseInfo[i][hPrice]/2); //Give the player 50% of the house value back!
  176. SendClientMessage(playerid, COLOR_GREEN, "House sold!");
  177. SaveHouse(i);
  178. LoadHouseVisual(i, true); //Load House Visual. Now, I've added ', true': It will RELOAD now!
  179. return 1;
  180. }
  181. }
  182. }
  183. return 1;
  184. }
  185. return 0;
  186. }
Add Comment
Please, Sign In to add comment