Advertisement
Guest User

Untitled

a guest
May 13th, 2012
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.94 KB | None | 0 0
  1. CMD:createhouse(playerid,params[])
  2. {
  3. if(!IsPlayerAdmin(playerid)) return SendClientMessage(playerid,-1,"You aren't an admin!");//Check if the player is currently rcon logged in.
  4. new HousePrice,id = HouseCount;//Creating the house price for the selected value in the command, and the last house id created.
  5. if(sscanf(params,"i",HousePrice)) return SendClientMessage(playerid,-1,"USAGE: /createhouse [price]");//Checking if the player uses the correct syntax. The parameter "i" in sscanf means integer, also could be used as "d".
  6. new Float:x,Float:y,Float:z;//Creating the floats, to store the player's position.
  7. GetPlayerPos(playerid,x,y,z);//Getting the player's position and storing it
  8. HInfo[id][Price] = HousePrice;//Setting the house price to the selected one.
  9. HInfo[id][Owned] = 0;//Setting the house id owned = 0
  10. HInfo[id][XPos] = x;//Storing the XPos value to the player's x.
  11. HInfo[id][YPos] = y;//Storing the YPos value to the player's y.
  12. HInfo[id][ZPos] = z;//Storing the ZPos value to the player's z.
  13. HInfo[id][VirtualWorld] = GetPlayerVirtualWorld(playerid);
  14. format(HInfo[id][Owner],24,"Nonusablenameforthishouse");//Formating the "Owner" house id value to "Nonusablenameforthishouse".
  15. SendClientMessage(playerid,-1,"House created");
  16. HouseEnter[id] = AddStaticPickup(1273, -1, x, y, z, 0);//Creating the checkpoint and storing it in the HouseEnter value.
  17. HouseExit[id] = CreateDynamicCP(443.9237,509.4609,1001.4195,1.5,GetPlayerVirtualWorld(playerid));//Creating the house exit checkpoint and storing it in the HouseExit value.
  18. new INI:File = INI_Open(UserPath(playerid));
  19. INI_SetTag(File, "House");
  20. INI_WriteInt(File,"Price",HousePrice);//Writing in the place "Price" the inputted "Price" value.
  21. INI_WriteInt(File,"Owned",0);//Setting to "Owned" = 0 in the ini file.
  22. INI_WriteInt(File,"VirtualWorld",GetPlayerVirtualWorld(playerid));//Writing "VirtualWorld" = GetPlayerVirtualWorld(..);
  23. INI_WriteFloat(File,"XPos",x);//Writing the players pos for the check point position.
  24. INI_WriteFloat(File,"YPos",y);//Self explanatory.
  25. INI_WriteFloat(File,"ZPos",z);//Self explanatory.
  26. INI_WriteString(File,"Owner","Nonusablenameforthishouse");//Writing a string in "Owned" to "Nonusablenameforthishouse"
  27. INI_Close(File);//Closing the file with SII.
  28. HouseCount++;
  29. return 1;
  30. }
  31.  
  32. CMD:buyhouse(playerid,params[])
  33. {
  34. for(new i = 0; i < MAX_HOUSES;i++)//Loop threw all houses.
  35. {
  36. new id = HouseCount;
  37. if(!IsPlayerInRangeOfPoint(playerid,8.0,HInfo[i][XPos],HInfo[i][YPos],HInfo[i][ZPos])) continue;//Check if the player is near a house checkpoint
  38. 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.
  39. if(HInfo[i][Owned] == 1) return SendClientMessage(playerid,-1,"This house is already owned");//Checking if the house is already owned.
  40. AddStaticPickup(1272, -1, HInfo[i][XPos],HInfo[i][YPos],HInfo[i][ZPos], 0);
  41. DestroyPickup(HouseEnter[id]);
  42. HInfo[i][Owned] = 1;//Setting the house owned var to 1.
  43. GameTextForPlayer(i, "Bought!", 3000, 1);
  44. GetPlayerName(playerid,pname,sizeof(pname));//Retrieving the player's name.
  45. new INI:File = INI_Open(UserPath(playerid));
  46. INI_SetTag(File, "House");
  47. INI_WriteInt(File, "Owned",1);//Setting in the ini file "Owned" to 1
  48. INI_WriteString(File, "Owner",pname);//Setting the "Owner" to the player's name.
  49. INI_Close(File);//Closing the ini
  50. return 1;
  51. }
  52. SendClientMessage(playerid,-1,"You aren't near a house!");
  53. return 1;
  54. }
  55.  
  56.  
  57. public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
  58. {
  59.  
  60. if(newkeys == KEY_CROUCH)
  61. {
  62. for(new i = 0; i < MAX_HOUSES;i++)//Looping threw all houses.
  63. {
  64. new pickupid;
  65. if(pickupid == HouseEnter[i])//Checking if the checkpoint id corresponds to one of the house interiors
  66. {
  67. new pName[24];//Creating the new var for the players name
  68. GetPlayerName(playerid,pName,24);//Storing the players name
  69. 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.
  70. {
  71. SetPVarInt(playerid,"PlayersInteriorHouse",GetPlayerInterior(playerid));//Storing, so later we can reset it back
  72. SetPVarInt(playerid,"PlayerVirtualWorldHouse",GetPlayerVirtualWorld(playerid));//Storing, so later we can reset it back
  73. SetPlayerPos(playerid,446.7281,507.0475,1001.9195);//Setting the players position.
  74. SetPlayerInterior(playerid,12);//Setting the players interior.
  75. SetPlayerVirtualWorld(playerid,HInfo[i][VirtualWorld]);//Preventing players from different houses,
  76. PlayerInHouseID[playerid] = i;
  77. }
  78. 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.
  79. {
  80. SendClientMessage(playerid,-1,"You don't own this house");
  81. }
  82. if(HInfo[i][Owned] == 0)//Simply checking if the house isn't owned.
  83. {
  84. SendClientMessage(playerid,-1,"/buy to buy this lovely house");
  85. }
  86. }
  87. if(pickupid == HouseExit[i])//Checking if the checkpointid is an House exit
  88. {
  89. SetPlayerPos(playerid,HInfo[i][XPos]+3,HInfo[i][YPos],HInfo[i][ZPos]);//Setting the players position to checkpoint position +3
  90. SetPlayerInterior(playerid,GetPVarInt(playerid,"PlayersInteriorHouse"));//Setting the players interior to the one we stored
  91. SetPlayerVirtualWorld(playerid,GetPVarInt(playerid,"PlayerVirtualWorldHouse"));//Setting the players virtual world to the one we stored.
  92. }
  93. }
  94. }
  95. return 1;
  96. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement