Advertisement
filip2000

House System

May 25th, 2017
1,582
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 20.25 KB | None | 0 0
  1. /*
  2.  
  3.             HOUSE SYSTEM 1.00  
  4.             LAST UPDATE: 22/05/2017                    
  5.  [>] Script made by - Filip.
  6.         Contacts: @filip2000 (TELEGRAM)
  7.                   filip.jurewicz11 (SKYPE)
  8.  
  9. */
  10.  
  11. #define MAX_HOUSES 500
  12.  
  13. #define PICKUP_HOUSE_SALE   1272
  14. #define PICKUP_HOUSE_SOLD   1273
  15. #define PICKUP_HOUSE_TYPE   23
  16.  
  17. #define HOUSE_AREA_RANGE 2.0
  18.  
  19. enum E_HOUSE_INFO
  20. {
  21.     ID,
  22.     hOwner[MAX_PLAYER_NAME],
  23.     Float: hX,
  24.     Float: hY,
  25.     Float: hZ,
  26.     Float: hAngle,
  27.  
  28.     hInterior,
  29.     hInt,
  30.     hVW,
  31.     hPrice,
  32.     hOwned,
  33.     hDoor,
  34.     hSafe,
  35.     hPickup,
  36.     Text3D: hLabel,
  37.  
  38.     hCreatedAt[12]
  39. };
  40.  
  41. enum E_HOUSE_INTERIOR_INFO
  42. {
  43.     Float: iX,
  44.     Float: iY,
  45.     Float: iZ,
  46.     ID
  47. };
  48.  
  49. new HouseInteriors[][E_HOUSE_INTERIOR_INFO] =
  50. {
  51.     {2233.4900, -1114.4435, 1050.8828, 5},
  52.     {2196.3943, -1204.1359, 1049.0234, 6},
  53.     {2318.1616, -1026.3762, 1050.2109, 9},
  54.     {421.8333, 2536.9814, 10.0000, 10},
  55.     {225.5707, 1240.0643, 1082.1406, 2},
  56.     {2496.2087, -1692.3149, 1014.7422, 3},
  57.     {226.7545, 1114.4180, 1080.9952, 5},
  58.     {2269.9636, -1210.3275, 1047.5625, 10}
  59. };
  60.  
  61. new
  62.     HouseInfo[MAX_HOUSES][E_HOUSE_INFO],
  63.     Iterator: HouseIter<MAX_HOUSES>;
  64.  
  65. #define HOUSE_MAGIC 1000
  66. #define _house_included
  67. new houseArea[MAX_HOUSES];
  68. new PlayerText: houseText[MAX_PLAYERS][1];
  69. new playerHouseArea[MAX_PLAYERS];
  70. new playerInsideHouse[MAX_PLAYERS];
  71.  
  72. public OnGameModeInit()
  73. {
  74.     House_Load();
  75.     #if defined h_OnGameModeInit
  76.         h_OnGameModeInit();
  77.     #endif
  78.     return 1;
  79. }
  80.  
  81. #if defined _ALS_OnGameModeInit
  82.     #undef OnGameModeInit
  83. #else
  84.     #define _ALS_OnGameModeInit
  85. #endif
  86.  
  87. #define OnGameModeInit h_OnGameModeInit
  88. #if defined h_OnGameModeInit
  89.     forward h_OnGameModeInit();
  90. #endif
  91.  
  92. public OnPlayerConnect(playerid)
  93. {
  94.     House_CreateTD(playerid);
  95.     House_ResetStats(playerid);
  96.     #if defined h_OnPlayerConnect
  97.         h_OnPlayerConnect(playerid);
  98.     #endif
  99.     return 1;
  100. }
  101.  
  102. #if defined _ALS_OnPlayerConnect
  103.     #undef OnPlayerConnect
  104. #else
  105.     #define _ALS_OnPlayerConnect
  106. #endif
  107.  
  108. #define OnPlayerConnect h_OnPlayerConnect
  109. #if defined h_OnPlayerConnect
  110.     forward h_OnPlayerConnect(playerid);
  111. #endif
  112.  
  113. public OnPlayerEnterDynamicArea(playerid, areaid)
  114. {
  115.     new houseid = Streamer_GetIntData(STREAMER_TYPE_AREA, areaid, E_STREAMER_EXTRA_ID) - HOUSE_MAGIC;
  116.     if(0 <= houseid < MAX_HOUSES)
  117.     {
  118.         playerHouseArea[playerid] = houseid;
  119.         if(HouseInfo[houseid][hOwned])
  120.         {
  121.             PlayerTextDrawSetString(playerid, houseText[playerid][0], sprintf("~w~Press_~y~/henter~w~_to_enter_inside_this_house."));
  122.             PlayerTextDrawShow(playerid, houseText[playerid][0]);
  123.         }
  124.         else
  125.         {
  126.             PlayerTextDrawSetString(playerid, houseText[playerid][0], sprintf("~w~Press_~y~/henter~w~_to_enter_inside_this_house.~n~Press_~y~/buyhouse~w~_to_buy_this_house.~n~Price:_~y~%i~w~$", HouseInfo[houseid][hPrice]));
  127.             PlayerTextDrawShow(playerid, houseText[playerid][0]);
  128.         }
  129.  
  130.     }
  131.     #if defined h_OnPlayerEnterDynamicArea
  132.         return h_OnPlayerEnterDynamicArea(playerid, areaid);
  133.     #else
  134.         return 1;
  135.     #endif
  136. }
  137. #if defined _ALS_OnPlayerEnterDynamicArea
  138.     #undef OnPlayerEnterDynamicArea
  139. #else
  140.     #define _ALS_OnPlayerEnterDynamicArea
  141. #endif
  142.  
  143. #define OnPlayerEnterDynamicArea h_OnPlayerEnterDynamicArea
  144. #if defined h_OnPlayerEnterDynamicArea
  145.     forward h_OnPlayerEnterDynamicArea(playerid, areaid);
  146. #endif
  147.  
  148. public OnPlayerLeaveDynamicArea(playerid, areaid)
  149. {
  150.     if(playerHouseArea[playerid] >= 0)
  151.     {
  152.         playerHouseArea[playerid] = -1;
  153.         PlayerTextDrawHide(playerid, houseText[playerid][0]);
  154.     }
  155.     #if defined h_OnPlayerLeaveDynamicArea
  156.         return h_OnPlayerLeaveDynamicArea(playerid, areaid);
  157.     #else
  158.         return 1;
  159.     #endif
  160. }
  161. #if defined _ALS_OnPlayerLeaveDynamicArea
  162.     #undef OnPlayerLeaveDynamicArea
  163. #else
  164.     #define _ALS_OnPlayerLeaveDynamicArea
  165. #endif
  166.  
  167. #define OnPlayerLeaveDynamicArea h_OnPlayerLeaveDynamicArea
  168. #if defined h_OnPlayerLeaveDynamicArea
  169.     forward h_OnPlayerLeaveDynamicArea(playerid, areaid);
  170. #endif
  171.  
  172. House_Load() return mysql_tquery(handlesql, "SELECT * FROM `houses` ORDER BY `ID`", "House_OnLoad", "");
  173.  
  174. House_OnLoad(); public House_OnLoad()
  175. {
  176.     new rows = cache_num_rows();
  177.     if(rows)
  178.     {
  179.         for(new i; i < rows; i++)
  180.         {
  181.             new id = Iter_Free(HouseIter);
  182.             if(id != -1)
  183.             {
  184.                 cache_get_value_int(i, "ID", HouseInfo[id][ID]);
  185.                 cache_get_value(i, "h_Owner", HouseInfo[id][hOwner], MAX_PLAYER_NAME);
  186.                 cache_get_value(i, "h_CreatedAt", HouseInfo[id][hCreatedAt], 12);
  187.  
  188.                 cache_get_value_float(i, "h_X", HouseInfo[id][hX]);
  189.                 cache_get_value_float(i, "h_Y", HouseInfo[id][hZ]);
  190.                 cache_get_value_float(i, "h_Z", HouseInfo[id][hY]);
  191.                 cache_get_value_float(i, "h_Angle", HouseInfo[id][hAngle]);
  192.  
  193.                 cache_get_value_int(i, "h_Interior", HouseInfo[id][hInterior]);
  194.                 cache_get_value_int(i, "h_Int", HouseInfo[id][hInt]);
  195.                 cache_get_value_int(i, "h_VW", HouseInfo[id][hVW]);
  196.                 cache_get_value_int(i, "h_Price", HouseInfo[id][hPrice]);
  197.                 cache_get_value_int(i, "h_Owned", HouseInfo[id][hOwned]);
  198.                 cache_get_value_int(i, "h_Door", HouseInfo[id][hDoor]);
  199.                 cache_get_value_int(i, "h_Safe", HouseInfo[id][hSafe]);
  200.  
  201.                 Iter_Add(HouseIter, id);
  202.             }
  203.         }
  204.     }
  205.     printf("[House] %i houses was loaded.", rows);
  206. }
  207.  
  208. House_Created(houseid); public House_Created(houseid)
  209. {
  210.     HouseInfo[houseid][ID] = cache_insert_id();
  211.     return House_Save(houseid);
  212. }
  213.  
  214. House_Create(Float: X, Float: Y, Float: Z, Float: Angle, Interior, Int, Virtualworld, Price)
  215. {
  216.     new id = Iter_Free(HouseIter);
  217.     if(id != -1)
  218.     {
  219.         new mounths, days, years;
  220.         House_SetInterior(id, Interior);
  221.  
  222.         format(HouseInfo[id][hOwner], MAX_PLAYER_NAME, "n/a");
  223.         HouseInfo[id][hOwned] = 0;
  224.         HouseInfo[id][hPrice] = Price;
  225.         HouseInfo[id][hVW] = Virtualworld;
  226.         HouseInfo[id][hInt] = Int;
  227.         HouseInfo[id][hX] = X;
  228.         HouseInfo[id][hY] = Y;
  229.         HouseInfo[id][hZ] = Z;
  230.         HouseInfo[id][hAngle] = Angle;
  231.  
  232.         getdate(years, mounths, days);
  233.         format(HouseInfo[id][hCreatedAt], 12, "%i/%i/%i", days, mounths, years);
  234.         Iter_Add(HouseIter, id);
  235.         mysql_tquery(handlesql, "INSERT INTO `houses` (`h_X`) VALUES (0)", "House_Created", "i", id);
  236.     }
  237.     return id;
  238. }
  239.  
  240. House_Save(houseid)
  241. {
  242.     new query[256];
  243.     mysql_format(handlesql, query, sizeof query, "UPDATE `houses` SET `h_X` = '%f', `h_Y` = '%f', `h_Z` = '%f', `h_Angle` = '%f', `h_VW` = '%i', `h_Interior` = '%i', `h_Price` = '%i', `h_Owner` = '%e', `h_CreatedAt` = '%e', `h_Safe` = '%i', `h_Int` = '%i', `h_Owned` = '%i' WHERE `ID` = '%i'",
  244.         HouseInfo[houseid][hX],
  245.         HouseInfo[houseid][hY],
  246.         HouseInfo[houseid][hZ],
  247.         HouseInfo[houseid][hAngle],
  248.         HouseInfo[houseid][hVW],
  249.         HouseInfo[houseid][hInterior],
  250.         HouseInfo[houseid][hPrice],
  251.         HouseInfo[houseid][hOwner],
  252.         HouseInfo[houseid][hCreatedAt],
  253.         HouseInfo[houseid][hSafe],
  254.         HouseInfo[houseid][hInt],
  255.         HouseInfo[houseid][hOwned],
  256.         HouseInfo[houseid][ID]);
  257.     mysql_tquery(handlesql, query);
  258.     House_Refresh(houseid);
  259.     return 1;
  260. }
  261.  
  262. House_Delete(houseid)
  263. {
  264.     new query[128];
  265.     mysql_format(handlesql, query, sizeof query, "DELETE FROM `houses` WHERE `ID` = '%i'", HouseInfo[houseid][ID]);
  266.     mysql_query(handlesql, query);
  267.  
  268.     HouseInfo[houseid][hOwner] = EOS;
  269.     HouseInfo[houseid][hCreatedAt] = EOS;
  270.  
  271.     HouseInfo[houseid][hPrice] = HouseInfo[houseid][hVW] =
  272.     HouseInfo[houseid][hInterior] = HouseInfo[houseid][hInt] =
  273.     HouseInfo[houseid][hOwned] = HouseInfo[houseid][hSafe] =
  274.     HouseInfo[houseid][hDoor] = HouseInfo[houseid][ID] = -1;
  275.  
  276.     HouseInfo[houseid][hX] = HouseInfo[houseid][hY] =
  277.     HouseInfo[houseid][hZ] = HouseInfo[houseid][hAngle] = 0.0;
  278.  
  279.     DestroyDynamicPickup(HouseInfo[houseid][hPickup]);
  280.     DestroyDynamicArea(houseArea[houseid]);
  281.     DestroyDynamic3DTextLabel(HouseInfo[houseid][hLabel]);
  282.  
  283.     Iter_Remove(HouseIter, houseid);
  284.     return 1;
  285. }
  286.  
  287. House_Refresh(houseid)
  288. {
  289.     DestroyDynamicPickup(HouseInfo[houseid][hPickup]);
  290.     DestroyDynamicArea(houseArea[houseid]);
  291.     DestroyDynamic3DTextLabel(HouseInfo[houseid][hLabel]);
  292.  
  293.     House_CreatePickup(houseid);
  294.     House_CreateSphere(houseid);
  295.     House_Create3DText(houseid);
  296.     return 1;
  297. }
  298.  
  299. House_CreatePickup(houseid)
  300. {
  301.     HouseInfo[houseid][hPickup] = CreateDynamicPickup(HouseInfo[houseid][hOwned] ? PICKUP_HOUSE_SOLD : PICKUP_HOUSE_SALE,
  302.         PICKUP_HOUSE_TYPE,
  303.         HouseInfo[houseid][hX],
  304.         HouseInfo[houseid][hY],
  305.         HouseInfo[houseid][hZ],
  306.         HouseInfo[houseid][hVW],
  307.         HouseInfo[houseid][hInt]);
  308.     return HouseInfo[houseid][hPickup];
  309. }
  310.  
  311. House_CreateSphere(houseid)
  312. {
  313.     houseArea[houseid] = CreateDynamicSphere(
  314.         HouseInfo[houseid][hX],
  315.         HouseInfo[houseid][hY],
  316.         HouseInfo[houseid][hZ],
  317.         HOUSE_AREA_RANGE,
  318.         HouseInfo[houseid][hVW],
  319.         HouseInfo[houseid][hInt]);
  320.  
  321.     Streamer_SetIntData(STREAMER_TYPE_AREA, houseArea[houseid], E_STREAMER_EXTRA_ID, houseid + HOUSE_MAGIC);
  322.     return houseArea[houseid];
  323. }
  324.  
  325. House_Create3DText(houseid)
  326. {
  327.     new str[128];
  328.     if(HouseInfo[houseid][hOwned] == 0)
  329.         format(str, sizeof str, "House [%i]\nPrice: %i$", houseid, HouseInfo[houseid][hPrice]);
  330.     else
  331.         format(str, sizeof str, "House [%i]\nOwner: %s", houseid, HouseInfo[houseid][hOwner]);
  332.  
  333.     HouseInfo[houseid][hLabel] = CreateDynamic3DTextLabel(str, -1,
  334.         HouseInfo[houseid][hX], HouseInfo[houseid][hY], HouseInfo[houseid][hZ], 5.0, INVALID_PLAYER_ID, INVALID_VEHICLE_ID, HouseInfo[houseid][hVW], HouseInfo[houseid][hInt]);
  335.  
  336.     return 1;
  337. }
  338.  
  339. House_SetInterior(id, int) return HouseInfo[id][hInterior] = HouseInteriors[int][ID];
  340.  
  341. House_Sell(houseid)
  342. {
  343.     HouseInfo[houseid][hOwner] = EOS;
  344.     HouseInfo[houseid][hDoor] = HouseInfo[houseid][hSafe] = HouseInfo[houseid][hOwned] = 0;
  345.     House_Save(houseid);
  346.     return 1;
  347. }
  348.  
  349. House_ResetStats(playerid)
  350. {
  351.     playerHouseArea[playerid] = playerInsideHouse[playerid] = -1;
  352.     return 1;
  353. }
  354.  
  355. House_CreateTD(playerid)
  356. {
  357.     houseText[playerid][0] = CreatePlayerTextDraw(playerid, 21.555515, 116.826690, "Press_/henter_to_enter_inside_this_house.~n~Press_/buyhouse_to_buy_this_house.~n~Price:_0000$");
  358.     PlayerTextDrawLetterSize(playerid, houseText[playerid][0], 0.186222, 1.052444);
  359.     PlayerTextDrawTextSize(playerid, houseText[playerid][0], 154.000000, 0.000000);
  360.     PlayerTextDrawAlignment(playerid, houseText[playerid][0], 1);
  361.     PlayerTextDrawColor(playerid, houseText[playerid][0], -1);
  362.     PlayerTextDrawUseBox(playerid, houseText[playerid][0], 1);
  363.     PlayerTextDrawBoxColor(playerid, houseText[playerid][0], 150);
  364.     PlayerTextDrawSetShadow(playerid, houseText[playerid][0], 0);
  365.     PlayerTextDrawSetOutline(playerid, houseText[playerid][0], 1);
  366.     PlayerTextDrawBackgroundColor(playerid, houseText[playerid][0], 255);
  367.     PlayerTextDrawFont(playerid, houseText[playerid][0], 1);
  368.     PlayerTextDrawSetProportional(playerid, houseText[playerid][0], 1);
  369.     PlayerTextDrawSetShadow(playerid, houseText[playerid][0], 0);
  370.     return 1;
  371. }
  372.  
  373. CMD:ahouse(playerid, params[])
  374. {
  375.     if(!IsPlayerAdmin(playerid)) return SendClientMessage(playerid, 0xFF6347FF, "You are not authorized to use this command.");
  376.     new
  377.         cmd[32], value_1, value_2;
  378.     if(sscanf(params, "s[32]D(-1)D(-1)", cmd, value_1, value_2))
  379.     {
  380.         SendClientMessage(playerid, 0xFF6347FF, "SYNTAX{FFFFFF}: /ahouse [cmd]");
  381.         SendClientMessage(playerid, 0xFF6347FF, ">{FFFFFF} create | save | delete");
  382.         SendClientMessage(playerid, 0xFF6347FF, ">{FFFFFF} stats | near | sell | createdat");
  383.         return 1;
  384.     }
  385.     if(!strcmp(cmd, "create", false))
  386.     {
  387.         if(value_1 == -1) return SendClientMessage(playerid, 0xFF6347FF, "SYNTAX{FFFFFF}: /ahouse create [interior] [price]");
  388.         if(value_1 < 0 || value_1 > sizeof HouseInteriors) return SendClientMessage(playerid, 0xFF6347FF, "ERROR: {FFFFFF}Invalid interior ID. (0, 7)");
  389.         if(value_2 == -1) return SendClientMessage(playerid, 0xFF6347FF, "SYNTAX{FFFFFF}: /ahouse create [interior] [price]");
  390.         new Float: X, Float: Y, Float: Z, Float: Angle;
  391.         GetPlayerPos(playerid, X, Y, Z);
  392.         GetPlayerFacingAngle(playerid, Angle);
  393.         new id = House_Create(X, Y, Z, Angle, value_1, GetPlayerInterior(playerid), GetPlayerVirtualWorld(playerid), value_2);
  394.         if(id == -1) return SendClientMessage(playerid, 0xFF6347FF, "ERROR: {FFFFFF}Can't create more houses.");
  395.         SendClientMessage(playerid, 0xFF6347FF, "AdmCmd{FFFFFF}: House has been created.");
  396.         return 1;
  397.     }
  398.     if(!strcmp(cmd, "save", false))
  399.     {
  400.         if(!Iter_Contains(HouseIter, value_1)) return SendClientMessage(playerid, 0xFF6347FF, "ERROR: {FFFFFF}Invalid house ID.");
  401.         SendClientMessage(playerid, 0xFF6347FF, sprintf("AdmCmd: {FFFFFF}House #%i has been updated.", value_1));
  402.         House_Save(value_1);
  403.         return 1;
  404.     }
  405.     if(!strcmp(cmd, "delete", false))
  406.     {
  407.         if(!Iter_Contains(HouseIter, value_1)) return SendClientMessage(playerid, 0xFF6347FF, "ERROR: {FFFFFF}Invalid house ID.");
  408.         SendClientMessage(playerid, 0xFF6347FF, sprintf("AdmCmd: {FFFFFF}House #%i has been deleted.", value_1));
  409.         House_Delete(value_1);
  410.         return 1;
  411.     }
  412.     if(!strcmp(cmd, "near", false))
  413.     {
  414.         new str[128];
  415.         if(playerHouseArea[playerid] >= 0) format(str, sizeof str, "AdmCmd: {FFFFFF}You are near house #%i.", playerHouseArea[playerid]);
  416.         else format(str, sizeof str, "AdmCmd: {FFFFFF}You are not near house.");
  417.         return SendClientMessage(playerid, 0xFF6347FF, str);
  418.     }
  419.     if(!strcmp(cmd, "sell", false))
  420.     {
  421.         if(!Iter_Contains(HouseIter, value_1)) return SendClientMessage(playerid, 0xFF6347FF, "ERROR: {FFFFFF}Invalid house ID.");
  422.         if(!HouseInfo[value_1][hOwned]) return SendClientMessage(playerid, 0xFF6347FF, "ERROR: {FFFFFF}This house is already set for sale.");
  423.         SendClientMessage(playerid, 0xFF6347FF, sprintf("AdmCmd: {FFFFFF}House #%i has been setup for sale.", value_1));
  424.         House_Sell(value_1);
  425.     }
  426.     if(!strcmp(cmd, "createdat", false))
  427.     {
  428.         if(!Iter_Contains(HouseIter, value_1)) return SendClientMessage(playerid, 0xFF6347FF, "ERROR: {FFFFFF}Invalid house ID.");
  429.         SendClientMessage(playerid, 0xFF6347FF, sprintf("AdmCmd: {FFFFFF}House #%i was created at %s.", HouseInfo[value_1][hCreatedAt]));
  430.         return 1;
  431.     }
  432.     if(!strcmp(cmd, "stats", false))
  433.     {
  434.         if(!Iter_Contains(HouseIter, value_1)) return SendClientMessage(playerid, 0xFF6347FF, "ERROR: {FFFFFF}Invalid house ID.");
  435.         new str[28];
  436.         if(HouseInfo[value_1][hDoor])
  437.             str = "Locked";
  438.         else
  439.             str = "Unlocked";
  440.         SendClientMessage(playerid, 0xFF6347FF, "House Information:");
  441.         SendClientMessage(playerid, -1, sprintf("** ID: %i Database ID: %i - Owner: %s - Door: %s**", value_1, HouseInfo[value_1][ID], HouseInfo[value_1][hOwner], str));
  442.         SendClientMessage(playerid, -1, sprintf("** Safe: %i$ - Interior: %i - Price: %i$ **", HouseInfo[value_1][hSafe], HouseInfo[value_1][hInterior], HouseInfo[value_1][hPrice]));
  443.         return 1;
  444.     }
  445.     return 1;
  446. }
  447.  
  448. CMD:house(playerid, params[])
  449. {
  450.     new
  451.         cmd[32], value_1, value_2;
  452.     if(sscanf(params, "s[32]D(-1)D(-1)", cmd, value_1, value_2))
  453.     {
  454.         SendClientMessage(playerid, 0xFF6347FF, "SYNTAX{FFFFFF}: /house [cmd]");
  455.         SendClientMessage(playerid, 0xFF6347FF, ">{FFFFFF} door | withdraw | deposit | balance");
  456.         return 1;
  457.     }
  458.     if(!strcmp(cmd, "door", false))
  459.     {
  460.         if(playerHouseArea[playerid] >= 0 || playerInsideHouse[playerid] >= 0)
  461.         {
  462.             new houseid, name_str[MAX_PLAYER_NAME];
  463.             if(playerHouseArea[playerid] != -1)
  464.                 houseid = playerHouseArea[playerid];
  465.             else if(playerInsideHouse[playerid] != -1)
  466.                 houseid = playerInsideHouse[playerid];
  467.  
  468.             GetPlayerName(playerid, name_str, MAX_PLAYER_NAME);
  469.             if(!strcmp(name_str, HouseInfo[houseid][hOwner], false))
  470.             {
  471.                 if(HouseInfo[houseid][hDoor])
  472.                     HouseInfo[houseid][hDoor] = 0, SendClientMessage(playerid, -1, "Door unlocked.");
  473.                 else
  474.                     HouseInfo[houseid][hDoor] = 1, SendClientMessage(playerid, -1, "Door locked.");
  475.             }
  476.             else return SendClientMessage(playerid, 0xFF6347FF, "You are not near your own house.");
  477.         }
  478.         else return SendClientMessage(playerid, 0xFF6347FF, "You are not near house.");
  479.     }
  480.     if(!strcmp(cmd, "withdraw", false))
  481.     {
  482.         if(playerInsideHouse[playerid] >= 0)
  483.         {
  484.             new houseid = playerInsideHouse[playerid], name_str[MAX_PLAYER_NAME];
  485.             GetPlayerName(playerid, name_str, MAX_PLAYER_NAME);
  486.             if(!strcmp(name_str, HouseInfo[houseid][hOwner], false))
  487.             {
  488.                 if(value_1 == -1 || value_1 < 0) return SendClientMessage(playerid, 0xFF6347FF, "SYNTAX{FFFFFF}: /house withdraw [amount]");
  489.                 if(value_1 > HouseInfo[houseid][hSafe]) return SendClientMessage(playerid, 0xFF6347FF, "Your house haven't this amount.");
  490.                 GivePlayerMoney(playerid, value_1);
  491.                 House_Save(houseid);
  492.                 return 1;
  493.             }
  494.             else return SendClientMessage(playerid, 0xFF6347FF, "You are not near your own house.");
  495.         }
  496.         else return SendClientMessage(playerid, 0xFF6347FF, "You are not near house.");
  497.     }
  498.     if(!strcmp(cmd, "deposit", false))
  499.     {
  500.         if(playerInsideHouse[playerid] >= 0)
  501.         {
  502.             new houseid = playerInsideHouse[playerid], name_str[MAX_PLAYER_NAME];
  503.             GetPlayerName(playerid, name_str, MAX_PLAYER_NAME);
  504.             if(!strcmp(name_str, HouseInfo[houseid][hOwner], false))
  505.             {
  506.                 if(value_1 == -1 || value_1 < 0) return SendClientMessage(playerid, 0xFF6347FF, "SYNTAX{FFFFFF}: /house deposit [amount]");
  507.                 if(value_1 > GetPlayerMoney(playerid)) return SendClientMessage(playerid, 0xFF6347FF, "You haven't this amount.");
  508.                 GivePlayerMoney(playerid, -value_1);
  509.                 HouseInfo[houseid][hSafe] += value_1;
  510.                 House_Save(houseid);
  511.                 return 1;
  512.             }
  513.             else return SendClientMessage(playerid, 0xFF6347FF, "You are not near your own house.");
  514.         }
  515.         else return SendClientMessage(playerid, 0xFF6347FF, "You are not near house.");
  516.     }
  517.     if(!strcmp(cmd, "balance", false))
  518.     {
  519.         if(playerInsideHouse[playerid] >= 0)
  520.         {
  521.             new houseid = playerInsideHouse[playerid], name_str[MAX_PLAYER_NAME];
  522.             GetPlayerName(playerid, name_str, MAX_PLAYER_NAME);
  523.             if(!strcmp(name_str, HouseInfo[houseid][hOwner], false))
  524.             {
  525.                 new str[128];
  526.                 format(str, sizeof str, "House Safe{FFFFFF}: %i$.", HouseInfo[houseid][hSafe]);
  527.                 SendClientMessage(playerid, 0xFF6347FF, str);
  528.                 return 1;
  529.             }
  530.             else return SendClientMessage(playerid, 0xFF6347FF, "You are not near your own house.");
  531.         }
  532.         else return SendClientMessage(playerid, 0xFF6347FF, "You are not near house.");
  533.     }
  534.     return 1;
  535. }
  536.  
  537. CMD:henter(playerid, params[])
  538. {
  539.     if(playerHouseArea[playerid] >= 0)
  540.     {
  541.         new houseid = playerHouseArea[playerid];
  542.         if(!HouseInfo[houseid][hDoor])
  543.         {
  544.             new name_str[MAX_PLAYER_NAME];
  545.             playerInsideHouse[playerid] = houseid;
  546.             SetPlayerInterior(playerid, HouseInteriors[HouseInfo[houseid][hInterior]][ID]);
  547.             SetPlayerVirtualWorld(playerid, HouseInfo[houseid][ID]);
  548.             SetPlayerPos(playerid, HouseInteriors[HouseInfo[houseid][hInterior]][iX], HouseInteriors[HouseInfo[houseid][hInterior]][iY], HouseInteriors[HouseInfo[houseid][hInterior]][iZ]);
  549.             GetPlayerName(playerid, name_str, MAX_PLAYER_NAME);
  550.             if(!strcmp(name_str, HouseInfo[houseid][hOwner], false))
  551.             {
  552.                 SendClientMessage(playerid, 0x9EC73DFF, sprintf("Welcome to your house %s!", name_str));
  553.                 SendClientMessage(playerid, -1, "Use /house to see all avaible commands.");
  554.             }
  555.             return 1;
  556.         }
  557.         else return SendClientMessage(playerid, 0xFF6347FF, "Door is locked.");
  558.     }
  559.     else return SendClientMessage(playerid, 0xFF6347FF, "You are not near house.");
  560. }
  561.  
  562. CMD:hexit(playerid, params[])
  563. {
  564.     if(playerInsideHouse[playerid] >= 0)
  565.     {
  566.         new houseid = playerInsideHouse[playerid];
  567.         if(!HouseInfo[houseid][hDoor])
  568.         {
  569.             SetPlayerInterior(playerid, HouseInfo[houseid][hInt]);
  570.             SetPlayerVirtualWorld(playerid, HouseInfo[houseid][hVW]);
  571.             SetPlayerPos(playerid, HouseInfo[houseid][hX], HouseInfo[houseid][hY], HouseInfo[houseid][hZ]);
  572.             SetPlayerFacingAngle(playerid, HouseInfo[houseid][hAngle]);
  573.             playerInsideHouse[playerid] = -1;
  574.             return 1;
  575.         }
  576.         else return SendClientMessage(playerid, 0xFF6347FF, "Door is locked.");
  577.     }
  578.     else return SendClientMessage(playerid, 0xFF6347FF, "You are not inside house.");
  579. }
  580.  
  581. CMD:buyhouse(playerid, params[])
  582. {
  583.     if(playerHouseArea[playerid] >= 0)
  584.     {
  585.         new houseid = playerHouseArea[playerid];
  586.         if(!HouseInfo[houseid][hOwned])
  587.         {
  588.             if(GetPlayerMoney(playerid < HouseInfo[houseid][hPrice])) return SendClientMessage(playerid, 0xFF6347FF, "You not have enought money to buy this house.");
  589.             new name_str[MAX_PLAYER_NAME];
  590.             GetPlayerName(playerid, name_str, MAX_PLAYER_NAME);
  591.             GivePlayerMoney(playerid, -HouseInfo[houseid][hPrice]);
  592.             HouseInfo[houseid][hOwned] = 1;
  593.             format(HouseInfo[houseid][hOwner], MAX_PLAYER_NAME, "%s", name_str);
  594.             House_Save(houseid);
  595.             SendClientMessage(playerid, 0xFF6347FF, sprintf("> {FFFFFF}You have bought this house for %i$.", HouseInfo[houseid][hPrice]));
  596.             return 1;
  597.         }
  598.         else return SendClientMessage(playerid, 0xFF6347FF, "This house is already sold.");
  599.     }
  600.     else return SendClientMessage(playerid, 0xFF6347FF, "You are not near house.");
  601. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement