Guest User

Untitled

a guest
Dec 18th, 2012
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 11.20 KB | None | 0 0
  1. #include <a_samp>
  2. #include <streamer>
  3. #include <SII>
  4. #include <zcmd>
  5. #include <sscanf2>
  6.  
  7. #define LABELTEXT1 "{00FF00}House Name: {0099FF}%s\n{00FF00}House Owner: {FFFFFF}No Owner\n{00FF00}House Value: {FFFFFF}$%d\n{00FF00}For Sale: {FFFFFF}Yes\n{00FF00}House ID: {FFFFFF}%d"
  8. #define LABELTEXT2 "House Name: {FFFFFF}%s\n{FF0000}House Owner: {FFFFFF}%s\n{FF0000}House Value: {FFFFFF}$%d\n{FF0000}For Sale: {FFFFFF}No\n{00BC00}{FF0000}House ID: {FFFFFF}%d"
  9. #define DEFAULT_HOUSE_NAME "House For Sale!"
  10.  
  11. #define MAX_HOUSES 10000
  12. #define DIALOG_BHOUSE 5000
  13. #define DIALOG_MHOUSE 5001
  14. #define DIALOG_MHOUSE2 5002
  15. #define DIALOG_C-ENTER 5003
  16. enum HouseInfo
  17. {
  18. HouseName[54],
  19. Owner[24],
  20. Owned,
  21. Price,
  22. Float:XPos,
  23. Float:YPos,
  24. Float:ZPos,
  25. VirtualWorld,
  26. Text3D:HouseLabel
  27. }
  28. new HInfo[MAX_HOUSES][HouseInfo];
  29.  
  30. new HouseCount;
  31. new HouseEnter[MAX_HOUSES];
  32. new PlayerInHouseID[MAX_PLAYERS];
  33. new IsInterior[MAX_PLAYERS];
  34.  
  35. public OnGameModeInit()
  36. {
  37. print("\n|=====================================================================|");
  38. print("|---------------------------------------------------------------------|");
  39. print("|*~*~*~*~*~*~*~*~*Windrush House System 100% ready!!~*~*~*~*~*~*~*~*~*|");
  40. print("|---------------------------------------------------------------------|");
  41. print("|=====================================================================|\n");
  42.  
  43. LoadHouses();
  44. return 1;
  45. }
  46. public OnPlayerDisconnect(playerid)
  47. {
  48. IsInterior[playerid] = 0;
  49. return 1;
  50. }
  51.  
  52. CMD:chouse(playerid,params[])
  53. {
  54. new HousePrice,id = HouseCount;
  55. new Float:x,Float:y,Float:z;
  56. new file[40],labelstring[300];
  57.  
  58. if(sscanf(params,"i",HousePrice)) return SendClientMessage(playerid,-1,"USAGE: /createhouse <price>");
  59. if(!IsPlayerAdmin(playerid)) return SendClientMessage(playerid,-1,"You aren't an admin!");
  60.  
  61. GetPlayerPos(playerid,x,y,z);
  62. HInfo[id][Price] = HousePrice;
  63. HInfo[id][Owned] = 0;
  64. HInfo[id][XPos] = x;
  65. HInfo[id][YPos] = y;
  66. HInfo[id][ZPos] = z;
  67. HInfo[id][VirtualWorld] = GetPlayerVirtualWorld(playerid);
  68. format(HInfo[id][Owner],24,"Nonusablenameforthishouse");
  69. SendClientMessage(playerid,-1,"House created");
  70. HouseEnter[id] = CreateDynamicCP(x,y,z,1.5,GetPlayerVirtualWorld(playerid));
  71.  
  72. format(file,sizeof(file),"FHouse/Houses/%i.ini",id);
  73. INI_Open(file);
  74. INI_WriteString("HouseName",DEFAULT_HOUSE_NAME);
  75. INI_WriteInt("Price",HousePrice);
  76. INI_WriteInt("Owned",0);
  77. INI_WriteInt("VirtualWorld",GetPlayerVirtualWorld( playerid));
  78. INI_WriteFloat("XPos",x);
  79. INI_WriteFloat("YPos",y);
  80. INI_WriteFloat("ZPos",z);
  81. INI_WriteString("Owner","Nonusablenameforthishouse ");
  82. INI_Save();
  83. INI_Close();
  84. format(labelstring,sizeof(labelstring),LABELTEXT1,DEFAULT_HOUSE_NAME,HousePrice,id);
  85. HInfo[id][HouseLabel] = Create3DTextLabel(labelstring,0xFF0000FF,x,y,z,25.0,GetPlayerVirtualWorld(playerid));
  86. HouseCount++;
  87. return 1;
  88. }
  89. CMD:sellh(playerid,params[])
  90. {
  91. for(new i = 0; i < MAX_HOUSES;i++)
  92. {
  93. if(!IsPlayerInRangeOfPoint(playerid,8.0,HInfo[i][XPos],HInfo[i][YPos],HInfo[i][ZPos])) continue;
  94. if(HInfo[i][Owned] == 0) return SendClientMessage(playerid,-1,"This house isn't owned");
  95. new pName[24], id = HouseCount;
  96.  
  97. GetPlayerName(playerid,pName,sizeof(pName));
  98. if(HInfo[i][Owned] == 1 && strcmp(pName,HInfo[i][Owner]) != 0) return SendClientMessage(playerid,-1,"You aren't the owner of this house!");
  99. HInfo[i][Owned] = 0;
  100. new file[60],string[300];
  101. format(HInfo[i][Owner],24,"Nonusablenameforthishouse");
  102. format(file,sizeof(file),"FHouse/Houses/%i.ini",id);
  103. INI_Open(file);
  104. INI_WriteString("HouseName",DEFAULT_HOUSE_NAME);
  105. INI_WriteInt("Owned",0);
  106. INI_WriteString("Owner","Nonusablenameforthishouse ");
  107. INI_Save();
  108. INI_Close();
  109. format(string,sizeof(string),LABELTEXT1,DEFAULT_HOUSE_NAME,HInfo[id][Price],id);//Formating the string, so we can update the label of the house
  110. Update3DTextLabelText(HInfo[i][HouseLabel],0xFF0000FF,string);//Updating the label with a red color
  111. return 1;
  112. }
  113. return 1;
  114. }
  115. CMD:hmenu(playerid,params[])
  116. {
  117. if(IsInterior[playerid] == 1)
  118. {
  119. new string[128];
  120. strcat(string,"{00FF00}Change House Name\n",sizeof(string));
  121. strcat(string,"{FF0000}Exit House\n",sizeof(string));
  122. ShowPlayerDialog(playerid,DIALOG_MHOUSE,DIALOG_STYLE_LIST,"{00FF00}House System",string,"Ok","Cancel");
  123. }
  124. else return SendClientMessage(playerid,0xFF0000FF,"You Must In The Inside of The House");
  125. return 1;
  126. }
  127.  
  128.  
  129. public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
  130. {
  131. //==============================================================================
  132. //--Buy-A-House-----------------------------------------------------------------
  133. //==============================================================================
  134. if(dialogid == DIALOG_BHOUSE)
  135. {
  136. if(response)
  137. {
  138. BuyHouse(playerid);
  139. }
  140. }
  141. //==============================================================================
  142. // House Menu------------------------------------------------------------------
  143. //==============================================================================
  144.  
  145. if(dialogid == DIALOG_MHOUSE)
  146. {
  147. switch(listitem)
  148. {
  149. case 0:
  150. {
  151. if(IsPlayerOwnedHouse(playerid))
  152. {
  153. ShowPlayerDialog(playerid,DIALOG_MHOUSE2,DIALOG_STYLE_INPUT,"{00FF00}House System","Type Your New Name Of Your House","Finish","Close");
  154. }
  155. }
  156. case 1:
  157. {
  158. SetPlayerPos(playerid,HInfo[playerid][XPos],HInfo[playerid][YPos],HInfo[playerid][ZPos]);
  159. SetPlayerInterior(playerid,GetPVarInt(playerid,"PlayersInteriorHouse"));
  160. SetPlayerVirtualWorld(playerid,GetPVarInt(playerid ,"PlayerVirtualWorldHouse"));
  161. IsInterior[playerid] = 0;
  162. }
  163. }
  164. }
  165. //==============================================================================
  166. if(dialogid == DIALOG_MHOUSE2)
  167. {
  168. if(response)
  169. {
  170. for(new i = 0; i < MAX_HOUSES;i++)
  171. {
  172. new string[300],file[60],pName[24],id = HouseCount;
  173. GetPlayerName(playerid,pName,sizeof(pName));
  174. format(file,sizeof(file),"FHouse/Houses/%i.ini",id);
  175. INI_Open(file);
  176. INI_WriteString("HouseName",inputtext);
  177. INI_Save();
  178. INI_Close();
  179. format(string,sizeof(string),LABELTEXT2,inputtext,pName,HInfo[i][Price],id);
  180. Update3DTextLabelText(HInfo[i][HouseLabel],0xFF0000FF,string);
  181. }
  182. }
  183. }
  184. //==============================================================================
  185. // When player Enter CP--------------------------------------------------------
  186. //==============================================================================
  187.  
  188. if(dialogid == DIALOG_C-ENTER)
  189. {
  190. if(response)
  191. {
  192. for(new i = 0; i < MAX_HOUSES;i++)
  193. {
  194. SetPVarInt(playerid,"PlayersInteriorHouse",GetPlayerInterior(playerid));//Storing, so later we can reset it back
  195. SetPVarInt(playerid,"PlayerVirtualWorldHouse",GetPlayerVirtualWorld(playerid));//Storing, so later we can reset it back
  196. SetPlayerInterior(playerid,12);//Setting the players interior.
  197. SetPlayerPos(playerid,2496.049804,-1695.238159,1014.742187) ;//Setting the players position.
  198. SetPlayerVirtualWorld(playerid,HInfo[playerid][VirtualWorld]);//Preventing players from different houses, finding each other.
  199. PlayerInHouseID[playerid] = i;
  200. IsInterior[playerid] = 1;
  201. }
  202. }
  203. }
  204. //==============================================================================
  205. return 1;
  206. }
  207.  
  208. public OnPlayerEnterDynamicCP(playerid,checkpointid)
  209. {
  210. for(new i = 0; i < MAX_HOUSES;i++)//Looping threw all houses.
  211. {
  212. if(checkpointid == HouseEnter[i])//Checking if the checkpoint id corresponds to one of the house interiors
  213. {
  214. new pName[24];//Creating the new var for the players name
  215. GetPlayerName(playerid,pName,24);//Storing the players name
  216.  
  217. if(HInfo[i][Owned] == 1 && strcmp(HInfo[i][Owner],pName) == 0)//String comparing between the players name and the house owners name, to check if they match.
  218. {
  219. ShowPlayerDialog(playerid,DIALOG_C-ENTER,DIALOG_STYLE_MSGBOX,"{00FF00}House System","{FF0000}Are You Sure To Enter To Your House?","Yes","No");
  220. }
  221. if(HInfo[i][Owned] == 1 && strcmp(HInfo[i][Owner],pName) != 0)//Checking if the house is owned but the house owner and the players name don't match.
  222. {
  223. SendClientMessage(playerid,-1,"You don't own this house");
  224. }
  225. if(HInfo[i][Owned] == 0)//Simply checking if the house isn't owned.
  226. {
  227. ShowPlayerDialog(playerid, DIALOG_BHOUSE,DIALOG_STYLE_MSGBOX,"{00FF00}House System","{FFFFFF}Are You Sure To Buy This House?","Yes","No");
  228. }
  229. }
  230. }
  231. return 1;
  232. }
  233. stock LoadHouses()
  234. {
  235. new file[60],houseowner[24];
  236. for(new i = 0; i < MAX_HOUSES;i++)
  237. {
  238. format(file,sizeof(file),"FAdmin/Houses/%i.ini",i);
  239. if(!INI_Exist(file)) continue;
  240. INI_Open(file);
  241. HInfo[i][HouseName] = INI_ReadString("HouseName",DEFAULT_HOUSE_NAME);
  242. HInfo[i][Price] = INI_ReadInt("Price");
  243. HInfo[i][Owned] = INI_ReadInt("Owned");
  244. HInfo[i][XPos] = INI_ReadInt("XPos");
  245. HInfo[i][YPos] = INI_ReadInt("YPos");
  246. HInfo[i][ZPos] = INI_ReadInt("ZPos");
  247. HInfo[i][VirtualWorld] = INI_ReadInt("VirtualWorld");
  248. INI_ReadString(houseowner,"Owner");
  249. format(HInfo[i][Owner],24,"%s",houseowner);
  250. HouseEnter[i] = CreateDynamicCP(HInfo[i][XPos],HInfo[i][YPos],HInfo[i][ZPos],1.5,HInfo[i][VirtualWorld]);
  251. new labelstring[300];
  252. switch(HInfo[i][Owned])
  253. {
  254. case 0:{format(labelstring,sizeof(labelstring),"Owned: No \nPrice: %i",HInfo[i][Price]);}//If it isnt...
  255. case 1:{format(labelstring,sizeof(labelstring),"Owned: Yes \nPrice: %i \nOwner: %s",HInfo[i][Price],HInfo[i][Owner]);}//If it is...
  256. }
  257. HInfo[i][HouseLabel] = Create3DTextLabel(labelstring,0xFF0000FF,HInfo[i][XPos],HInfo[i][YPos],HInfo[i][ZPos],25.0,HInfo[i][VirtualWorld]);//Creating the label with the formatted string.
  258. HouseCount++;
  259. INI_Close();
  260. }
  261. return 1;
  262. }
  263. stock BuyHouse(playerid)
  264. {
  265. for(new i = 0; i < MAX_HOUSES;i++)
  266. {
  267. new file[60],string[300],pName[24], id = HouseCount;
  268. new hname[MAX_PLAYER_NAME+9];
  269. GetPlayerName(playerid,pName,sizeof(pName));
  270. format(hname,sizeof(hname),"%s's House",pName);
  271. if(!IsPlayerInRangeOfPoint(playerid,8.0,HInfo[i][XPos],HInfo[i][YPos],HInfo[i][ZPos])) continue;//Check if the player is near a house checkpoint
  272. if(GetPlayerMoney(playerid) < HInfo[i][Price]) return SendClientMessage(playerid,-1,"You don't have enough money");//Checking the players money, to see if he has enough to buy the house.
  273. if(HInfo[i][Owned] == 1) return SendClientMessage(playerid,-1,"This house is already owned");//Checking if the house is already owned.
  274. HInfo[i][Owned] = 1;
  275.  
  276. format(HInfo[i][Owner],24,"%s",pName);
  277. format(file,sizeof(file),"FHouse/Houses/%i.ini",id);
  278. INI_Open(file);
  279. INI_WriteString("HouseName",hname);
  280. INI_WriteInt("Owned",1);
  281. INI_WriteString("Owner",pName);
  282. INI_Save();
  283. INI_Close();
  284. format(string,sizeof(string),LABELTEXT2,hname,pName,HInfo[playerid][Price],id);
  285. Update3DTextLabelText(HInfo[i][HouseLabel],0xFF0000FF,string);
  286. GivePlayerMoney(playerid,-HInfo[i][Price]);
  287. return 1;
  288. }
  289. return 1;
  290. }
  291. stock IsPlayerOwnedHouse(playerid)
  292. {
  293. new pName[24];
  294. GetPlayerName(playerid,pName,sizeof(pName));
  295. if(HInfo[playerid][Owned] == 1 && strcmp(HInfo[playerid][Owner],pName) == 0)
  296. {
  297. return 1;
  298. }
  299. return 0;
  300. }
Advertisement
Add Comment
Please, Sign In to add comment