S32_Business.inc 34 KB

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