Advertisement
Sasino97

[ENGLISH]Sasinosoft Houses 2.2 (Store Sell Bug Fixed)

Jan 24th, 2013
2,634
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 56.82 KB | None | 0 0
  1. /*
  2.                                      ___                                                 ___  _  
  3.                                     (  _`\               _                             /'___)( )_
  4.                                     | (_(_)   _ _   ___ (_)  ___     _     ___    _   | (__  | ,_)
  5.                                     `\__ \  /'_` )/',__)| |/' _ `\ /'_`\ /',__) /'_`\ | ,__) | |  
  6.                                     ( )_) |( (_| |\__, \| || ( ) |( (_) )\__, \( (_) )| |    | |_
  7.                                     `\____)`\__,_)(____/(_)(_) (_)`\___/'(____/`\___/'(_)    `\__)
  8.                                    
  9.                                     ( ) ( )                                     /'__`\    /' _`\
  10.                                     | |_| |   _    _   _   ___    __    ___    (_)  ) )   | ( ) |
  11.                                     |  _  | /'_`\ ( ) ( )/',__) /'__`\/',__)      /' /    | | | |
  12.                                     | | | |( (_) )| (_) |\__, \(  ___/\__, \    /' /( ) _ | (_) |
  13.                                     (_) (_)`\___/'`\___/'(____/`\____)(____/   (_____/'(_)`\___/'
  14.                                                                                                  
  15. */
  16. // Sasinosoft Houses 2.0 - By Sasino97 - December 2012 - January 2013
  17. // Totally rewritten from scratch
  18. // This filterscript only works for SA-MP Server 0.3e or higher
  19.  
  20. /*
  21.                                                             PLACE THIS IN YOUR GAMEMODE:
  22.    
  23.            
  24. #define BOX_STYLE_CMD "{33AA33}COMMAND"
  25. #define BOX_STYLE_ERROR "{FF0000}ERROR"
  26. #define BOX_STYLE_WARNING "{FF8000}WARNING"
  27.  
  28. stock CreateHouse(Float:eX, Float:eY, Float:eZ, Float:iX, Float:iY, Float:iZ, price, interior, exterior = 0, virtualWorld = 1)
  29. {
  30.     return CallRemoteFunction("FS_CreateHouse", "ffffffiiii", eX, eY, eZ, iX, iY, iZ, price, interior, exterior, virtualWorld);
  31. }
  32. stock CreateBusiness(title[MAX_PLAYER_NAME], earning, Float:eX, Float:eY, Float:eZ, Float:iX, Float:iY, Float:iZ, price, interior, exterior = 0, virtualWorld = 1, iconmarker = 37, itemlist[1024] = "_")
  33. {
  34.     return CallRemoteFunction("FS_CreateBusiness", "siffffffiiiiis", title, earning, eX, eY, eZ, iX, iY, iZ, price, interior, exterior, virtualWorld, iconmarker, itemlist);
  35. }
  36. stock GiveBusinessMoney(shopid, money) { return CallRemoteFunction("FS_GiveBusinessMoney", "ii", shopid, money); }
  37. stock GetBusinessMoney(shopid) { return CallRemoteFunction("FS_GetBusinessMoney", "i", shopid); }
  38. stock GiveBusinessGoods(shopid, goods) { return CallRemoteFunction("FS_GiveBusinessGoods", "ii", shopid, goods); }
  39. stock GetBusinessGoods(shopid) { return CallRemoteFunction("FS_GetBusinessGoods", "i", shopid); }
  40. stock MsgBox(playerid, style[], text[]) { return CallRemoteFunction("FS_MsgBox", "iss", playerid, style, text); }
  41.  
  42. forward OnPlayerBuyItem(playerid, shopid, itemid);
  43. public OnPlayerBuyItem(playerid, shopid, itemid)
  44. {
  45.     // Put here code
  46.     return 1;
  47. }
  48.  
  49. */
  50.  
  51. #include <a_samp>
  52. #include <SII> // NOTICE: Make sure that INI_MAX_LINES in SII.inc is at least 512 (By default it's 256) otherwise not all of the furniture will be saved. If you don't want to, then decrease the furniture limit to 30.
  53. #include <streamer>
  54.  
  55. #define FILTERSCRIPT
  56.  
  57. #if !defined EditObject
  58. #error "This filterscript only works for SA-MP Server 0.3e or higher. Please download the lastest SA-MP Server package."
  59. #endif
  60.  
  61. // Main Settings
  62. // Warning: changing any of these and then recompling the code could result in bugs if there are already created houses or businesses. Change them before using it in your game.
  63. #define MAX_HOUSES 50 // Set to whatever you want (default = 50). A big value could cause long looping times.
  64. #define MAX_SHOPS 50 // Set to whatever you want (default = 50). A big value could cause long looping times.
  65. #define MAX_TITLE 20 // The max length of the title of a shop
  66. #define MAX_TITLE_STR "20" // The same as above, but make it as string.
  67. #define MAX_FURNITURE 50 // The max number of furniture a house can have. If you make this bigger remember to edit MAX_INI_LINES into SII
  68. #define VISIT_TIME 60000 // The time a player has to visit a house.
  69. #define HOUSE_FILE "Sasinosoft/Houses/House%d.ini" //Set to whatever you want (default = "Sasinosoft/Houses/House%d.ini")
  70. #define SHOP_FILE "Sasinosoft/Shops/Shop%d.ini" //Set to whatever you want (default = "Sasinosoft/Houses/House%d.ini")
  71. #define SAVED_HOUSES_FILE "Sasinosoft/Houses/SavedHouses.txt" // The file where the houses saved with /savehouse are written
  72. #define SAVED_SHOPS_FILE "Sasinosoft/Shops/SavedShops.txt" // The file where the stores/shops saved with /savestore are written
  73. #define GOOD_PRICE 100 // 1 good = 1 player can buy 1 item (default = 100$ per good)
  74. #define SELL_MULTIPLIER 0.8 // When a player sells a house, a furniture or a shop he will receive the initial price of the shop multiplied by this value
  75. #define INVALID_OWNER "LOK18F75J" // Never change this. If you set this to a common nickname and that player connects I don't know what will happen. If you change this while there are unbought houses they will result as bought.
  76. #define INVALID_HOUSE_ID -255 // Use only a negative value
  77. #define KEY KEY_LOOK_BEHIND // The key to press to open dialogs
  78. #define KEY_STRING "\"MMB\"" // The same, but in a string
  79. #define NO_ITEMS_STRING "{FF0000}Nothing to buy" // String displayed in a shop without nothing to buy
  80. #define MAP_ICONS 1 // If defined to 1, on the map will be created icons.
  81. #define CONSOLE 1 // if defined to 1, the important things are printed to the console (and then to server_log.txt)
  82. #define ShowNoMoneyMessage(%0) FS_MsgBox(%0, BOX_STYLE_ERROR, "You don't have enough money.") // A useful macro
  83.  
  84.  
  85. // Furniture
  86. #define FURNITURE_NUMBER 55
  87. #define INVALID_FURNITURE_ID 0
  88. stock FurnitureInfo[][] =
  89. {// {[0]object, [1]price, [2]name}
  90.     {0, 0, "INVALID_FURNITURE_ID"}, // 0
  91.     {2165, 1500, "Desk and PC"}, // 1
  92.     {2356, 100, "Desk chair"}, // 2
  93.     {2028, 350, "CJD500 console"}, // 3
  94.     {2779, 600, "Arcade machine"}, // 4
  95.     {2030, 750, "Marble table"}, // 5
  96.     {2086, 1000, "Glass table"}, // 6
  97.     {2112, 300, "Wood table"}, // 7
  98.     {2115, 600, "Big wood table"}, // 8
  99.     {2079, 80, "Chair A"}, // 9
  100.     {2120, 150, "Chair B"}, // 10
  101.     {2121, 50, "Red folding chair"}, // 11
  102.     {2096, 100, "Rocking chair"}, // 12
  103.     {2069, 100, "Lamp"}, // 13
  104.     {2103, 800, "Radio"}, // 14
  105.     {2132, 200, "White Sink"}, // 15
  106.     {2141, 900, "White Fridge"}, // 16
  107.     {2149, 600, "Microwave oven"}, // 17
  108.     {2161, 500, "Book shelf"}, // 18
  109.     {2167, 750, "Wardrobe"}, // 19
  110.     {2202, 1500, "Photocopier"}, // 20
  111.     {2313, 900, "TV Shelf + DVD Player"}, // 21
  112.     {2312, 1200, "Television A"}, // 22
  113.     {2316, 1200, "Television B"}, // 23
  114.     {2322, 1200, "Television C"}, // 24
  115.     {2298, 1000, "Blue Bed"}, // 25
  116.     {2299, 1000, "Brown Bed"}, // 26
  117.     {2300, 1000, "Yellow Bed"}, // 27
  118.     {2301, 1000, "Green and Blue Bed"}, // 28
  119.     {2526, 1250, "Bath"}, // 29
  120.     {2527, 1200, "Shower"}, // 30
  121.     {2524, 200, "Washbasin"}, // 31
  122.     {2525, 200, "Toilet"}, // 32
  123.     {1208, 1200, "Washing Machine"}, // 33
  124.     {1762, 1200, "Armchair A"}, // 34
  125.     {1765, 1200, "Armchair B"}, // 35
  126.     {1761, 700, "Sofa A"}, // 36
  127.     {1764, 700, "Sofa B"}, // 37
  128.     {1409, 20, "Trash can"}, // 38
  129.     {2627, 1000, "Tapis Roulant"}, // 39
  130.     {2630, 800, "Cyclette"}, // 40
  131.     {2964, 1000, "Pool Table"}, // 41
  132.     {1502, 200, "Door"}, // 42
  133.     {19317, 600, "Bass Guitar"}, // 43
  134.     {2134, 300, "White Kitchen Part 1"}, // 44
  135.     {2133, 300, "White Kitchen Part 2"}, // 45
  136.     {2131, 300, "White Kitchen Part 3"}, // 46
  137.     {2130, 200, "Red Sink"}, // 47
  138.     {2128, 900, "Red Fridge"}, // 48
  139.     {2127, 300, "Red Kitchen Part 1"}, // 49
  140.     {2129, 300, "Red Kitchen Part 2"}, // 50
  141.     {2294, 300, "Red Kitchen Part 3"}, // 51
  142.     {19166, 100, "San Andreas Picture"}, // 52
  143.     {19172, 100, "Santa Maria Beach Picture"}, // 53
  144.     {19173, 100, "San Fierro Picture"} // 54
  145.     // Add more if you wish, but remember to redefine FURNITURE_NUMBER
  146. };
  147.  
  148. // Box styles
  149. #define BOX_STYLE_CMD "{33AA33}COMMAND"
  150. #define BOX_STYLE_ERROR "{FF0000}ERROR"
  151. #define BOX_STYLE_WARNING "{FF8000}WARNING"
  152.  
  153. // Dialogs
  154. #define DIALOG_FORSALE_HOUSE 470 //
  155. #define DIALOG_MY_HOUSE 471 //
  156. #define DIALOG_OTHERS_HOUSE 472 //
  157. #define DIALOG_FORSALE_BIZ 473 //
  158. #define DIALOG_MY_BIZ 474 //
  159. #define DIALOG_OTHERS_BIZ 475 //
  160. #define DIALOG_HOUSE_MENU 476 //
  161. #define DIALOG_SELL_HOUSE 477 //
  162. #define DIALOG_RENAME_SHOP 478 //
  163. #define DIALOG_SELL_SHOP 479 //
  164. #define DIALOG_SUPPLY 480 //
  165. #define DIALOG_STORE_MONEY 481 //
  166. #define DIALOG_WITHDRAW_MONEY 482 //
  167. #define DIALOG_EDIT_FURNITURE 483 //
  168. #define DIALOG_SELL_FURNITURE 484 //
  169. #define DIALOG_BUY_FURNITURE 485 //
  170. #define DIALOG_MOVE_FURNITURE 486 //
  171. #define DIALOG_FURNITURE_BOUGHT 487 //
  172. #define DIALOG_SHOP 488 //
  173. #define DIALOG_SHOP_MENU 489 //
  174.  
  175. stock SetLastHouse(playerid, houseid)       { return SetPVarInt(playerid, "LastHouse", houseid); }
  176. stock SetLastShop(playerid, shopid)         { return SetPVarInt(playerid, "LastShop", shopid); }
  177. stock GetLastHouse(playerid)                { return GetPVarInt(playerid, "LastHouse"); }
  178. stock GetLastShop(playerid)                 { return GetPVarInt(playerid, "LastShop"); }
  179.  
  180. new pVisitTimer[MAX_PLAYERS];
  181.  
  182. enum hInfo
  183. {
  184.     Owner[MAX_PLAYER_NAME],
  185.     Price,
  186.     Interior,
  187.     Exterior,
  188.     VirtualWorld, // Useful for making 2 houses with the same interior
  189.     Locked,
  190.     Float:InteriorX,
  191.     Float:InteriorY,
  192.     Float:InteriorZ,
  193.     Float:ExteriorX,
  194.     Float:ExteriorY,
  195.     Float:ExteriorZ,
  196.     // Storage
  197.     Money,
  198.     Weapon[13],
  199.     Ammo[13],
  200.     // Furniture
  201.     FCount,
  202.     FModel[MAX_FURNITURE],
  203.     FurnitureObj[MAX_FURNITURE],
  204.     Float:FPosX[MAX_FURNITURE],
  205.     Float:FPosY[MAX_FURNITURE],
  206.     Float:FPosZ[MAX_FURNITURE],
  207.     Float:FRotX[MAX_FURNITURE],
  208.     Float:FRotY[MAX_FURNITURE],
  209.     Float:FRotZ[MAX_FURNITURE]
  210. };
  211.  
  212. new HouseInfo[MAX_HOUSES][hInfo];
  213. new HousePickup[MAX_HOUSES];
  214. new HousePickup2[MAX_HOUSES];
  215. new HouseIcon[MAX_HOUSES];
  216.  
  217. enum bInfo
  218. {
  219.     bTitle[MAX_TITLE],
  220.     bOwner[MAX_PLAYER_NAME],
  221.     bPrice,
  222.     bInterior,
  223.     bExterior,
  224.     bVirtualWorld,
  225.     bLocked,
  226.     Float:bInteriorX,
  227.     Float:bInteriorY,
  228.     Float:bInteriorZ,
  229.     Float:bExteriorX,
  230.     Float:bExteriorY,
  231.     Float:bExteriorZ,
  232.     // Stats
  233.     bEarning,
  234.     bGoods,
  235.     bMoney,
  236.     bItemList[1024]
  237. };
  238.  
  239. new BusinessInfo[MAX_SHOPS][bInfo];
  240. new BusinessPickup[MAX_SHOPS];
  241. new BusinessPickup2[MAX_SHOPS];
  242. new BusinessIcon[MAX_HOUSES];
  243.  
  244. public OnFilterScriptInit()
  245. {
  246.     print("\n---------------------------------------");
  247.     print("          Sasinosoft Houses 2.0        \n");
  248.     print("---------------------------------------\n");
  249.     print("Sasinosoft Houses by Sasino97 2.0 has been loaded.");
  250.     return 1;
  251. }
  252.  
  253. public OnFilterScriptExit()
  254. {
  255.     for(new i=0;i<MAX_HOUSES;i++)
  256.     {
  257.         DestroyDynamicPickup(HousePickup[i]);
  258.         DestroyDynamicPickup(HousePickup2[i]);
  259.         DestroyDynamicMapIcon(HouseIcon[i]);
  260.     }
  261.     for(new i=0;i<MAX_SHOPS;i++)
  262.     {
  263.         DestroyDynamicPickup(BusinessPickup[i]);
  264.         DestroyDynamicPickup(BusinessPickup2[i]);
  265.         DestroyDynamicMapIcon(BusinessIcon[i]);
  266.     }
  267.     return 1;
  268. }
  269.  
  270. public OnPlayerConnect(playerid)
  271. {
  272.     SetLastHouse(playerid, INVALID_HOUSE_ID);
  273.     SetLastShop(playerid, INVALID_HOUSE_ID);
  274.     return 1;
  275. }
  276.  
  277. public OnPlayerSpawn(playerid)
  278. {
  279.     SetPlayerVirtualWorld(playerid, 0);
  280.     SetLastHouse(playerid, INVALID_HOUSE_ID);
  281.     SetLastShop(playerid, INVALID_HOUSE_ID);
  282.     return 1;
  283. }
  284.  
  285. public OnPlayerEditDynamicObject(playerid, objectid, response, Float:x, Float:y, Float:z, Float:rx, Float:ry, Float:rz)
  286. {
  287.     if(response == EDIT_RESPONSE_UPDATE) return 1;
  288.     new ini[64];
  289.     new key[24];
  290.     for(new hID = 0; hID < MAX_HOUSES; hID ++)
  291.     {
  292.         for(new i = 0; i < MAX_FURNITURE; i ++)
  293.         {
  294.             if(objectid == HouseInfo[hID][FurnitureObj][i])
  295.             {
  296.                 if(response) // Clicked on the save icon
  297.                 {
  298.                     format(ini, 64, HOUSE_FILE, hID);
  299.                     INI_Open(ini);
  300.  
  301.                     HouseInfo[hID][FPosX][i] = x; HouseInfo[hID][FPosY][i] = y; HouseInfo[hID][FPosZ][i] = z;
  302.                     HouseInfo[hID][FRotX][i] = rx; HouseInfo[hID][FRotY][i] = ry; HouseInfo[hID][FRotZ][i] = rz;
  303.                     format(key, 24, "FPosX%d", i); INI_WriteFloat(key, HouseInfo[hID][FPosX][i]);
  304.                     format(key, 24, "FPosY%d", i); INI_WriteFloat(key, HouseInfo[hID][FPosY][i]);
  305.                     format(key, 24, "FPosZ%d", i); INI_WriteFloat(key, HouseInfo[hID][FPosZ][i]);
  306.                     format(key, 24, "FRotX%d", i); INI_WriteFloat(key, HouseInfo[hID][FRotX][i]);
  307.                     format(key, 24, "FRotY%d", i); INI_WriteFloat(key, HouseInfo[hID][FRotY][i]);
  308.                     format(key, 24, "FRotZ%d", i); INI_WriteFloat(key, HouseInfo[hID][FRotZ][i]);
  309.                    
  310.                     SetDynamicObjectPos(objectid, HouseInfo[hID][FPosX][i], HouseInfo[hID][FPosY][i], HouseInfo[hID][FPosZ][i]);
  311.                     SetDynamicObjectRot(objectid, HouseInfo[hID][FRotX][i], HouseInfo[hID][FRotY][i], HouseInfo[hID][FRotZ][i]);
  312.                
  313.                     INI_Save();
  314.                     INI_Close();
  315.                 }
  316.                 else // Pressed ESC
  317.                 {
  318.                     SetDynamicObjectPos(objectid, HouseInfo[hID][FPosX][i], HouseInfo[hID][FPosY][i], HouseInfo[hID][FPosZ][i]);
  319.                     SetDynamicObjectRot(objectid, HouseInfo[hID][FRotX][i], HouseInfo[hID][FRotY][i], HouseInfo[hID][FRotZ][i]);
  320.                 }
  321.                 break;
  322.             }
  323.         }
  324.     }
  325.     return 1;
  326. }
  327.  
  328. #define Command(%0) !strcmp(cmd, %0, true)
  329. public OnPlayerCommandText(playerid, cmdtext[])
  330. {
  331.     // Commands that help scripters to create new houses and stores for the game
  332.     new cmd[256];
  333.     new idx;
  334.     cmd = strtok(cmdtext, idx);
  335.    
  336.     if(Command("/savehouse"))
  337.     {
  338.         if(IsPlayerAdmin(playerid))
  339.         {
  340.             new Float:X, Float:Y, Float:Z;
  341.             new I;
  342.             GetPlayerPos(playerid, X, Y, Z);
  343.             I = GetPlayerInterior(playerid);
  344.            
  345.             new comment[128];
  346.             comment = strrest(cmdtext, idx);
  347.             new File: fileid = fopen(SAVED_HOUSES_FILE, io_append);
  348.             if(fileid)
  349.             {
  350.                 new string[256];
  351.                 format(string, 256, "CreateHouse(%.2f, %.2f, %.2f, interiorX, interiorY, interiorZ, price, interior, %d, virtualworld); // %s\r\n", X, Y, Z, I, comment);
  352.                 fwrite(fileid, string);
  353.                 fclose(fileid);
  354.                 FS_MsgBox(playerid, "{33AA33}SUCCESS", "The house has been saved to \""SAVED_HOUSES_FILE"\"");
  355.             }
  356.             else FS_MsgBox(playerid, BOX_STYLE_ERROR, "An error has occurred! Maybe the directory doesn't exist.");
  357.             return 1;
  358.         }
  359.     }
  360.     if(Command("/savestore") || Command("/savebiz") || Command("/saveshop"))
  361.     {
  362.         if(IsPlayerAdmin(playerid))
  363.         {
  364.             new Float:X, Float:Y, Float:Z;
  365.             new I;
  366.             GetPlayerPos(playerid, X, Y, Z);
  367.             I = GetPlayerInterior(playerid);
  368.             new comment[128];
  369.             comment = strrest(cmdtext, idx);
  370.             new File: fileid = fopen(SAVED_SHOPS_FILE, io_append);
  371.             if(fileid)
  372.             {
  373.                 new string[256];
  374.                 format(string, 256, "CreateBusiness(title, earning, %.2f, %.2f, %.2f, interiorX, interiorY, interiorZ, price, interior, %d, virtualworld, iconmarker, item_list[]); // %s\r\n", X, Y, Z, I, comment);
  375.                 fwrite(fileid, string);
  376.                 fclose(fileid);
  377.                 FS_MsgBox(playerid, "{33AA33}SUCCESS", "The store has been saved to \""SAVED_SHOPS_FILE"\"");
  378.             }
  379.             else FS_MsgBox(playerid, BOX_STYLE_ERROR, "An error has occurred! Maybe the directory doesn't exist.");
  380.             return 1;
  381.         }
  382.     }
  383.     return 0;
  384. }
  385.  
  386. public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
  387. {
  388.     if(newkeys & KEY)
  389.     {
  390.         new name[24];
  391.         GetPlayerName(playerid, name, 24);
  392.         for(new i=0; i<MAX_HOUSES; i++)
  393.         {
  394.             if(IsPlayerInRangeOfPoint(playerid, 1, HouseInfo[i][InteriorX], HouseInfo[i][InteriorY], HouseInfo[i][InteriorZ]) && GetPlayerVirtualWorld(playerid) == HouseInfo[i][VirtualWorld])
  395.             {
  396.                 return ExitHouse(playerid, i);
  397.             }
  398.         }
  399.         for(new i=0; i<MAX_SHOPS; i++)
  400.         {
  401.             if(IsPlayerInRangeOfPoint(playerid, 1, BusinessInfo[i][bInteriorX], BusinessInfo[i][bInteriorY], BusinessInfo[i][bInteriorZ]) && GetPlayerVirtualWorld(playerid) == BusinessInfo[i][bVirtualWorld])
  402.             {
  403.                 return ExitShop(playerid, i);
  404.             }
  405.         }
  406.         if(GetHouseID(playerid) != INVALID_HOUSE_ID) return OpenHouseDialog(playerid, GetHouseID(playerid));
  407.         if(GetShopID(playerid) != INVALID_HOUSE_ID) return OpenBusinessDialog(playerid, GetShopID(playerid));
  408.        
  409.         new LH = GetLastHouse(playerid);
  410.         if(LH != INVALID_HOUSE_ID && !strcmp(name, HouseInfo[LH][Owner], true))
  411.         {
  412.             ShowHouseMenu(playerid);
  413.             return 1;
  414.         }
  415.         new LS = GetLastShop(playerid);
  416.         if(LS != INVALID_HOUSE_ID)
  417.         {
  418.             if(!strcmp(name, BusinessInfo[LS][bOwner], true)) // he is the owner
  419.             {
  420.                 ShowBusinessMenu(playerid);
  421.             }
  422.             else
  423.             {
  424.                 ShowPlayerDialog(playerid, DIALOG_SHOP, DIALOG_STYLE_LIST, BusinessInfo[LS][bTitle], BusinessInfo[LS][bItemList], "Buy", "Cancel");
  425.             }
  426.             return 1;
  427.         }
  428.     }
  429.     return 1;
  430. }
  431.  
  432. public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
  433. {
  434.     new hID = GetHouseID(playerid);
  435.     new sID = GetShopID(playerid);
  436.     switch(dialogid)
  437.     {
  438.         case DIALOG_HOUSE_MENU:
  439.         {
  440.             hID = GetLastHouse(playerid);
  441.             if(!response) return 1;
  442.             switch(listitem)
  443.             {
  444.                 case 0: // Store money
  445.                 {
  446.                     new string[128];
  447.                     format(string, 128, "Current money: %d - Insert the money to deposit", HouseInfo[hID][Money]);
  448.                     ShowPlayerDialog(playerid, DIALOG_STORE_MONEY, DIALOG_STYLE_INPUT, "{33AA33}STORE MONEY", string, "OK", "Cancel");
  449.                 }
  450.                 case 1: // Withdraw money
  451.                 {
  452.                     new string[128];
  453.                     format(string, 128, "Current money: %d - Insert the money to withdraw", HouseInfo[hID][Money]);
  454.                     ShowPlayerDialog(playerid, DIALOG_WITHDRAW_MONEY, DIALOG_STYLE_INPUT, "{33AA33}WITHDRAW MONEY", string, "OK", "Cancel");
  455.                 }
  456.                 case 2: // Store weapons
  457.                 {  
  458.                     new ini[64];
  459.                     format(ini, 64, HOUSE_FILE, hID);
  460.                     INI_Open(ini);
  461.                     new key[24];
  462.                     for(new x = 0; x < 13; x ++)
  463.                     {
  464.                         format(key, 24, "Weapon%d", x);
  465.                         HouseInfo[hID][Weapon][x] = INI_ReadInt(key);
  466.                         format(key, 24, "Ammo%d", x);
  467.                         HouseInfo[hID][Ammo][x] = INI_ReadInt(key);
  468.                         GivePlayerWeapon(playerid, HouseInfo[hID][Weapon][x], HouseInfo[hID][Ammo][x]);
  469.                     }
  470.                     INI_Close();
  471.                     INI_Open(ini);
  472.                     for(new x = 0; x < 13; x ++)
  473.                     {
  474.                         GetPlayerWeaponData(playerid, x, HouseInfo[hID][Weapon][x], HouseInfo[hID][Ammo][x]);
  475.                         if(HouseInfo[hID][Weapon][x] == 0) continue;
  476.                         format(key, 24, "Weapon%d", x);
  477.                         INI_WriteInt(key, HouseInfo[hID][Weapon][x]);
  478.                         format(key, 24, "Ammo%d", x);
  479.                         INI_WriteInt(key, HouseInfo[hID][Ammo][x]);
  480.                     }
  481.                     INI_Save();
  482.                     INI_Close();
  483.                     ResetPlayerWeapons(playerid);
  484.                     FS_MsgBox(playerid, BOX_STYLE_CMD, "All weapons stored.");
  485.                 }
  486.                 case 3: // Collect weapons
  487.                 {
  488.                     new ini[64];
  489.                     new key[24];
  490.                     format(ini, 64, HOUSE_FILE, hID);
  491.                    
  492.                     // Read weapons and give them to player
  493.                     INI_Open(ini);
  494.                     new count = 0;
  495.                     for(new x = 0; x < 13; x ++)
  496.                     {
  497.                         format(key, 24, "Weapon%d", x);
  498.                         HouseInfo[hID][Weapon][x] = INI_ReadInt(key);
  499.                         format(key, 24, "Ammo%d", x);
  500.                         HouseInfo[hID][Ammo][x] = INI_ReadInt(key);
  501.                         if(HouseInfo[hID][Weapon][x] != 0)
  502.                         {
  503.                             count += 1;
  504.                             GivePlayerWeapon(playerid, HouseInfo[hID][Weapon][x], HouseInfo[hID][Ammo][x]);
  505.                         }
  506.                     }
  507.                     INI_Close();
  508.                     // Delete weapons from storage
  509.                     INI_Open(ini);
  510.                     for(new x = 0; x < 13; x ++)
  511.                     {
  512.                         HouseInfo[hID][Weapon][x] = 0;
  513.                         HouseInfo[hID][Ammo][x] = 0;
  514.                         format(key, 24, "Weapon%d", x);
  515.                         INI_WriteInt(key, HouseInfo[hID][Weapon][x]);
  516.                         format(key, 24, "Ammo%d", x);
  517.                         INI_WriteInt(key, HouseInfo[hID][Ammo][x]);
  518.                     }
  519.                     INI_Save();
  520.                     INI_Close();
  521.                     format(key, 24, "%d weapons collected.", count);
  522.                     if(count != 0) FS_MsgBox(playerid, BOX_STYLE_CMD, key);
  523.                     else FS_MsgBox(playerid, BOX_STYLE_ERROR, "You have no weapons in your storage!");
  524.                 }
  525.                 case 4: // Edit furniture
  526.                 {
  527.                     new bigstring[2048];
  528.                     new string[64];
  529.                     hID = GetLastHouse(playerid);
  530.                     for(new i = 0; i < MAX_FURNITURE; i++)
  531.                     {
  532.                         if(HouseInfo[hID][FModel][i] == INVALID_FURNITURE_ID)
  533.                         {
  534.                             format(string, 64, "%d - {FF0000}Empty", i+1);
  535.                         }
  536.                         else
  537.                         {
  538.                             if(HouseInfo[hID][FPosX][i] != 0.0) format(string, 64, "%d - %s - {33AA33}in house", i+1, FurnitureInfo[HouseInfo[hID][FModel][i]][2]); // Edit
  539.                             else format(string, 64, "%d - %s - {0000FF}in storage", i+1, FurnitureInfo[HouseInfo[hID][FModel][i]][2]); // Place
  540.                         }
  541.                         format(bigstring, sizeof(bigstring), "%s%s\n", bigstring, string);
  542.                     }
  543.                     ShowPlayerDialog(playerid, DIALOG_EDIT_FURNITURE, DIALOG_STYLE_LIST, "{33AA33}Select a furniture to place/edit.", bigstring, "Edit", "Cancel");
  544.                 }
  545.                 case 5: // Buy furniture
  546.                 {
  547.                     ShowFurnitureMenu(playerid);
  548.                 }
  549.                 case 6: // Sell furniture
  550.                 {
  551.                     new bigstring[2048];
  552.                     new string[64];
  553.                     hID = GetLastHouse(playerid);
  554.                     for(new i = 0; i < MAX_FURNITURE; i++)
  555.                     {
  556.                         if(HouseInfo[hID][FModel][i] == INVALID_FURNITURE_ID)
  557.                         {
  558.                             format(string, 64, "%d - {FF0000}Empty", i+1);
  559.                         }
  560.                         else
  561.                         {
  562.                             format(string, 64, "%d - %s {33AA33}(%d$)", i+1, FurnitureInfo[HouseInfo[hID][FModel][i]][2], floatround(FurnitureInfo[HouseInfo[hID][FModel][i]][1]*SELL_MULTIPLIER));
  563.                         }
  564.                         format(bigstring, sizeof(bigstring), "%s%s\n", bigstring, string);
  565.                     }
  566.                     ShowPlayerDialog(playerid, DIALOG_SELL_FURNITURE, DIALOG_STYLE_LIST, "{33AA33}Select a furniture to sell.", bigstring, "Sell", "Cancel");
  567.                 }
  568.             }
  569.             return 1;
  570.         }
  571.         case DIALOG_EDIT_FURNITURE:
  572.         {
  573.             if(!response) return 1;
  574.             new i = listitem;
  575.             hID = GetLastHouse(playerid);
  576.             if(HouseInfo[hID][FModel][i] == INVALID_FURNITURE_ID) return FS_MsgBox(playerid, BOX_STYLE_ERROR, "Invalid furniture selected.");
  577.             if(HouseInfo[hID][FPosX][i] != 0.0)
  578.             {
  579.                 if(!IsValidDynamicObject(HouseInfo[hID][FurnitureObj][i])) return FS_MsgBox(playerid, BOX_STYLE_ERROR, "Invalid dynamic object.");
  580.                 EditDynamicObject(playerid, HouseInfo[hID][FurnitureObj][i]);
  581.             }
  582.             else
  583.             {
  584.                 new Float:X, Float:Y, Float:Z;
  585.                 GetPlayerPos(playerid, X, Y, Z);
  586.                 GetXYInFrontOfPlayer(playerid, X, Y, 2.0);
  587.                 HouseInfo[hID][FPosX][i] = X; HouseInfo[hID][FPosY][i] = Y; HouseInfo[hID][FPosZ][i] = Z;
  588.                 HouseInfo[hID][FRotX][i] = 0; HouseInfo[hID][FRotY][i] = 0; HouseInfo[hID][FRotZ][i] = 0;
  589.                 HouseInfo[hID][FurnitureObj][i] = CreateDynamicObject(FurnitureInfo[HouseInfo[hID][FModel][i]][0], HouseInfo[hID][FPosX][i], HouseInfo[hID][FPosY][i], HouseInfo[hID][FPosZ][i], HouseInfo[hID][FRotX][i], HouseInfo[hID][FRotY][i], HouseInfo[hID][FRotZ][i], HouseInfo[hID][VirtualWorld], HouseInfo[hID][Interior], -1, 50.0);
  590.                 SaveFurniturePosition(hID, i);
  591.             }
  592.             return 1;
  593.         }
  594.         case DIALOG_BUY_FURNITURE:
  595.         {
  596.             if(!response) return 1;
  597.             if(GetPlayerMoney(playerid) < FurnitureInfo[listitem][1]) return ShowNoMoneyMessage(playerid);
  598.             hID = GetLastHouse(playerid);
  599.             BuyFurniture(playerid, hID, listitem+1);
  600.             return 1;
  601.         }
  602.         case DIALOG_SELL_FURNITURE:
  603.         {
  604.             if(!response) return 1;
  605.             new i = listitem;
  606.             new fname[128];
  607.             hID = GetLastHouse(playerid);
  608.             if(HouseInfo[hID][FModel][i] == INVALID_FURNITURE_ID) return FS_MsgBox(playerid, BOX_STYLE_ERROR, "Invalid furniture selected.");
  609.             new money = floatround(FurnitureInfo[HouseInfo[hID][FModel][i]][1]*SELL_MULTIPLIER);
  610.             GivePlayerMoney(playerid, money);
  611.             format(fname, 128, "{FFFFFF}You sold a {0000FF}\"%s\"{FFFFFF} for {33AA33}%d$.", FurnitureInfo[HouseInfo[hID][FModel][i]][2], money);
  612.             FS_MsgBox(playerid, BOX_STYLE_CMD, fname);
  613.             HouseInfo[hID][FModel][i] = INVALID_FURNITURE_ID;
  614.             HouseInfo[hID][FPosX][i] = 0; HouseInfo[hID][FPosY][i] = 0; HouseInfo[hID][FPosZ][i] = 0;
  615.             HouseInfo[hID][FRotX][i] = 0; HouseInfo[hID][FRotY][i] = 0; HouseInfo[hID][FRotZ][i] = 0;
  616.             if(IsValidDynamicObject(HouseInfo[hID][FurnitureObj][i])) DestroyDynamicObject(HouseInfo[hID][FurnitureObj][i]);
  617.             HouseInfo[hID][FurnitureObj][i] = 0;
  618.             HouseInfo[hID][FCount] -= 1;
  619.             format(fname, 128, HOUSE_FILE, hID);
  620.             new key[24];
  621.             INI_Open(fname);
  622.             INI_WriteInt("FCount", HouseInfo[hID][FCount]);
  623.             format(key, 24, "FModel%d", i); INI_WriteInt(key, INVALID_FURNITURE_ID);
  624.             INI_Save();
  625.             INI_Close();
  626.            
  627.             return 1;
  628.         }
  629.         case DIALOG_FURNITURE_BOUGHT:
  630.         {
  631.             if(response) ShowFurnitureMenu(playerid);
  632.             return 1;
  633.         }
  634.         case DIALOG_STORE_MONEY:
  635.         {
  636.             if(!response) return 1;
  637.            
  638.             new string[128];
  639.             hID = GetLastHouse(playerid);
  640.             sID = GetLastShop(playerid);
  641.             new val = strval(inputtext);
  642.             if(val < 0 || val > GetPlayerMoney(playerid)) return ShowNoMoneyMessage(playerid);
  643.             GivePlayerMoney(playerid, -val);
  644.             HouseInfo[hID][Money] += val;
  645.             format(string, 128, "%d$ stored in your house.", val);
  646.             FS_MsgBox(playerid, BOX_STYLE_CMD, string);
  647.             format(string, 128, HOUSE_FILE, hID);
  648.             INI_Open(string);
  649.             INI_WriteInt("Money", HouseInfo[hID][Money]);
  650.             INI_Save();
  651.             INI_Close();
  652.             return 1;
  653.         }
  654.         case DIALOG_WITHDRAW_MONEY:
  655.         {
  656.             if(!response) return 1;
  657.            
  658.             new string[128];
  659.             hID = GetLastHouse(playerid);
  660.             sID = GetLastShop(playerid);
  661.             new val = strval(inputtext);
  662.             if(val < 0 || val > HouseInfo[hID][Money]) return ShowNoMoneyMessage(playerid);
  663.             GivePlayerMoney(playerid, val);
  664.             HouseInfo[hID][Money] -= val;
  665.             format(string, 128, "%d$ withdrew from your house.", val);
  666.             FS_MsgBox(playerid, BOX_STYLE_CMD, string);
  667.             format(string, 128, HOUSE_FILE, hID);
  668.             INI_Open(string);
  669.             INI_WriteInt("Money", HouseInfo[hID][Money]);
  670.             INI_Save();
  671.             INI_Close();
  672.             return 1;
  673.         }
  674.         case DIALOG_FORSALE_HOUSE:
  675.         {
  676.             if(!response) return 1;
  677.             if(listitem == 0)
  678.             {
  679.                 if(GetPlayerMoney(playerid) < HouseInfo[hID][Price]) return ShowNoMoneyMessage(playerid);
  680.                 BuyHouse(playerid, hID);
  681.             }
  682.             else if(listitem == 1)
  683.             {
  684.                 EnterHouse(playerid, hID);
  685.                 FS_MsgBox(playerid, BOX_STYLE_CMD, "You are visiting this house.");
  686.                 pVisitTimer[playerid] = SetTimerEx("ExitHouse", VISIT_TIME, false, "ii", playerid, hID);
  687.             }
  688.             return 1;
  689.         }
  690.         case DIALOG_MY_HOUSE:
  691.         {
  692.             if(!response) return 1;
  693.             switch(listitem)
  694.             {
  695.                 case 0: // entra
  696.                 {
  697.                     EnterHouse(playerid, hID);
  698.                 }
  699.                 case 1: // apri/chiudi
  700.                 {
  701.                     LockUnlockHouse(playerid, hID);
  702.                 }
  703.                 case 2: // vendi
  704.                 {
  705.                     new string[64];
  706.                     format(string, 64, "{33AA33}Do you want to sell your house for %d$?\n{FF0000}All the money, the weapons and the furniture in your storage will remain there, and the next owner can use them.", floatround(HouseInfo[hID][Price]*SELL_MULTIPLIER));
  707.                     ShowPlayerDialog(playerid, DIALOG_SELL_HOUSE, DIALOG_STYLE_MSGBOX, "{FF8000}CONFIRMATION", string, "Sell", "Don't sell");
  708.                 }
  709.             }
  710.             return 1;
  711.         }
  712.         case DIALOG_OTHERS_HOUSE:
  713.         {
  714.             if(!response) return 1;
  715.             if(HouseInfo[hID][Locked] == 1)
  716.             {
  717.                 FS_MsgBox(playerid, BOX_STYLE_ERROR, "This house is {FF0000}locked.");
  718.             }
  719.             else
  720.             {
  721.                 EnterHouse(playerid, hID);
  722.             }
  723.             return 1;
  724.         }
  725.         case DIALOG_SELL_HOUSE:
  726.         {
  727.             if(response)
  728.             {
  729.                 SellHouse(playerid, hID);
  730.             }
  731.             else
  732.             {
  733.                 FS_MsgBox(playerid, BOX_STYLE_WARNING, "House not sold.");
  734.             }
  735.             return 1;
  736.         }
  737.         case DIALOG_SHOP:
  738.         {
  739.             if(!response) return 1;
  740.             sID = GetLastShop(playerid);
  741.             CallRemoteFunction("OnPlayerBuyItem", "iii", playerid, sID, listitem);
  742.             return 1;
  743.         }
  744.         case DIALOG_SHOP_MENU:
  745.         {
  746.             sID = GetLastShop(playerid);
  747.             if(!response) return 1;
  748.             switch(listitem)
  749.             {
  750.                 case 0: //Rename your shop
  751.                 {
  752.                     new string[68];
  753.                     format(string, 68, "Current Name: %s", BusinessInfo[sID][bTitle]);
  754.                     ShowPlayerDialog(playerid, DIALOG_RENAME_SHOP, DIALOG_STYLE_INPUT, "{33AA33}RENAME", string, "OK", "Cancel");
  755.                 }
  756.                 case 1: //Collect your earnings
  757.                 {
  758.                     if(BusinessInfo[sID][bMoney] == 0) return FS_MsgBox(playerid, BOX_STYLE_ERROR, "The cash register is empty.");
  759.                     new string[128];
  760.                     GivePlayerMoney(playerid, BusinessInfo[sID][bMoney]);
  761.                     format(string, 128, "You earned %d$.", BusinessInfo[sID][bMoney]);
  762.                     FS_MsgBox(playerid, BOX_STYLE_CMD, string);
  763.                    
  764.                     BusinessInfo[sID][bMoney] = 0;
  765.                     format(string, 128, SHOP_FILE, sID);
  766.                     INI_Open(string);
  767.                     INI_WriteInt("Money", 0);
  768.                     INI_Save();
  769.                     INI_Close();
  770.                 }
  771.                 case 2: //Supply goods for your shop
  772.                 {
  773.                     new string[68];
  774.                     format(string, 68, "Goods price: %d$/good", GOOD_PRICE);
  775.                     ShowPlayerDialog(playerid, DIALOG_SUPPLY, DIALOG_STYLE_INPUT, "{33AA33}Enter the amount to buy", string, "OK", "Cancel");
  776.                 }
  777.                 case 3:
  778.                 {
  779.                     ShowPlayerDialog(playerid, DIALOG_SHOP, DIALOG_STYLE_LIST, "{33AA33}Select an item from your shop.", BusinessInfo[sID][bItemList], "Buy", "Cancel");
  780.                 }
  781.             }
  782.             return 1;
  783.         }
  784.         case DIALOG_FORSALE_BIZ:
  785.         {
  786.             if(!response) return 1;
  787.             switch(listitem)
  788.             {
  789.                 case 0:
  790.                 {
  791.                     if(GetPlayerMoney(playerid) < BusinessInfo[sID][bEarning]) return ShowNoMoneyMessage(playerid);
  792.                     GivePlayerMoney(playerid, -BusinessInfo[sID][bEarning]);
  793.                     EnterShop(playerid, sID);
  794.                 }
  795.                 case 1:
  796.                 {
  797.                     if(GetPlayerMoney(playerid) < BusinessInfo[sID][bPrice]) return ShowNoMoneyMessage(playerid);
  798.                     BuyShop(playerid, sID);
  799.                 }
  800.             }
  801.             return 1;
  802.         }
  803.         case DIALOG_MY_BIZ:
  804.         {
  805.             if(!response) return 1;
  806.             switch(listitem)
  807.             {
  808.                 case 0: //Enter your shop
  809.                 {
  810.                     EnterShop(playerid, sID);
  811.                 }
  812.                 case 1: //Open/Close the shop
  813.                 {
  814.                     LockUnlockShop(playerid, sID);
  815.                 }
  816.                 case 2: //Sell your shop
  817.                 {
  818.                     new string[64];
  819.                     format(string, 64, "{33AA33}Do you want to sell your store for %d$?\n{FF0000}All the money and the goods will remain there.", floatround(BusinessInfo[sID][bPrice]*SELL_MULTIPLIER));
  820.                     ShowPlayerDialog(playerid, DIALOG_SELL_SHOP, DIALOG_STYLE_MSGBOX, "{FF8000}CONFIRMATION", string, "Sell", "Don't sell");
  821.                 }
  822.             }
  823.             return 1;
  824.         }
  825.         case DIALOG_SELL_SHOP:
  826.         {
  827.             if(response)
  828.             {
  829.                 SellShop(playerid, sID); // Changed in 2.2, previously it was hID, and it was making a bug where player couldn't sell their stores.
  830.             }
  831.             else
  832.             {
  833.                 FS_MsgBox(playerid, BOX_STYLE_WARNING, "Store not sold.");
  834.             }
  835.             return 1;
  836.         }
  837.         case DIALOG_OTHERS_BIZ:
  838.         {
  839.             if(!response) return 1;
  840.             if(BusinessInfo[sID][bLocked] == 1) return FS_MsgBox(playerid, BOX_STYLE_ERROR, "This store is closed.");
  841.             //if(BusinessInfo[sID][bGoods] <= 0) return FS_MsgBox(playerid, BOX_STYLE_ERROR, "This store is out of stock.");
  842.             if(GetPlayerMoney(playerid) < BusinessInfo[sID][bEarning]) return ShowNoMoneyMessage(playerid);
  843.            
  844.             GivePlayerMoney(playerid, -BusinessInfo[sID][bEarning]);
  845.             EnterShop(playerid, sID);
  846.             BusinessInfo[sID][bMoney] += BusinessInfo[sID][bEarning];
  847.             //BusinessInfo[sID][bGoods] -= 1;
  848.             new filename[128];
  849.             format(filename, 128, SHOP_FILE, sID);
  850.             INI_Open(filename);
  851.             INI_WriteInt("Money", BusinessInfo[sID][bMoney]);
  852.             //INI_WriteInt("Goods", BusinessInfo[sID][bGoods]);
  853.             INI_Save();
  854.             INI_Close();
  855.             return 1;
  856.         }
  857.         case DIALOG_RENAME_SHOP:
  858.         {
  859.             sID = GetLastShop(playerid);
  860.             if(!response) return 1;
  861.             if(strlen(inputtext) > MAX_TITLE) return FS_MsgBox(playerid, BOX_STYLE_ERROR, "The max length is "MAX_TITLE_STR"!");
  862.             format(BusinessInfo[sID][bTitle], MAX_TITLE, inputtext);
  863.             new filename[128];
  864.             format(filename, 128, SHOP_FILE, sID);
  865.             INI_Open(filename);
  866.             INI_WriteString("Title", BusinessInfo[sID][bTitle]);
  867.             INI_Save();
  868.             INI_Close();
  869.             format(filename, 128, "Store name changed to %s!", BusinessInfo[sID][bTitle]);
  870.             FS_MsgBox(playerid, BOX_STYLE_CMD, filename); // I used again filename here to not create a new var and waste more cells.
  871.             return 1;
  872.         }
  873.         case DIALOG_SUPPLY:
  874.         {
  875.             sID = GetLastShop(playerid);
  876.             if(!response) return 1;
  877.             new value = strval(inputtext);
  878.             if(value <= 0 || value > 500) return FS_MsgBox(playerid, BOX_STYLE_ERROR, "Enter an amount between 1 and 500!");
  879.             new cost = GOOD_PRICE * value;
  880.             if(GetPlayerMoney(playerid) < cost) return ShowNoMoneyMessage(playerid);
  881.             BusinessInfo[sID][bGoods] += value;
  882.             GivePlayerMoney(playerid, -cost);
  883.             new filename[128];
  884.             format(filename, 128, SHOP_FILE, sID);
  885.             INI_Open(filename);
  886.             INI_WriteInt("Goods", BusinessInfo[sID][bGoods]);
  887.             INI_Save();
  888.             INI_Close();
  889.             format(filename, 128, "You just bought %d goods for your store for %d$!", value, cost);
  890.             FS_MsgBox(playerid, BOX_STYLE_CMD, filename);
  891.             return 1;
  892.         }
  893.     }
  894.     return 0;
  895. }
  896.  
  897. forward FS_MsgBox(playerid, caption[], text[]);
  898. public FS_MsgBox(playerid, caption[], text[])
  899. {
  900.     ShowPlayerDialog(playerid, 469, DIALOG_STYLE_MSGBOX, caption, text, "OK", "");
  901.     return 1;
  902. }
  903.  
  904. forward FS_CreateHouse(Float:eX, Float:eY, Float:eZ, Float:iX, Float:iY, Float:iZ, price, interior, exterior, virtualWorld);
  905. public FS_CreateHouse(Float:eX, Float:eY, Float:eZ, Float:iX, Float:iY, Float:iZ, price, interior, exterior, virtualWorld)
  906. {
  907.     static hCount;
  908.     new hID = hCount; hCount += 1;
  909.    
  910.     HouseInfo[hID][Price] = price;
  911.     HouseInfo[hID][Interior] = interior;
  912.     HouseInfo[hID][Exterior] = exterior;
  913.     HouseInfo[hID][VirtualWorld] = virtualWorld;
  914.     HouseInfo[hID][InteriorX] = iX;
  915.     HouseInfo[hID][InteriorY] = iY;
  916.     HouseInfo[hID][InteriorZ] = iZ;
  917.     HouseInfo[hID][ExteriorX] = eX;
  918.     HouseInfo[hID][ExteriorY] = eY;
  919.     HouseInfo[hID][ExteriorZ] = eZ;
  920.    
  921.     new housefile[64];
  922.     format(housefile, 64, HOUSE_FILE, hID);
  923.    
  924.     if(!INI_Exist(housefile)) // If not existing
  925.     {
  926.         INI_Open(housefile);
  927.         //
  928.         format(HouseInfo[hID][Owner], MAX_PLAYER_NAME, INVALID_OWNER);   INI_WriteString("Owner", HouseInfo[hID][Owner]);
  929.         HouseInfo[hID][Locked] = 1;  INI_WriteInt("Locked", HouseInfo[hID][Locked]);
  930.         HouseInfo[hID][Money] = 0;  INI_WriteInt("Money", HouseInfo[hID][Money]);
  931.         new key[24];
  932.         for(new x = 0; x < 13; x ++)
  933.         {
  934.             HouseInfo[hID][Weapon][x] = 0;  
  935.             HouseInfo[hID][Ammo][x] = 0;  
  936.             format(key, 24, "Weapon%d", x); INI_WriteInt(key, HouseInfo[hID][Weapon][x]);
  937.             format(key, 24, "Ammo%d", x); INI_WriteInt(key, HouseInfo[hID][Ammo][x]);
  938.         }
  939.         HouseInfo[hID][FCount] = 0;  INI_WriteInt("FCount", HouseInfo[hID][FCount]);
  940.         for(new i = 0; i < MAX_FURNITURE; i ++)
  941.         {
  942.             HouseInfo[hID][FModel][i] = INVALID_FURNITURE_ID;
  943.             HouseInfo[hID][FPosX][i] = 0.0; HouseInfo[hID][FPosY][i] = 0.0; HouseInfo[hID][FPosZ][i] = 0.0;
  944.             HouseInfo[hID][FRotX][i] = 0.0; HouseInfo[hID][FRotY][i] = 0.0; HouseInfo[hID][FRotZ][i] = 0.0;
  945.             format(key, 24, "FModel%d", i); INI_WriteInt(key, HouseInfo[hID][FModel][i]);
  946.             format(key, 24, "FPosX%d", i); INI_WriteFloat(key, HouseInfo[hID][FPosX][i]);
  947.             format(key, 24, "FPosY%d", i); INI_WriteFloat(key, HouseInfo[hID][FPosY][i]);
  948.             format(key, 24, "FPosZ%d", i); INI_WriteFloat(key, HouseInfo[hID][FPosZ][i]);
  949.             format(key, 24, "FRotX%d", i); INI_WriteFloat(key, HouseInfo[hID][FRotX][i]);
  950.             format(key, 24, "FRotY%d", i); INI_WriteFloat(key, HouseInfo[hID][FRotY][i]);
  951.             format(key, 24, "FRotZ%d", i); INI_WriteFloat(key, HouseInfo[hID][FRotZ][i]);
  952.         }
  953.  
  954.         //
  955.         INI_Save();
  956.         INI_Close();
  957.        
  958.         #if CONSOLE == 1
  959.         printf("Created new house - ID: %d - Ext: %d, %f, %f, %f - Int: %d, %f, %f, %f - Price: %d - World: %d", hID, HouseInfo[hID][Exterior], HouseInfo[hID][ExteriorX], HouseInfo[hID][ExteriorY], HouseInfo[hID][ExteriorZ], HouseInfo[hID][Interior], HouseInfo[hID][InteriorX], HouseInfo[hID][InteriorY], HouseInfo[hID][InteriorZ], HouseInfo[hID][Price], HouseInfo[hID][VirtualWorld]);
  960.         #endif
  961.     }
  962.     else
  963.     {
  964.         INI_Open(housefile);
  965.         //
  966.         INI_ReadString(HouseInfo[hID][Owner], "Owner", MAX_PLAYER_NAME);
  967.         HouseInfo[hID][Locked] = INI_ReadInt("Locked");
  968.         HouseInfo[hID][Money] = INI_ReadInt("Money");
  969.         new key[32];
  970.         for(new x = 0; x < 13; x ++)
  971.         {
  972.             format(key, 32, "Weapon%d", x);
  973.             HouseInfo[hID][Weapon][x] = INI_ReadInt(key);
  974.             format(key, 32, "Ammo%d", x);
  975.             HouseInfo[hID][Ammo][x] = INI_ReadInt(key);
  976.         }
  977.         HouseInfo[hID][FCount] = INI_ReadInt("FCount");
  978.         for(new i = 0; i < MAX_FURNITURE; i ++)
  979.         {
  980.             format(key, 32, "FModel%d", i); HouseInfo[hID][FModel][i] = INI_ReadInt(key);
  981.             format(key, 32, "FPosX%d", i); HouseInfo[hID][FPosX][i] = INI_ReadFloat(key);
  982.             format(key, 32, "FPosY%d", i); HouseInfo[hID][FPosY][i] = INI_ReadFloat(key);
  983.             format(key, 32, "FPosZ%d", i); HouseInfo[hID][FPosZ][i] = INI_ReadFloat(key);
  984.             format(key, 32, "FRotX%d", i); HouseInfo[hID][FRotX][i] = INI_ReadFloat(key);
  985.             format(key, 32, "FRotY%d", i); HouseInfo[hID][FRotY][i] = INI_ReadFloat(key);
  986.             format(key, 32, "FRotZ%d", i); HouseInfo[hID][FRotZ][i] = INI_ReadFloat(key);
  987.             if(HouseInfo[hID][FPosX][i] != 0.0) HouseInfo[hID][FurnitureObj][i] = CreateDynamicObject(FurnitureInfo[HouseInfo[hID][FModel][i]][0], HouseInfo[hID][FPosX][i], HouseInfo[hID][FPosY][i], HouseInfo[hID][FPosZ][i], HouseInfo[hID][FRotX][i], HouseInfo[hID][FRotY][i], HouseInfo[hID][FRotZ][i], HouseInfo[hID][VirtualWorld], HouseInfo[hID][Interior], -1, 50.0);
  988.         }
  989.         //
  990.         INI_Save();
  991.         INI_Close();
  992.        
  993.         #if CONSOLE == 1
  994.         printf("Loaded house - ID: %d - Owner: %s - Locked: %d", hID, HouseInfo[hID][Owner], HouseInfo[hID][Locked]);
  995.         #endif
  996.     }
  997.     if(!strcmp(HouseInfo[hID][Owner], INVALID_OWNER, true)) //for sale
  998.     {
  999.         HousePickup[hID] = CreateDynamicPickup(1273, 23, HouseInfo[hID][ExteriorX], HouseInfo[hID][ExteriorY], HouseInfo[hID][ExteriorZ]);
  1000.         #if MAP_ICONS == 1
  1001.         HouseIcon[hID] = CreateDynamicMapIcon(HouseInfo[hID][ExteriorX], HouseInfo[hID][ExteriorY], HouseInfo[hID][ExteriorZ], 31, 0, _, _, _, 800.0);
  1002.         #endif
  1003.     }
  1004.     else // not for sale
  1005.     {
  1006.         HousePickup[hID] = CreateDynamicPickup(1318, 23, HouseInfo[hID][ExteriorX], HouseInfo[hID][ExteriorY], HouseInfo[hID][ExteriorZ]);
  1007.         #if MAP_ICONS == 1
  1008.         HouseIcon[hID] = CreateDynamicMapIcon(HouseInfo[hID][ExteriorX], HouseInfo[hID][ExteriorY], HouseInfo[hID][ExteriorZ], 32, 0, _, _, _, 800.0);
  1009.         #endif
  1010.     }
  1011.     HousePickup2[hID] = CreateDynamicPickup(1318, 23, HouseInfo[hID][InteriorX], HouseInfo[hID][InteriorY], HouseInfo[hID][InteriorZ]);
  1012.     Create3DTextLabel("House - Press "KEY_STRING" to open the menu", 0xFFFF00FF, HouseInfo[hID][ExteriorX],HouseInfo[hID][ExteriorY], HouseInfo[hID][ExteriorZ]+1, 20, 0, 1);
  1013.     Create3DTextLabel("Press "KEY_STRING" to exit", 0xFFFF00FF, HouseInfo[hID][InteriorX], HouseInfo[hID][InteriorY], HouseInfo[hID][InteriorZ]+1, 20, HouseInfo[hID][VirtualWorld], 1);
  1014.     return hID;
  1015. }
  1016.  
  1017. forward FS_CreateBusiness(title[MAX_PLAYER_NAME], earning, Float:eX, Float:eY, Float:eZ, Float:iX, Float:iY, Float:iZ, price, interior, exterior, virtualWorld, iconmarker, itemlist[1024]);
  1018. public FS_CreateBusiness(title[MAX_PLAYER_NAME], earning, Float:eX, Float:eY, Float:eZ, Float:iX, Float:iY, Float:iZ, price, interior, exterior, virtualWorld, iconmarker, itemlist[1024])
  1019. {
  1020.     static bCount;
  1021.     new hID = bCount; bCount += 1;
  1022.    
  1023.     BusinessInfo[hID][bPrice] = price;
  1024.     BusinessInfo[hID][bInterior] = interior;
  1025.     BusinessInfo[hID][bExterior] = exterior;
  1026.     BusinessInfo[hID][bVirtualWorld] = virtualWorld;
  1027.     BusinessInfo[hID][bInteriorX] = iX;
  1028.     BusinessInfo[hID][bInteriorY] = iY;
  1029.     BusinessInfo[hID][bInteriorZ] = iZ;
  1030.     BusinessInfo[hID][bExteriorX] = eX;
  1031.     BusinessInfo[hID][bExteriorY] = eY;
  1032.     BusinessInfo[hID][bExteriorZ] = eZ;
  1033.     BusinessInfo[hID][bEarning] = earning;
  1034.     if(strcmp(itemlist, "_") != 0) format(BusinessInfo[hID][bItemList], 1024, itemlist);
  1035.     else format(BusinessInfo[hID][bItemList], 1024, NO_ITEMS_STRING);
  1036.    
  1037.     new bizfile[64];
  1038.     format(bizfile, 64, SHOP_FILE, hID);
  1039.    
  1040.     if(!INI_Exist(bizfile)) // If not existing
  1041.     {
  1042.         INI_Open(bizfile);
  1043.         //
  1044.         format(BusinessInfo[hID][bTitle], MAX_PLAYER_NAME, title);   INI_WriteString("Title", BusinessInfo[hID][bTitle]);
  1045.         format(BusinessInfo[hID][bOwner], MAX_PLAYER_NAME, INVALID_OWNER);   INI_WriteString("Owner", BusinessInfo[hID][bOwner]);
  1046.         BusinessInfo[hID][bLocked] = 0;  INI_WriteInt("Locked", BusinessInfo[hID][bLocked]);
  1047.         BusinessInfo[hID][bMoney] = 0;  INI_WriteInt("Money", BusinessInfo[hID][bMoney]);
  1048.         BusinessInfo[hID][bGoods] = 10;  INI_WriteInt("Goods", BusinessInfo[hID][bGoods]);
  1049.         //
  1050.         INI_Save();
  1051.         INI_Close();
  1052.        
  1053.         #if CONSOLE == 1
  1054.         printf("Created new business - ID: %d - Name: %s - Ext: %d, %f, %f, %f - Int: %d, %f, %f, %f - Price: %d - World: %d", hID, BusinessInfo[hID][bTitle], BusinessInfo[hID][bExterior], BusinessInfo[hID][bExteriorX], BusinessInfo[hID][bExteriorY], BusinessInfo[hID][bExteriorZ], BusinessInfo[hID][bInterior], BusinessInfo[hID][bInteriorX], BusinessInfo[hID][bInteriorY], BusinessInfo[hID][bInteriorZ], BusinessInfo[hID][bPrice], BusinessInfo[hID][bVirtualWorld]);
  1055.         #endif
  1056.     }
  1057.     else
  1058.     {
  1059.         INI_Open(bizfile);
  1060.         //
  1061.         INI_ReadString(BusinessInfo[hID][bTitle], "Title", MAX_TITLE);
  1062.         INI_ReadString(BusinessInfo[hID][bOwner], "Owner", MAX_PLAYER_NAME);
  1063.         BusinessInfo[hID][bLocked] = INI_ReadInt("Locked");
  1064.         BusinessInfo[hID][bMoney] = INI_ReadInt("Money");
  1065.         BusinessInfo[hID][bGoods] = INI_ReadInt("Goods");
  1066.         //
  1067.         INI_Close();
  1068.        
  1069.         #if CONSOLE == 1
  1070.         printf("Loaded store - ID: %d - Title: %s - Owner: %s", hID, BusinessInfo[hID][bTitle], BusinessInfo[hID][bOwner]);
  1071.         #endif
  1072.     }
  1073.     if(!strcmp(BusinessInfo[hID][bOwner], INVALID_OWNER, true)) //for sale
  1074.     {
  1075.         BusinessPickup[hID] = CreateDynamicPickup(1272, 23, BusinessInfo[hID][bExteriorX], BusinessInfo[hID][bExteriorY], BusinessInfo[hID][bExteriorZ]);
  1076.     }
  1077.     else // not for sale
  1078.     {
  1079.         BusinessPickup[hID] = CreateDynamicPickup(1318, 23, BusinessInfo[hID][bExteriorX], BusinessInfo[hID][bExteriorY], BusinessInfo[hID][bExteriorZ]);
  1080.     }
  1081.     #if MAP_ICONS == 1
  1082.     BusinessIcon[hID] = CreateDynamicMapIcon(BusinessInfo[hID][bExteriorX], BusinessInfo[hID][bExteriorY], BusinessInfo[hID][bExteriorZ], iconmarker, 0, _, _, _, 800.0);
  1083.     #endif
  1084.     BusinessPickup2[hID] = CreateDynamicPickup(1318, 23, BusinessInfo[hID][bInteriorX], BusinessInfo[hID][bInteriorY], BusinessInfo[hID][bInteriorZ]);
  1085.     Create3DTextLabel("Business - Press "KEY_STRING" to open the menu", 0xFFFF00FF, BusinessInfo[hID][bExteriorX],BusinessInfo[hID][bExteriorY], BusinessInfo[hID][bExteriorZ]+1, 20, 0, 1);
  1086.     Create3DTextLabel("Press "KEY_STRING" to exit", 0xFFFF00FF, BusinessInfo[hID][bInteriorX], BusinessInfo[hID][bInteriorY], BusinessInfo[hID][bInteriorZ]+1, 20, BusinessInfo[hID][bVirtualWorld], 1);
  1087.     return hID;
  1088. }
  1089.  
  1090. forward FS_GiveBusinessMoney(shopid, money);
  1091. public FS_GiveBusinessMoney(shopid, money)
  1092. {
  1093.     if(BusinessInfo[shopid][bMoney] + money < 0) return 0;
  1094.     BusinessInfo[shopid][bMoney] += money;
  1095.     new filename[128];
  1096.     format(filename, 128, SHOP_FILE, shopid);
  1097.     INI_Open(filename);
  1098.     INI_WriteInt("Money", BusinessInfo[shopid][bMoney]);
  1099.     INI_Save();
  1100.     INI_Close();
  1101.     return 1;
  1102. }
  1103.  
  1104. forward FS_GiveBusinessGoods(shopid, goods);
  1105. public FS_GiveBusinessGoods(shopid, goods)
  1106. {
  1107.     if(!strcmp(BusinessInfo[shopid][bOwner], INVALID_OWNER, true)) return 1;
  1108.     if(BusinessInfo[shopid][bGoods] + goods < 0) return 0;
  1109.     BusinessInfo[shopid][bGoods] += goods;
  1110.     new filename[128];
  1111.     format(filename, 128, SHOP_FILE, shopid);
  1112.     INI_Open(filename);
  1113.     INI_WriteInt("Goods", BusinessInfo[shopid][bGoods]);
  1114.     INI_Save();
  1115.     INI_Close();
  1116.     return 1;
  1117. }
  1118.  
  1119. forward FS_GetBusinessMoney(shopid); public FS_GetBusinessMoney(shopid) { return BusinessInfo[shopid][bMoney]; }
  1120. forward FS_GetBusinessGoods(shopid); public FS_GetBusinessGoods(shopid) { return BusinessInfo[shopid][bGoods]; }
  1121.  
  1122. stock BuyFurniture(playerid, houseid, modelid) // modelid is the furniture model id while fid is the instance id of a furniture.
  1123. {
  1124.     new fid = 0;
  1125.     while(fid < MAX_FURNITURE)
  1126.     {
  1127.         if(HouseInfo[houseid][FModel][fid] == INVALID_FURNITURE_ID) break;
  1128.         fid ++;
  1129.     }
  1130.     if(fid == MAX_FURNITURE || HouseInfo[houseid][FCount] >= MAX_FURNITURE) return FS_MsgBox(playerid, BOX_STYLE_ERROR, "You can't buy anymore furniture.");
  1131.     HouseInfo[houseid][FCount] += 1;
  1132.     new fname[64]; format(fname, 64, HOUSE_FILE, houseid);
  1133.     new key[24];
  1134.     HouseInfo[houseid][FModel][fid] = modelid;
  1135.     GivePlayerMoney(playerid, -FurnitureInfo[modelid][1]);
  1136.     INI_Open(fname);
  1137.     INI_WriteInt("FCount", HouseInfo[houseid][FCount]);
  1138.     format(key, 24, "FModel%d", fid); INI_WriteInt(key, HouseInfo[houseid][FModel][fid]);
  1139.     INI_Save();
  1140.     INI_Close();
  1141.     ShowPlayerDialog(playerid, DIALOG_FURNITURE_BOUGHT, DIALOG_STYLE_MSGBOX, "{33AA33}Do you want to keep shopping?", "{33AA33}You bought a new furniture!\n{FFFFFF}To put it into your house open the menu and select \"Place/Edit furniture\".", "Continue", "Finish");
  1142.     return fid;
  1143. }
  1144.  
  1145. stock SaveFurniturePosition(houseid, furnid) // Furnid is the instance id of the furniture.
  1146. {
  1147.     new fname[64]; format(fname, 64, HOUSE_FILE, houseid);
  1148.     new key[32];
  1149.     INI_Open(fname);
  1150.     format(key, 24, "FPosX%d", furnid); INI_WriteFloat(key, HouseInfo[houseid][FPosX][furnid]);
  1151.     format(key, 24, "FPosY%d", furnid); INI_WriteFloat(key, HouseInfo[houseid][FPosY][furnid]);
  1152.     format(key, 24, "FPosZ%d", furnid); INI_WriteFloat(key, HouseInfo[houseid][FPosZ][furnid]);
  1153.     format(key, 24, "FRotX%d", furnid); INI_WriteFloat(key, HouseInfo[houseid][FRotX][furnid]);
  1154.     format(key, 24, "FRotY%d", furnid); INI_WriteFloat(key, HouseInfo[houseid][FRotY][furnid]);
  1155.     format(key, 24, "FRotZ%d", furnid); INI_WriteFloat(key, HouseInfo[houseid][FRotZ][furnid]);
  1156.     INI_Save();
  1157.     INI_Close();
  1158.     return 1;
  1159. }
  1160.  
  1161. stock OpenHouseDialog(playerid, houseid)
  1162. {
  1163.     if(!strcmp(HouseInfo[houseid][Owner], INVALID_OWNER, true)) // the house is for sale
  1164.     {
  1165.         new string[128];
  1166.         if(GetPlayerMoney(playerid) >= HouseInfo[houseid][Price]) format(string, 128, "{33AA33}Buy this house for %d$\n{33AA33}Visit this house", HouseInfo[houseid][Price]);
  1167.         else format(string, 128, "{FF0000}Buy this house for %d$\n{33AA33}Visit this house", HouseInfo[houseid][Price]);
  1168.        
  1169.         ShowPlayerDialog(playerid, DIALOG_FORSALE_HOUSE, DIALOG_STYLE_LIST, "{33AA33}House for sale!", string, "OK", "Close");
  1170.         return 1;
  1171.     }
  1172.     else // not for sale
  1173.     {
  1174.         new string[128];
  1175.         new string2[128];
  1176.         new name[24];
  1177.         GetPlayerName(playerid, name, 24);
  1178.         if(!strcmp(name, HouseInfo[houseid][Owner], true)) // The player is the owner
  1179.         {
  1180.             ShowPlayerDialog(playerid, DIALOG_MY_HOUSE, DIALOG_STYLE_LIST, "{33AA33}Owned House - Owner: you", "{33AA33}Enter your house\n{33AA33}Open/Close the door\n{33AA33}Sell your house", "OK", "Close");
  1181.             return 0;
  1182.         }
  1183.         else // The player is not the owner
  1184.         {
  1185.             format(string, 128, "{33AA33}Owned House - Owner: %s", HouseInfo[houseid][Owner]);
  1186.             if(HouseInfo[houseid][Locked] == 0) format(string2, 128, "{33AA33}Enter this house");
  1187.             else format(string2, 128, "{FF0000}Enter this house");
  1188.             ShowPlayerDialog(playerid, DIALOG_OTHERS_HOUSE, DIALOG_STYLE_LIST, string, string2, "OK", "Close");
  1189.             return -1;
  1190.         }
  1191.     }
  1192. }
  1193.  
  1194. stock OpenBusinessDialog(playerid, bizid)
  1195. {
  1196.     if(!strcmp(BusinessInfo[bizid][bOwner], INVALID_OWNER, true))
  1197.     {
  1198.         new string[128];
  1199.         if(GetPlayerMoney(playerid) >= BusinessInfo[bizid][bPrice]) format(string, 128, "{33AA33}Enter this store (%d$)\n{33AA33}Buy this store for %d$", BusinessInfo[bizid][bEarning], BusinessInfo[bizid][bPrice]);
  1200.         else format(string, 128, "{33AA33}Enter this store (%d$)\n{FF0000}Buy this store for %d$", BusinessInfo[bizid][bEarning], BusinessInfo[bizid][bPrice]);
  1201.        
  1202.         ShowPlayerDialog(playerid, DIALOG_FORSALE_BIZ, DIALOG_STYLE_LIST, "{33AA33}Store for sale!", string, "OK", "Close");
  1203.         return 1;
  1204.     }
  1205.     else
  1206.     {
  1207.         new string[128];
  1208.         new string2[256];
  1209.         new name[24];
  1210.         GetPlayerName(playerid, name, 24);
  1211.         if(!strcmp(name, BusinessInfo[bizid][bOwner], true))
  1212.         {
  1213.             format(string, 128, "{33AA33}%s - Owner: you - Goods: %d - Earnings: %d$", BusinessInfo[bizid][bTitle], BusinessInfo[bizid][bGoods], BusinessInfo[bizid][bMoney]);
  1214.             format(string2, 256, "{33AA33}Enter your store\n{33AA33}Open/Close the store\n{33AA33}Sell your store");                                 
  1215.             ShowPlayerDialog(playerid, DIALOG_MY_BIZ, DIALOG_STYLE_LIST, string, string2, "OK", "Close");
  1216.             return 0;
  1217.         }
  1218.         else
  1219.         {
  1220.             format(string, 128, "{33AA33}%s - Owner: %s", BusinessInfo[bizid][bTitle], BusinessInfo[bizid][bOwner]);
  1221.             if(BusinessInfo[bizid][bLocked] == 0 || GetPlayerMoney(playerid) >= BusinessInfo[bizid][bEarning]) format(string2, 256, "{33AA33}Enter this store (%d$)", BusinessInfo[bizid][bEarning]);
  1222.             else format(string2, 256, "{FF0000}Enter this store (%d$)", BusinessInfo[bizid][bEarning]);
  1223.             ShowPlayerDialog(playerid, DIALOG_OTHERS_BIZ, DIALOG_STYLE_LIST, string, string2, "OK", "Close");
  1224.             return -1;
  1225.         }
  1226.     }
  1227. }
  1228.  
  1229. stock ShowHouseMenu(playerid)
  1230. {
  1231.     return ShowPlayerDialog(playerid, DIALOG_HOUSE_MENU, DIALOG_STYLE_LIST, "{33AA33}House Menu", "Store money\nWithdraw money\nStore weapons\nCollect weapons\nPlace/Edit furniture\nBuy new furniture\nSell furniture", "OK", "Cancel");
  1232. }
  1233.  
  1234. stock ShowBusinessMenu(playerid)
  1235. {
  1236.     return ShowPlayerDialog(playerid, DIALOG_SHOP_MENU, DIALOG_STYLE_LIST, "{33AA33}Store Menu", "Rename your store\nCollect your earnings\nSupply goods for your store\nBuy an item from your store", "OK", "Cancel");
  1237. }
  1238.  
  1239. stock GetHouseID(playerid)
  1240. {
  1241.     for(new i=0; i<MAX_HOUSES; i++)
  1242.     {
  1243.         if(IsPlayerInRangeOfPoint(playerid, 1, HouseInfo[i][ExteriorX], HouseInfo[i][ExteriorY], HouseInfo[i][ExteriorZ]))
  1244.         {
  1245.             return i;
  1246.         }
  1247.     }
  1248.     return INVALID_HOUSE_ID;
  1249. }
  1250.  
  1251. stock GetShopID(playerid)
  1252. {
  1253.     for(new i=0; i<MAX_SHOPS; i++)
  1254.     {
  1255.         if(IsPlayerInRangeOfPoint(playerid, 1, BusinessInfo[i][bExteriorX], BusinessInfo[i][bExteriorY], BusinessInfo[i][bExteriorZ]))
  1256.         {
  1257.             return i;
  1258.         }
  1259.     }
  1260.     return INVALID_HOUSE_ID;
  1261. }
  1262.  
  1263. stock BuyHouse(playerid, houseid)
  1264. {
  1265.     new string[64];
  1266.     new name[24];
  1267.     GetPlayerName(playerid, name, 24);
  1268.     GivePlayerMoney(playerid, -HouseInfo[houseid][Price]);
  1269.     format(HouseInfo[houseid][Owner], 24, name);
  1270.     HouseInfo[houseid][Locked] = 0;
  1271.     format(string, 64, HOUSE_FILE, houseid);
  1272.     INI_Open(string);
  1273.     INI_WriteString("Owner", HouseInfo[houseid][Owner]);
  1274.     INI_WriteInt("Locked", HouseInfo[houseid][Locked]);
  1275.     INI_Save();
  1276.     INI_Close();
  1277.    
  1278.     DestroyDynamicPickup(HousePickup[houseid]);
  1279.     HousePickup[houseid] = CreateDynamicPickup(1318, 23, HouseInfo[houseid][ExteriorX], HouseInfo[houseid][ExteriorY], HouseInfo[houseid][ExteriorZ]);
  1280.     #if MAP_ICONS == 1
  1281.     DestroyDynamicMapIcon(HouseIcon[houseid]);
  1282.     HouseIcon[houseid] = CreateDynamicMapIcon(HouseInfo[houseid][ExteriorX], HouseInfo[houseid][ExteriorY], HouseInfo[houseid][ExteriorZ], 32, 0, _, _, _, 800.0);
  1283.     #endif
  1284.    
  1285.     #if CONSOLE == 1
  1286.     printf("Player %s(%d) bought house ID %d.", name, playerid, houseid);
  1287.     #endif
  1288.     FS_MsgBox(playerid, "{33AA33}ACTION", "You bought this house.");
  1289.     return 1;
  1290. }
  1291.  
  1292. stock BuyShop(playerid, shopid)
  1293. {
  1294.     new string[64];
  1295.     new name[24];
  1296.     GetPlayerName(playerid, name, 24);
  1297.     GivePlayerMoney(playerid, -BusinessInfo[shopid][bPrice]);
  1298.     format(BusinessInfo[shopid][bOwner], 24, name);
  1299.     BusinessInfo[shopid][bLocked] = 0;
  1300.     format(string, 64, SHOP_FILE, shopid);
  1301.     INI_Open(string);
  1302.     INI_WriteString("Owner", BusinessInfo[shopid][bOwner]);
  1303.     INI_WriteInt("Locked", BusinessInfo[shopid][bLocked]);
  1304.     INI_Save();
  1305.     INI_Close();
  1306.     DestroyDynamicPickup(BusinessPickup[shopid]);
  1307.     BusinessPickup[shopid] = CreateDynamicPickup(1318, 23, BusinessInfo[shopid][bExteriorX], BusinessInfo[shopid][bExteriorY], BusinessInfo[shopid][bExteriorZ]);
  1308.     #if CONSOLE == 1
  1309.     printf("Player %s(%d) bought store ID %d.", name, playerid, shopid);
  1310.     #endif
  1311.     FS_MsgBox(playerid, "{33AA33}ACTION", "You bought this store.");
  1312.     return 1;
  1313. }
  1314.  
  1315. stock SellHouse(playerid, houseid)
  1316. {
  1317.     new string[256];
  1318.     new name[24];
  1319.     GetPlayerName(playerid, name, 24);
  1320.     GivePlayerMoney(playerid, floatround(HouseInfo[houseid][Price]*SELL_MULTIPLIER));
  1321.     format(HouseInfo[houseid][Owner], 24, INVALID_OWNER);
  1322.     HouseInfo[houseid][Locked] = 1;
  1323.     format(string, 256, HOUSE_FILE, houseid);
  1324.     INI_Open(string);
  1325.     INI_WriteString("Owner", HouseInfo[houseid][Owner]);
  1326.     INI_WriteInt("Locked", HouseInfo[houseid][Locked]);
  1327.     INI_Save();
  1328.     INI_Close();
  1329.    
  1330.     DestroyDynamicPickup(HousePickup[houseid]);
  1331.     HousePickup[houseid] = CreateDynamicPickup(1273, 23, HouseInfo[houseid][ExteriorX], HouseInfo[houseid][ExteriorY], HouseInfo[houseid][ExteriorZ]);
  1332.     #if MAP_ICONS == 1
  1333.     DestroyDynamicMapIcon(HouseIcon[houseid]);
  1334.     HouseIcon[houseid] = CreateDynamicMapIcon(HouseInfo[houseid][ExteriorX], HouseInfo[houseid][ExteriorY], HouseInfo[houseid][ExteriorZ], 31, 0, _, _, _, 800.0);
  1335.     #endif
  1336.  
  1337.     #if CONSOLE == 1
  1338.     printf("Player %s(%d) sold house ID %d.", name, playerid, houseid);
  1339.     #endif
  1340.     FS_MsgBox(playerid, "{33AA33}ACTION", "You sold this house.");
  1341.     return 1;
  1342. }
  1343.  
  1344. stock SellShop(playerid, shopid)
  1345. {
  1346.     new string[256];
  1347.     new name[24];
  1348.     GetPlayerName(playerid, name, 24);
  1349.     GivePlayerMoney(playerid, floatround(BusinessInfo[shopid][bPrice]*SELL_MULTIPLIER));
  1350.     format(BusinessInfo[shopid][bOwner], 24, INVALID_OWNER);
  1351.     BusinessInfo[shopid][bLocked] = 1;
  1352.     format(string, 256, SHOP_FILE, shopid);
  1353.     INI_Open(string);
  1354.     INI_WriteString("Owner", BusinessInfo[shopid][bOwner]);
  1355.     INI_WriteInt("Locked", BusinessInfo[shopid][bLocked]);
  1356.     INI_Save();
  1357.     INI_Close();
  1358.     DestroyDynamicPickup(BusinessPickup[shopid]);
  1359.     BusinessPickup[shopid] = CreateDynamicPickup(1272, 23, BusinessInfo[shopid][bExteriorX], BusinessInfo[shopid][bExteriorY], BusinessInfo[shopid][bExteriorZ]);
  1360.     #if CONSOLE == 1
  1361.     printf("Player %s(%d) sold store ID %d.", name, playerid, shopid);
  1362.     #endif
  1363.     FS_MsgBox(playerid, "{33AA33}ACTION", "You sold this store.");
  1364.     return 1;
  1365. }
  1366.  
  1367. forward player_unfreeze(playerid);
  1368. public player_unfreeze(playerid) { return TogglePlayerControllable(playerid, true); }
  1369.  
  1370. stock EnterHouse(playerid, houseid)
  1371. {
  1372.     SetPlayerPos(playerid, HouseInfo[houseid][InteriorX], HouseInfo[houseid][InteriorY], HouseInfo[houseid][InteriorZ]);
  1373.     SetPlayerInterior(playerid, HouseInfo[houseid][Interior]);
  1374.     SetPlayerVirtualWorld(playerid, HouseInfo[houseid][VirtualWorld]);
  1375.     SetLastHouse(playerid, houseid);
  1376.     TogglePlayerControllable(playerid, false);
  1377.     GameTextForPlayer(playerid, "~r~Please Wait", 2000, 5);
  1378.     SetTimerEx("player_unfreeze", 2000, false, "i", playerid);
  1379.     return 1;
  1380. }
  1381.  
  1382. stock EnterShop(playerid, shopid)
  1383. {
  1384.     SetPlayerPos(playerid, BusinessInfo[shopid][bInteriorX], BusinessInfo[shopid][bInteriorY], BusinessInfo[shopid][bInteriorZ]);
  1385.     SetPlayerInterior(playerid, BusinessInfo[shopid][bInterior]);
  1386.     SetPlayerVirtualWorld(playerid, BusinessInfo[shopid][bVirtualWorld]);
  1387.     SetLastShop(playerid, shopid);
  1388.     return 1;
  1389. }
  1390.  
  1391. forward ExitHouse(playerid, houseid);
  1392. public ExitHouse(playerid, houseid)
  1393. {
  1394.     SetPlayerPos(playerid, HouseInfo[houseid][ExteriorX], HouseInfo[houseid][ExteriorY], HouseInfo[houseid][ExteriorZ]);
  1395.     SetPlayerInterior(playerid, HouseInfo[houseid][Exterior]);
  1396.     SetPlayerVirtualWorld(playerid, 0);
  1397.     SetLastHouse(playerid, INVALID_HOUSE_ID);
  1398.     KillTimer(pVisitTimer[playerid]);
  1399.     return 1;
  1400. }
  1401.  
  1402. stock ExitShop(playerid, shopid)
  1403. {
  1404.     SetPlayerPos(playerid, BusinessInfo[shopid][bExteriorX], BusinessInfo[shopid][bExteriorY], BusinessInfo[shopid][bExteriorZ]);
  1405.     SetPlayerInterior(playerid, BusinessInfo[shopid][bExterior]);
  1406.     SetPlayerVirtualWorld(playerid, 0);
  1407.     SetLastShop(playerid, INVALID_HOUSE_ID);
  1408.     return 1;
  1409. }
  1410.  
  1411. stock LockUnlockHouse(playerid, houseid)
  1412. {
  1413.     if(HouseInfo[houseid][Locked] == 0)
  1414.     {
  1415.         HouseInfo[houseid][Locked] = 1;
  1416.         FS_MsgBox(playerid, BOX_STYLE_CMD, "House {FF0000}locked");
  1417.     }
  1418.     else
  1419.     {
  1420.         HouseInfo[houseid][Locked] = 0;
  1421.         FS_MsgBox(playerid, BOX_STYLE_CMD, "House {33AA33}unlocked");
  1422.     }
  1423.     new string[128];
  1424.     format(string, 128, HOUSE_FILE, houseid);
  1425.     INI_Open(string);
  1426.     INI_WriteInt("Locked", HouseInfo[houseid][Locked]);
  1427.     INI_Save();
  1428.     INI_Close();
  1429.     return 1;
  1430. }
  1431.  
  1432. stock LockUnlockShop(playerid, shopid)
  1433. {
  1434.     if(BusinessInfo[shopid][bLocked] == 0)
  1435.     {
  1436.         BusinessInfo[shopid][bLocked] = 1;
  1437.         FS_MsgBox(playerid, BOX_STYLE_CMD, "Store {FF0000}locked");
  1438.     }
  1439.     else
  1440.     {
  1441.         BusinessInfo[shopid][bLocked] = 0;
  1442.         FS_MsgBox(playerid, BOX_STYLE_CMD, "Store {33AA33}unlocked");
  1443.     }
  1444.     new string[128];
  1445.     format(string, 128, SHOP_FILE, shopid);
  1446.     INI_Open(string);
  1447.     INI_WriteInt("Locked", BusinessInfo[shopid][bLocked]);
  1448.     INI_Save();
  1449.     INI_Close();
  1450.     return 1;
  1451. }
  1452.  
  1453. stock GetEarnings(playerid, shopid)
  1454. {
  1455.     if(BusinessInfo[shopid][Money] <= 0) return FS_MsgBox(playerid, BOX_STYLE_ERROR, "The cash register is empty!");
  1456.     new string[64];
  1457.     GivePlayerMoney(playerid, BusinessInfo[shopid][Money]);
  1458.     format(string, 64, "You withdrew %d$!", BusinessInfo[shopid][Money]);
  1459.     FS_MsgBox(playerid, "{33AA33}ACTION", string);
  1460.     BusinessInfo[shopid][bMoney] = 0;
  1461.     format(string, 64, SHOP_FILE, shopid);
  1462.     INI_Open(string);
  1463.     INI_WriteInt("Money", BusinessInfo[shopid][Money]);
  1464.     INI_Save();
  1465.     INI_Close();
  1466.     return 1;
  1467. }
  1468.  
  1469. stock AddEarnings(shopid, money)
  1470. {
  1471.     BusinessInfo[shopid][bMoney] += money;
  1472.     new string[64];
  1473.     format(string, 64, SHOP_FILE, shopid);
  1474.     INI_Open(string);
  1475.     INI_WriteInt("Money", BusinessInfo[shopid][Money]);
  1476.     INI_Save();
  1477.     INI_Close();
  1478.     return 1;
  1479. }
  1480.  
  1481. stock ShowFurnitureMenu(playerid)
  1482. {
  1483.     new bigstring[2048];
  1484.     new string[64];
  1485.     new money = GetPlayerMoney(playerid);
  1486.     new i = 1;
  1487.     while(i < FURNITURE_NUMBER)
  1488.     {
  1489.         if(money >= FurnitureInfo[i][1]) format(string, 64, "{33AA33}%s - %d$", FurnitureInfo[i][2], FurnitureInfo[i][1]);
  1490.         else format(string, 64, "{FF0000}%s - %d$", FurnitureInfo[i][2], FurnitureInfo[i][1]);
  1491.         format(bigstring, sizeof(bigstring), "%s%s\n", bigstring, string);
  1492.         i++;
  1493.     }
  1494.     ShowPlayerDialog(playerid, DIALOG_BUY_FURNITURE, DIALOG_STYLE_LIST, "{33AA33}Buy a new furniture!", bigstring, "Buy", "Cancel");
  1495.     return 1;
  1496. }
  1497.  
  1498. stock GetXYInFrontOfPlayer(playerid, &Float:x, &Float:y, Float:distance)
  1499. {
  1500.     new Float:a;
  1501.     GetPlayerPos(playerid, x, y, a);
  1502.     GetPlayerFacingAngle(playerid, a);
  1503.     if (GetPlayerVehicleID(playerid))
  1504.     {
  1505.       GetVehicleZAngle(GetPlayerVehicleID(playerid), a);
  1506.     }
  1507.     x += (distance * floatsin(-a, degrees));
  1508.     y += (distance * floatcos(-a, degrees));
  1509. }
  1510.  
  1511. stock strtok(const string[], &index)
  1512. {
  1513.     new length = strlen(string);
  1514.     while ((index < length) && (string[index] <= ' '))
  1515.     {
  1516.         index++;
  1517.     }
  1518.  
  1519.     new offset = index;
  1520.     new result[20];
  1521.     while ((index < length) && (string[index] > ' ') && ((index - offset) < (sizeof(result) - 1)))
  1522.     {
  1523.         result[index - offset] = string[index];
  1524.         index++;
  1525.     }
  1526.     result[index - offset] = EOS;
  1527.     return result;
  1528. }
  1529.  
  1530. stock strrest(const string[], &index)
  1531. {
  1532.     new length = strlen(string);
  1533.     while ((index < length) && (string[index] <= ' '))
  1534.     {
  1535.         index++;
  1536.     }
  1537.     new offset = index;
  1538.     new result[128];
  1539.     while ((index < length) && ((index - offset) < (sizeof(result) - 1)))
  1540.     {
  1541.         result[index - offset] = string[index];
  1542.         index++;
  1543.     }
  1544.     result[index - offset] = EOS;
  1545.     return result;
  1546. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement