Advertisement
Stefantjuh97

House

Nov 28th, 2012
152
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 9.24 KB | None | 0 0
  1. // on top
  2.  
  3. #define                 MAX_HOUSES                          1000
  4.  
  5. new SpawnedHouses
  6.  
  7. enum HouseData
  8. {
  9.     hInteriorID,
  10.     Float: hInteriorX,
  11.     Float: hInteriorY,
  12.     Float: hInteriorZ,
  13.     HousePrice,
  14.     hExteriorID,
  15.     Float: hExteriorX,
  16.     Float: hExteriorY,
  17.     HouseCocaine,
  18.     HousePot,
  19.     HouseMaterials,
  20.     WeaponSlot1,
  21.     WeaponSlot2,
  22.     WeaponSlot3,
  23.     WeaponSlot1Ammo,
  24.     WeaponSlot2Ammo,
  25.     WeaponSlot3Ammo,
  26.     Float: hExteriorZ,
  27.     VaultMoney,
  28.     HPickupID,
  29.     hOwner[255],
  30.     LockStatus,
  31. };
  32.  
  33. enum PlayerStatistics
  34. {
  35.     HouseInterior,
  36.     HouseExterior,
  37.     House,
  38.     Float: hExtX,
  39.     Float: hExtY,
  40.     Float: hExtZ,
  41.     Float: hIntX,
  42.     Float: hIntY,
  43.     Float: hIntZ,
  44.     hIntID,
  45.     hExtID,
  46.     InHouse,
  47. };
  48.  
  49.     new Houses[MAX_HOUSES][HouseData];
  50.     new Player[MAX_PLAYERS][PlayerStatistics];
  51. // on gamemodeinit
  52.     InitHouses();
  53.  
  54. stock InitHouses()
  55. {
  56.     new FileName[128];
  57.     for(new i = 0; i < MAX_HOUSES; i++)
  58.     {
  59.         format(FileName, sizeof(FileName), "Houses/House_%d.ini", i);
  60.         if(fexist(FileName))
  61.         {
  62.             Houses[i][hInteriorID] = dini_Int(FileName, "InteriorID");
  63.             Houses[i][hInteriorX] = dini_Float(FileName, "InteriorX");
  64.             Houses[i][hInteriorY] = dini_Float(FileName, "InteriorY");
  65.             Houses[i][hInteriorZ] = dini_Float(FileName, "InteriorZ");
  66.            
  67.             Houses[i][HousePrice] = dini_Int(FileName, "HousePrice");
  68.            
  69.             Houses[i][hExteriorID] = dini_Int(FileName, "ExteriorID");
  70.             Houses[i][hExteriorX] = dini_Float(FileName, "ExteriorX");
  71.             Houses[i][hExteriorY] = dini_Float(FileName, "ExteriorY");
  72.             Houses[i][hExteriorZ] = dini_Float(FileName, "ExteriorZ");
  73.  
  74.             Houses[i][VaultMoney] = dini_Int(FileName, "VaultMoney");
  75.             Houses[i][HouseCocaine] = dini_Int(FileName, "HouseCocaine");
  76.             Houses[i][HousePot] = dini_Int(FileName, "HousePot");
  77.             Houses[i][HouseMaterials] = dini_Int(FileName, "HouseMaterials");
  78.            
  79.             Houses[i][hOwner] = dini_Get(FileName, "Owner");
  80.            
  81.             Houses[i][LockStatus] = dini_Int(FileName, "LockStatus");
  82.            
  83.             Houses[i][WeaponSlot1] = dini_Int(FileName, "WeaponSlot1");
  84.             Houses[i][WeaponSlot2] = dini_Int(FileName, "WeaponSlot2");
  85.             Houses[i][WeaponSlot3] = dini_Int(FileName, "WeaponSlot3");
  86.            
  87.             if(strcmp(Houses[i][hOwner], "Nobody", true) == 0)
  88.             {
  89.                 Houses[i][LockStatus] = 0;
  90.                 Houses[i][HPickupID] = CreateDynamicPickup(1273, 23, Houses[i][hExteriorX], Houses[i][hExteriorY], Houses[i][hExteriorZ], 0, -1, -1, 150.0);
  91.             }
  92.             else
  93.             {
  94.                 Houses[i][HPickupID] = CreateDynamicPickup(1318, 23, Houses[i][hExteriorX], Houses[i][hExteriorY], Houses[i][hExteriorZ], 0, -1, -1, 150.0);
  95.             }
  96.  
  97.             printf("[system] House %d spawned.", i);
  98.             SpawnedHouses++;
  99.        }
  100.     }
  101.     return 1;
  102. }
  103.  
  104. command(createhouse, playerid, params[])
  105. {
  106.     new Usage[128], string[128];
  107.     if(sscanf(params, "z", Usage))
  108.     {
  109.         if(Player[playerid][AdminLevel] >= 6)
  110.         {
  111.             SendClientMessage(playerid, WHITE, "SYNTAX: /createhouse [usage]");
  112.             SendClientMessage(playerid, GREY, "Usage: Interior, Exterior or Complete.");
  113.         }
  114.     }
  115.     else
  116.     {
  117.         if(Player[playerid][AdminLevel] >= 6)
  118.         {
  119.             if(strcmp(Usage, "exterior", true) == 0)
  120.             {
  121.                 Player[playerid][HouseExterior]++;
  122.                 Player[playerid][hExtID] = GetPlayerInterior(playerid);
  123.                 GetPlayerPos(playerid, Player[playerid][hExtX], Player[playerid][hExtY], Player[playerid][hExtZ]);
  124.                 format(string, sizeof(string), "Exterior set! (X: %f, Y: %f, Z: %f).", Player[playerid][hExtX], Player[playerid][hExtY], Player[playerid][hExtZ]);
  125.                 SendClientMessage(playerid, WHITE, string);
  126.             }
  127.             if(strcmp(Usage, "interior", true) == 0)
  128.             {
  129.                 Player[playerid][HouseInterior]++;
  130.                 Player[playerid][hIntID] = GetPlayerInterior(playerid);
  131.                 GetPlayerPos(playerid, Player[playerid][hIntX], Player[playerid][hIntY], Player[playerid][hIntZ]);
  132.                 format(string, sizeof(string), "Interior set! (X: %f, Y: %f, Z: %f).", Player[playerid][hIntX], Player[playerid][hIntY], Player[playerid][hIntZ]);
  133.                 SendClientMessage(playerid, WHITE, string);
  134.             }
  135.             if(strcmp(Usage, "complete", true) == 0)
  136.             {
  137.                 if(Player[playerid][HouseInterior] > 0 || Player[playerid][HouseExterior] > 0)
  138.                 {
  139.                     new NewHouseID = SpawnedHouses+1;
  140.  
  141.                     if(NewHouseID >= MAX_HOUSES)
  142.                     {
  143.                         SendClientMessage(playerid, WHITE, "Too many houses are currently spawned!");
  144.                     }
  145.                     else
  146.                     {
  147.                         format(string, sizeof(string), "Houses/House_%d.ini", NewHouseID);
  148.  
  149.                         if(!fexist(string))
  150.                         {
  151.                             Houses[NewHouseID][hInteriorID] = Player[playerid][hIntID];
  152.                             Houses[NewHouseID][hExteriorID] = Player[playerid][hExtID];
  153.                             Houses[NewHouseID][hInteriorX] = Player[playerid][hIntX];
  154.                             Houses[NewHouseID][hInteriorY] = Player[playerid][hIntY];
  155.                             Houses[NewHouseID][hInteriorZ] = Player[playerid][hIntZ];
  156.                             Houses[NewHouseID][hExteriorX] = Player[playerid][hExtX];
  157.                             Houses[NewHouseID][hExteriorY] = Player[playerid][hExtY];
  158.                             Houses[NewHouseID][hExteriorZ] = Player[playerid][hExtZ];
  159.                             format(Houses[NewHouseID][hOwner], 255, "Nobody");
  160.                             Houses[NewHouseID][LockStatus] = 0;
  161.                             Houses[NewHouseID][HPickupID] = CreateDynamicPickup(1273, 23, Houses[NewHouseID][hExteriorX], Houses[NewHouseID][hExteriorY], Houses[NewHouseID][hExteriorZ], 0, -1, -1, 150.0);
  162.  
  163.                             dini_Create(string);
  164.                             dini_IntSet(string, "InteriorID", Houses[NewHouseID][hInteriorID]);
  165.                             dini_FloatSet(string, "InteriorX", Houses[NewHouseID][hInteriorX]);
  166.                             dini_FloatSet(string, "InteriorY", Houses[NewHouseID][hInteriorY]);
  167.                             dini_FloatSet(string, "InteriorZ", Houses[NewHouseID][hInteriorZ]);
  168.  
  169.                             dini_IntSet(string, "HousePrice", 0);
  170.  
  171.                             dini_IntSet(string, "ExteriorID", 0);
  172.                             dini_FloatSet(string, "ExteriorX", Houses[NewHouseID][hExteriorX]);
  173.                             dini_FloatSet(string, "ExteriorY", Houses[NewHouseID][hExteriorY]);
  174.                             dini_FloatSet(string, "ExteriorZ", Houses[NewHouseID][hExteriorZ]);
  175.  
  176.                             dini_IntSet(string, "VaultMoney", -1);
  177.                            
  178.                             dini_IntSet(string, "HouseCocaine", -1);
  179.                             dini_IntSet(string, "HousePot", -1);
  180.                             dini_IntSet(string, "HouseMaterials", -1);
  181.  
  182.                             dini_Set(string, "Owner", "Nobody");
  183.  
  184.                             dini_IntSet(string, "LockStatus", Houses[NewHouseID][LockStatus]);
  185.  
  186.                             Player[playerid][HouseExterior]--;
  187.                             Player[playerid][HouseInterior]--;
  188.  
  189.                             SpawnedHouses++;
  190.                             SendClientMessage(playerid, NICESKY, "Successfully created house!");
  191.                             SetPlayerInterior(playerid, Houses[NewHouseID][hExteriorID]);
  192.                             SetPlayerPos(playerid, Houses[NewHouseID][hExteriorX], Houses[NewHouseID][hExteriorY], Houses[NewHouseID][hExteriorZ]);
  193.                         }
  194.                         else
  195.                         {
  196.                             SendClientMessage(playerid, WHITE, "Error: File already exists!");
  197.                         }
  198.                     }
  199.                 }
  200.                 else
  201.                 {
  202.                     SendClientMessage(playerid, WHITE, "You must select an exterior and an interior first!");
  203.                 }
  204.             }
  205.         }
  206.     }
  207.     return 1;
  208. }
  209.  
  210. command(buyhouse, playerid, params[])
  211. {
  212.     #pragma unused params
  213.     new string[128];
  214.     if(Player[playerid][House] == 0)
  215.     {
  216.         for(new h = 0; h < sizeof(Houses); h++)
  217.         {
  218.             if(IsPlayerInRangeOfPoint(playerid, 5, Houses[h][hExteriorX], Houses[h][hExteriorY], Houses[h][hExteriorZ]))
  219.             {
  220.                 if(strcmp(Houses[h][hOwner], "Nobody", true) == 0)
  221.                 {
  222.                     if(Houses[h][HousePrice] == -1)
  223.                     {
  224.                         SendClientMessage(playerid, WHITE, "This house isn't purchasable.");
  225.                     }
  226.                     else
  227.                     {
  228.                         if(Player[playerid][Money] >= Houses[h][HousePrice])
  229.                         {
  230.                             Player[playerid][Money] -= Houses[h][HousePrice];
  231.                             format(Houses[h][hOwner], 128, "%s", GetName(playerid));
  232.                             format(string, sizeof(string), "Congratulations! You are now the owner of this property (House %d)", h);
  233.                             SendClientMessage(playerid, ANNOUNCEMENT, string);
  234.                             Player[playerid][House] = h;
  235.                             DestroyDynamicPickup(Houses[h][HPickupID]);
  236.                             Houses[h][HPickupID] = CreateDynamicPickup(1318, 23, Houses[h][hExteriorX], Houses[h][hExteriorY], Houses[h][hExteriorZ], 0, -1, -1, 150.0);
  237.                             SaveHouse(h);
  238.                             SendClientMessage(playerid, WHITE, "By purchasing a house, you've unlocked a bunch of new commands; use /help to find them out!");
  239.                         }
  240.                         else
  241.                         {
  242.                             SendClientMessage(playerid, WHITE, "You do not have enough money to purchase this house.");
  243.                         }
  244.                     }
  245.                 }
  246.                 else
  247.                 {
  248.                     SendClientMessage(playerid, WHITE, "Sorry, this house is not available!");
  249.                 }
  250.             }
  251.         }
  252.     }
  253.     else
  254.     {
  255.         SendClientMessage(playerid, WHITE, "You already have a house, type /abandonhouse.");
  256.     }
  257.     return 1;
  258. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement