Advertisement
Guest User

Yet Another Business System

a guest
Dec 19th, 2015
2,000
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 56.49 KB | None | 0 0
  1. #define     FILTERSCRIPT
  2. #include    <a_samp>
  3. #include    <a_mysql>
  4. #include    <streamer>
  5. #include    <sscanf2>
  6. #include    <YSI\y_iterate>
  7. #include    <zcmd>
  8.  
  9. #define     SQL_HOST            "sql host"
  10. #define     SQL_USER            "sql username"
  11. #define     SQL_PASSWORD        "sql password"
  12. #define     SQL_DBNAME          "database name"
  13.  
  14. #define     MAX_BUSINESS        (100)
  15. #define     MAX_BUSINESS_NAME   (32)    // maximum length of a business's name (default: 32)
  16. #define     BUSINESS_INTERVAL   (30)    // give money to businesses every x minutes, also saves businesses (default: 30)
  17. #define     BUSINESS_DAYS       (7)     // if a business's owner doesn't visit their business after x days, it will get reset (default: 7)
  18. #define     LIMIT_PER_PLAYER    (3)     // a player can buy up to x businesses - you can set this to 0 if you want it unlimited (default: 3)
  19. #define     INVALID_BUSINESS    (-1)
  20.  
  21. enum    e_businessdialogs
  22. {
  23.     DIALOG_BUY_BUSINESS = 21500,
  24.     DIALOG_BUY_BUSINESS_FROM_OWNER,
  25.     DIALOG_MANAGE_BUSINESS,
  26.     DIALOG_MANAGE_BUSINESS_NAME,
  27.     DIALOG_MANAGE_BUSINESS_SAFE,
  28.     DIALOG_MANAGE_DEPOSIT_TO_SAFE,
  29.     DIALOG_MANAGE_TAKE_FROM_SAFE,
  30.     DIALOG_MANAGE_SELL,
  31.     DIALOG_MANAGE_SELL_TO_PLAYERS,
  32.     DIALOG_MANAGE_PERMISSIONS,
  33.     DIALOG_MANAGE_GIVE_PERM_NAME,
  34.     DIALOG_MANAGE_GIVE_PERM_DEPOSIT,
  35.     DIALOG_MANAGE_GIVE_PERM_TAKE,
  36.     DIALOG_MANAGE_LIST_PERMS,
  37.     DIALOG_MANAGE_EDIT_PERMS,
  38.     DIALOG_MANAGE_SAFE_LOGS,
  39.     DIALOG_ADMIN_BUSINESS_TYPE
  40. }
  41.  
  42. enum    e_businessperms
  43. {
  44.     PERM_CAN_USE_SAFE,
  45.     PERM_CAN_DEPOSIT,
  46.     PERM_CAN_TAKE
  47. }
  48.  
  49. enum    e_business
  50. {
  51.     // saved
  52.     Name[MAX_BUSINESS_NAME],
  53.     Owner[MAX_PLAYER_NAME],
  54.     Float: BusinessX,
  55.     Float: BusinessY,
  56.     Float: BusinessZ,
  57.     Closed,
  58.     Price,
  59.     SalePrice,
  60.     Earning,
  61.     Money,
  62.     Type,
  63.     LastVisited,
  64.     // not saved
  65.     Text3D: BusinessLabel,
  66.     BusinessPickup,
  67.     bool: Save
  68. }
  69.  
  70. enum    e_businessint
  71. {
  72.     InteriorName[32],
  73.     Float: InteriorX,
  74.     Float: InteriorY,
  75.     Float: InteriorZ,
  76.     InteriorID,
  77.     ExitPickup,
  78.     Text3D: ExitLabel
  79. };
  80.  
  81. new
  82.     BusinessSQL,
  83.     BusinessData[MAX_BUSINESS][e_business],
  84.     Iterator: Business<MAX_BUSINESS>;
  85.    
  86. new
  87.     InBusiness[MAX_PLAYERS] = {INVALID_BUSINESS, ...},
  88.     ListPage[MAX_PLAYERS];
  89.  
  90. new
  91.     BusinessStates[2][16] = {"{2ECC71}Open", "{E74C3C}Closed"},
  92.     PermissionStates[2][16] = {"{E74C3C}No", "{2ECC71}Yes"};
  93.  
  94. new
  95.     BusinessInteriors[][e_businessint] = {
  96.         {"24/7 1", -25.884498, -185.868988, 1003.546875, 17},
  97.         {"24/7 2", 6.091179, -29.271898, 1003.549438, 10},
  98.         {"24/7 3", -30.946699, -89.609596, 1003.546875, 18},
  99.         {"24/7 4", -25.132598, -139.066986, 1003.546875, 16},
  100.         {"24/7 5", -27.312299, -29.277599, 1003.557250, 4},
  101.         {"24/7 6", -26.691598, -55.714897, 1003.546875, 6},
  102.         {"Ammunation 1", 286.148986, -40.644397, 1001.515625, 1},
  103.         {"Ammunation 2", 286.800994, -82.547599, 1001.515625, 4},
  104.         {"Ammunation 3", 296.919982, -108.071998, 1001.515625, 6},
  105.         {"Ammunation 4", 314.820983, -141.431991, 999.601562, 7},
  106.         {"Ammunation 5", 316.524993, -167.706985, 999.593750, 6},
  107.         {"Sex Shop", -103.559165, -24.225606, 1000.718750, 3},
  108.         {"Binco", 207.737991, -109.019996, 1005.132812, 15},
  109.         {"Didier Sachs", 204.332992, -166.694992, 1000.523437, 14},
  110.         {"ProLaps", 207.054992, -138.804992, 1003.507812, 3},
  111.         {"Sub Urban", 203.777999, -48.492397, 1001.804687, 1},
  112.         {"Victim", 226.293991, -7.431529, 1002.210937, 5},
  113.         {"Zip", 161.391006, -93.159156, 1001.804687, 18},
  114.         {"Alhambra", 493.390991, -22.722799, 1000.679687, 17},
  115.         {"Bar", 501.980987, -69.150199, 998.757812, 11},
  116.         {"Burger Shot", 375.962463, -65.816848, 1001.507812, 10},
  117.         {"Cluckin' Bell", 369.579528, -4.487294, 1001.858886, 9},
  118.         {"Well Stacked Pizza", 373.825653, -117.270904, 1001.499511, 5},
  119.         {"Strip Club", 1204.809936, -11.586799, 1000.921875, 2},
  120.         {"Pleasure Domes", -2640.762939, 1406.682006, 906.460937, 3},
  121.         {"Barber 1", 411.625976, -21.433298, 1001.804687, 2},
  122.         {"Barber 2", 418.652984, -82.639793, 1001.804687, 3},
  123.         {"Barber 3", 412.021972, -52.649898, 1001.898437, 12},
  124.         {"Tatoo Parlour", -204.439987, -26.453998, 1002.273437, 16}
  125.     };
  126.  
  127. convertNumber(value)
  128. {
  129.     // http://forum.sa-mp.com/showthread.php?p=843781#post843781
  130.     new string[24];
  131.     format(string, sizeof(string), "%d", value);
  132.  
  133.     for(new i = (strlen(string) - 3); i > (value < 0 ? 1 : 0) ; i -= 3)
  134.     {
  135.         strins(string[i], ",", 0);
  136.     }
  137.  
  138.     return string;
  139. }
  140.  
  141. Business_Save(businessid)
  142. {
  143.     new query[256];
  144.     mysql_format(BusinessSQL, query, sizeof(query), "UPDATE business SET Name='%e', Owner='%e', Closed='%d', Price='%d', SalePrice='%d', Earning='%d', Money='%d', Type='%d', LastVisited='%d' WHERE ID='%d'",
  145.     BusinessData[businessid][Name], BusinessData[businessid][Owner], BusinessData[businessid][Closed], BusinessData[businessid][Price], BusinessData[businessid][SalePrice], BusinessData[businessid][Earning],
  146.     BusinessData[businessid][Money], BusinessData[businessid][Type], BusinessData[businessid][LastVisited], businessid);
  147.     mysql_tquery(BusinessSQL, query, "", "");
  148.    
  149.     BusinessData[businessid][Save] = false;
  150.     return 1;
  151. }
  152.  
  153. Business_UpdateLabel(businessid)
  154. {
  155.     new label[256];
  156.     if(strcmp(BusinessData[businessid][Owner], "-")) {
  157.         if(BusinessData[businessid][SalePrice] > 0) {
  158.             format(label, sizeof(label), "{2ECC71}%s's Business For Sale (ID: %d)\n\n{FFFFFF}%s\n{FFFFFF}Interior: {3498DB}%s\n{2ECC71}$%s\n{FFFFFF}Earns {2ECC71}$%s {FFFFFF}every {2ECC71}%d {FFFFFF}minutes.", BusinessData[businessid][Owner], businessid, BusinessData[businessid][Name], BusinessInteriors[ BusinessData[businessid][Type] ][InteriorName], convertNumber(BusinessData[businessid][SalePrice]), convertNumber(BusinessData[businessid][Earning]), BUSINESS_INTERVAL);
  159.         }else{
  160.             format(label, sizeof(label), "{E67E22}%s's Business (ID: %d)\n\n{FFFFFF}%s\n{FFFFFF}Interior: {3498DB}%s\n%s", BusinessData[businessid][Owner], businessid, BusinessData[businessid][Name], BusinessInteriors[ BusinessData[businessid][Type] ][InteriorName], BusinessStates[ BusinessData[businessid][Closed] ]);
  161.         }
  162.     }else{
  163.         format(label, sizeof(label), "{2ECC71}Business For Sale (ID: %d)\n\n{FFFFFF}Interior: {3498DB}%s\n{2ECC71}$%s\n{FFFFFF}Earns {2ECC71}$%s {FFFFFF}every {2ECC71}%d {FFFFFF}minutes.", businessid, BusinessInteriors[ BusinessData[businessid][Type] ][InteriorName], convertNumber(BusinessData[businessid][Price]), convertNumber(BusinessData[businessid][Earning]), BUSINESS_INTERVAL);
  164.     }
  165.  
  166.     UpdateDynamic3DTextLabelText(BusinessData[businessid][BusinessLabel], -1, label);
  167.     return 1;
  168. }
  169.  
  170. Business_GetOwnerID(businessid)
  171. {
  172.     foreach(new i : Player)
  173.     {
  174.         if(!strcmp(BusinessData[businessid][Owner], Player_GetName(i), true)) return i;
  175.     }
  176.  
  177.     return INVALID_PLAYER_ID;
  178. }
  179.  
  180. Business_KickEveryone(businessid)
  181. {
  182.     foreach(new i : Player)
  183.     {
  184.         if(InBusiness[i] == businessid) Player_KickFromBusiness(i);
  185.     }
  186.    
  187.     return 1;
  188. }
  189.  
  190. Business_RemoveSafeLogs(businessid)
  191. {
  192.     new query[128];
  193.     mysql_format(BusinessSQL, query, sizeof(query), "DELETE FROM business_safelogs WHERE BusinessID=%d", businessid);
  194.     mysql_tquery(BusinessSQL, query, "", "");
  195.     return 1;
  196. }
  197.  
  198. Business_RemovePerms(businessid)
  199. {
  200.     new query[128];
  201.     mysql_format(BusinessSQL, query, sizeof(query), "DELETE FROM business_perms WHERE BusinessID=%d", businessid);
  202.     mysql_tquery(BusinessSQL, query, "", "");
  203.     return 1;
  204. }
  205.  
  206. Business_Reset(businessid)
  207. {
  208.     format(BusinessData[businessid][Name], MAX_BUSINESS_NAME, "Business");
  209.     format(BusinessData[businessid][Owner], MAX_PLAYER_NAME, "-");
  210.     BusinessData[businessid][Closed] = 0;
  211.     BusinessData[businessid][SalePrice] = 0;
  212.     BusinessData[businessid][Money] = 0;
  213.     BusinessData[businessid][LastVisited] = 0;
  214.  
  215.     Business_KickEveryone(businessid);
  216.     Business_RemoveSafeLogs(businessid);
  217.     Business_RemovePerms(businessid);
  218.     Business_UpdateLabel(businessid);
  219.     Business_Save(businessid);
  220.     return 1;
  221. }
  222.  
  223. Player_GetName(playerid)
  224. {
  225.     new name[MAX_PLAYER_NAME];
  226.     GetPlayerName(playerid, name, MAX_PLAYER_NAME);
  227.     return name;
  228. }
  229.  
  230. Player_OwnsBusiness(playerid, businessid)
  231. {
  232.     if(!IsPlayerConnected(playerid)) return 0;
  233.     if(!strcmp(BusinessData[businessid][Owner], Player_GetName(playerid), true)) return 1;
  234.     return 0;
  235. }
  236.  
  237. Player_BusinessCount(playerid)
  238. {
  239.     #if LIMIT_PER_PLAYER != 0
  240.     new count;
  241.     foreach(new i : Business)
  242.     {
  243.         if(Player_OwnsBusiness(playerid, i)) count++;
  244.     }
  245.  
  246.     return count;
  247.     #else
  248.     return 0;
  249.     #endif
  250. }
  251.  
  252. Player_CheckAnyPermission(playerid, businessid)
  253. {
  254.     new query[144], Cache: perm_check;
  255.     mysql_format(BusinessSQL, query, sizeof(query), "SELECT null FROM business_perms WHERE Name='%e' && BusinessID=%d LIMIT 1", Player_GetName(playerid), businessid);
  256.     perm_check = mysql_query(BusinessSQL, query);
  257.     new result = cache_num_rows();
  258.     cache_delete(perm_check);
  259.     return result;
  260. }
  261.  
  262. Player_CheckPermission(playerid, businessid, permid)
  263. {
  264.     if(Player_OwnsBusiness(playerid, businessid)) return 1;
  265.     new query[144], PermsList[3][32] = {"Can_Deposit=1 || Can_Take=1", "Can_Deposit=1", "Can_Take=1"}, Cache: perm_check;
  266.     mysql_format(BusinessSQL, query, sizeof(query), "SELECT null FROM business_perms WHERE Name='%e' && BusinessID=%d && %e LIMIT 1", Player_GetName(playerid), businessid, PermsList[permid]);
  267.     perm_check = mysql_query(BusinessSQL, query);
  268.     new result = cache_num_rows();
  269.     cache_delete(perm_check);
  270.     return result;
  271. }
  272.  
  273. Player_GoToBusiness(playerid, businessid)
  274. {
  275.     SetPVarInt(playerid, "BusinessPickup", gettime() + 8);
  276.     InBusiness[playerid] = businessid;
  277.     SetPlayerVirtualWorld(playerid, businessid);
  278.     new type = BusinessData[businessid][Type];
  279.     SetPlayerInterior(playerid, BusinessInteriors[type][InteriorID]);
  280.     SetPlayerPos(playerid, BusinessInteriors[type][InteriorX], BusinessInteriors[type][InteriorY], BusinessInteriors[type][InteriorZ]);
  281.    
  282.     if(Player_OwnsBusiness(playerid, businessid))
  283.     {
  284.         BusinessData[businessid][LastVisited] = gettime();
  285.         BusinessData[businessid][Save] = true;
  286.     }
  287.  
  288.     SendClientMessage(playerid, -1, "Use {3498DB}/business {FFFFFF}to open the business menu.");
  289.     return 1;
  290. }
  291.  
  292. Player_ShowBusinessMenu(playerid)
  293. {
  294.     new id = InBusiness[playerid], is_owned = Player_OwnsBusiness(playerid, id), string[256];
  295.     format(string, sizeof(string), "{%s}Business Name\t%s\n{%s}Status\t%s\n{%s}Permissions\n{%s}Business Safe\n{%s}Sell Business",
  296.     (is_owned) ? ("FFFFFF") : ("E74C3C"), BusinessData[id][Name], // Business Name
  297.     (is_owned) ? ("FFFFFF") : ("E74C3C"), BusinessStates[ BusinessData[id][Closed] ], // Business State
  298.     (is_owned) ? ("FFFFFF") : ("E74C3C"), // Permissions
  299.     (Player_CheckPermission(playerid, id, PERM_CAN_USE_SAFE)) ? ("FFFFFF") : ("E74C3C"), // Business Safe
  300.     (is_owned) ? ("FFFFFF") : ("E74C3C")); // Sell Business
  301.     ShowPlayerDialog(playerid, DIALOG_MANAGE_BUSINESS, DIALOG_STYLE_TABLIST, "Business Management", string, "Choose", "Cancel");
  302.     return 1;
  303. }
  304.  
  305. Player_ShowBusinessSafe(playerid)
  306. {
  307.     new id = InBusiness[playerid], is_owned = Player_OwnsBusiness(playerid, id), string[196];
  308.     format(string, sizeof(string), "{%s}Deposit Money\t{2ECC71}$%s\n{%s}Take Money\t{2ECC71}$%s\n{%s}Safe Logs\n{%s}Clear Safe Logs",
  309.     (Player_CheckPermission(playerid, id, PERM_CAN_DEPOSIT)) ? ("FFFFFF") : ("E74C3C"), convertNumber(GetPlayerMoney(playerid)), // Deposit Money
  310.     (Player_CheckPermission(playerid, id, PERM_CAN_TAKE)) ? ("FFFFFF") : ("E74C3C"), convertNumber(BusinessData[id][Money]), // Take Money
  311.     (is_owned) ? ("FFFFFF") : ("E74C3C"), // Safe Logs
  312.     (is_owned) ? ("FFFFFF") : ("E74C3C")); // Clear Safe Logs
  313.     ShowPlayerDialog(playerid, DIALOG_MANAGE_BUSINESS_SAFE, DIALOG_STYLE_TABLIST, "Business Management: Safe", string, "Choose", "Cancel");
  314.     return 1;
  315. }
  316.  
  317. Player_ShowBusinessSale(playerid)
  318. {
  319.     new id = InBusiness[playerid], string[128];
  320.     format(string, sizeof(string), "Sell Instantly\t{2ECC71}$%s\n%s", convertNumber(floatround(BusinessData[id][Price] * 0.85)), (BusinessData[id][SalePrice] > 0) ? ("Remove From Sale") : ("Put On Sale"));
  321.     ShowPlayerDialog(playerid, DIALOG_MANAGE_SELL, DIALOG_STYLE_TABLIST, "Business Management: Sell", string, "Choose", "Cancel");
  322.     return 1;
  323. }
  324.  
  325. Player_ShowPermissionMenu(playerid)
  326. {
  327.     ShowPlayerDialog(playerid, DIALOG_MANAGE_PERMISSIONS, DIALOG_STYLE_LIST, "Business Management: Permissions", "Give Permissions\nPlayers With Permissions\nRemove All Permissions", "Choose", "Cancel");
  328.     return 1;
  329. }
  330.  
  331. Player_KickFromBusiness(playerid)
  332. {
  333.     new id = InBusiness[playerid];
  334.     SetPVarInt(playerid, "BusinessCooldown", gettime() + 8);
  335.     SetPlayerVirtualWorld(playerid, 0);
  336.     SetPlayerInterior(playerid, 0);
  337.     SetPlayerPos(playerid, BusinessData[id][BusinessX], BusinessData[id][BusinessY], BusinessData[id][BusinessZ]);
  338.     InBusiness[playerid] = INVALID_BUSINESS;
  339.     return 1;
  340. }
  341.  
  342. Player_GetID(name[])
  343. {
  344.     foreach(new i : Player)
  345.     {
  346.         if(!strcmp(Player_GetName(i), name, true)) return i;
  347.     }
  348.    
  349.     return INVALID_PLAYER_ID;
  350. }
  351.  
  352. Player_ShowPermissionEditing(playerid)
  353. {
  354.     new permid = GetPVarInt(playerid, "EditingPerm"), query[128], Cache: perm_data;
  355.     mysql_format(BusinessSQL, query, sizeof(query), "SELECT Name, Can_Deposit, Can_Take FROM business_perms WHERE ID=%d LIMIT 1", permid);
  356.     perm_data = mysql_query(BusinessSQL, query);
  357.     if(cache_num_rows() > 0) {
  358.         new string[128], name[MAX_PLAYER_NAME];
  359.         cache_get_field_content(0, "Name", name);
  360.         format(string, sizeof(string), "Permission Owner:\t%s\nCan Deposit Money:\t%s\nCan Take Money:\t%s\nRemove", name, PermissionStates[ cache_get_field_content_int(0, "Can_Deposit") ], PermissionStates[ cache_get_field_content_int(0, "Can_Take") ]);
  361.         ShowPlayerDialog(playerid, DIALOG_MANAGE_EDIT_PERMS, DIALOG_STYLE_TABLIST, "Business Management: Edit Permissions", string, "Choose", "Cancel");
  362.     }else{
  363.         SendClientMessage(playerid, 0xE74C3CFF, "ERROR: {FFFFFF}Invalid permission.");
  364.     }
  365.  
  366.     cache_delete(perm_data);
  367.     return 1;
  368. }
  369.  
  370. Player_ResetPermissionSettings(playerid, msg = 0)
  371. {
  372.     DeletePVar(playerid, "Perm_GivingTo");
  373.     DeletePVar(playerid, "Perm_Deposit");
  374.     if(msg) SendClientMessage(playerid, 0xE74C3CFF, "ERROR: {FFFFFF}You can't give permissions to offline players.");
  375.     return 1;
  376. }
  377.  
  378. Player_ShowSafeLogs(playerid)
  379. {
  380.     new query[256], Cache: safe_logs;
  381.     mysql_format(BusinessSQL, query, sizeof(query), "SELECT Name, Amount, FROM_UNIXTIME(Date, '%%d/%%m/%%Y %%H:%%i:%%s') as ActionDate FROM business_safelogs WHERE BusinessID=%d ORDER BY Date DESC LIMIT %d, 15", InBusiness[playerid], ListPage[playerid] * 1);
  382.     safe_logs = mysql_query(BusinessSQL, query);
  383.     new rows = cache_num_rows();
  384.     if(rows) {
  385.         new list[1096], name[MAX_PLAYER_NAME], date[24], amount;
  386.         format(list, sizeof(list), "By\tAmount\tDate\n");
  387.         for(new i; i < rows; ++i)
  388.         {
  389.             cache_get_field_content(i, "Name", name);
  390.             cache_get_field_content(i, "ActionDate", date);
  391.             amount = cache_get_field_content_int(i, "Amount");
  392.             format(list, sizeof(list), "%s%s\t{%s}$%s\t%s\n", list, name, (amount < 0) ? ("E74C3C") : ("2ECC71"), convertNumber(amount), date);
  393.         }
  394.  
  395.         new title[48];
  396.         format(title, sizeof(title), "Business Management: Safe Log (Page %d)", ListPage[playerid]+1);
  397.         ShowPlayerDialog(playerid, DIALOG_MANAGE_SAFE_LOGS, DIALOG_STYLE_TABLIST_HEADERS, title, list, "Next", "Previous");
  398.     }else{
  399.         SendClientMessage(playerid, -1, "Can't find any more safe history.");
  400.     }
  401.  
  402.     cache_delete(safe_logs);
  403.     return 1;
  404. }
  405.  
  406. forward BusinessTimer();
  407. forward LoadBusinesses();
  408. forward OnBusinessCreated(businessid);
  409. forward BusinessSaleMoney(playerid);
  410. forward OnPermChange(playerid);
  411. forward OnPermRemoved(playerid);
  412.  
  413. public BusinessTimer()
  414. {
  415.     foreach(new i : Business)
  416.     {
  417.         if((gettime() - BusinessData[i][LastVisited]) > BUSINESS_DAYS * 86400)
  418.         {
  419.             Business_Reset(i);
  420.             continue;
  421.         }
  422.        
  423.         if(!BusinessData[i][Closed] && BusinessData[i][SalePrice] == 0 && strcmp(BusinessData[i][Owner], "-"))
  424.         {
  425.             BusinessData[i][Money] += BusinessData[i][Earning];
  426.             BusinessData[i][Save] = true;
  427.         }
  428.        
  429.         if(BusinessData[i][Save]) Business_Save(i);
  430.     }
  431.    
  432.     return 1;
  433. }
  434.  
  435. public LoadBusinesses()
  436. {
  437.     new rows = cache_num_rows();
  438.     if(rows)
  439.     {
  440.         new id, label[256];
  441.         for(new i; i < rows; i++)
  442.         {
  443.             id = cache_get_field_content_int(i, "ID");
  444.             cache_get_field_content(i, "Name", BusinessData[id][Name], .max_len = MAX_BUSINESS_NAME);
  445.             cache_get_field_content(i, "Owner", BusinessData[id][Owner], .max_len = MAX_PLAYER_NAME);
  446.             BusinessData[id][BusinessX] = cache_get_field_content_float(i, "BusinessX");
  447.             BusinessData[id][BusinessY] = cache_get_field_content_float(i, "BusinessY");
  448.             BusinessData[id][BusinessZ] = cache_get_field_content_float(i, "BusinessZ");
  449.             BusinessData[id][Closed] = cache_get_field_content_int(i, "Closed");
  450.             BusinessData[id][Price] = cache_get_field_content_int(i, "Price");
  451.             BusinessData[id][SalePrice] = cache_get_field_content_int(i, "SalePrice");
  452.             BusinessData[id][Earning] = cache_get_field_content_int(i, "Earning");
  453.             BusinessData[id][Money] = cache_get_field_content_int(i, "Money");
  454.             BusinessData[id][Type] = cache_get_field_content_int(i, "Type");
  455.             BusinessData[id][LastVisited] = cache_get_field_content_int(i, "LastVisited");
  456.            
  457.             if(strcmp(BusinessData[id][Owner], "-")) {
  458.                 if(BusinessData[id][SalePrice] > 0) {
  459.                     format(label, sizeof(label), "{2ECC71}%s's Business For Sale (ID: %d)\n\n{FFFFFF}%s\n{FFFFFF}Interior: {3498DB}%s\n{2ECC71}$%s\n{FFFFFF}Earns {2ECC71}$%s {FFFFFF}every {2ECC71}%d {FFFFFF}minutes.", BusinessData[id][Owner], id, BusinessData[id][Name], BusinessInteriors[ BusinessData[id][Type] ][InteriorName], convertNumber(BusinessData[id][SalePrice]), convertNumber(BusinessData[id][Earning]), BUSINESS_INTERVAL);
  460.                 }else{
  461.                     format(label, sizeof(label), "{E67E22}%s's Business (ID: %d)\n\n{FFFFFF}%s\n{FFFFFF}Interior: {3498DB}%s\n%s", BusinessData[id][Owner], id, BusinessData[id][Name], BusinessInteriors[ BusinessData[id][Type] ][InteriorName], BusinessStates[ BusinessData[id][Closed] ]);
  462.                 }
  463.             }else{
  464.                 format(label, sizeof(label), "{2ECC71}Business For Sale (ID: %d)\n\n{FFFFFF}Interior: {3498DB}%s\n{2ECC71}$%s\n{FFFFFF}Earns {2ECC71}$%s {FFFFFF}every {2ECC71}%d {FFFFFF}minutes.", id, BusinessInteriors[ BusinessData[id][Type] ][InteriorName], convertNumber(BusinessData[id][Price]), convertNumber(BusinessData[id][Earning]), BUSINESS_INTERVAL);
  465.             }
  466.  
  467.             BusinessData[id][BusinessPickup] = CreateDynamicPickup(1272, 1, BusinessData[id][BusinessX], BusinessData[id][BusinessY], BusinessData[id][BusinessZ]);
  468.             BusinessData[id][BusinessLabel] = CreateDynamic3DTextLabel(label, -1, BusinessData[id][BusinessX], BusinessData[id][BusinessY], BusinessData[id][BusinessZ]+0.35, 15.0, .testlos = 1);
  469.             Iter_Add(Business, id);
  470.         }
  471.  
  472.         printf("  [Business System] Loaded %d businesses.", rows);
  473.     }
  474. }
  475.  
  476. public OnBusinessCreated(businessid)
  477. {
  478.     Business_Save(businessid);
  479.     return 1;
  480. }
  481.  
  482. public BusinessSaleMoney(playerid)
  483. {
  484.     new rows = cache_num_rows();
  485.     if(rows)
  486.     {
  487.         new new_owner[MAX_PLAYER_NAME], amount, string[128];
  488.         for(new i; i < rows; i++)
  489.         {
  490.             cache_get_field_content(i, "NewOwner", new_owner);
  491.             amount = cache_get_field_content_int(i, "Amount");
  492.            
  493.             format(string, sizeof(string), "You sold a business to %s for $%s. (Transaction ID: #%d)", new_owner, convertNumber(amount), cache_get_field_content_int(i, "ID"));
  494.             SendClientMessage(playerid, -1, string);
  495.             GivePlayerMoney(playerid, amount);
  496.         }
  497.  
  498.         new query[128];
  499.         mysql_format(BusinessSQL, query, sizeof(query), "DELETE FROM business_transactions WHERE OldOwner='%e'", Player_GetName(playerid));
  500.         mysql_tquery(BusinessSQL, query, "", "");
  501.     }
  502.    
  503.     return 1;
  504. }
  505.  
  506. public OnPermChange(playerid)
  507. {
  508.     Player_ShowPermissionEditing(playerid);
  509.     return 1;
  510. }
  511.  
  512. public OnPermRemoved(playerid)
  513. {
  514.     SendClientMessage(playerid, -1, "Permission removed.");
  515.     Player_ShowPermissionMenu(playerid);
  516.     return 1;
  517. }
  518.  
  519. public OnFilterScriptInit()
  520. {
  521.     DisableInteriorEnterExits();
  522.    
  523.     BusinessSQL = mysql_connect(SQL_HOST, SQL_USER, SQL_DBNAME, SQL_PASSWORD);
  524.     mysql_log(LOG_ERROR | LOG_WARNING, LOG_TYPE_HTML);
  525.     if(mysql_errno()) return printf("  [Business System] Can't connect to MySQL. (Error #%d)", mysql_errno());
  526.    
  527.     // create tables if they don't exist
  528.     new query[1024];
  529.     format(query, sizeof(query), "CREATE TABLE IF NOT EXISTS `business` (\
  530.       `ID` int(11) NOT NULL default '0',\
  531.       `Name` varchar(%d) default NULL,\
  532.       `Owner` varchar(24) default '-',\
  533.       `BusinessX` float default NULL,\
  534.       `BusinessY` float default NULL,\
  535.       `BusinessZ` float default NULL,\
  536.       `Closed` tinyint(1) default NULL,\
  537.       `Price` int(11) default NULL,\
  538.       `SalePrice` int(11) default NULL,\
  539.      `Earning` int(11) default NULL,", MAX_BUSINESS_NAME);
  540.    
  541.     format(query, sizeof(query), "%s\
  542.       `Money` int(11) default NULL,\
  543.       `Type` int(11) default NULL,\
  544.       `LastVisited` int(11) default NULL,\
  545.       PRIMARY KEY  (`ID`),\
  546.       UNIQUE KEY `ID` (`ID`)\
  547.     ) ENGINE=InnoDB DEFAULT CHARSET=utf8;", query);
  548.    
  549.     mysql_tquery(BusinessSQL, query, "", "");
  550.    
  551.     mysql_tquery(BusinessSQL, "CREATE TABLE IF NOT EXISTS `business_perms` (\
  552.       `ID` int(11) NOT NULL auto_increment,\
  553.       `Name` varchar(24) default NULL,\
  554.       `BusinessID` int(11) default NULL,\
  555.       `Can_Deposit` tinyint(1) default NULL,\
  556.       `Can_Take` tinyint(1) default NULL,\
  557.       PRIMARY KEY  (`ID`),\
  558.       KEY `BusinessID` (`BusinessID`),\
  559.       CONSTRAINT `business_perms_ibfk_1` FOREIGN KEY (`BusinessID`) REFERENCES `business` (`ID`) ON DELETE CASCADE\
  560.     ) ENGINE=InnoDB DEFAULT CHARSET=utf8;", "", "");
  561.    
  562.     mysql_tquery(BusinessSQL, "CREATE TABLE IF NOT EXISTS `business_safelogs` (\
  563.       `ID` int(11) NOT NULL auto_increment,\
  564.       `Name` varchar(24) default NULL,\
  565.       `BusinessID` int(11) default NULL,\
  566.       `Amount` int(11) default NULL,\
  567.       `Date` int(11) default NULL,\
  568.       PRIMARY KEY  (`ID`),\
  569.       KEY `BusinessID` (`BusinessID`),\
  570.       CONSTRAINT `business_safelogs_ibfk_1` FOREIGN KEY (`BusinessID`) REFERENCES `business` (`ID`) ON DELETE CASCADE\
  571.     ) ENGINE=InnoDB DEFAULT CHARSET=utf8;", "", "");
  572.    
  573.     mysql_tquery(BusinessSQL, "CREATE TABLE IF NOT EXISTS `business_transactions` (\
  574.       `ID` int(11) NOT NULL auto_increment,\
  575.       `OldOwner` varchar(24) default NULL,\
  576.       `NewOwner` varchar(24) default NULL,\
  577.       `Amount` int(11) default NULL,\
  578.       PRIMARY KEY  (`ID`)\
  579.     ) ENGINE=MyISAM DEFAULT CHARSET=utf8;", "", "");
  580.    
  581.     for(new i; i < MAX_BUSINESS; ++i)
  582.     {
  583.         format(BusinessData[i][Name], MAX_PLAYER_NAME, "Business");
  584.         format(BusinessData[i][Owner], MAX_PLAYER_NAME, "-");
  585.         BusinessData[i][BusinessLabel] = Text3D: INVALID_3DTEXT_ID;
  586.         BusinessData[i][BusinessPickup] = -1;
  587.     }
  588.    
  589.     for(new i; i < sizeof(BusinessInteriors); i++)
  590.     {
  591.         BusinessInteriors[i][ExitPickup] = CreateDynamicPickup(19197, 1, BusinessInteriors[i][InteriorX], BusinessInteriors[i][InteriorY], BusinessInteriors[i][InteriorZ] + 0.25, .interiorid = BusinessInteriors[i][InteriorID]);
  592.         BusinessInteriors[i][ExitLabel] = CreateDynamic3DTextLabel("Leave Business", 0xE67E22FF, BusinessInteriors[i][InteriorX], BusinessInteriors[i][InteriorY], BusinessInteriors[i][InteriorZ] + 0.45, 10.0, .testlos = 1, .interiorid = BusinessInteriors[i][InteriorID]);
  593.     }
  594.    
  595.     mysql_tquery(BusinessSQL, "SELECT * FROM business", "LoadBusinesses", "");
  596.     SetTimer("BusinessTimer", BUSINESS_INTERVAL * 60000, true);
  597.     return 1;
  598. }
  599.  
  600. public OnFilterScriptExit()
  601. {
  602.     foreach(new i : Business)
  603.     {
  604.         if(BusinessData[i][Save]) Business_Save(i);
  605.     }
  606.    
  607.     mysql_close(BusinessSQL);
  608.     return 1;
  609. }
  610.  
  611. public OnPlayerConnect(playerid)
  612. {
  613.     InBusiness[playerid] = INVALID_BUSINESS;
  614.     ListPage[playerid] = 0;
  615.     return 1;
  616. }
  617.  
  618. public OnPlayerSpawn(playerid)
  619. {
  620.     InBusiness[playerid] = INVALID_BUSINESS;
  621.    
  622.     new query[128];
  623.     mysql_format(BusinessSQL, query, sizeof(query), "SELECT * FROM business_transactions WHERE OldOwner='%e'", Player_GetName(playerid));
  624.     mysql_tquery(BusinessSQL, query, "BusinessSaleMoney", "i", playerid);
  625.     return 1;
  626. }
  627.  
  628. public OnPlayerPickUpDynamicPickup(playerid, pickupid)
  629. {
  630.     if(GetPVarInt(playerid, "BusinessCooldown") < gettime())
  631.     {
  632.         if(InBusiness[playerid] == INVALID_BUSINESS) {
  633.             foreach(new i : Business)
  634.             {
  635.                 if(pickupid == BusinessData[i][BusinessPickup])
  636.                 {
  637.                     SetPVarInt(playerid, "BusinessCooldown", gettime() + 8);
  638.                     SetPVarInt(playerid, "PickupBusinessID", i);
  639.                     if(Player_OwnsBusiness(playerid, i)) return Player_GoToBusiness(playerid, i);
  640.                    
  641.                     if(!strcmp(BusinessData[i][Owner], "-") || BusinessData[i][SalePrice] > 0) {
  642.                         new string[128];
  643.                         if(BusinessData[i][SalePrice] > 0) {
  644.                             format(string, sizeof(string), "This business is for sale. You can buy it if the owner is online.\nPrice: {2ECC71}$%s", convertNumber(BusinessData[i][SalePrice]));
  645.                             ShowPlayerDialog(playerid, DIALOG_BUY_BUSINESS_FROM_OWNER, DIALOG_STYLE_MSGBOX, "Business For Sale", string, "Buy", "Cancel");
  646.                         }else{
  647.                             format(string, sizeof(string), "This business is for sale.\nPrice: {2ECC71}$%s", convertNumber(BusinessData[i][Price]));
  648.                             ShowPlayerDialog(playerid, DIALOG_BUY_BUSINESS, DIALOG_STYLE_MSGBOX, "Business For Sale", string, "Buy", "Cancel");
  649.                         }
  650.                     }else{
  651.                         if(!BusinessData[i][Closed]) {
  652.                             Player_GoToBusiness(playerid, i);
  653.                         }else{
  654.                             SendClientMessage(playerid, 0xE74C3CFF, "ERROR: {FFFFFF}You can't enter this business right now.");
  655.                         }
  656.                     }
  657.  
  658.                     return 1;
  659.                 }
  660.             }
  661.         }else{
  662.             for(new i; i < sizeof(BusinessInteriors); i++)
  663.             {
  664.                 if(pickupid == BusinessInteriors[i][ExitPickup])
  665.                 {
  666.                     Player_KickFromBusiness(playerid);
  667.                     return 1;
  668.                 }
  669.             }
  670.         }
  671.     }
  672.    
  673.     return 1;
  674. }
  675.  
  676. public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
  677. {
  678.     switch(dialogid)
  679.     {
  680.         case DIALOG_BUY_BUSINESS:
  681.         {
  682.             if(!response) return 1;
  683.             new id = GetPVarInt(playerid, "PickupBusinessID");
  684.             if(!IsPlayerInRangeOfPoint(playerid, 2.0, BusinessData[id][BusinessX], BusinessData[id][BusinessY], BusinessData[id][BusinessZ])) return SendClientMessage(playerid, 0xE74C3CFF, "ERROR: {FFFFFF}You're not near a business.");
  685.             if(BusinessData[id][Price] > GetPlayerMoney(playerid)) return SendClientMessage(playerid, 0xE74C3CFF, "ERROR: {FFFFFF}You can't afford this business.");
  686.             #if LIMIT_PER_PLAYER > 0
  687.             if(Player_BusinessCount(playerid) + 1 > LIMIT_PER_PLAYER) return SendClientMessage(playerid, 0xE74C3CFF, "ERROR: {FFFFFF}You can't buy any more businesses.");
  688.             #endif
  689.             if(strcmp(BusinessData[id][Owner], "-")) return SendClientMessage(playerid, 0xE74C3CFF, "ERROR: {FFFFFF}Someone already owns this business.");
  690.             GivePlayerMoney(playerid, -BusinessData[id][Price]);
  691.             GetPlayerName(playerid, BusinessData[id][Owner], MAX_PLAYER_NAME);
  692.             BusinessData[id][LastVisited] = gettime();
  693.             BusinessData[id][Save] = true;
  694.  
  695.             Business_UpdateLabel(id);
  696.             Business_RemoveSafeLogs(id);
  697.             Business_RemovePerms(id);
  698.             Player_GoToBusiness(playerid, id);
  699.             return 1;
  700.         }
  701.        
  702.         case DIALOG_BUY_BUSINESS_FROM_OWNER:
  703.         {
  704.             if(!response) return 1;
  705.             new id = GetPVarInt(playerid, "PickupBusinessID");
  706.             if(!IsPlayerInRangeOfPoint(playerid, 2.0, BusinessData[id][BusinessX], BusinessData[id][BusinessY], BusinessData[id][BusinessZ])) return SendClientMessage(playerid, 0xE74C3CFF, "ERROR: {FFFFFF}You're not near a business.");
  707.             if(BusinessData[id][SalePrice] > GetPlayerMoney(playerid)) return SendClientMessage(playerid, 0xE74C3CFF, "ERROR: {FFFFFF}You can't afford this business.");
  708.             #if LIMIT_PER_PLAYER > 0
  709.             if(Player_BusinessCount(playerid) + 1 > LIMIT_PER_PLAYER) return SendClientMessage(playerid, 0xE74C3CFF, "ERROR: {FFFFFF}You can't buy any more businesses.");
  710.             #endif
  711.             if(!strcmp(BusinessData[id][Owner], "-")) return SendClientMessage(playerid, 0xE74C3CFF, "ERROR: {FFFFFF}This business doesn't have an owner.");
  712.             new ownerid = Business_GetOwnerID(id);
  713.            
  714.             if(IsPlayerConnected(ownerid)) {
  715.                 GivePlayerMoney(ownerid, BusinessData[id][SalePrice]);
  716.  
  717.                 new string[128];
  718.                 format(string, sizeof(string), "%s(%d) has bought your business for $%s.", Player_GetName(playerid), playerid, convertNumber(BusinessData[id][SalePrice]));
  719.                 SendClientMessage(ownerid, -1, string);
  720.             }else{
  721.                 new query[128];
  722.                 mysql_format(BusinessSQL, query, sizeof(query), "INSERT INTO business_transactions SET OldOwner='%e', NewOwner='%e', Amount=%d", BusinessData[id][Owner], Player_GetName(playerid), BusinessData[id][SalePrice]);
  723.                 mysql_tquery(BusinessSQL, query, "", "");
  724.             }
  725.            
  726.             GivePlayerMoney(playerid, -BusinessData[id][SalePrice]);
  727.             GetPlayerName(playerid, BusinessData[id][Owner], MAX_PLAYER_NAME);
  728.             BusinessData[id][LastVisited] = gettime();
  729.             BusinessData[id][SalePrice] = 0;
  730.             BusinessData[id][Closed] = 0;
  731.             BusinessData[id][Save] = true;
  732.            
  733.             Business_UpdateLabel(id);
  734.             Business_RemoveSafeLogs(id);
  735.             Business_RemovePerms(id);
  736.             Player_GoToBusiness(playerid, id);
  737.             return 1;
  738.         }
  739.        
  740.         case DIALOG_MANAGE_BUSINESS:
  741.         {
  742.             if(!response) return 1;
  743.             if(InBusiness[playerid] == INVALID_BUSINESS) return SendClientMessage(playerid, 0xE74C3CFF, "ERROR: {FFFFFF}You're not in a business.");
  744.             new string[128], id = InBusiness[playerid];
  745.             if(listitem == 0)
  746.             {
  747.                 // Business Name
  748.                 if(!Player_OwnsBusiness(playerid, id)) return SendClientMessage(playerid, 0xE74C3CFF, "ERROR: {FFFFFF}You don't own this business.");
  749.                 format(string, sizeof(string), "Current Business Name: %s\n\n{FFFFFF}Write your new business name:", BusinessData[ InBusiness[playerid] ][Name]);
  750.                 ShowPlayerDialog(playerid, DIALOG_MANAGE_BUSINESS_NAME, DIALOG_STYLE_INPUT, "Business Management: Name", string, "Change", "Cancel");
  751.             }
  752.            
  753.             if(listitem == 1)
  754.             {
  755.                 // Business Status
  756.                 if(!Player_OwnsBusiness(playerid, id)) return SendClientMessage(playerid, 0xE74C3CFF, "ERROR: {FFFFFF}You don't own this business.");
  757.                 BusinessData[id][Closed] = !BusinessData[id][Closed];
  758.                 BusinessData[id][Save] = true;
  759.                 Business_UpdateLabel(id);
  760.                 Player_ShowBusinessMenu(playerid);
  761.             }
  762.            
  763.             if(listitem == 2)
  764.             {
  765.                 if(!Player_OwnsBusiness(playerid, InBusiness[playerid])) return SendClientMessage(playerid, 0xE74C3CFF, "ERROR: {FFFFFF}You don't own this business.");
  766.                 Player_ShowPermissionMenu(playerid);
  767.             }
  768.            
  769.             if(listitem == 3)
  770.             {
  771.                 if(BusinessData[id][SalePrice] > 0) return SendClientMessage(playerid, 0xE74C3CFF, "ERROR: {FFFFFF}You can't use the safe while the business is on sale.");
  772.                 if(!Player_CheckPermission(playerid, id, PERM_CAN_USE_SAFE)) return SendClientMessage(playerid, 0xE74C3CFF, "ERROR: {FFFFFF}You don't have enough permissions.");
  773.                 Player_ShowBusinessSafe(playerid);
  774.             }
  775.            
  776.             if(listitem == 4)
  777.             {
  778.                 if(!Player_OwnsBusiness(playerid, id)) return SendClientMessage(playerid, 0xE74C3CFF, "ERROR: {FFFFFF}You don't own this business.");
  779.                 Player_ShowBusinessSale(playerid);
  780.             }
  781.            
  782.             return 1;
  783.         }
  784.        
  785.         case DIALOG_MANAGE_BUSINESS_NAME:
  786.         {
  787.             if(!response) return Player_ShowBusinessMenu(playerid);
  788.             if(InBusiness[playerid] == INVALID_BUSINESS) return SendClientMessage(playerid, 0xE74C3CFF, "ERROR: {FFFFFF}You're not in a business.");
  789.             if(!Player_OwnsBusiness(playerid, InBusiness[playerid])) return SendClientMessage(playerid, 0xE74C3CFF, "ERROR: {FFFFFF}You don't own this business.");
  790.             if(!(1 <= strlen(inputtext) <= MAX_BUSINESS_NAME)) return ShowPlayerDialog(playerid, DIALOG_MANAGE_BUSINESS_NAME, DIALOG_STYLE_INPUT, "Business Management: Name", "{E74C3C}ERROR: {FFFFFF}The business name you entered is either too short or too long.", "Change", "Cancel");
  791.             new id = InBusiness[playerid];
  792.             format(BusinessData[id][Name], MAX_BUSINESS_NAME, "%s", inputtext);
  793.             BusinessData[id][Save] = true;
  794.            
  795.             Business_UpdateLabel(id);
  796.             Player_ShowBusinessMenu(playerid);
  797.             return 1;
  798.         }
  799.        
  800.         case DIALOG_MANAGE_BUSINESS_SAFE:
  801.         {
  802.             if(!response) return Player_ShowBusinessMenu(playerid);
  803.             if(InBusiness[playerid] == INVALID_BUSINESS) return SendClientMessage(playerid, 0xE74C3CFF, "ERROR: {FFFFFF}You're not in a business.");
  804.             if(BusinessData[ InBusiness[playerid] ][SalePrice] > 0) return SendClientMessage(playerid, 0xE74C3CFF, "ERROR: {FFFFFF}You can't use the safe while the business is on sale.");
  805.             if(!Player_CheckPermission(playerid, InBusiness[playerid], PERM_CAN_USE_SAFE)) return SendClientMessage(playerid, 0xE74C3CFF, "ERROR: {FFFFFF}You don't have enough permissions.");
  806.             new string[128], id = InBusiness[playerid];
  807.             if(listitem == 0)
  808.             {
  809.                 if(!Player_CheckPermission(playerid, InBusiness[playerid], PERM_CAN_DEPOSIT)) return SendClientMessage(playerid, 0xE74C3CFF, "ERROR: {FFFFFF}You can't deposit money to this business.");
  810.                 format(string, sizeof(string), "Your Money: {2ECC71}$%s\n\n{FFFFFF}Write the amount you want to deposit:", convertNumber(GetPlayerMoney(playerid)));
  811.                 ShowPlayerDialog(playerid, DIALOG_MANAGE_DEPOSIT_TO_SAFE, DIALOG_STYLE_INPUT, "Business Safe: Deposit", string, "Deposit", "Cancel");
  812.             }
  813.            
  814.             if(listitem == 1)
  815.             {
  816.                 if(!Player_CheckPermission(playerid, InBusiness[playerid], PERM_CAN_TAKE)) return SendClientMessage(playerid, 0xE74C3CFF, "ERROR: {FFFFFF}You can't take money from this business.");
  817.                 format(string, sizeof(string), "Business's Money: {2ECC71}$%s\n\n{FFFFFF}Write the amount you want to take:", convertNumber(BusinessData[id][Money]));
  818.                 ShowPlayerDialog(playerid, DIALOG_MANAGE_TAKE_FROM_SAFE, DIALOG_STYLE_INPUT, "Business Safe: Take", string, "Take", "Cancel");
  819.             }
  820.            
  821.             if(listitem == 2)
  822.             {
  823.                 if(!Player_OwnsBusiness(playerid, InBusiness[playerid])) return SendClientMessage(playerid, 0xE74C3CFF, "ERROR: {FFFFFF}You don't own this business.");
  824.                 ListPage[playerid] = 0;
  825.                 Player_ShowSafeLogs(playerid);
  826.             }
  827.            
  828.             if(listitem == 3)
  829.             {
  830.                 if(!Player_OwnsBusiness(playerid, InBusiness[playerid])) return SendClientMessage(playerid, 0xE74C3CFF, "ERROR: {FFFFFF}You don't own this business.");
  831.                 Business_RemoveSafeLogs(id);
  832.                 Player_ShowBusinessSafe(playerid);
  833.             }
  834.            
  835.             return 1;
  836.         }
  837.        
  838.         case DIALOG_MANAGE_DEPOSIT_TO_SAFE:
  839.         {
  840.             if(!response) return Player_ShowBusinessSafe(playerid);
  841.             if(InBusiness[playerid] == INVALID_BUSINESS) return SendClientMessage(playerid, 0xE74C3CFF, "ERROR: {FFFFFF}You're not in a business.");
  842.             if(BusinessData[ InBusiness[playerid] ][SalePrice] > 0) return SendClientMessage(playerid, 0xE74C3CFF, "ERROR: {FFFFFF}You can't use the safe while the business is on sale.");
  843.             if(!Player_CheckPermission(playerid, InBusiness[playerid], PERM_CAN_DEPOSIT)) return SendClientMessage(playerid, 0xE74C3CFF, "ERROR: {FFFFFF}You can't deposit money to this business.");
  844.             if(!(1 <= strval(inputtext) <= 100000000)) return ShowPlayerDialog(playerid, DIALOG_MANAGE_DEPOSIT_TO_SAFE, DIALOG_STYLE_INPUT, "Business Safe: Deposit", "{E74C3C}ERROR: {FFFFFF}You can't deposit less than $1 or more than $100.000.000 at once.", "Deposit", "Cancel");
  845.             if(strval(inputtext) > GetPlayerMoney(playerid)) return ShowPlayerDialog(playerid, DIALOG_MANAGE_DEPOSIT_TO_SAFE, DIALOG_STYLE_INPUT, "Business Safe: Deposit", "{E74C3C}ERROR: {FFFFFF}You don't have that much money on you.", "Deposit", "Cancel");
  846.             new id = InBusiness[playerid], amount = strval(inputtext);
  847.             GivePlayerMoney(playerid, -amount);
  848.             BusinessData[id][Money] += amount;
  849.             BusinessData[id][Save] = true;
  850.  
  851.             new query[144];
  852.             mysql_format(BusinessSQL, query, sizeof(query), "INSERT INTO business_safelogs SET Name='%e', BusinessID=%d, Amount='%d', Date=UNIX_TIMESTAMP()", Player_GetName(playerid), id, amount);
  853.             mysql_tquery(BusinessSQL, query, "", "");
  854.             Player_ShowBusinessSafe(playerid);
  855.             return 1;
  856.         }
  857.        
  858.         case DIALOG_MANAGE_TAKE_FROM_SAFE:
  859.         {
  860.             if(!response) return Player_ShowBusinessSafe(playerid);
  861.             if(InBusiness[playerid] == INVALID_BUSINESS) return SendClientMessage(playerid, 0xE74C3CFF, "ERROR: {FFFFFF}You're not in a business.");
  862.             if(BusinessData[ InBusiness[playerid] ][SalePrice] > 0) return SendClientMessage(playerid, 0xE74C3CFF, "ERROR: {FFFFFF}You can't use the safe while the business is on sale.");
  863.             if(!Player_CheckPermission(playerid, InBusiness[playerid], PERM_CAN_TAKE)) return SendClientMessage(playerid, 0xE74C3CFF, "ERROR: {FFFFFF}You can't take money from this business.");
  864.             if(!(1 <= strval(inputtext) <= 100000000)) return ShowPlayerDialog(playerid, DIALOG_MANAGE_TAKE_FROM_SAFE, DIALOG_STYLE_INPUT, "Business Safe: Take", "{E74C3C}ERROR: {FFFFFF}You can't take less than $1 or more than $100.000.000 at once.", "Take", "Cancel");
  865.             if(strval(inputtext) > BusinessData[ InBusiness[playerid] ][Money]) return ShowPlayerDialog(playerid, DIALOG_MANAGE_TAKE_FROM_SAFE, DIALOG_STYLE_INPUT, "Business Safe: Take", "{E74C3C}ERROR: {FFFFFF}This business don't have that much money.", "Take", "Cancel");
  866.             new id = InBusiness[playerid], amount = strval(inputtext);
  867.             GivePlayerMoney(playerid, amount);
  868.             BusinessData[id][Money] -= amount;
  869.             BusinessData[id][Save] = true;
  870.  
  871.             new query[144];
  872.             mysql_format(BusinessSQL, query, sizeof(query), "INSERT INTO business_safelogs SET Name='%e', BusinessID=%d, Amount='%d', Date=UNIX_TIMESTAMP()", Player_GetName(playerid), id, -amount);
  873.             mysql_tquery(BusinessSQL, query, "", "");
  874.             Player_ShowBusinessSafe(playerid);
  875.             return 1;
  876.         }
  877.        
  878.         case DIALOG_MANAGE_SELL:
  879.         {
  880.             if(!response) return Player_ShowBusinessMenu(playerid);
  881.             if(InBusiness[playerid] == INVALID_BUSINESS) return SendClientMessage(playerid, 0xE74C3CFF, "ERROR: {FFFFFF}You're not in a business.");
  882.             if(!Player_OwnsBusiness(playerid, InBusiness[playerid])) return SendClientMessage(playerid, 0xE74C3CFF, "ERROR: {FFFFFF}You don't own this business.");
  883.             new id = InBusiness[playerid];
  884.             if(listitem == 0)
  885.             {
  886.                 new price = floatround(BusinessData[id][Price] * 0.85), string[128];
  887.                 format(string, sizeof(string), "You sold your business for $%s. You also got the $%s in the safe.", convertNumber(price), convertNumber(BusinessData[id][Money]));
  888.                 SendClientMessage(playerid, -1, string);
  889.                
  890.                 GivePlayerMoney(playerid, price + BusinessData[id][Money]);
  891.                 Business_Reset(id);
  892.             }
  893.  
  894.             if(listitem == 1)
  895.             {
  896.                 if(BusinessData[id][SalePrice] > 0) {
  897.                     BusinessData[id][SalePrice] = 0;
  898.                     BusinessData[id][Save] = true;
  899.                    
  900.                     Business_UpdateLabel(id);
  901.                     SendClientMessage(playerid, -1, "Your business is no longer for sale.");
  902.                 }else{
  903.                     if(BusinessData[id][Money] > 0) return SendClientMessage(playerid, 0xE74C3CFF, "ERROR: {FFFFFF}You can't put your business on sale if there's money in the business safe.");
  904.                     ShowPlayerDialog(playerid, DIALOG_MANAGE_SELL_TO_PLAYERS, DIALOG_STYLE_INPUT, "Business Management: Sell", "How much do you want for your business?", "Put On Sale", "Cancel");
  905.                 }
  906.             }
  907.            
  908.             return 1;
  909.         }
  910.        
  911.         case DIALOG_MANAGE_SELL_TO_PLAYERS:
  912.         {
  913.             if(!response) return Player_ShowBusinessSale(playerid);
  914.             if(InBusiness[playerid] == INVALID_BUSINESS) return SendClientMessage(playerid, 0xE74C3CFF, "ERROR: {FFFFFF}You're not in a business.");
  915.             if(!Player_OwnsBusiness(playerid, InBusiness[playerid])) return SendClientMessage(playerid, 0xE74C3CFF, "ERROR: {FFFFFF}You don't own this business.");
  916.             if(!(1 <= strval(inputtext) <= 100000000)) return ShowPlayerDialog(playerid, DIALOG_MANAGE_SELL_TO_PLAYERS, DIALOG_STYLE_INPUT, "Business Management: Sell", "{E74C3C}ERROR: {FFFFFF}You can't put your business on sale for less than $1 or more than $100.000.000.", "Put On Sale", "Cancel");
  917.             new id = InBusiness[playerid], string[128];
  918.             BusinessData[id][SalePrice] = strval(inputtext);
  919.             BusinessData[id][Save] = true;
  920.            
  921.             Business_UpdateLabel(id);
  922.             format(string, sizeof(string), "You put your business on sale for $%s.", convertNumber(strval(inputtext)));
  923.             SendClientMessage(playerid, -1, string);
  924.             return 1;
  925.         }
  926.        
  927.         case DIALOG_MANAGE_PERMISSIONS:
  928.         {
  929.             if(!response) return Player_ShowBusinessMenu(playerid);
  930.             if(InBusiness[playerid] == INVALID_BUSINESS) return SendClientMessage(playerid, 0xE74C3CFF, "ERROR: {FFFFFF}You're not in a business.");
  931.             if(!Player_OwnsBusiness(playerid, InBusiness[playerid])) return SendClientMessage(playerid, 0xE74C3CFF, "ERROR: {FFFFFF}You don't own this business.");
  932.             new id = InBusiness[playerid];
  933.             if(listitem == 0) ShowPlayerDialog(playerid, DIALOG_MANAGE_GIVE_PERM_NAME, DIALOG_STYLE_INPUT, "Business Management: Give Permission", "Write the player's name:", "Continue", "Cancel");
  934.             if(listitem == 1)
  935.             {
  936.                 new string[1256], query[128], name[MAX_PLAYER_NAME], Cache: find_perms;
  937.                 format(string, sizeof(string), "ID\tName\tCan Deposit\tCan Take\n");
  938.                 mysql_format(BusinessSQL, query, sizeof(query), "SELECT * FROM business_perms WHERE BusinessID=%d ORDER BY Name ASC", id);
  939.                 find_perms = mysql_query(BusinessSQL, query);
  940.                 new rows = cache_num_rows();
  941.                 if(rows > 0) {
  942.                     for(new i; i < rows; i++)
  943.                     {
  944.                         cache_get_field_content(i, "Name", name);
  945.                         format(string, sizeof(string), "%s%d\t%s\t%s\t%s\n", string, cache_get_field_content_int(i, "ID"), name, PermissionStates[ cache_get_field_content_int(i, "Can_Deposit") ], PermissionStates[ cache_get_field_content_int(i, "Can_Take") ]);
  946.                     }
  947.  
  948.                     ShowPlayerDialog(playerid, DIALOG_MANAGE_LIST_PERMS, DIALOG_STYLE_TABLIST_HEADERS, "Business Management: Permissions", string, "Edit", "Cancel");
  949.                 }else{
  950.                     SendClientMessage(playerid, -1, "This business has no players with permissions.");
  951.                 }
  952.                
  953.                 cache_delete(find_perms);
  954.             }
  955.  
  956.             if(listitem == 2)
  957.             {
  958.                 Business_RemovePerms(id);
  959.                 SendClientMessage(playerid, -1, "All permissions removed.");
  960.             }
  961.  
  962.             return 1;
  963.         }
  964.  
  965.         case DIALOG_MANAGE_GIVE_PERM_NAME:
  966.         {
  967.             if(!response) return Player_ShowPermissionMenu(playerid);
  968.             if(InBusiness[playerid] == INVALID_BUSINESS) return SendClientMessage(playerid, 0xE74C3CFF, "ERROR: {FFFFFF}You're not in a business.");
  969.             if(!Player_OwnsBusiness(playerid, InBusiness[playerid])) return SendClientMessage(playerid, 0xE74C3CFF, "ERROR: {FFFFFF}You don't own this business.");
  970.             if(!(1 <= strlen(inputtext) <= MAX_PLAYER_NAME)) return ShowPlayerDialog(playerid, DIALOG_MANAGE_GIVE_PERM_NAME, DIALOG_STYLE_INPUT, "Business Management: Give Permission", "{E74C3C}ERROR: {FFFFFF}The player name you entered is either too short or too long.", "Continue", "Cancel");
  971.             new permid = Player_GetID(inputtext);
  972.             if(!IsPlayerConnected(permid)) return ShowPlayerDialog(playerid, DIALOG_MANAGE_GIVE_PERM_NAME, DIALOG_STYLE_INPUT, "Business Management: Give Permission", "{E74C3C}ERROR: {FFFFFF}You can't give permissions to offline players.", "Continue", "Cancel");
  973.             if(playerid == permid) return ShowPlayerDialog(playerid, DIALOG_MANAGE_GIVE_PERM_NAME, DIALOG_STYLE_INPUT, "Business Management: Give Permission", "{E74C3C}ERROR: {FFFFFF}You can't give permissions to yourself.", "Continue", "Cancel");
  974.             if(Player_CheckAnyPermission(playerid, InBusiness[playerid])) return ShowPlayerDialog(playerid, DIALOG_MANAGE_GIVE_PERM_NAME, DIALOG_STYLE_INPUT, "Business Management: Give Permission", "{E74C3C}ERROR: {FFFFFF}This player already has permissions, please use the \"Players With Permissions\" menu.", "Continue", "Cancel");
  975.             SetPVarString(playerid, "Perm_GivingTo", inputtext);
  976.             ShowPlayerDialog(playerid, DIALOG_MANAGE_GIVE_PERM_DEPOSIT, DIALOG_STYLE_TABLIST_HEADERS, "Business Management: Give Permission", "Can this player deposit money in the business safe?\nNo\nYes", "Continue", "Cancel");
  977.             return 1;
  978.         }
  979.        
  980.         case DIALOG_MANAGE_GIVE_PERM_DEPOSIT:
  981.         {
  982.             if(!response) return Player_ShowPermissionMenu(playerid);
  983.             if(InBusiness[playerid] == INVALID_BUSINESS) return SendClientMessage(playerid, 0xE74C3CFF, "ERROR: {FFFFFF}You're not in a business.");
  984.             if(!Player_OwnsBusiness(playerid, InBusiness[playerid])) return SendClientMessage(playerid, 0xE74C3CFF, "ERROR: {FFFFFF}You don't own this business.");
  985.             new name[MAX_PLAYER_NAME];
  986.             GetPVarString(playerid, "Perm_GivingTo", name, MAX_PLAYER_NAME);
  987.             new permid = Player_GetID(name);
  988.             if(!IsPlayerConnected(permid)) return Player_ResetPermissionSettings(playerid, 1);
  989.             SetPVarInt(playerid, "Perm_Deposit", listitem);
  990.             ShowPlayerDialog(playerid, DIALOG_MANAGE_GIVE_PERM_TAKE, DIALOG_STYLE_TABLIST_HEADERS, "Business Management: Give Permission", "Can this player take money from the business safe?\nNo\nYes", "Finish", "Cancel");
  991.             return 1;
  992.         }
  993.        
  994.         case DIALOG_MANAGE_GIVE_PERM_TAKE:
  995.         {
  996.             if(!response) return Player_ShowPermissionMenu(playerid);
  997.             if(InBusiness[playerid] == INVALID_BUSINESS) return SendClientMessage(playerid, 0xE74C3CFF, "ERROR: {FFFFFF}You're not in a business.");
  998.             if(!Player_OwnsBusiness(playerid, InBusiness[playerid])) return SendClientMessage(playerid, 0xE74C3CFF, "ERROR: {FFFFFF}You don't own this business.");
  999.             new name[MAX_PLAYER_NAME];
  1000.             GetPVarString(playerid, "Perm_GivingTo", name, MAX_PLAYER_NAME);
  1001.             new permid = Player_GetID(name);
  1002.             if(!IsPlayerConnected(permid)) return Player_ResetPermissionSettings(playerid, 1);
  1003.             new query[144];
  1004.             mysql_format(BusinessSQL, query, sizeof(query), "INSERT INTO business_perms SET Name='%e', BusinessID=%d, Can_Take=%d, Can_Deposit=%d", name, InBusiness[playerid], listitem, GetPVarInt(playerid, "Perm_Deposit"));
  1005.             mysql_tquery(BusinessSQL, query, "", "");
  1006.            
  1007.             format(query, sizeof(query), "Gave permissions to %s.", name);
  1008.             SendClientMessage(playerid, -1, query);
  1009.             format(query, sizeof(query), "%s can deposit money: %s.", name, PermissionStates[ GetPVarInt(playerid, "Perm_Deposit") ]);
  1010.             SendClientMessage(playerid, -1, query);
  1011.             format(query, sizeof(query), "%s can take money: %s.", name, PermissionStates[listitem]);
  1012.             SendClientMessage(playerid, -1, query);
  1013.             Player_ResetPermissionSettings(playerid);
  1014.             return 1;
  1015.         }
  1016.        
  1017.         case DIALOG_MANAGE_LIST_PERMS:
  1018.         {
  1019.             if(!response) return Player_ShowPermissionMenu(playerid);
  1020.             if(InBusiness[playerid] == INVALID_BUSINESS) return SendClientMessage(playerid, 0xE74C3CFF, "ERROR: {FFFFFF}You're not in a business.");
  1021.             if(!Player_OwnsBusiness(playerid, InBusiness[playerid])) return SendClientMessage(playerid, 0xE74C3CFF, "ERROR: {FFFFFF}You don't own this business.");
  1022.             new permid = strval(inputtext);
  1023.             SetPVarInt(playerid, "EditingPerm", permid);
  1024.             Player_ShowPermissionEditing(playerid);
  1025.             return 1;
  1026.         }
  1027.        
  1028.         case DIALOG_MANAGE_EDIT_PERMS:
  1029.         {
  1030.             if(!response) return Player_ShowPermissionMenu(playerid);
  1031.             if(InBusiness[playerid] == INVALID_BUSINESS) return SendClientMessage(playerid, 0xE74C3CFF, "ERROR: {FFFFFF}You're not in a business.");
  1032.             if(!Player_OwnsBusiness(playerid, InBusiness[playerid])) return SendClientMessage(playerid, 0xE74C3CFF, "ERROR: {FFFFFF}You don't own this business.");
  1033.             if(listitem == 0) Player_ShowPermissionEditing(playerid);
  1034.             if(listitem == 1)
  1035.             {
  1036.                 new query[128];
  1037.                 mysql_format(BusinessSQL, query, sizeof(query), "UPDATE business_perms SET Can_Deposit = NOT Can_Deposit WHERE ID=%d", GetPVarInt(playerid, "EditingPerm"));
  1038.                 mysql_tquery(BusinessSQL, query, "OnPermChange", "i", playerid);
  1039.             }
  1040.            
  1041.             if(listitem == 2)
  1042.             {
  1043.                 new query[128];
  1044.                 mysql_format(BusinessSQL, query, sizeof(query), "UPDATE business_perms SET Can_Take = NOT Can_Take WHERE ID=%d", GetPVarInt(playerid, "EditingPerm"));
  1045.                 mysql_tquery(BusinessSQL, query, "OnPermChange", "i", playerid);
  1046.             }
  1047.            
  1048.             if(listitem == 3)
  1049.             {
  1050.                 new query[64];
  1051.                 mysql_format(BusinessSQL, query, sizeof(query), "DELETE FROM business_perms WHERE ID=%d", GetPVarInt(playerid, "EditingPerm"));
  1052.                 mysql_tquery(BusinessSQL, query, "OnPermRemoved", "i", playerid);
  1053.             }
  1054.            
  1055.             return 1;
  1056.         }
  1057.        
  1058.         case DIALOG_MANAGE_SAFE_LOGS:
  1059.         {
  1060.             if(InBusiness[playerid] == INVALID_BUSINESS) return SendClientMessage(playerid, 0xE74C3CFF, "ERROR: {FFFFFF}You're not in a business.");
  1061.             if(!Player_OwnsBusiness(playerid, InBusiness[playerid])) return SendClientMessage(playerid, 0xE74C3CFF, "ERROR: {FFFFFF}You don't own this business.");
  1062.             if(!response) {
  1063.                 ListPage[playerid]--;
  1064.                 if(ListPage[playerid] < 0)
  1065.                 {
  1066.                     ListPage[playerid] = 0;
  1067.                     Player_ShowBusinessSafe(playerid);
  1068.                     return 1;
  1069.                 }
  1070.             }else{
  1071.                 ListPage[playerid]++;
  1072.             }
  1073.            
  1074.             Player_ShowSafeLogs(playerid);
  1075.             return 1;
  1076.         }
  1077.  
  1078.         case DIALOG_ADMIN_BUSINESS_TYPE:
  1079.         {
  1080.             if(!response) return 1;
  1081.             if(!IsPlayerAdmin(playerid)) return 1;
  1082.             new id = GetPVarInt(playerid, "EditingBusinessType");
  1083.             BusinessData[id][Type] = listitem;
  1084.             Business_UpdateLabel(id);
  1085.             Business_Save(id);
  1086.  
  1087.             new string[128];
  1088.             format(string, sizeof(string), "Business's type set to %s.", BusinessInteriors[listitem][InteriorName]);
  1089.             SendClientMessage(playerid, -1, string);
  1090.             return 1;
  1091.         }
  1092.     }
  1093.    
  1094.     return 0;
  1095. }
  1096.  
  1097. CMD:business(playerid, params[])
  1098. {
  1099.     if(InBusiness[playerid] == INVALID_BUSINESS) return SendClientMessage(playerid, 0xE74C3CFF, "ERROR: {FFFFFF}You're not in a business.");
  1100.     Player_ShowBusinessMenu(playerid);
  1101.     return 1;
  1102. }
  1103.  
  1104. CMD:createbusiness(playerid, params[])
  1105. {
  1106.     if(!IsPlayerAdmin(playerid)) return SendClientMessage(playerid, 0xE74C3CFF, "ERROR: {FFFFFF}Only RCON admins can use this command.");
  1107.     new id = Iter_Free(Business);
  1108.     if(id == -1) return SendClientMessage(playerid, 0xE74C3CFF, "ERROR: {FFFFFF}You can't create any more businesses.");
  1109.     new price, earning, type;
  1110.     if(sscanf(params, "iii", price, earning, type)) return SendClientMessage(playerid, 0xE88732FF, "USAGE: {FFFFFF}/createbusiness [price] [earning] [type]");
  1111.     if(!(0 <= type <= sizeof(BusinessInteriors)-1)) return SendClientMessage(playerid, 0xE74C3CFF, "ERROR: {FFFFFF}Invalid business type.");
  1112.     SetPVarInt(playerid, "BusinessCooldown", gettime() + 8);
  1113.     format(BusinessData[id][Name], MAX_BUSINESS_NAME, "Business");
  1114.     format(BusinessData[id][Owner], MAX_PLAYER_NAME, "-");
  1115.     GetPlayerPos(playerid, BusinessData[id][BusinessX], BusinessData[id][BusinessY], BusinessData[id][BusinessZ]);
  1116.     BusinessData[id][Closed] = 0;
  1117.     BusinessData[id][Price] = price;
  1118.     BusinessData[id][SalePrice] = 0;
  1119.     BusinessData[id][Earning] = earning;
  1120.     BusinessData[id][Money] = 0;
  1121.     BusinessData[id][Type] = type;
  1122.     BusinessData[id][LastVisited] = 0;
  1123.     BusinessData[id][BusinessPickup] = CreateDynamicPickup(1272, 1, BusinessData[id][BusinessX], BusinessData[id][BusinessY], BusinessData[id][BusinessZ]);
  1124.     BusinessData[id][BusinessLabel] = CreateDynamic3DTextLabel("Business", -1, BusinessData[id][BusinessX], BusinessData[id][BusinessY], BusinessData[id][BusinessZ]+0.35, 15.0, .testlos = 1);
  1125.     Business_UpdateLabel(id);
  1126.     Iter_Add(Business, id);
  1127.    
  1128.     new query[128];
  1129.     mysql_format(BusinessSQL, query, sizeof(query), "INSERT INTO business SET ID=%d, BusinessX=%f, BusinessY=%f, BusinessZ=%f, Price=%d, Type=%d", id, BusinessData[id][BusinessX], BusinessData[id][BusinessY], BusinessData[id][BusinessZ], price, type);
  1130.     mysql_tquery(BusinessSQL, query, "OnBusinessCreated", "i", id);
  1131.     return 1;
  1132. }
  1133.  
  1134. CMD:gotobusiness(playerid, params[])
  1135. {
  1136.     if(!IsPlayerAdmin(playerid)) return SendClientMessage(playerid, 0xE74C3CFF, "ERROR: {FFFFFF}Only RCON admins can use this command.");
  1137.     new id;
  1138.     if(sscanf(params, "i", id)) return SendClientMessage(playerid, 0xE88732FF, "USAGE: {FFFFFF}/gotobusiness [business id]");
  1139.     if(!Iter_Contains(Business, id)) return SendClientMessage(playerid, 0xE74C3CFF, "ERROR: {FFFFFF}The business you specified ID of doesn't exist.");
  1140.     SetPVarInt(playerid, "BusinessCooldown", gettime() + 8);
  1141.     SetPlayerPos(playerid, BusinessData[id][BusinessX], BusinessData[id][BusinessY], BusinessData[id][BusinessZ]);
  1142.     SetPlayerInterior(playerid, 0);
  1143.     SetPlayerVirtualWorld(playerid, 0);
  1144.     InBusiness[playerid] = INVALID_BUSINESS;
  1145.     return 1;
  1146. }
  1147.  
  1148. CMD:setbusinessprice(playerid, params[])
  1149. {
  1150.     if(!IsPlayerAdmin(playerid)) return SendClientMessage(playerid, 0xE74C3CFF, "ERROR: {FFFFFF}Only RCON admins can use this command.");
  1151.     new id, price;
  1152.     if(sscanf(params, "ii", id, price)) return SendClientMessage(playerid, 0xE88732FF, "USAGE: {FFFFFF}/setbusinessprice [business id] [new price]");
  1153.     if(!Iter_Contains(Business, id)) return SendClientMessage(playerid, 0xE74C3CFF, "ERROR: {FFFFFF}The business you specified ID of doesn't exist.");
  1154.     BusinessData[id][Price] = price;
  1155.     Business_UpdateLabel(id);
  1156.     Business_Save(id);
  1157.  
  1158.     new string[128];
  1159.     format(string, sizeof(string), "Business's price set to $%s.", convertNumber(price));
  1160.     SendClientMessage(playerid, -1, string);
  1161.     return 1;
  1162. }
  1163.  
  1164. CMD:setbusinessearning(playerid, params[])
  1165. {
  1166.     if(!IsPlayerAdmin(playerid)) return SendClientMessage(playerid, 0xE74C3CFF, "ERROR: {FFFFFF}Only RCON admins can use this command.");
  1167.     new id, earning;
  1168.     if(sscanf(params, "ii", id, earning)) return SendClientMessage(playerid, 0xE88732FF, "USAGE: {FFFFFF}/setbusinessearning [business id] [new earning]");
  1169.     if(!Iter_Contains(Business, id)) return SendClientMessage(playerid, 0xE74C3CFF, "ERROR: {FFFFFF}The business you specified ID of doesn't exist.");
  1170.     BusinessData[id][Earning] = earning;
  1171.     Business_UpdateLabel(id);
  1172.     Business_Save(id);
  1173.  
  1174.     new string[128];
  1175.     format(string, sizeof(string), "Business's earning set to $%s every %d minutes.", convertNumber(earning), BUSINESS_INTERVAL);
  1176.     SendClientMessage(playerid, -1, string);
  1177.     return 1;
  1178. }
  1179.  
  1180. CMD:setbusinesstype(playerid, params[])
  1181. {
  1182.     if(!IsPlayerAdmin(playerid)) return SendClientMessage(playerid, 0xE74C3CFF, "ERROR: {FFFFFF}Only RCON admins can use this command.");
  1183.     new id, type = -1;
  1184.     if(sscanf(params, "iI(-1)", id, type)) return SendClientMessage(playerid, 0xE88732FF, "USAGE: {FFFFFF}/setbusinesstype [business id] [type (optional)]");
  1185.     if(!Iter_Contains(Business, id)) return SendClientMessage(playerid, 0xE74C3CFF, "ERROR: {FFFFFF}The business you specified ID of doesn't exist.");
  1186.     if(type == -1) {
  1187.         SetPVarInt(playerid, "EditingBusinessType", id);
  1188.        
  1189.         new string[1024];
  1190.         format(string, sizeof(string), "Type\tName\n");
  1191.         for(new i; i < sizeof(BusinessInteriors); i++) format(string, sizeof(string), "%s%d\t%s\n", string, i, BusinessInteriors[i][InteriorName]);
  1192.         ShowPlayerDialog(playerid, DIALOG_ADMIN_BUSINESS_TYPE, DIALOG_STYLE_TABLIST_HEADERS, "Business Types", string, "Set", "Cancel");
  1193.     }else{
  1194.         if(!(0 <= type <= sizeof(BusinessInteriors)-1)) return SendClientMessage(playerid, 0xE74C3CFF, "ERROR: {FFFFFF}Invalid business type.");
  1195.         BusinessData[id][Type] = type;
  1196.         Business_UpdateLabel(id);
  1197.         Business_Save(id);
  1198.        
  1199.         new string[128];
  1200.         format(string, sizeof(string), "Business's type set to %s.", BusinessInteriors[type][InteriorName]);
  1201.         SendClientMessage(playerid, -1, string);
  1202.     }
  1203.    
  1204.     return 1;
  1205. }
  1206.  
  1207. CMD:resetbusiness(playerid, params[])
  1208. {
  1209.     if(!IsPlayerAdmin(playerid)) return SendClientMessage(playerid, 0xE74C3CFF, "ERROR: {FFFFFF}Only RCON admins can use this command.");
  1210.     new id;
  1211.     if(sscanf(params, "i", id)) return SendClientMessage(playerid, 0xE88732FF, "USAGE: {FFFFFF}/resetbusiness [business id]");
  1212.     if(!Iter_Contains(Business, id)) return SendClientMessage(playerid, 0xE74C3CFF, "ERROR: {FFFFFF}The business you specified ID of doesn't exist.");
  1213.     Business_Reset(id);
  1214.     SendClientMessage(playerid, -1, "Business reset.");
  1215.     return 1;
  1216. }
  1217.  
  1218. CMD:deletebusiness(playerid, params[])
  1219. {
  1220.     if(!IsPlayerAdmin(playerid)) return SendClientMessage(playerid, 0xE74C3CFF, "ERROR: {FFFFFF}Only RCON admins can use this command.");
  1221.     new id;
  1222.     if(sscanf(params, "i", id)) return SendClientMessage(playerid, 0xE88732FF, "USAGE: {FFFFFF}/deletebusiness [business id]");
  1223.     if(!Iter_Contains(Business, id)) return SendClientMessage(playerid, 0xE74C3CFF, "ERROR: {FFFFFF}The business you specified ID of doesn't exist.");
  1224.     DestroyDynamic3DTextLabel(BusinessData[id][BusinessLabel]);
  1225.     DestroyDynamicPickup(BusinessData[id][BusinessPickup]);
  1226.     format(BusinessData[id][Name], MAX_BUSINESS_NAME, "Business");
  1227.     format(BusinessData[id][Owner], MAX_PLAYER_NAME, "-");
  1228.     BusinessData[id][Closed] = 0;
  1229.     BusinessData[id][SalePrice] = 0;
  1230.     BusinessData[id][Money] = 0;
  1231.     BusinessData[id][LastVisited] = 0;
  1232.     BusinessData[id][BusinessLabel] = Text3D: INVALID_3DTEXT_ID;
  1233.     BusinessData[id][BusinessPickup] = -1;
  1234.     BusinessData[id][Save] = false;
  1235.     Business_KickEveryone(id);
  1236.     Iter_Remove(Business, id);
  1237.    
  1238.     new query[64];
  1239.     mysql_format(BusinessSQL, query, sizeof(query), "DELETE FROM business WHERE ID=%d", id);
  1240.     mysql_tquery(BusinessSQL, query, "", "");
  1241.     SendClientMessage(playerid, -1, "Business deleted.");
  1242.     return 1;
  1243. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement