Advertisement
Sasino97

[ENGLISH]Sasinosoft Houses

Jul 3rd, 2011
937
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 28.93 KB | None | 0 0
  1. /*
  2. *        Sasi-Houses (Sasinosoft Houses), Simple House-Store System, Very Roleplaying.
  3. *
  4. *                                  AUTHOR: [GF]Sasino97
  5. */
  6.  
  7. #include <a_samp>                                                        //THANKS TO THE SA-MP TEAM
  8. #include <SII>                                                           //THANKS TO [DRuG]Slick FOR "Slick's INI Include (SII)"
  9.  
  10. #define FILTERSCRIPT
  11. #define INVALID_HOUSE_ID            -255                                 //Use a negative number here (Default -255)
  12.  
  13. #define MAX_HOUSES                  100                                  //Max houses
  14. #define MAX_BUSINESSES              100                                  //Max stores
  15. #define HOUSE_FILE                  "SasiHouses/Houses/HouseID%d.ini"    //If you want you can change the tree
  16. #define BIZ_FILE                    "SasiHouses/Stores/BizID%d.ini"      //If you want you can change the tree
  17. #define PRINT_HOUSES                                                     //This will print the log, (Write false or comment to disable)
  18. #define KEY_ENTER_PROPERTY          KEY_SUBMISSION                       //Use the key you want (Default Is Mouse Cen).
  19.  
  20. #define DIALOG_FORSALE_HOUSE        1500
  21. #define DIALOG_OTHERS_HOUSE         1501
  22. #define DIALOG_MY_HOUSE             1502
  23. #define DIALOG_SELL_HOUSE           1503
  24. #define DIALOG_FORSALE_STORE        1504
  25. #define DIALOG_OTHERS_STORE         1505
  26. #define DIALOG_MY_STORE             1506
  27. #define DIALOG_SELL_STORE           1507
  28. #define DIALOG_RENAME_STORE         1508
  29.  
  30. new HousePickup[MAX_HOUSES];
  31. new BizPickup[MAX_BUSINESSES];
  32.  
  33. enum HouseInfo
  34. {
  35.   Name[24],
  36.   Cost,
  37.   Sell,
  38.   Interior,
  39.   VirtualWorld,
  40.   Locked,
  41.   Float:InteriorX,
  42.   Float:InteriorY,
  43.   Float:InteriorZ,
  44.   Float:ExteriorX,
  45.   Float:ExteriorY,
  46.   Float:ExteriorZ,
  47. }
  48.  
  49. new hInfo[MAX_HOUSES][HouseInfo];
  50.  
  51. enum BusinessInfo
  52. {
  53.   bName[24],
  54.   bTitle[51],
  55.   bCost,
  56.   bSell,
  57.   bInterior,
  58.   bVirtualWorld,
  59.   bLocked,
  60.   Float:bInteriorX,
  61.   Float:bInteriorY,
  62.   Float:bInteriorZ,
  63.   Float:bExteriorX,
  64.   Float:bExteriorY,
  65.   Float:bExteriorZ,
  66. }
  67.  
  68. new bInfo[MAX_BUSINESSES][BusinessInfo];
  69.  
  70. public OnFilterScriptInit()
  71. {
  72.   print("\n-------------FILTERSCRIPT----------------- ");
  73.   print(" Sasinosoft Houses, Simple House/Store System");
  74.   print("          By [GF]Sasino97 Loaded.            ");
  75.   print("------------------------------------------\n ");
  76.  
  77.   //All Houses Here.
  78.  
  79.   //          ID,   extX,      extY,      extZ,     intX,    intY,       intZ,  price, sell, int,   vw
  80.   CreateHouse(0, 2140.7082, -1176.7008, 23.9921, 234.6087, 1187.8195, 1080.2578, 1000, 900,   3,    0);
  81.  
  82.   //All Stores Here.
  83.  
  84.   //             ID  Titolo Default     extX         extY      extZ     intX       intY       intz   buy    sell  int  vw
  85.   CreateBusiness(0,   "Ammu Nation"  ,2145.7082, -1176.7008, 23.9921, 285.8361, -39.0166, 1001.5156, 1500, 500,    1,   0);
  86.   return 1;
  87. }
  88.  
  89. public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
  90. {
  91.   switch(dialogid)
  92.   {
  93.     case DIALOG_FORSALE_HOUSE:
  94.     {
  95.       if(!response) return 1;
  96.       if(GetPlayerMoney(playerid) < hInfo[GetHouseID(playerid)][Cost]) return ShowNoMoneyMessage(playerid);
  97.       BuyHouse(playerid, GetHouseID(playerid));
  98.       return 1;
  99.     }
  100.     case DIALOG_FORSALE_STORE:
  101.     {
  102.       if(!response) return 1;
  103.       if(GetPlayerMoney(playerid) < bInfo[GetBizID(playerid)][bCost]) return ShowNoMoneyMessage(playerid);
  104.       BuyBusiness(playerid, GetBizID(playerid));
  105.       return 1;
  106.     }
  107.     case DIALOG_OTHERS_HOUSE:
  108.     {
  109.       if(!response) return 1;
  110.       if(hInfo[GetHouseID(playerid)][Locked] == 1) return ShowLockedHouseMessage(playerid);
  111.       EnterHouse(playerid, GetHouseID(playerid));
  112.       return 1;
  113.     }
  114.     case DIALOG_OTHERS_STORE:
  115.     {
  116.       if(!response) return 1;
  117.       if(bInfo[GetBizID(playerid)][bLocked] == 1) return ShowLockedStoreMessage(playerid);
  118.       EnterBusiness(playerid, GetBizID(playerid));
  119.       return 1;
  120.     }
  121.     case DIALOG_MY_HOUSE:
  122.     {
  123.       if(!response) return 1;
  124.       switch(listitem)
  125.       {
  126.         case 0:
  127.         {
  128.           if(hInfo[GetHouseID(playerid)][Locked] == 1) return ShowLockedHouseMessage(playerid);
  129.           EnterHouse(playerid, GetHouseID(playerid));
  130.           return 1;
  131.         }
  132.         case 1:
  133.         {
  134.           if(hInfo[GetHouseID(playerid)][Locked] == 1)
  135.           {
  136.             hInfo[GetHouseID(playerid)][Locked] = 0;
  137.             UnlockYourHouseMessage(playerid);
  138.           }
  139.           else
  140.           {
  141.             hInfo[GetHouseID(playerid)][Locked] = 1;
  142.             LockYourHouseMessage(playerid);
  143.           }
  144.           return 1;
  145.         }
  146.         case 2:
  147.         {
  148.           new string[101];
  149.           format(string,sizeof(string), "Do you really want to sell your house for $%d?", hInfo[GetHouseID(playerid)][Sell]);
  150.           ShowPlayerDialog(playerid, DIALOG_SELL_HOUSE, DIALOG_STYLE_MSGBOX, "{33AA33}COMMAND", string, "Yes", "No");
  151.           return 1;
  152.         }
  153.        
  154.       }
  155.       return 1;
  156.     }
  157.     case DIALOG_MY_STORE:
  158.     {
  159.       if(!response) return 1;
  160.       switch(listitem)
  161.       {
  162.         case 0:
  163.         {
  164.           if(bInfo[GetBizID(playerid)][bLocked] == 1) return ShowLockedStoreMessage(playerid);
  165.           EnterBusiness(playerid, GetBizID(playerid));
  166.           return 1;
  167.         }
  168.         case 1:
  169.         {
  170.           if(bInfo[GetBizID(playerid)][bLocked] == 1)
  171.           {
  172.             bInfo[GetBizID(playerid)][bLocked] = 0;
  173.             UnlockYourStoreMessage(playerid);
  174.           }
  175.           else
  176.           {
  177.             bInfo[GetBizID(playerid)][bLocked] = 1;
  178.             LockYourStoreMessage(playerid);
  179.           }
  180.           return 1;
  181.         }
  182.         case 2:
  183.         {
  184.           ShowPlayerDialog(playerid, DIALOG_RENAME_STORE,DIALOG_STYLE_INPUT, "Write a new name for your store","You can make colors using {RRGGBB} codes", "OK", "Cancel");
  185.           return 1;
  186.         }
  187.         case 3:
  188.         {
  189.           new string[256];
  190.           format(string,sizeof(string), "Do you really want to sell your store for $%d?", bInfo[GetBizID(playerid)][bSell]);
  191.           ShowPlayerDialog(playerid, DIALOG_SELL_STORE, DIALOG_STYLE_MSGBOX, "{33AA33}COMMAND", string, "Yes", "No");
  192.           return 1;
  193.         }
  194.  
  195.       }
  196.       return 1;
  197.     }
  198.     case DIALOG_SELL_HOUSE:
  199.     {
  200.       if(!response) return 1;
  201.       SellHouse(playerid, GetHouseID(playerid));
  202.       return 1;
  203.     }
  204.     case DIALOG_SELL_STORE:
  205.     {
  206.       if(!response) return 1;
  207.       SellBusiness(playerid, GetBizID(playerid));
  208.       return 1;
  209.     }
  210.     case DIALOG_RENAME_STORE:
  211.     {
  212.       if(!response) return 1;
  213.       if(strlen(inputtext) >= 51)
  214.       {
  215.         ShowPlayerDialog(playerid, 1499, DIALOG_STYLE_MSGBOX, "{FF0000}ERROR", "The max lenght is 50 characters", "OK", "");
  216.         return 1;
  217.       }
  218.       new string[256];
  219.       format(bInfo[GetBizID(playerid)][bTitle],51, inputtext);
  220.       format(string, 256, BIZ_FILE, GetBizID(playerid));
  221.       INI_Open(string);
  222.       INI_WriteString("Title",bInfo[GetBizID(playerid)][bTitle]);
  223.       INI_Save();
  224.       INI_Close();
  225.       return 1;
  226.     }
  227.   }
  228.   return 0;
  229. }
  230.  
  231. public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
  232. {
  233.   if(newkeys & KEY_ENTER_PROPERTY)
  234.   {
  235.     for(new i=0; i<MAX_HOUSES; i++)
  236.     {
  237.       if(IsPlayerNearPoint(2.0, playerid, hInfo[i][InteriorX], hInfo[i][InteriorY], hInfo[i][InteriorZ]))
  238.       {
  239.         ExitHouse(playerid, i);
  240.       }
  241.     }
  242.     for(new i=0; i<MAX_BUSINESSES; i++)
  243.     {
  244.       if(IsPlayerNearPoint(2.0, playerid, bInfo[i][bInteriorX], bInfo[i][bInteriorY], bInfo[i][bInteriorZ]))
  245.       {
  246.         ExitBusiness(playerid, i);
  247.       }
  248.     }
  249.     if(GetHouseID(playerid) != INVALID_HOUSE_ID)
  250.     {
  251.       OpenHouseDialog(playerid, GetHouseID(playerid));
  252.       return 1;
  253.     }
  254.     else if(GetBizID(playerid) != INVALID_HOUSE_ID)
  255.     {
  256.       OpenBusinessDialog(playerid, GetBizID(playerid));
  257.       return 1;
  258.     }
  259.    
  260.   }
  261.   return 1;
  262. }
  263.  
  264. /*
  265.                              CreateHouse
  266.  Function: Creates a house.
  267.  
  268.  To use in: OnFilterScriptInit
  269.  
  270.  Arguments:
  271.    -houseid: The ID of the house. Don't create 2 houses with the same ID.
  272.    -eX, eY, eZ: La posizione esteriore della casa (L'entrata)
  273.    -iX, iY, iZ: La posizione interiore della casa (L'uscita)
  274.    -BuyPrice: Il costo della casa
  275.    -SellPrice: La quantità che viene data al proprietario quando la rivende
  276.    -INT: L' ID dell'interior della casa
  277.    -VW: Il mondo virtuale della casa (Usa 2 VW diversi se vuoi avere 2 case con lo stesso interior)
  278.  
  279.  Returns:
  280.    -true(1): Quando la casa esisteva gia, ed è stata caricata
  281.    -null(-1): Quando la casa non esisteva ed è stata creata
  282.    -false(0): Quando è impossibile caricare o creare
  283. */
  284.  
  285. stock CreateHouse(houseid, Float:eX, Float:eY, Float:eZ, Float:iX, Float:iY, Float:iZ, BuyPrice, SellPrice, INT, VW)
  286. {
  287.   new housefile[51];
  288.   format(housefile, sizeof(housefile), HOUSE_FILE, houseid);
  289.   if(!INI_Exist(housefile)) //Se il file non esiste:
  290.   {
  291.     INI_Open(housefile);
  292.     format(hInfo[houseid][Name], 24, "ForSale");
  293.     INI_WriteString("Name", "ForSale");
  294.  
  295.     hInfo[houseid][Cost] = BuyPrice;
  296.     INI_WriteInt("Cost", BuyPrice);
  297.  
  298.     hInfo[houseid][Sell] = SellPrice;
  299.     INI_WriteInt("Sell", SellPrice);
  300.  
  301.     hInfo[houseid][Interior] = INT;
  302.     INI_WriteInt("Interior", INT);
  303.  
  304.     hInfo[houseid][VirtualWorld] = VW;
  305.     INI_WriteInt("VirtualWorld", VW);
  306.  
  307.     hInfo[houseid][Locked] = 1;
  308.     INI_WriteInt("Locked", 1);
  309.  
  310.     hInfo[houseid][InteriorX] = iX;
  311.     hInfo[houseid][InteriorY] = iY;
  312.     hInfo[houseid][InteriorZ] = iZ;
  313.     INI_WriteFloat("InteriorX", iX);
  314.     INI_WriteFloat("InteriorY", iY);
  315.     INI_WriteFloat("InteriorZ", iZ);
  316.  
  317.     hInfo[houseid][ExteriorX] = eX;
  318.     hInfo[houseid][ExteriorY] = eY;
  319.     hInfo[houseid][ExteriorZ] = eZ;
  320.     INI_WriteFloat("ExteriorX", eX);
  321.     INI_WriteFloat("ExteriorY", eY);
  322.     INI_WriteFloat("ExteriorZ", eZ);
  323.  
  324.     HousePickup[houseid] = CreatePickup(1273, 23, eX, eY, eZ);
  325.     Create3DTextLabel("Use mouse cen to open the menu", 0x33AA33AA, eX, eY, eZ+1, 20, 0, 1);
  326.     Create3DTextLabel("Use mouse cen to exit the house", 0x33AA33AA, iX, iY, iZ+1, 20, VW, 1);
  327.  
  328.     #if defined PRINT_HOUSES
  329.     print("------------Nuova Casa Creata------------");
  330.     printf("- Houseid: %d", houseid);
  331.     printf("- Costo: %d", BuyPrice);
  332.     printf("- Ricavo Vendita: %d", SellPrice);
  333.     printf("- Interior: %d", INT);
  334.     printf("- Virtual World: %d", VW);
  335.     print("-----------------------------------------");
  336.     #endif
  337.     INI_Save();
  338.     INI_Close();
  339.     return -1;
  340.   }
  341.   else if(INI_Exist(housefile))//altrimenti, se esiste il file
  342.   {
  343.     new destination[24];
  344.    
  345.     INI_Open(housefile);
  346.    
  347.     INI_ReadString(destination, "Name");
  348.     format(hInfo[houseid][Name], 24, destination);
  349.     hInfo[houseid][Locked] = INI_ReadInt("Locked");
  350.    
  351.     INI_Close();
  352.    
  353.     hInfo[houseid][Cost] = BuyPrice;
  354.     hInfo[houseid][Sell] = SellPrice;
  355.  
  356.     hInfo[houseid][Interior] = INT;
  357.     hInfo[houseid][VirtualWorld] = VW;
  358.    
  359.     hInfo[houseid][InteriorX] = iX;
  360.     hInfo[houseid][InteriorY] = iY;
  361.     hInfo[houseid][InteriorZ] = iZ;
  362.  
  363.     hInfo[houseid][ExteriorX] = eX;
  364.     hInfo[houseid][ExteriorY] = eY;
  365.     hInfo[houseid][ExteriorZ] = eZ;
  366.  
  367.     if(strcmp(hInfo[houseid][Name],"ForSale",true) == 0)
  368.     {
  369.       HousePickup[houseid] = CreatePickup(1273, 23, eX, eY, eZ);
  370.     }
  371.     else
  372.     {
  373.       HousePickup[houseid] = CreatePickup(1272, 23, eX, eY, eZ);
  374.     }
  375.     Create3DTextLabel("Use mouse cen to open the menu", 0x33AA33AA, eX, eY, eZ+1, 20, 0, 1);
  376.     Create3DTextLabel("Use mouse cen to exit the house", 0x33AA33AA, iX, iY, iZ+1, 20, VW, 1);
  377.     #if defined PRINT_HOUSES
  378.     print("------------Casa Esistente Caricata------------");
  379.     printf("- Houseid: %d", houseid);
  380.     printf("- Costo: %d", BuyPrice);
  381.     printf("- Ricavo Vendita: %d", SellPrice);
  382.     printf("- Interior: %d", INT);
  383.     printf("- Virtual World: %d", VW);
  384.     print("----------------------------------------------");
  385.     #endif
  386.     return 1;
  387.   }
  388.   print("E Impossibile Creare Una Casa. Controlla Di Avere Le Seguenti Cartelle In Scriptfiles:");
  389.   print("SasiHouses ------>");
  390.   print("           Houses");
  391.   print("           Stores");
  392.   return 0;
  393. }
  394.  
  395. /*
  396.                              CreateBusiness
  397.  Funzione: Crea Un Negozio.
  398.  
  399.  Da Usare Con: OnFilterScriptInit
  400.  
  401.  Parametri:
  402.    -bizid: L'ID del negozio. Non creare 2 negozi con lo stesso ID.
  403.    -defaultname: Il nome iniziale del negozio.
  404.    -eX, eY, eZ: La posizione esteriore del negozio (L'entrata)
  405.    -iX, iY, iZ: La posizione interiore del negozio (L'uscita)
  406.    -BuyPrice: Il costo del negozio
  407.    -SellPrice: La quantità che viene data al proprietario quando lo rivende
  408.    -INT: L'ID dell'interior del negozio
  409.    -VW: Il mondo virtuale del negozio (Usa 2 VW diversi se vuoi avere 2 negozi con lo stesso interior)
  410.  
  411.  Riporta:
  412.    -true(1): Quando il negozio esisteva gia, ed è stata caricata
  413.    -null(-1): Quando il negozio non esisteva ed è stata creata
  414.    -false(0): Quando è impossibile caricare o creare
  415. */
  416.  
  417. stock CreateBusiness(bizid, defaultname[51], Float:eX, Float:eY, Float:eZ, Float:iX, Float:iY, Float:iZ, BuyPrice, SellPrice, INT, VW)
  418. {
  419.   new bizfile[51];
  420.   format(bizfile, sizeof(bizfile), BIZ_FILE, bizid);
  421.   if(!INI_Exist(bizfile))
  422.   {
  423.     INI_Open(bizfile);
  424.     format(bInfo[bizid][bName], 24, "ForSale");
  425.     INI_WriteString("Owner", "ForSale");
  426.  
  427.     format(bInfo[bizid][bTitle], 51, defaultname);
  428.     INI_WriteString("Title", defaultname);
  429.  
  430.     bInfo[bizid][bCost] = BuyPrice;
  431.     INI_WriteInt("Cost", BuyPrice);
  432.  
  433.     bInfo[bizid][bSell] = SellPrice;
  434.     INI_WriteInt("Sell", SellPrice);
  435.  
  436.     bInfo[bizid][bInterior] = INT;
  437.     INI_WriteInt("Interior", INT);
  438.  
  439.     bInfo[bizid][bVirtualWorld] = VW;
  440.     INI_WriteInt("VirtualWorld", VW);
  441.  
  442.     bInfo[bizid][bLocked] = 1;
  443.     INI_WriteInt("Locked", 1);
  444.  
  445.     bInfo[bizid][bInteriorX] = iX;
  446.     bInfo[bizid][bInteriorY] = iY;
  447.     bInfo[bizid][bInteriorZ] = iZ;
  448.     INI_WriteFloat("bInteriorX", iX);
  449.     INI_WriteFloat("bInteriorY", iY);
  450.     INI_WriteFloat("bInteriorZ", iZ);
  451.  
  452.     bInfo[bizid][bExteriorX] = eX;
  453.     bInfo[bizid][bExteriorY] = eY;
  454.     bInfo[bizid][bExteriorZ] = eZ;
  455.     INI_WriteFloat("ExteriorX", eX);
  456.     INI_WriteFloat("ExteriorY", eY);
  457.     INI_WriteFloat("ExteriorZ", eZ);
  458.  
  459.     BizPickup[bizid] = CreatePickup(1318, 23, eX, eY, eZ);
  460.  
  461.     Create3DTextLabel("Use mouse cen to open the menu", 0x33AA33AA, eX, eY, eZ+1, 20, 0, 1);
  462.     Create3DTextLabel("Use mouse cen to exit the store", 0x33AA33AA, iX, iY, iZ+1, 20, VW, 1);
  463.  
  464.     #if defined PRINT_HOUSES
  465.     print("------------New Business Created------------");
  466.     printf("- Business ID: %d", bizid);
  467.     printf("- Buy Cost: %d", BuyPrice);
  468.     printf("- Sell Cost: %d", SellPrice);
  469.     printf("- Interior: %d", INT);
  470.     printf("- Virtual World: %d", VW);
  471.     print("--------------------------------------------");
  472.     #endif
  473.     INI_Save();
  474.     INI_Close();
  475.     return -1;
  476.   }
  477.   else if(INI_Exist(bizfile))
  478.   {
  479.     new destination[24];
  480.     new dest2[24];
  481.  
  482.     INI_Open(bizfile);
  483.  
  484.     INI_ReadString(destination, "Name");
  485.     INI_ReadString(dest2, "Title");
  486.     format(bInfo[bizid][bName], 24, destination);
  487.     format(bInfo[bizid][bTitle], 51, dest2);
  488.     bInfo[bizid][bLocked] = INI_ReadInt("Locked");
  489.  
  490.     INI_Close();
  491.  
  492.     bInfo[bizid][bCost] = BuyPrice;
  493.     bInfo[bizid][bSell] = SellPrice;
  494.  
  495.     bInfo[bizid][bInterior] = INT;
  496.     bInfo[bizid][bVirtualWorld] = VW;
  497.  
  498.     bInfo[bizid][bInteriorX] = iX;
  499.     bInfo[bizid][bInteriorY] = iY;
  500.     bInfo[bizid][bInteriorZ] = iZ;
  501.  
  502.     bInfo[bizid][bExteriorX] = eX;
  503.     bInfo[bizid][bExteriorY] = eY;
  504.     bInfo[bizid][bExteriorZ] = eZ;
  505.  
  506.     BizPickup[bizid] = CreatePickup(1318, 23, eX, eY, eZ);
  507.    
  508.     Create3DTextLabel("Use mouse cen to open the menu", 0x33AA33AA, eX, eY, eZ+1, 20, 0, 1);
  509.     Create3DTextLabel("Use mouse cen to exit the store", 0x33AA33AA, iX, iY, iZ+1, 20, VW, 1);
  510.    
  511.     #if defined PRINT_HOUSES
  512.     print("------------Business Loaded------------");
  513.     printf("- Business ID: %d", bizid);
  514.     printf("- Buy Cost: %d", BuyPrice);
  515.     printf("- Sell Cost: %d", SellPrice);
  516.     printf("- Interior: %d", INT);
  517.     printf("- Virtual World: %d", VW);
  518.     print("---------------------------------------");
  519.     #endif
  520.     return 1;
  521.   }
  522.   print("E Impossibile Creare Un Negozio. Controlla Di Avere Le Seguenti Cartelle In Scriptfiles:");
  523.   print("SasiHouses ------>");
  524.   print("           Houses");
  525.   print("           Stores");
  526.   return 0;
  527. }
  528.  
  529. /*
  530.                              OpenHouseDialog
  531.  Function: Shows the dialog.
  532.  
  533.  Parameters:
  534.    -playerid: The ID of the player.
  535.    -houseid: The ID of the house.
  536.  
  537.  Returns:
  538.    -true(1): When the house is for sale.
  539.    -null(-1): When the house is bought.
  540.    -false(0): When the house is bought and playerid is the owner.
  541. */
  542.  
  543. stock OpenHouseDialog(playerid, houseid)
  544. {
  545.   if(strcmp(hInfo[houseid][Name], "ForSale",true) == 0)
  546.   {
  547.     new string[180];
  548.     if(GetPlayerMoney(playerid) >= hInfo[houseid][Cost]) { format(string,sizeof(string),"{33AA33}Buy this house for $%d", hInfo[houseid][Cost]); }
  549.     else { format(string,sizeof(string),"{FF0000}Buy this house for $%d", hInfo[houseid][Cost]); }
  550.     ShowPlayerDialog(playerid, DIALOG_FORSALE_HOUSE, DIALOG_STYLE_LIST, "{33AA33}For Sale!", string, "OK", "Close");
  551.     return 1;
  552.   }
  553.   else
  554.   {
  555.     new string2[180];
  556.     new name[24];
  557.     GetPlayerName(playerid,name,sizeof(name));
  558.     if(strcmp(hInfo[houseid][Name], name, true) == 0)
  559.     {
  560.       ShowPlayerDialog(playerid, DIALOG_MY_HOUSE,DIALOG_STYLE_LIST, "{33AA33}Welcome back to your house", "{33AA33}Enter in your house\n{33AA33}Open/Close the door\n{33AA33}Sell your house", "OK", "Close");
  561.       return 0;
  562.     }
  563.     else
  564.     {
  565.       if(hInfo[houseid][Locked] == 1) { format(string2, sizeof(string2), "{FF0000}Enter this house");}
  566.       else { format(string2, sizeof(string2), "{33AA33}Enter this house"); }
  567.       ShowPlayerDialog(playerid, DIALOG_OTHERS_HOUSE,DIALOG_STYLE_LIST, "{33AA33}House", string2, "OK", "Chiudi");
  568.       return -1;
  569.     }
  570.  
  571.   }
  572.  
  573. }
  574.  
  575. /*
  576.                              OpenBusinessDialog
  577.  Function: Shows the dialog.
  578.  
  579.  Parameters:
  580.    -playerid: The ID of the player.
  581.    -bizid: The ID of the business.
  582.  
  583.  Returns:
  584.    -true(1): When the biz is for sale.
  585.    -null(-1): When the biz is bought.
  586.    -false(0): When the biz is bought and playerid is the owner.
  587. */
  588.  
  589. stock OpenBusinessDialog(playerid, bizid)
  590. {
  591.   if(strcmp(bInfo[bizid][bName], "ForSale",true) == 0)
  592.   {
  593.     new string[256];
  594.     new str2[180];
  595.     if(GetPlayerMoney(playerid) >= bInfo[bizid][bCost]) { format(string,sizeof(string),"{33AA33}Buy this store for $%d", bInfo[bizid][bCost]); }
  596.     else { format(string,sizeof(string),"{FF0000}Buy this store for $%d", bInfo[bizid][bCost]); }
  597.     format(str2,sizeof(str2),"{FF0000}\"%s\" {33AA33}Store For Sale!",bInfo[bizid][bTitle]);
  598.     ShowPlayerDialog(playerid, DIALOG_FORSALE_STORE, DIALOG_STYLE_LIST, str2, string, "OK", "Close");
  599.     return 1;
  600.   }
  601.   else
  602.   {
  603.     new string[180];
  604.     new string2[180];
  605.     new name[24];
  606.     GetPlayerName(playerid,name,sizeof(name));
  607.     if(strcmp(bInfo[bizid][bName], name, true) == 0)
  608.     {
  609.       new str[256];
  610.       format(str,sizeof(str), "{33AA33}Welcome back to {FF0000}\"%s\"", bInfo[bizid][bTitle]);
  611.       ShowPlayerDialog(playerid, DIALOG_MY_STORE, DIALOG_STYLE_LIST, str, "{33AA33}Enter your store\n{33AA33}Open/close the store\n{33AA33}Rename your store\n{33AA33}Sell your store", "OK", "Close");
  612.       return 0;
  613.     }
  614.     else
  615.     {
  616.       format(string, sizeof(string), "%s\n{33AA33}Proprietario: %s", bInfo[bizid][bTitle], bInfo[bizid][bName]);
  617.       if(bInfo[bizid][bLocked] == 1) { format(string2, sizeof(string2), "{FF0000}Enter this store");}
  618.       else { format(string2, sizeof(string2), "{33AA33}Enter this store"); }
  619.       ShowPlayerDialog(playerid, DIALOG_OTHERS_STORE, DIALOG_STYLE_LIST, string, string2, "OK", "Close");
  620.       return -1;
  621.     }
  622.  
  623.   }
  624.  
  625. }
  626.  
  627. /*
  628.                              GetHouseID
  629.  Function: Gets the house ID of the player.
  630.  
  631.  Parameters:
  632.    -playerid: The ID of the player.
  633.  
  634.  Returns:
  635.    -houseid(): When playerid is near to any house pickup
  636.    -invalid(-255): When playerid isn't near to any house
  637.  
  638. */
  639.  
  640. stock GetHouseID(playerid)
  641. {
  642.   for(new i=0; i<MAX_HOUSES; i++)
  643.   {
  644.     if(IsPlayerNearPoint(2.0, playerid, hInfo[i][ExteriorX], hInfo[i][ExteriorY], hInfo[i][ExteriorZ]))
  645.     {
  646.       return i;
  647.     }
  648.   }
  649.   return INVALID_HOUSE_ID;
  650. }
  651.  
  652. /*
  653.                              GetBizID
  654.  Function: Gets the biz ID of the player.
  655.  
  656.  Parameters:
  657.    -playerid: The ID of the player.
  658.  
  659.  Returns:
  660.    -bizid): When playerid is near to any biz pickup
  661.    -invalid(-255): When playerid isn't near to any biz
  662.  
  663. */
  664.  
  665. stock GetBizID(playerid)
  666. {
  667.   for(new i=0; i<MAX_HOUSES; i++)
  668.   {
  669.     if(IsPlayerNearPoint(2.0, playerid, bInfo[i][bExteriorX], bInfo[i][bExteriorY], bInfo[i][bExteriorZ]))
  670.     {
  671.       return i;
  672.     }
  673.   }
  674.   return INVALID_HOUSE_ID;
  675. }
  676.  
  677. /*
  678.                              IsPlayerNearPoint
  679.  Function: Returns wheter playerid is near a point
  680.  
  681.  Parameters:
  682.    -radi: The radius of the sphere.
  683.    -playerid: The ID of the player.
  684.    -x, y, z: The coordinates of the second point
  685.  
  686.  Returns:
  687.    -true: When playerid is connected and near x,y,z
  688.    -false: When playerid is connected but isn't near x,y,z
  689.    -null: When playerid isn't connected
  690. */
  691.  
  692. stock IsPlayerNearPoint(Float:radi, playerid, Float:x, Float:y, Float:z)
  693. {
  694.   if(IsPlayerConnected(playerid))
  695.   {
  696.       new Float:oldposx, Float:oldposy, Float:oldposz;
  697.       new Float:tempposx, Float:tempposy, Float:tempposz;
  698.       GetPlayerPos(playerid, oldposx, oldposy, oldposz);
  699.       tempposx = (oldposx -x);
  700.       tempposy = (oldposy -y);
  701.       tempposz = (oldposz -z);
  702.       if (((tempposx < radi) && (tempposx > -radi)) && ((tempposy < radi) && (tempposy > -radi)) && ((tempposz < radi) && (tempposz > -radi)))
  703.       {
  704.         return 1;
  705.       }
  706.       return 0;
  707.   }
  708.   return -1;
  709. }
  710.  
  711. /*
  712.                              BuyHouse
  713.  Function: The player buys the house
  714.  
  715.  Parameters:
  716.    -playerid: The ID of the player.
  717.    -houseid: The ID of the house.
  718.  
  719.  Returns:
  720.    -true(1): When bought successfully
  721.    -false(0): When an error has occurred
  722. */
  723.  
  724. stock BuyHouse(playerid, houseid)
  725. {
  726.   new string2[256];
  727.   new name[24];
  728.   GetPlayerName(playerid, name, sizeof(name));
  729.   #if defined PRINT_HOUSES
  730.     printf("%s Bought House ID %d", name, houseid);
  731.   #endif
  732.   GivePlayerMoney(playerid, -hInfo[houseid][Cost]);
  733.   format(string2,sizeof(string2), HOUSE_FILE, houseid);
  734.   INI_Open(string2);
  735.   INI_WriteString("Name", name);
  736.   INI_WriteInt("Locked", 0);
  737.   INI_Save();
  738.   INI_Close();
  739.   hInfo[houseid][Name] = name;
  740.   hInfo[houseid][Locked] = 0;
  741.   DestroyPickup(HousePickup[houseid]);
  742.   HousePickup[houseid] = CreatePickup(1272, 23, hInfo[houseid][ExteriorX], hInfo[houseid][ExteriorY], hInfo[houseid][ExteriorZ]);
  743.   ShowBoughtHouseMessage(playerid);
  744.   return 1;
  745. }
  746.  
  747. /*
  748.                              BuyBusiness
  749.  Function: The player buys the biz
  750.  
  751.  Parameters:
  752.    -playerid: The ID of the player.
  753.    -bizid: The ID of the biz.
  754.  
  755.  Returns:
  756.    -true(1): When bought successfully
  757.    -false(0): When an error has occurred
  758. */
  759.  
  760. stock BuyBusiness(playerid, bizid)
  761. {
  762.   new string2[256];
  763.   new name[24];
  764.   GetPlayerName(playerid, name, sizeof(name));
  765.   #if defined PRINT_HOUSES
  766.     printf("%s Bought Store ID %d", name, bizid);
  767.   #endif
  768.   GivePlayerMoney(playerid, -bInfo[bizid][bCost]);
  769.   format(string2,sizeof(string2), BIZ_FILE, bizid);
  770.   INI_Open(string2);
  771.   INI_WriteString("Name", name);
  772.   INI_WriteInt("Locked", 0);
  773.   INI_Save();
  774.   INI_Close();
  775.   bInfo[bizid][bName] = name;
  776.   bInfo[bizid][bLocked] = 0;
  777.   ShowBoughtStoreMessage(playerid);
  778.   return 1;
  779. }
  780.  
  781. /*
  782.                              SellHouse
  783.  Function: The player sells the house
  784.  
  785.  Parameters:
  786.    -playerid: The ID of the player.
  787.    -houseid: The ID of the house.
  788.  
  789.  Returns:
  790.    -true(1): When sold successfully
  791.    -false(0): When an error has occurred
  792. */
  793.  
  794. stock SellHouse(playerid, houseid)
  795. {
  796.   new string[256];
  797.   new name[24];
  798.   GetPlayerName(playerid, name, sizeof(name));
  799.   format(string,sizeof(string),HOUSE_FILE, houseid);
  800.   INI_Open(string);
  801.   INI_WriteString("Name","ForSale");
  802.   INI_WriteInt("Locked", 1);
  803.   INI_Save();
  804.   INI_Close();
  805.   #if defined PRINT_HOUSES
  806.     printf("%s Sold House ID %d", name, houseid);
  807.   #endif
  808.   GivePlayerMoney(playerid, hInfo[houseid][Sell]);
  809.   hInfo[houseid][Locked] = 1;
  810.   format(hInfo[houseid][Name], 255, "ForSale");
  811.   DestroyPickup(HousePickup[houseid]);
  812.   HousePickup[houseid] = CreatePickup(1273, 23, hInfo[houseid][ExteriorX], hInfo[houseid][ExteriorY], hInfo[houseid][ExteriorZ]);
  813.   ShowSoldHouseMessage(playerid);
  814.   return 1;
  815. }
  816.  
  817. /*
  818.                              SellBusiness
  819.  Function: The player sells the business
  820.  
  821.  Parameters:
  822.    -playerid: The ID of the player.
  823.    -bizid: The ID of the biz.
  824.  
  825.  Returns:
  826.    -true(1): When sold successfully
  827.    -false(0): When an error has occurred
  828. */
  829.  
  830. stock SellBusiness(playerid, bizid)
  831. {
  832.   new string[256];
  833.   new name[24];
  834.   GetPlayerName(playerid, name, sizeof(name));
  835.   format(string,sizeof(string),BIZ_FILE, bizid);
  836.   INI_Open(string);
  837.   INI_WriteString("Name","ForSale");
  838.   INI_WriteInt("Locked", 1);
  839.   INI_Save();
  840.   INI_Close();
  841.   #if defined PRINT_HOUSES
  842.     printf("%s Sold Store ID %d", name, bizid);
  843.   #endif
  844.   GivePlayerMoney(playerid, bInfo[bizid][bSell]);
  845.   bInfo[bizid][bLocked] = 1;
  846.   format(bInfo[bizid][bName], 255, "ForSale");
  847.   ShowSoldStoreMessage(playerid);
  848.   return 1;
  849. }
  850.  
  851. /*
  852.                              EnterHouse
  853.  Function: The player enters the house
  854.  
  855.  Parameters:
  856.    -playerid: The ID of the player.
  857.    -houseid: The ID of the house.
  858.  
  859.  Returns:
  860.    -true(1): Everyway
  861. */
  862.  
  863. stock EnterHouse(playerid, houseid)
  864. {
  865.   SetPlayerPos(playerid, hInfo[houseid][InteriorX], hInfo[houseid][InteriorY], hInfo[houseid][InteriorZ]);
  866.   SetPlayerInterior(playerid, hInfo[houseid][Interior]);
  867.   SetPlayerVirtualWorld(playerid, hInfo[houseid][VirtualWorld]);
  868.   return 1;
  869. }
  870.  
  871. /*
  872.                              EnterBusiness
  873.  Function: The player enters the business
  874.  
  875.  Parameters:
  876.    -playerid: The ID of the player.
  877.    -bizid: The ID of the biz.
  878.  
  879.  Returns:
  880.    -true(1): Everyway
  881. */
  882.  
  883. stock EnterBusiness(playerid, bizid)
  884. {
  885.   SetPlayerPos(playerid, bInfo[bizid][bInteriorX], bInfo[bizid][bInteriorY], bInfo[bizid][bInteriorZ]);
  886.   SetPlayerInterior(playerid, bInfo[bizid][bInterior]);
  887.   SetPlayerVirtualWorld(playerid, bInfo[bizid][bVirtualWorld]);
  888.   new string[180];
  889.   format(string,sizeof(string),"Welcome to %s!", bInfo[bizid][bTitle]);
  890.   ShowPlayerDialog(playerid,1499,DIALOG_STYLE_MSGBOX, string, "", "OK", "");
  891.   return 1;
  892. }
  893.  
  894. /*
  895.                              ExitHouse
  896.  Function: The player exits the house
  897.  
  898.  Parameters:
  899.    -playerid: The ID of the player.
  900.    -houseid: The ID of the house.
  901.  
  902.  Returns:
  903.    -true(1): Everyway
  904. */
  905.  
  906. stock ExitHouse(playerid, houseid)
  907. {
  908.   SetPlayerPos(playerid, hInfo[houseid][ExteriorX], hInfo[houseid][ExteriorY], hInfo[houseid][ExteriorZ]);
  909.   SetPlayerInterior(playerid, 0);
  910.   SetPlayerVirtualWorld(playerid, 0);
  911.   return 1;
  912. }
  913.  
  914. /*
  915.                              ExitBusiness
  916.  Function: The player exits the business
  917.  
  918.  Parameters:
  919.    -playerid: The ID of the player.
  920.    -bizid: The ID of the biz.
  921.  
  922.  Returns:
  923.    -true(1): Everyway
  924. */
  925.  
  926. stock ExitBusiness(playerid, bizid)
  927. {
  928.   SetPlayerPos(playerid, bInfo[bizid][bExteriorX], bInfo[bizid][bExteriorY], bInfo[bizid][bExteriorZ]);
  929.   SetPlayerInterior(playerid, 0);
  930.   SetPlayerVirtualWorld(playerid, 0);
  931.   return 1;
  932. }
  933.  
  934. //MESSAGES
  935.  
  936. stock ShowLockedHouseMessage(playerid)
  937. {
  938.   ShowPlayerDialog(playerid, 1499, DIALOG_STYLE_MSGBOX, "{FF0000}ERROR","This house is locked!","OK","");
  939.   return 1;
  940. }
  941.  
  942. stock ShowLockedStoreMessage(playerid)
  943. {
  944.   ShowPlayerDialog(playerid, 1499, DIALOG_STYLE_MSGBOX, "{FF0000}ERROR","Sorry, this store is closed. Come later.","OK","");
  945.   return 1;
  946. }
  947.  
  948. stock ShowNoMoneyMessage(playerid)
  949. {
  950.   ShowPlayerDialog(playerid, 1499, DIALOG_STYLE_MSGBOX, "{FF0000}ERROR","You don't have enough money!","OK","");
  951.   return 1;
  952. }
  953.  
  954. stock ShowSoldHouseMessage(playerid)
  955. {
  956.   new string[51];
  957.   format(string,sizeof(string),"House sold for $%d!", hInfo[GetHouseID(playerid)][Sell]);
  958.   ShowPlayerDialog(playerid, 1499, DIALOG_STYLE_MSGBOX, "{33AA33}COMMAND", string, "OK", "");
  959.   return 1;
  960. }
  961.  
  962. stock ShowSoldStoreMessage(playerid)
  963. {
  964.   new string[51];
  965.   format(string,sizeof(string),"Store sold for $%d!", hInfo[GetHouseID(playerid)][Sell]);
  966.   ShowPlayerDialog(playerid, 1499, DIALOG_STYLE_MSGBOX, "{33AA33}COMMAND", string, "OK", "");
  967.   return 1;
  968. }
  969.  
  970. stock ShowBoughtHouseMessage(playerid)
  971. {
  972.   new string[51];
  973.   format(string,sizeof(string),"House bought for $%d!", hInfo[GetHouseID(playerid)][Cost]);
  974.   ShowPlayerDialog(playerid, 1499, DIALOG_STYLE_MSGBOX, "{33AA33}COMMAND", string, "OK", "");
  975.   return 1;
  976. }
  977.  
  978. stock ShowBoughtStoreMessage(playerid)
  979. {
  980.   new string[51];
  981.   format(string,sizeof(string),"Store bought for $%d!", hInfo[GetHouseID(playerid)][Cost]);
  982.   ShowPlayerDialog(playerid, 1499, DIALOG_STYLE_MSGBOX, "{33AA33}COMMAND", string, "OK", "");
  983.   return 1;
  984. }
  985.  
  986. stock LockYourHouseMessage(playerid)
  987. {
  988.   ShowPlayerDialog(playerid, 1499, DIALOG_STYLE_MSGBOX, "{33AA33}COMMAND","House closed!","OK","");
  989.   return 1;
  990. }
  991.  
  992. stock LockYourStoreMessage(playerid)
  993. {
  994.   ShowPlayerDialog(playerid, 1499, DIALOG_STYLE_MSGBOX, "{33AA33}COMMAND","Store closed!","OK","");
  995.   return 1;
  996. }
  997.  
  998. stock UnlockYourHouseMessage(playerid)
  999. {
  1000.   ShowPlayerDialog(playerid, 1499, DIALOG_STYLE_MSGBOX, "{33AA33}COMMAND","House open!","OK","");
  1001.   return 1;
  1002. }
  1003.  
  1004. stock UnlockYourStoreMessage(playerid)
  1005. {
  1006.   ShowPlayerDialog(playerid, 1499, DIALOG_STYLE_MSGBOX, "{33AA33}COMMAND","Store open!","OK","");
  1007.   return 1;
  1008. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement