Advertisement
System32

S32_Business

Nov 13th, 2011
1,441
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 34.59 KB | None | 0 0
  1. /*
  2.  * S32_Business - Create business with just one line (MySQL)!
  3.  * Copyright(c)System32
  4.  * This file is provided as is (no warranties)
  5.  
  6.  
  7.  * How I made a house system I need business to!
  8.  * Functions: 21
  9.  * Commands: 5
  10.  * Callbacks: 2
  11.  * Credits:
  12.      * System32 - Almost everything!
  13.      * The Guy - Helped me a lot, thank you!
  14.      * Y_Less - y_hooks, y_commands, sscanf & foreach!
  15.      * G-Stylezz (BlueG) - MySQL plugin!
  16.  * That is basically it, have fun with this include and easy scripting!
  17.  */
  18.  
  19. #if !defined _inc_a_samp
  20.     #include <a_samp>
  21. #endif
  22. #if !defined _inc_a_mysql
  23.     #include <a_mysql>
  24. #endif
  25. #if !defined _inc_foreach
  26.     #include <foreach>
  27. #endif
  28. #include <YSI\y_hooks>
  29. #include <YSI\y_commands>
  30.  
  31. #define MAX_BUSINESS 150
  32. #define business_version "v1.0.0"
  33. #define BUSINES_PAYMENT 1000
  34. #if !defined MAX_BUSINESS
  35.     #error Please define the max business (#define MAX_BUSINESS)
  36. #endif
  37.  
  38.  
  39. #define COLOR_LIME                                              0x10F441AA
  40. #define COLOR_KRED                                              0xFF0000FF
  41. #define COLOR_YELLOW                                            0xFFFF00AA
  42.  
  43. enum bInfo
  44. {
  45.     bOwner[24],
  46.     Float: bEnterX,
  47.     Float: bEnterY,
  48.     Float: bEnterZ,
  49.     Float: bExitX,
  50.     Float: bExitY,
  51.     Float: bExitZ,
  52.     bInterior,
  53.     bPrice,
  54.     bVirtualWorld,
  55.     bOwned,
  56.     bLocked,
  57.     bMoney,
  58.     Text3D: bLabel,
  59.     bPickup
  60. };
  61. new BusinessInfo[MAX_BUSINESS][bInfo];
  62.  
  63. new Iterator:Business<MAX_BUSINESS>, bstring[128], BQuery[1000], BusinessID, bsavingstring[500], PaymentTimer;
  64. new bool: PlayerEnteredHisBusiness[MAX_PLAYERS] = false;
  65.  
  66. forward OnPlayerEnterBusiness(playerid, businessid);
  67. forward OnPlayerExitBusiness(playerid, businessid);
  68. forward PaymentUp();
  69.  
  70.  
  71. //*****************************           *****************************
  72. //***************************** FUNCTIONS *****************************
  73. //*****************************           *****************************
  74.  
  75.  
  76.  
  77.  
  78. /*
  79.  
  80.  • Function: CreateBusiness(Float: EnterX, Float: EnterY, Float: EnterZ, Interior, Float: InteriorX, Float: InteriorY, Float: InteriorZ, Price, VirtualWorld, RentPrice)
  81.  • Data storage: MySQL (G-Stylezzz's plugin)
  82.  • Usage: Creating business, use this in OnGameModeInit or OnFilterScriptInit!
  83.  • Parameters:
  84.         EnterX, EnterY, EnterZ: Coordinates where you can enter business, also on that coordiantes will create pickup and 3D text!
  85.         ExitX, ExitY, ExitZ: Coordinates where you can exit business, this coordinates are coordiantes of interior, you can find interiors on http://weedarr.wikidot.com/interior or http://wiki.sa-mp.com/wiki/InteriorIDs
  86.         Interior: ID of interior you want, see the web page on the parameter above
  87.         Price: Price for buying business
  88.         VirtulWorld: Always increase this because if you have 2 same interior and player are in the (Example one is in his house, second is in his too) they will see themself, It will look that they have same house! (Bad explained :/)
  89.  • Example: CreateBusiness(-2395.9585,-601.2695,132.6484, 3, 384.808624,173.804992,1008.382812, 7000, 0);
  90.  
  91. */
  92.  
  93. stock CreateBusiness(Float: EnterX, Float: EnterY, Float: EnterZ, Interior, Float: ExitX, Float: ExitY, Float: ExitZ, Price, VirtualWorld)
  94. {
  95.     format(BQuery, sizeof(BQuery), "SELECT * FROM `business` WHERE `BusinessID` = %d", BusinessID);
  96.     mysql_query(BQuery);
  97.     mysql_store_result();
  98.     if(mysql_num_rows() == 0)
  99.     {
  100.         format(BusinessInfo[BusinessID][bOwner], 24, "None");
  101.         BusinessInfo[BusinessID][bEnterX] = EnterX;
  102.         BusinessInfo[BusinessID][bEnterY] = EnterY;
  103.         BusinessInfo[BusinessID][bEnterZ] = EnterZ;
  104.         BusinessInfo[BusinessID][bExitX] = ExitX;
  105.         BusinessInfo[BusinessID][bExitY] = ExitY;
  106.         BusinessInfo[BusinessID][bExitZ] = ExitZ;
  107.         BusinessInfo[BusinessID][bInterior] = Interior;
  108.         BusinessInfo[BusinessID][bVirtualWorld] = VirtualWorld;
  109.         BusinessInfo[BusinessID][bPrice] = Price;
  110.         format(bstring, sizeof(bstring), "For sale!\nPrice: %d\nBusiness ID: %d\nType /buybusiness to buy business!", Price, BusinessID);
  111.         format(BQuery, sizeof(BQuery), "INSERT INTO `business` (`User`, `EnterX`, `EnterY`, `EnterZ`, `ExitX`, `ExitY`, `ExitZ`, `Interior`, `Price`, `VirtualWorld`, `Owned`, `Locked`, `Money`, `BusinessID`) VALUES");
  112.         format(BQuery, sizeof(BQuery), "%s ('None', %f, %f, %f, %f, %f, %f, %d, %d, %d, 0, 0, 0, %d)", BQuery, BusinessInfo[BusinessID][bEnterX], BusinessInfo[BusinessID][bEnterY], BusinessInfo[BusinessID][bEnterZ], BusinessInfo[BusinessID][bExitX], BusinessInfo[BusinessID][bExitY], BusinessInfo[BusinessID][bExitZ], BusinessInfo[BusinessID][bInterior], BusinessInfo[BusinessID][bPrice], BusinessInfo[BusinessID][bVirtualWorld], BusinessID);
  113.         mysql_query(BQuery);
  114.         BusinessInfo[BusinessID][bLabel] = Create3DTextLabel(bstring, 0x21DD00FF, EnterX, EnterY, EnterZ, 40.0, 0);
  115.         BusinessInfo[BusinessID][bPickup] = CreatePickup(1272, 23, EnterX, EnterY, EnterZ, 0);
  116.     }
  117.     else
  118.     {
  119.         if(mysql_fetch_row_format(BQuery, "|"))
  120.         {
  121.             mysql_fetch_field_row(bsavingstring, "User"); format(BusinessInfo[BusinessID][bOwner], 24, "%s", bsavingstring);
  122.             mysql_fetch_field_row(bsavingstring, "EnterX"); BusinessInfo[BusinessID][bEnterX] = floatstr(bsavingstring);
  123.             mysql_fetch_field_row(bsavingstring, "EnterY"); BusinessInfo[BusinessID][bEnterY] = floatstr(bsavingstring);
  124.             mysql_fetch_field_row(bsavingstring, "EnterZ"); BusinessInfo[BusinessID][bEnterZ] = floatstr(bsavingstring);
  125.             mysql_fetch_field_row(bsavingstring, "ExitX"); BusinessInfo[BusinessID][bExitX] = floatstr(bsavingstring);
  126.             mysql_fetch_field_row(bsavingstring, "ExitY"); BusinessInfo[BusinessID][bExitY] = floatstr(bsavingstring);
  127.             mysql_fetch_field_row(bsavingstring, "ExitZ"); BusinessInfo[BusinessID][bExitZ] = floatstr(bsavingstring);
  128.             mysql_fetch_field_row(bsavingstring, "Interior"); BusinessInfo[BusinessID][bInterior] = strval(bsavingstring);
  129.             mysql_fetch_field_row(bsavingstring, "Price"); BusinessInfo[BusinessID][bPrice] = strval(bsavingstring);
  130.             mysql_fetch_field_row(bsavingstring, "VirtualWorld"); BusinessInfo[BusinessID][bVirtualWorld] = strval(bsavingstring);
  131.             mysql_fetch_field_row(bsavingstring, "Owned"); BusinessInfo[BusinessID][bOwned] = strval(bsavingstring);
  132.             mysql_fetch_field_row(bsavingstring, "Locked"); BusinessInfo[BusinessID][bLocked] = strval(bsavingstring);
  133.             mysql_fetch_field_row(bsavingstring, "Money"); BusinessInfo[BusinessID][bMoney] = strval(bsavingstring);
  134.             if(BusinessInfo[BusinessID][bOwned] == 1)
  135.             {
  136.                 format(bstring, sizeof(bstring), "Owner: %s\nBusiness ID: %d", BusinessInfo[BusinessID][bOwner], BusinessID);
  137.                 BusinessInfo[BusinessID][bLabel] = Create3DTextLabel(bstring, 0x21DD00FF, BusinessInfo[BusinessID][bEnterX], BusinessInfo[BusinessID][bEnterY], BusinessInfo[BusinessID][bEnterZ], 40.0, 0);
  138.                 BusinessInfo[BusinessID][bPickup] = CreatePickup(1239, 23, BusinessInfo[BusinessID][bEnterX], BusinessInfo[BusinessID][bEnterY], BusinessInfo[BusinessID][bEnterZ], 0);
  139.             }
  140.             else
  141.             {
  142.                 format(bstring, sizeof(bstring), "For sale!\nPrice: %d\nBusiness ID: %d\nType /buybusiness to buy business!", Price, BusinessID);
  143.                 BusinessInfo[BusinessID][bLabel] = Create3DTextLabel(bstring, 0x21DD00FF, BusinessInfo[BusinessID][bEnterX], BusinessInfo[BusinessID][bEnterY], BusinessInfo[BusinessID][bEnterZ], 40.0, 0);
  144.                 BusinessInfo[BusinessID][bPickup] = CreatePickup(1272, 23, BusinessInfo[BusinessID][bEnterX], BusinessInfo[BusinessID][bEnterY], BusinessInfo[BusinessID][bEnterZ], 0);
  145.             }
  146.         }
  147.     }
  148.     mysql_free_result();
  149.     Iter_Add(Business, BusinessID);
  150.     BusinessID++;
  151.     if(BusinessID > MAX_BUSINESS)
  152.     {
  153.         print("You reached maximum number of houses! Please enlarge the #define MAX_HOUSES\nin S32_House.inc! If you don't enlarge it, some houses won't work properly!");
  154.     }
  155.     return 1;
  156. }
  157.  
  158. /*
  159.  
  160.  • Function: GetBusinessUser(businessid)
  161.  • Usage: Getting name of user of specific business!
  162.  • Parameters:
  163.         businessid: ID of business that you want to get user (owner)
  164.  • Example: format(string, sizeof(string), "Business user of business id %d is %s", businessid, GetHouseUser(businessid));
  165.  
  166. */
  167.  
  168. stock GetBusinessUser(businessid)
  169. {
  170.     new howner1[24];
  171.     format(howner1, sizeof(howner1), "%s", BusinessInfo[businessid][bOwner]);
  172.     return howner1;
  173. }
  174.  
  175.  
  176.  
  177. /*
  178.  
  179.  • Function: GetBusinessEnterPos(houseid)
  180.  • Usage: Getting the enter position (XYZ) of specific business!
  181.  • Parameters:
  182.         businessid: ID of business that you want to get enter position
  183.  • Example: format(string, sizeof(string), "Business enter XYZ of business id %d is %s", businessid, GetBusinessEnterPos(businessid));
  184.  
  185. */
  186.  
  187. stock GetBusinessEnterPos(businessid)
  188. {
  189.     new getxyz1[128];
  190.     format(getxyz1, sizeof(getxyz1), "%f, %f, %f", BusinessInfo[businessid][bEnterX], BusinessInfo[businessid][bEnterY], BusinessInfo[businessid][bEnterZ]);
  191.     return getxyz1;
  192. }
  193.  
  194.  
  195.  
  196. /*
  197.  
  198.   • Function: GetBusinessExitPos(houseid)
  199.  • Usage: Getting the exit position (XYZ) of specific business!
  200.  • Parameters:
  201.         businessid: ID of business that you want to get exit position
  202.  • Example: format(string, sizeof(string), "Business exit XYZ of business id %d is %s", businessid, GetBusinessExitPos(businessid));
  203.  
  204. */
  205.  
  206. stock GetBusinessExitPos(businessid)
  207. {
  208.     new getxyz[128];
  209.     format(getxyz, sizeof(getxyz), "%f, %f, %f", BusinessInfo[businessid][bExitX], BusinessInfo[businessid][bExitY], BusinessInfo[businessid][bExitZ]);
  210.     return getxyz;
  211. }
  212.  
  213.  
  214.  
  215. /*
  216.  
  217.  • Function: GetBusinessEnterX(businessid)
  218.  • Usage: Getting the enter X position of specific business!
  219.  • Parameters:
  220.         businessid: ID of business that you want to get enter X position
  221.  • Example: format(string, sizeof(string), "Business enter X of business id %d is %s", businessid, GetBusinessEnterX(businessid));
  222.  
  223. */
  224.  
  225. stock GetBusinessEnterX(businessid)
  226. {
  227.     new getx1[128];
  228.     format(getx1, sizeof(getx1), "%f", BusinessInfo[businessid][bEnterX]);
  229.     return getx1;
  230. }
  231.  
  232.  
  233.  
  234. /*
  235.  
  236.  • Function: GetBusinessEnterY(businessid)
  237.  • Usage: Getting the enter Y position of specific business!
  238.  • Parameters:
  239.         businessid: ID of business that you want to get enter Y position
  240.  • Example: format(string, sizeof(string), "Business enter Y of business id %d is %s", businessid, GetBusinessEnterY(businessid));
  241.  
  242. */
  243.  
  244. stock GetBusinessEnterY(businessid)
  245. {
  246.     new gety1[128];
  247.     format(gety1, sizeof(gety1), "%f", BusinessInfo[businessid][bEnterY]);
  248.     return gety1;
  249. }
  250.  
  251.  
  252.  
  253. /*
  254.  
  255.  • Function: GetBusinessEnterZ(businessid)
  256.  • Usage: Getting the enter Z position of specific business!
  257.  • Parameters:
  258.         businessid: ID of business that you want to get enter Z position
  259.  • Example: format(string, sizeof(string), "Business enter Z of business id %d is %s", businessid, GetBusinessEnterZ(businessid));
  260.  
  261. */
  262.  
  263. stock GetBusinessEnterZ(businessid)
  264. {
  265.     new getz1[128];
  266.     format(getz1, sizeof(getz1), "%f", BusinessInfo[businessid][bEnterZ]);
  267.     return getz1;
  268. }
  269.  
  270.  
  271.  
  272. /*
  273.  
  274.  • Function: GetBusinessExitX(businessid)
  275.  • Usage: Getting the exit X position of specific business!
  276.  • Parameters:
  277.         businessid: ID of business that you want to get exit X position
  278.  • Example: format(string, sizeof(string), "Business exit X of business id %d is %s", businessid, GetBusinessExitX(businessid));
  279.  
  280. */
  281.  
  282. stock GetBusinessExitX(businessid)
  283. {
  284.     new getx1[128];
  285.     format(getx1, sizeof(getx1), "%f", BusinessInfo[businessid][bExitX]);
  286.     return getx1;
  287. }
  288.  
  289.  
  290.  
  291. /*
  292.  
  293.  • Function: GetBusinessExitY(businessid)
  294.  • Usage: Getting the exit Y position of specific business!
  295.  • Parameters:
  296.         businessid: ID of business that you want to get exit Y position
  297.  • Example: format(string, sizeof(string), "Business exit Y of business id %d is %s", businessid, GetBusinessExitY(businessid));
  298.  
  299. */
  300.  
  301. stock GetBusinessExitY(businessid)
  302. {
  303.     new gety1[128];
  304.     format(gety1, sizeof(gety1), "%f", BusinessInfo[businessid][bExitY]);
  305.     return gety1;
  306. }
  307.  
  308.  
  309.  
  310. /*
  311.  
  312.  • Function: GetBusinessExitZ(businessid)
  313.  • Usage: Getting the exit Z position of specific business!
  314.  • Parameters:
  315.         businessid: ID of business that you want to get exit Z position
  316.  • Example: format(string, sizeof(string), "Business exit Z of business id %d is %s", businessid, GetBusinessExitZ(businessid));
  317.  
  318. */
  319.  
  320. stock GetBusinessExitZ(businessid)
  321. {
  322.     new getz1[128];
  323.     format(getz1, sizeof(getz1), "%f", BusinessInfo[businessid][bExitZ]);
  324.     return getz1;
  325. }
  326.  
  327.  
  328.  
  329. /*
  330.  
  331.  • Function: GetBusinessPrice(businessid)
  332.  • Usage: Getting the price of specific business!
  333.  • Parameters:
  334.         businessid: ID of business that you want to get price
  335.  • Example: format(string, sizeof(string), "Business price of business id %d is %s", businessid, GetBusinessPrice(businessid));
  336.  
  337. */
  338.  
  339. stock GetBusinessPrice(businessid) return BusinessInfo[businessid][bPrice];
  340.  
  341.  
  342.  
  343. /*
  344.  
  345.  • Function: GetBusinessInterior(businessid)
  346.  • Usage: Getting the interior of specific business!
  347.  • Parameters:
  348.         businessid: ID of business that you want to get interior
  349.  • Example: format(string, sizeof(string), "Business interior of business id %d is %s", businessid, GetBusinessInterior(businessid));
  350.  
  351. */
  352.  
  353. stock GetBusinessInterior(businessid) return BusinessInfo[businessid][bInterior];
  354.  
  355.  
  356.  
  357. /*
  358.  
  359.  • Function: GetBusinessVirtualWorld(businessid)
  360.  • Usage: Getting the virtualworld of specific business!
  361.  • Parameters:
  362.         businessid: ID of business that you want to get virtualworld
  363.  • Example: format(string, sizeof(string), "Business virtualworld of business id %d is %s", businessid, GetBusinessVirtualWorld(businessid));
  364.  
  365. */
  366.  
  367. stock GetBusinessVirtualWorld(businessid) return BusinessInfo[businessid][bVirtualWorld];
  368.  
  369.  
  370.  
  371. /*
  372.  
  373.  • Function: GetBusinessMoney(businessid)
  374.  • Usage: Getting the money of specific business!
  375.  • Parameters:
  376.         businessid: ID of business that you want to get money
  377.  • Example: format(string, sizeof(string), "Business money of business id %d is %s", businessid, GetBusinessMoney(businessid));
  378.  
  379. */
  380.  
  381. stock GetBusinessMoney(businessid) return BusinessInfo[businessid][bMoney];
  382.  
  383.  
  384.  
  385. /*
  386.  
  387.  • Function: GetTotalBusiness(businessid)
  388.  • Usage: Getting the total business, use this in OnGameModeInit after all business!
  389.  • Example: printf("Total business: %d", GetTotalBusiness());
  390.  
  391. */
  392.  
  393. stock GetTotalBusiness() return Iter_Count(Business);
  394.  
  395.  
  396.  
  397. /*
  398.  
  399.  • Function: IsBusinessOwned(businessid)
  400.  • Usage: Checking if is bussines owned of specific business!
  401.  • Parameters:
  402.         businessid: ID of business that you want to check if is owned
  403.  • Example: if(IsBusinessOwned(businessid)) SendClientMessage(playerid, -1, "Business is owned!");
  404.             else SendClientMessage(palyerid, -1, "Business is not owned!");
  405.  
  406. */
  407.  
  408. stock IsBusinessOwned(businessid)
  409. {
  410.     if(BusinessInfo[businessid][bOwned] == 1) return 1;
  411.     else return 0;
  412. }
  413.  
  414.  
  415.  
  416. /*
  417.  
  418.  • Function: IsBusinessLocked(businessid)
  419.  • Usage: Checking if is business locked of specific business!
  420.  • Parameters:
  421.         businessid: ID of business that you want to check if is locked
  422.  • Example: if(IsBusinessOwned(businessid)) SendClientMessage(playerid, -1, "Business is locked!");
  423.             else SendClientMessage(palyerid, -1, "Business is not locked!");
  424.  
  425. */
  426.  
  427. stock IsBusinessLocked(businessid)
  428. {
  429.     if(BusinessInfo[businessid][bLocked] == 1) return 1;
  430.     else return 0;
  431. }
  432.  
  433.  
  434.  
  435. /*
  436.  
  437.  • Function: IsBusinessExist(businessid)
  438.  • Usage: Checking if is exist of specific business!
  439.  • Parameters:
  440.         businessid: ID of business that you want to check if is exist
  441.  • Example: if(IsBusinessExist(businessid)) SendClientMessage(playerid, -1, "Business exist!");
  442.             else SendClientMessage(palyerid, -1, "Business doesn't exist!");
  443.  
  444. */
  445.  
  446. stock IsBusinessExist(businessid)
  447. {
  448.     format(BQuery, sizeof(BQuery), "SELECT BusinessID FROM `business` WHERE `BusinessID` = %d", businessid);
  449.     mysql_query(BQuery);
  450.     mysql_store_result();
  451.     if(mysql_num_rows() == 1)
  452.     {
  453.         mysql_free_result();
  454.         return 1;
  455.     }
  456.     else
  457.     {
  458.         mysql_free_result();
  459.         return 0;
  460.     }
  461. }
  462.  
  463. /*
  464.  
  465.  • Function: IsPlayerBuyBusiness(playerid, businessid)
  466.  • Usage: Checking if is player buyed business (used when you try to buy business but you already have house)!
  467.  • Parameters:
  468.         playerid: ID of player that you want preform check
  469.         businessid: ID of business that you want to check if is player buy business
  470.  • Example: if(IsPlayerBuyBusiness(playerid, businessid)) return SendClientMessage(playerid, -1, "You buy this business already!");
  471.             else SendClientMessage(playerid, -1, "You didn't buy this business!");
  472.  
  473. */
  474.  
  475. stock IsPlayerBuyBusiness(playerid, businessid)
  476. {
  477.     format(BQuery, sizeof(BQuery), "SELECT User FROM `business` WHERE `User` = '%s' AND `BusinessID` = %d", GetName(playerid), businessid);
  478.     mysql_query(BQuery);
  479.     mysql_store_result();
  480.     if(mysql_num_rows() == 1)
  481.     {
  482.         mysql_free_result();
  483.         return 1;
  484.     }
  485.     else
  486.     {
  487.         mysql_free_result();
  488.         return 0;
  489.     }
  490. }
  491.  
  492. /*
  493.  
  494.  • Function: IsPlayerBuyBusiness(playerid, businessid)
  495.  • Usage: Checking if is player buyed any business!
  496.  • Parameters:
  497.         playerid: ID of player that you want preform check
  498.  • Example: if(IsPlayerBuyAnyBusiness(playerid)) return SendClientMessage(playerid, -1, "You buy any business already!");
  499.             else SendClientMessage(playerid, -1, "You didn't buy any business!");
  500.  
  501. */
  502.  
  503. stock IsPlayerBuyAnyBusiness(playerid)
  504. {
  505.     format(BQuery, sizeof(BQuery), "SELECT User FROM `business` WHERE `User` = '%s'", GetName(playerid));
  506.     mysql_query(BQuery);
  507.     mysql_store_result();
  508.     if(mysql_num_rows() == 1)
  509.     {
  510.         mysql_free_result();
  511.         return 1;
  512.     }
  513.     else
  514.     {
  515.         mysql_free_result();
  516.         return 0;
  517.     }
  518. }
  519.  
  520. /*
  521.  
  522.  • Function: IsPlayerBusinessOwner(playerid, businessid)
  523.  • Usage: Checking if is player owner of specific business!
  524.  • Parameters:
  525.         playerid: ID of player that you want preform check
  526.         businessid: ID of vusiness that you want to check if is player owner
  527.  • Example: if(IsPlayerBusinessOwner(playerid, businessid)) return SendClientMessage(playerid, -1, "You are owner of the business!");
  528.             else SendClientMessage(playerid, -1, "You are not owner of the business!");
  529.  
  530. */
  531.  
  532. stock IsPlayerBusinessOwner(playerid, businessid)
  533. {
  534.     if(!strcmp(BusinessInfo[businessid][bOwner], GetName(playerid), false)) return 1;
  535.     else return 0;
  536. }
  537.  
  538. //----Stocks for easier scripting!----
  539. /*stock GetName(playerid)
  540. {
  541.     new pName[MAX_PLAYER_NAME];
  542.     GetPlayerName(playerid, pName, MAX_PLAYER_NAME);
  543.     return pName;
  544. }*/
  545. //----End of stocks!----
  546.  
  547.  
  548. //*****************************          *****************************
  549. //***************************** COMMANDS *****************************
  550. //*****************************          *****************************
  551.  
  552.  
  553.  
  554. /*
  555.  
  556.  • Command: /buyhouse
  557.  • Processor: y_commands (YCMD)
  558.  • Usage: Buying business (Player must be in range of business he want to buy!)
  559.  
  560. */
  561.  
  562. YCMD:buybusiness(playerid, params[], help)
  563. {
  564.     #pragma unused help
  565.     #pragma unused params
  566.     foreach(Business, i)
  567.     {
  568.         if(IsPlayerInRangeOfPoint(playerid, 3.0, BusinessInfo[i][bEnterX], BusinessInfo[i][bEnterY], BusinessInfo[i][bEnterZ]))
  569.         {
  570.             if(BusinessInfo[i][bOwned] == 1) return SendClientMessage(playerid, COLOR_KRED, "Business is already owned!");
  571.             if(GetPlayerMoney(playerid) < BusinessInfo[i][bPrice]) return SendClientMessage(playerid, COLOR_KRED, "You don't have enough money!");
  572.  
  573.             new BQuery2[200];
  574.             format(BQuery2, sizeof(BQuery2), "SELECT User FROM `business` WHERE `User` = '%s'", GetName(playerid));
  575.             mysql_query(BQuery2);
  576.             mysql_store_result();
  577.             if(mysql_num_rows() == 1) return SendClientMessage(playerid, COLOR_KRED, "You have business already!");
  578.             mysql_free_result();
  579.  
  580.             format(BusinessInfo[i][bOwner], 24, "%s", GetName(playerid));
  581.             BusinessInfo[i][bOwned] = 1;
  582.             DestroyPickup(BusinessInfo[i][bPickup]);
  583.             BusinessInfo[i][bPickup] = CreatePickup(1239, 23, BusinessInfo[i][bEnterX], BusinessInfo[i][bEnterY], BusinessInfo[i][bEnterZ], 0);
  584.             format(bstring, sizeof(bstring), "Owner: %s\nBusiness ID: %d", BusinessInfo[i][bOwner], i);
  585.             Update3DTextLabelText(BusinessInfo[i][bLabel], 0x21DD00FF, bstring);
  586.             GivePlayerMoney(playerid, -BusinessInfo[i][bPrice]);
  587.             SendClientMessage(playerid, COLOR_LIME, "Business bought!");
  588.  
  589.             format(BQuery, sizeof(BQuery), "UPDATE `business` SET `User` = '%s', `Owned` = 1 WHERE `BusinessID` = %d", GetName(playerid), i);
  590.             mysql_query(BQuery);
  591.         }
  592.     }
  593.     return 1;
  594. }
  595.  
  596. /*
  597.  
  598.  • Command: /sellbusiness
  599.  • Processor: y_commands (YCMD)
  600.  • Usage: Selling business (Player must be in range of business he want to sell!)
  601.  
  602. */
  603.  
  604. YCMD:sellbusiness(playerid, params[], help)
  605. {
  606.     #pragma unused help
  607.     #pragma unused params
  608.     foreach(Business, i)
  609.     {
  610.         if(IsPlayerInRangeOfPoint(playerid, 3.0, BusinessInfo[i][bEnterX], BusinessInfo[i][bEnterY], BusinessInfo[i][bEnterZ]))
  611.         {
  612.             if(!strcmp(BusinessInfo[i][bOwner], GetName(playerid), false))
  613.             {
  614.                 format(BusinessInfo[i][bOwner], 24, "None");
  615.                 BusinessInfo[i][bOwned] = 0;
  616.                 BusinessInfo[i][bLocked] = 0;
  617.                 DestroyPickup(BusinessInfo[i][bPickup]);
  618.                 BusinessInfo[i][bPickup] = CreatePickup(1272, 23, BusinessInfo[i][bEnterX], BusinessInfo[i][bEnterY], BusinessInfo[i][bEnterZ], 0);
  619.                 format(bstring, sizeof(bstring), "For sale!\nPrice: %d\nBusiness ID: %d\nType /buybusiness to buy business!", BusinessInfo[i][bPrice], i);
  620.                 Update3DTextLabelText(BusinessInfo[i][bLabel], 0x21DD00FF, bstring);
  621.                 GivePlayerMoney(playerid, BusinessInfo[i][bPrice]);
  622.                 SendClientMessage(playerid, COLOR_LIME, "Business sold!");
  623.  
  624.                 format(BQuery, sizeof(BQuery), "UPDATE `business` SET `User` = 'None', `Owned` = 0, `Locked` = 0 WHERE `BusinessID` = %d", i);
  625.                 mysql_query(BQuery);
  626.             }
  627.         }
  628.     }
  629.     return 1;
  630. }
  631.  
  632. /*
  633.  
  634.  • Command: /lockbusiness
  635.  • Processor: y_commands (YCMD)
  636.  • Usage: Locking business (Player must be in range of his business to lock it!)
  637.  
  638. */
  639.  
  640. YCMD:lockbusiness(playerid, params[], help)
  641. {
  642.     #pragma unused help
  643.     #pragma unused params
  644.     foreach(Business, i)
  645.     {
  646.         if(IsPlayerInRangeOfPoint(playerid, 3.0, BusinessInfo[i][bEnterX], BusinessInfo[i][bEnterY], BusinessInfo[i][bEnterZ]) || IsPlayerInRangeOfPoint(playerid, 3.0, BusinessInfo[i][bExitX], BusinessInfo[i][bExitY], BusinessInfo[i][bExitZ]))
  647.         {
  648.             if(!strcmp(BusinessInfo[i][bOwner], GetName(playerid), false))
  649.             {
  650.                 BusinessInfo[i][bLocked] = 1;
  651.                 GameTextForPlayer(playerid, "Business ~r~locked!", 2000, 5);
  652.  
  653.                 format(BQuery, sizeof(BQuery), "UPDATE `business` SET `Locked` = 1 WHERE `BusinessID` = %d", i);
  654.                 mysql_query(BQuery);
  655.             }
  656.         }
  657.     }
  658.     return 1;
  659. }
  660.  
  661. /*
  662.  
  663.  • Command: /unlockbusiness
  664.  • Processor: y_commands (YCMD)
  665.  • Usage: Unlocking business (Player must be in range of his business to unlock it!)
  666.  
  667. */
  668.  
  669. YCMD:unlockbusiness(playerid, params[], help)
  670. {
  671.     #pragma unused help
  672.     #pragma unused params
  673.     foreach(Business, i)
  674.     {
  675.         if(IsPlayerInRangeOfPoint(playerid, 3.0, BusinessInfo[i][bEnterX], BusinessInfo[i][bEnterY], BusinessInfo[i][bEnterZ]) || IsPlayerInRangeOfPoint(playerid, 3.0, BusinessInfo[i][bExitX], BusinessInfo[i][bExitY], BusinessInfo[i][bExitZ]))
  676.         {
  677.             if(!strcmp(BusinessInfo[i][bOwner], GetName(playerid), false))
  678.             {
  679.                 BusinessInfo[i][bLocked] = 0;
  680.                 GameTextForPlayer(playerid, "Business ~g~unlocked!", 2000, 5);
  681.  
  682.                 format(BQuery, sizeof(BQuery), "UPDATE `business` SET `Locked` = 0 WHERE `BusinessID` = %d", i);
  683.                 mysql_query(BQuery);
  684.             }
  685.         }
  686.     }
  687.     return 1;
  688. }
  689.  
  690. /*
  691.  
  692.  • Command: /businesscontrol
  693.  • Processor: y_commands (YCMD)
  694.  • Usage: Controling your business: lock business, unlock business, storing money in business, taking money from business (Player must be in his house to control it!)
  695.  
  696. */
  697.  
  698. YCMD:businesscontrol(playerid, params[], help)
  699. {
  700.     #pragma unused help
  701.     #pragma unused params
  702.     foreach(Business, i)
  703.     {
  704.         if(IsPlayerInRangeOfPoint(playerid, 20.0, BusinessInfo[i][bExitX], BusinessInfo[i][bExitY], BusinessInfo[i][bExitZ]))
  705.         {
  706.             if(!strcmp(BusinessInfo[i][bOwner], GetName(playerid), false))
  707.             {
  708.                 if(PlayerEnteredHisBusiness[playerid] == true)
  709.                 {
  710.                     ShowPlayerDialog(playerid, 6560, DIALOG_STYLE_LIST, "   Control your business!", "Lock business\nUnlock business\nStore money\nTake money", "Ok", "Exit");
  711.                 }
  712.                 else SendClientMessage(playerid, COLOR_KRED, "You must enter your business!");
  713.             }
  714.         }
  715.     }
  716.     return 1;
  717. }
  718.  
  719.  
  720. public PaymentUp()
  721. {
  722.     foreach(Business, i)
  723.     {
  724.         new BQuery2[200];
  725.         format(BQuery2, sizeof(BQuery2), "SELECT BusinessID FROM `business` WHERE `BusinessID` = '%d'", i);
  726.         mysql_query(BQuery2);
  727.         mysql_store_result();
  728.         if(mysql_num_rows() == 1)
  729.         {
  730.             if(BusinessInfo[i][bOwned] == 1)
  731.             {
  732.                 BusinessInfo[i][bMoney] += BUSINES_PAYMENT;
  733.                 format(BQuery, sizeof(BQuery), "UPDATE `business` SET `Money` = %d WHERE `BusinessID` = %d", BusinessInfo[i][bMoney], i);
  734.                 mysql_query(BQuery);
  735.             }
  736.         }
  737.         mysql_free_result();
  738.     }
  739.     return 1;
  740. }
  741.  
  742.  
  743. //*****************************           *****************************
  744. //***************************** CALLBACKS *****************************
  745. //*****************************           *****************************
  746.  
  747.  
  748.  
  749. /*
  750.  
  751.  • Callback: OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])  (Hooked using y_hook)
  752.  • Action: Dialogs for house controling, later will be more for dynamic creating house!
  753.  
  754. */
  755.  
  756. Hook:B1_OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
  757. {
  758.     switch(dialogid)
  759.     {
  760.         case 6560:
  761.         {
  762.             if(!response) return 0;
  763.             switch(listitem)
  764.             {
  765.                 case 0:
  766.                 {
  767.                     foreach(Business, i)
  768.                     {
  769.                         if(IsPlayerInRangeOfPoint(playerid, 20.0, BusinessInfo[i][bExitX], BusinessInfo[i][bExitY], BusinessInfo[i][bExitZ]))
  770.                         {
  771.                             if(!strcmp(BusinessInfo[i][bOwner], GetName(playerid), false))
  772.                             {
  773.                                 BusinessInfo[i][bLocked] = 1;
  774.                                 GameTextForPlayer(playerid, "Business ~r~locked!", 2000, 5);
  775.                                 ShowPlayerDialog(playerid, 6560, DIALOG_STYLE_LIST, "   Control your business!", "Lock business\nUnlock business\nStore money\nTake money", "Ok", "Exit");
  776.  
  777.                                 format(BQuery, sizeof(BQuery), "UPDATE `business` SET `Locked` = 1 WHERE `BusinessID` = %d", i);
  778.                                 mysql_query(BQuery);
  779.                             }
  780.                         }
  781.                     }
  782.                 }
  783.                 case 1:
  784.                 {
  785.                     foreach(Business, i)
  786.                     {
  787.                         if(IsPlayerInRangeOfPoint(playerid, 20.0, BusinessInfo[i][bExitX], BusinessInfo[i][bExitY], BusinessInfo[i][bExitZ]))
  788.                         {
  789.                             if(!strcmp(BusinessInfo[i][bOwner], GetName(playerid), false))
  790.                             {
  791.                                 BusinessInfo[i][bLocked] = 0;
  792.                                 GameTextForPlayer(playerid, "Business ~g~unlocked!", 2000, 5);
  793.                                 ShowPlayerDialog(playerid, 6560, DIALOG_STYLE_LIST, "   Control your business!", "Lock business\nUnlock business\nStore money\nTake money", "Ok", "Exit");
  794.  
  795.                                 format(BQuery, sizeof(BQuery), "UPDATE `business` SET `Locked` = 0 WHERE `BusinessID` = %d", i);
  796.                                 mysql_query(BQuery);
  797.                             }
  798.                         }
  799.                     }
  800.                 }
  801.                 case 2:
  802.                 {
  803.                     foreach(Business, i)
  804.                     {
  805.                         if(IsPlayerInRangeOfPoint(playerid, 20.0, BusinessInfo[i][bExitX], BusinessInfo[i][bExitY], BusinessInfo[i][bExitZ]))
  806.                         {
  807.                             if(!strcmp(BusinessInfo[i][bOwner], GetName(playerid), false))
  808.                             {
  809.                                 format(bstring, sizeof(bstring), "Current stored money: %d\n\nType ammount of money that you want to store", BusinessInfo[i][bMoney]);
  810.                                 ShowPlayerDialog(playerid, 6561, DIALOG_STYLE_INPUT, "   Store money", bstring, "Ok", "Exit");
  811.                             }
  812.                         }
  813.                     }
  814.                 }
  815.                 case 3:
  816.                 {
  817.                     foreach(Business, i)
  818.                     {
  819.                         if(IsPlayerInRangeOfPoint(playerid, 20.0, BusinessInfo[i][bExitX], BusinessInfo[i][bExitY], BusinessInfo[i][bExitZ]))
  820.                         {
  821.                             if(!strcmp(BusinessInfo[i][bOwner], GetName(playerid), false))
  822.                             {
  823.                                 format(bstring, sizeof(bstring), "Current stored money: %d\n\nType ammount of money that you want to take", BusinessInfo[i][bMoney]);
  824.                                 ShowPlayerDialog(playerid, 6562, DIALOG_STYLE_INPUT, "   Store money", bstring, "Ok", "Exit");
  825.                             }
  826.                         }
  827.                     }
  828.                 }
  829.             }
  830.         }
  831.         case 6561:
  832.         {
  833.             if(!response) return ShowPlayerDialog(playerid, 6560, DIALOG_STYLE_LIST, "   Control your business!", "Lock business\nUnlock business\nStore money\nTake money", "Ok", "Exit");
  834.             foreach(Business, i)
  835.             {
  836.                 if(IsPlayerInRangeOfPoint(playerid, 20.0, BusinessInfo[i][bExitX], BusinessInfo[i][bExitY], BusinessInfo[i][bExitZ]))
  837.                 {
  838.                     if(!strcmp(BusinessInfo[i][bOwner], GetName(playerid), false))
  839.                     {
  840.                         new moneystring1[128];
  841.                         format(moneystring1, sizeof(moneystring1), "Current stored money: %d\n\nType ammount of money that you want to store", BusinessInfo[i][bMoney]);
  842.                         if(!strlen(inputtext)) return ShowPlayerDialog(playerid, 6561, DIALOG_STYLE_INPUT, "   Store money", bstring, "Ok", "Exit");
  843.                         if(GetPlayerMoney(playerid) < strval(inputtext))
  844.                         {
  845.                             SendClientMessage(playerid, COLOR_KRED, "You don't have enoguh money to store!");
  846.                             ShowPlayerDialog(playerid, 6561, DIALOG_STYLE_INPUT, "   Store money", bstring, "Ok", "Exit");
  847.                             return 1;
  848.                         }
  849.                         if(strval(inputtext) > 10000000)
  850.                         {
  851.                             SendClientMessage(playerid, COLOR_KRED, "You can store maximum 10000000!");
  852.                             ShowPlayerDialog(playerid, 6561, DIALOG_STYLE_INPUT, "   Store money", bstring, "Ok", "Exit");
  853.                             return 1;
  854.                         }
  855.                         BusinessInfo[i][bMoney] += strval(inputtext);
  856.                         GivePlayerMoney(playerid, -strval(inputtext));
  857.                         format(bstring, sizeof(bstring), "You store %d$! Current stored money: %d", strval(inputtext), BusinessInfo[i][bMoney]);
  858.                         SendClientMessage(playerid, COLOR_YELLOW, bstring);
  859.                         ShowPlayerDialog(playerid, 6560, DIALOG_STYLE_LIST, "   Control your business!", "Lock business\nUnlock business\nStore money\nTake money", "Ok", "Exit");
  860.  
  861.                         format(BQuery, sizeof(BQuery), "UPDATE `business` SET `Money` = %d WHERE `BusinessID` = %d", BusinessInfo[i][bMoney], i);
  862.                         mysql_query(BQuery);
  863.                     }
  864.                 }
  865.             }
  866.         }
  867.         case 6562:
  868.         {
  869.             if(!response) return ShowPlayerDialog(playerid, 6560, DIALOG_STYLE_LIST, "   Control your business!", "Lock business\nUnlock business\nStore money\nTake money", "Ok", "Exit");
  870.             foreach(Business, i)
  871.             {
  872.                 if(IsPlayerInRangeOfPoint(playerid, 20.0, BusinessInfo[i][bExitX], BusinessInfo[i][bExitY], BusinessInfo[i][bExitZ]))
  873.                 {
  874.                     if(!strcmp(BusinessInfo[i][bOwner], GetName(playerid), false))
  875.                     {
  876.                         new moneystring1[128];
  877.                         format(moneystring1, sizeof(moneystring1), "Current stored money: %d\n\nType ammount of money that you want to store", BusinessInfo[i][bMoney]);
  878.                         if(!strlen(inputtext)) return ShowPlayerDialog(playerid, 6561, DIALOG_STYLE_INPUT, "   Store money", bstring, "Ok", "Exit");
  879.                         if(strval(inputtext) > BusinessInfo[i][bMoney])
  880.                         {
  881.                             SendClientMessage(playerid, COLOR_KRED, "Business doesn't have so much money!");
  882.                             ShowPlayerDialog(playerid, 6562, DIALOG_STYLE_INPUT, "   Store money", bstring, "Ok", "Exit");
  883.                             return 1;
  884.                         }
  885.                         BusinessInfo[i][bMoney] -= strval(inputtext);
  886.                         GivePlayerMoney(playerid, strval(inputtext));
  887.                         format(bstring, sizeof(bstring), "You take %d$! Current stored money: %d", strval(inputtext), BusinessInfo[i][bMoney]);
  888.                         SendClientMessage(playerid, COLOR_YELLOW, bstring);
  889.                         ShowPlayerDialog(playerid, 6560, DIALOG_STYLE_LIST, "   Control your business!", "Lock business\nUnlock business\nStore money\nTake money", "Ok", "Exit");
  890.  
  891.                         format(BQuery, sizeof(BQuery), "UPDATE `business` SET `Money` = %d WHERE `BusinessID` = %d", BusinessInfo[i][bMoney], i);
  892.                         mysql_query(BQuery);
  893.                     }
  894.                 }
  895.             }
  896.         }
  897.     }
  898.     return 1;
  899. }
  900.  
  901. /*
  902.  
  903.  • Callback: OnPlayerKeyStateChange(playerid, newkeys, oldkeys)  (Hooked using y_hook)
  904.  • Action: Player can enter house (If is not locked!) using F or Enter (by default in GTA:SA)
  905.  
  906. */
  907.  
  908. Hook:B2_OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
  909. {
  910.     if(newkeys & KEY_SECONDARY_ATTACK && !IsPlayerInAnyVehicle(playerid))
  911.     {
  912.         foreach(Business, i)
  913.         {
  914.             if(IsPlayerInRangeOfPoint(playerid, 3.0, BusinessInfo[i][bEnterX], BusinessInfo[i][bEnterY], BusinessInfo[i][bEnterZ]))
  915.             {
  916.                 if(BusinessInfo[i][bLocked] == 0)
  917.                 {
  918.                     if(!strcmp(BusinessInfo[i][bOwner], GetName(playerid), false))
  919.                     {
  920.                         PlayerEnteredHisBusiness[playerid] = true;
  921.                     }
  922.                     SetPlayerInterior(playerid, BusinessInfo[i][bInterior]);
  923.                     SetPlayerVirtualWorld(playerid, BusinessInfo[i][bVirtualWorld]);
  924.                     SetPlayerPos(playerid, BusinessInfo[i][bExitX], BusinessInfo[i][bExitY], BusinessInfo[i][bExitZ]);
  925.                     return CallLocalFunction("OnPlayerEnterBusiness", "dd", playerid, i);
  926.                 }
  927.                 else SendClientMessage(playerid, COLOR_KRED, "Business is locked!");
  928.             }
  929.             else if(IsPlayerInRangeOfPoint(playerid, 3.0, BusinessInfo[i][bExitX], BusinessInfo[i][bExitY], BusinessInfo[i][bExitZ]) && GetPlayerInterior(playerid) == BusinessInfo[i][bInterior] && GetPlayerVirtualWorld(playerid) == BusinessInfo[i][bVirtualWorld])
  930.             {
  931.                 if(BusinessInfo[i][bLocked] == 0)
  932.                 {
  933.                     if(!strcmp(BusinessInfo[i][bOwner], GetName(playerid), false))
  934.                     {
  935.                         PlayerEnteredHisBusiness[playerid] = false;
  936.                     }
  937.                     SetPlayerInterior(playerid, 0);
  938.                     SetPlayerVirtualWorld(playerid, 0);
  939.                     SetPlayerPos(playerid, BusinessInfo[i][bEnterX], BusinessInfo[i][bEnterY], BusinessInfo[i][bEnterZ]);
  940.                     return CallLocalFunction("OnPlayerExitBusiness", "dd", playerid, i);
  941.                 }
  942.                 else SendClientMessage(playerid, COLOR_KRED, "Business is locked!");
  943.             }
  944.         }
  945.     }
  946.     return 1;
  947. }
  948.  
  949. Hook:B3_OnGameModeInit()
  950. {
  951.     PaymentTimer = SetTimer("PaymentUp", 3600000, 1);
  952.     return 1;
  953. }
  954.  
  955. Hook:B4_OnGameModeExit()
  956. {
  957.     KillTimer(PaymentTimer);
  958.     return 1;
  959. }
  960.  
  961. Hook:B5_OnPlayerConnect(playerid)
  962. {
  963.     new credits1[128];
  964.     format(credits1, sizeof(credits1), "This server use S32_Business %s by System32!", business_version);
  965.     SendClientMessage(playerid, COLOR_LIME, credits1);
  966.    
  967.     PlayerEnteredHisBusiness[playerid] = false;
  968.     return 1;
  969. }
  970.  
  971. Hook:B6_OnPlayerDisconnect(playerid)
  972. {
  973.     PlayerEnteredHisBusiness[playerid] = false;
  974.     return 1;
  975. }
  976.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement