Advertisement
Guest User

Untitled

a guest
Apr 3rd, 2010
355
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 16.06 KB | None | 0 0
  1. /* 'Its Just Business' Filterscipt made by Desert 2010.
  2. Thank you for downloading this filterscript. If you find any bugs please report them to me.
  3. When adding businesses please make sure that MAX_BUSINESS matches your ammount of businesses for most efficient use.
  4. If you are not sure about how many businesses you have open the Business.ini file which should be made in your scriptfiles directory.
  5. And find the highest number id like this 0X=1.100 and plus it with 1. Then you know you have 1 business. if 10 like 10X is the highest
  6. then you know you have 11 businesses. Simple right?
  7.  
  8. Credits to Y_Less and DracoBlue for DCMD sscanf and dini
  9. */
  10.  
  11.  
  12. #include <a_samp>
  13. #include <dutils>
  14. #include <dini>
  15.  
  16.  
  17. #define dcmd(%1,%2,%3) if ((strcmp((%3)[1], #%1, true, (%2)) == 0) && ((((%3)[(%2) + 1] == 0) && (dcmd_%1(playerid, "")))||(((%3)[(%2) + 1] == 32) && (dcmd_%1(playerid, (%3)[(%2) + 2]))))) return 1
  18. #pragma unused ret_memcpy
  19. #pragma tabsize 4
  20.  
  21. #define COLOUR_WHITE 0xFFFFFFFF
  22. #define COLOUR_GREEN 0x33AA33AA
  23. #define COLOUR_RED 0xFF3333AA
  24. #define COLOUR_YELLOW 0xFFFF00AA
  25. #define COLOUR_BLUE 0x0088FFAA
  26.  
  27. #define MAX_BUSINESS 10
  28.  
  29. forward PayTime();
  30.  
  31. new Businessid[MAX_BUSINESS];
  32. new OwnsBusiness[MAX_PLAYERS];
  33. new antispam[MAX_PLAYERS];
  34. forward AntiSpam(playerid);
  35.  
  36. public OnFilterScriptInit()
  37. {
  38. print("\n------------------------------------------------");
  39. print(" 'Its Just Business' has succesfully been loaded");
  40. print("------------------------------------------------\n");
  41. LoadBusinesses();
  42. SetTimer("PayTime",1000*60*10,1);
  43. if(!fexist("Business.ini"))
  44. {
  45. dini_Create("Business.ini");
  46. dini_IntSet("Business.ini","CurrentID",0);
  47. }
  48. return 1;
  49. }
  50.  
  51. public OnFilterScriptExit()
  52. {
  53. UnloadBusiness();
  54. return 1;
  55. }
  56.  
  57. public OnPlayerConnect(playerid)
  58. {
  59. new name[MAX_PLAYER_NAME];
  60. GetPlayerName(playerid,name,sizeof(name));
  61. if(strcmp(name,"NoOwner",false) == 0)
  62. {
  63. SendClientMessage(playerid,COLOUR_RED,"[Business system]: Sorry this name is not allowed in the server");
  64. Kick(playerid);
  65. }
  66. else
  67. {
  68. new ob = dini_Int("Business.ini",name);
  69. if(ob == 0) dini_IntSet("Business.ini",name,0);
  70. }
  71. return 1;
  72. }
  73.  
  74. public OnPlayerCommandText(playerid, cmdtext[])
  75. {
  76. dcmd(buybus,6,cmdtext);
  77. dcmd(sellbus,7,cmdtext);
  78. dcmd(createbus,9,cmdtext);
  79. dcmd(getprofit,9,cmdtext);
  80. return 0;
  81. }
  82.  
  83. dcmd_buybus(playerid,params[])
  84. {
  85. #pragma unused params
  86. new biz[50];
  87. new string[128];
  88. if(DoesPlayerOwnBusiness(playerid) == 1) return SendClientMessage(playerid,COLOUR_RED,"You do already own a business");
  89. if(IsPlayerInRangeOfBus(playerid) != -1)
  90. {
  91. new b = IsPlayerInRangeOfBus(playerid);
  92. format(biz,sizeof(biz),"%iOwner",b);
  93. if(dini_Int("Business.ini",biz) == 1) return SendClientMessage(playerid,COLOUR_RED,"You can't buy this business! Someone already ownes it");
  94. format(biz,sizeof(biz),"%iCost",b);
  95. if(dini_Int("Business.ini",biz) > GetPlayerMoney(playerid))
  96. {
  97. format(string,sizeof(string),"You do not have enough cash for this business! Price is $%i",dini_Int("Business.ini",biz));
  98. SendClientMessage(playerid,COLOUR_RED,string);
  99. }
  100. else
  101. {
  102. new name[MAX_PLAYER_NAME],bizname[MAX_STRING],cost;
  103. GetPlayerName(playerid,name,sizeof(name));
  104. format(biz,sizeof(biz),"%iCost",b);
  105. cost = dini_Int("Business.ini",biz);
  106. GivePlayerMoney(playerid,-cost);
  107. OwnsBusiness[playerid] = 1;
  108. format(biz,sizeof(biz),"%iOwnerName",b);
  109. dini_Set("business.ini",biz,name);
  110. format(biz,sizeof(biz),"%iBusinessname",b);
  111. bizname = dini_Get("Business.ini",biz);
  112. format(biz,sizeof(biz),"%iOwner",b);
  113. dini_IntSet("business.ini",biz,1);
  114. format(biz,sizeof(biz),"%iCash",b);
  115. dini_IntSet("business.ini",biz,0);
  116. format(biz,sizeof(biz),"%iPayment",b);
  117. new cash = dini_Int("business.ini",biz);
  118. format(string,sizeof(string),"You have succesfully bought %s! This business pays %i dollars per 10 minutes",bizname,cash);
  119. SendClientMessage(playerid,COLOUR_GREEN,string);
  120. dini_IntSet("Business.ini",name,1);
  121. }
  122. }
  123. else return SendClientMessage(playerid,COLOUR_RED,"You are not in range of any business");
  124. return 1;
  125. }
  126.  
  127. dcmd_sellbus(playerid,params[])
  128. {
  129. #pragma unused params
  130. if(DoesPlayerOwnBusiness(playerid) == 0) return SendClientMessage(playerid,COLOUR_RED,"You do not own any business");
  131. else
  132. {
  133. if(IsPlayerInRangeOfOwnedBusiness(playerid) != -1)
  134. {
  135. new biz[50],pname[MAX_PLAYER_NAME];
  136. new b = IsPlayerInRangeOfOwnedBusiness(playerid);
  137. new string[128];
  138. new name[MAX_STRING];
  139. format(biz,sizeof(biz),"%iBusinessname",b);
  140. name = dini_Get("business.ini",biz);
  141. format(string,sizeof(string),"You have sold %s",name);
  142. SendClientMessage(playerid,COLOUR_YELLOW,string);
  143. OwnsBusiness[playerid] = 0;
  144. format(biz,sizeof(biz),"%iOwner",b);
  145. dini_IntSet("business.ini",biz,0);
  146. format(biz,sizeof(biz),"%iCost",b);
  147. new cash = dini_Int("Business.ini",biz);
  148. GivePlayerMoney(playerid,cash);
  149. OwnsBusiness[playerid] = 0;
  150. GetPlayerName(playerid,pname,sizeof(pname));
  151. dini_IntSet("Business.ini",pname,0);
  152. }
  153. else return SendClientMessage(playerid,COLOUR_RED,"You are not in range of your business!");
  154. }
  155. return 1;
  156. }
  157.  
  158. dcmd_createbus(playerid,params[])
  159. {
  160. new cost,pay,name[100];
  161. if(!IsPlayerAdmin(playerid)) return 0;
  162. if(sscanf(params,"sii",name,cost,pay)) return SendClientMessage(playerid,COLOUR_RED,"Usage: /createbus NAME COST PAYMENT");
  163. else
  164. {
  165. new biz[100],Float:X,Float:Y,Float:Z;
  166. GetPlayerPos(playerid,X,Y,Z);
  167. new id = dini_Int("Business.ini","CurrentID");
  168. format(biz,sizeof(biz),"%iBusinessname",id);
  169. dini_Set("Business.ini",biz,name);
  170. format(biz,sizeof(biz),"%iPayment",id);
  171. dini_IntSet("Business.ini",biz,pay);
  172. format(biz,sizeof(biz),"%iCost",id);
  173. dini_IntSet("Business.ini",biz,cost);
  174. format(biz,sizeof(biz),"%iX",id);
  175. dini_FloatSet("Business.ini",biz,X);
  176. format(biz,sizeof(biz),"%iY",id);
  177. dini_FloatSet("Business.ini",biz,Y);
  178. format(biz,sizeof(biz),"%iZ",id);
  179. dini_FloatSet("Business.ini",biz,Z);
  180. format(biz,sizeof(biz),"%iOwnerName",id);
  181. dini_Set("business.ini",biz,"NoOwner");
  182. Businessid[id] = CreatePickup(1239,23,X,Y,Z,-1);
  183. id = id+1;
  184. dini_IntSet("Business.ini","CurrentID",id);
  185. SendClientMessage(playerid,COLOUR_YELLOW,"Succesfully created business");
  186. }
  187. return 1;
  188. }
  189.  
  190. dcmd_getprofit(playerid,params[])
  191. {
  192. #pragma unused params
  193. new b;
  194. if(DoesPlayerOwnBusiness(playerid) == 0) return SendClientMessage(playerid,COLOUR_RED,"You do now own a business!");
  195. if(IsPlayerInRangeOfOwnedBusiness(playerid) == -1) return SendClientMessage(playerid,COLOUR_RED,"You are not in range of your business!");
  196. else
  197. {
  198. b = IsPlayerInRangeOfOwnedBusiness(playerid);
  199. if(GetBusinessCashAmmount(b) == 0) return SendClientMessage(playerid,COLOUR_RED,"Your business does not contain any cash");
  200. else
  201. {
  202. new cash = GetBusinessCashAmmount(b);
  203. GivePlayerMoney(playerid,cash);
  204. new string[128],biz[50];
  205. format(string,sizeof(string),"You have recieved $%i from your business",cash);
  206. SendClientMessage(playerid,COLOUR_GREEN,string);
  207. format(biz,sizeof(biz),"%iCash",b);
  208. dini_IntSet("Business.ini",biz,0);
  209. }
  210. }
  211. return 1;
  212. }
  213.  
  214. public OnPlayerPickUpPickup(playerid, pickupid)
  215. {
  216. if(antispam[playerid] == pickupid) return 1;
  217. for(new b=0; b<MAX_BUSINESS; b++)
  218. {
  219. if(pickupid == Businessid[b])
  220. {
  221. antispam[playerid] = pickupid;
  222. SetTimerEx("AntiSpam",1000*30,0,"playerid",playerid);
  223. new biz[128];
  224. format(biz,sizeof(biz),"%iOwner",b);
  225. if(dini_Int("Business.ini",biz) == 1)
  226. {
  227. new name[MAX_PLAYER_NAME],name2[50];
  228. format(name2,sizeof(name2),"%iOwnerName",b);
  229. GetPlayerName(playerid,name,sizeof(name));
  230. format(biz,sizeof(biz),"%s",dini_Get("Business.ini",name2));
  231. if(strcmp(biz,name,false))
  232. {
  233. new bname[50],pname[MAX_PLAYER_NAME],string[128];
  234. format(biz,sizeof(biz),"%iBusinessname",b);
  235. format(bname,sizeof(bname),"%s",dini_Get("Business.ini",biz));
  236. format(biz,sizeof(biz),"%iOwnerName",b);
  237. format(pname,sizeof(pname),"%s",dini_Get("Business.ini",biz));
  238. format(string,sizeof(string),"Welcome to %s! This business is owned by %s",bname,pname);
  239. SendClientMessage(playerid,COLOUR_YELLOW,string);
  240. }
  241. else
  242. {
  243. format(biz,sizeof(biz),"Welcome back to your business %s. Use /getprofit to collect profit",name);
  244. SendClientMessage(playerid,COLOUR_YELLOW,biz);
  245. format(biz,sizeof(biz),"%iCash",b);
  246. new cash = dini_Int("Business.ini",biz);
  247. format(biz,sizeof(biz),"Your business contains $%i",cash);
  248. SendClientMessage(playerid,COLOUR_WHITE,biz);
  249. }
  250. }
  251. else
  252. {
  253. new bname[50],string[128];
  254. format(biz,sizeof(biz),"%iBusinessname",b);
  255. format(bname,sizeof(bname),"%s",dini_Get("Business.ini",biz));
  256. format(string,sizeof(string),"Welcome to %s! This business has no owner. Use /buybus to buy it",bname);
  257. SendClientMessage(playerid,COLOUR_WHITE,string);
  258. }
  259. }
  260. }
  261. return 1;
  262. }
  263.  
  264. public PayTime()
  265. {
  266. print("There has been a payday!");
  267. SendClientMessageToAll(COLOUR_BLUE,"Business's cash ammount has increased");
  268. for(new b=0; b<MAX_BUSINESS; b++)
  269. {
  270. new biz[50],pay,ammount;
  271. format(biz,sizeof(biz),"%iPayment",b);
  272. pay = dini_Int("Business.ini",biz);
  273. format(biz,sizeof(biz),"%iCash",b);
  274. ammount = dini_Int("Business.ini",biz);
  275. ammount = ammount+pay;
  276. dini_IntSet("Business.ini",biz,ammount);
  277. }
  278. return 1;
  279. }
  280.  
  281.  
  282. stock LoadBusinesses()
  283. {
  284. for(new b=0; b<MAX_BUSINESS; b++)
  285. {
  286. new biz[50],Float:x,Float:y,Float:z;
  287. format(biz,sizeof(biz),"%iX",b);
  288. x = dini_Float("Business.ini",biz);
  289. format(biz,sizeof(biz),"%iY",b);
  290. y = dini_Float("Business.ini",biz);
  291. format(biz,sizeof(biz),"%iZ",b);
  292. z = dini_Float("Business.ini",biz);
  293. Businessid[b] = CreatePickup(1239,23,x,y,z,-1);
  294. }
  295. return 1;
  296. }
  297.  
  298. stock DoesPlayerOwnBusiness(playerid)
  299. {
  300. new owns = 0;
  301. new name[MAX_PLAYER_NAME];
  302. GetPlayerName(playerid,name,sizeof(name));
  303. if(dini_Int("Business.ini",name) == 1) owns = 1;
  304. return owns;
  305. }
  306.  
  307. stock IsPlayerInRangeOfBus(playerid)
  308. {
  309. new range = -1;
  310. new biz[50];
  311. new Float:x,Float:y,Float:z;
  312. for(new i=0; i<MAX_BUSINESS; i++)
  313. {
  314. format(biz,sizeof(biz),"%iX",i);
  315. x = dini_Float("Business.ini",biz);
  316. format(biz,sizeof(biz),"%iY",i);
  317. y = dini_Float("Business.ini",biz);
  318. format(biz,sizeof(biz),"%iZ",i);
  319. z = dini_Float("Business.ini",biz);
  320. if(IsPlayerInRangeOfPoint(playerid,4,x,y,z))
  321. {
  322. range = i;
  323. }
  324. }
  325. return range;
  326. }
  327.  
  328. stock UnloadBusiness()
  329. {
  330. for(new b=0; b<MAX_BUSINESS; b++)
  331. {
  332. DestroyPickup(Businessid[b]);
  333. }
  334. return 1;
  335. }
  336.  
  337. stock IsPlayerInRangeOfOwnedBusiness(playerid)
  338. {
  339. new range = -1;
  340. new biz[50],name[MAX_STRING],pname[MAX_PLAYER_NAME];
  341. new Float:x,Float:y,Float:z;
  342. for(new i=0; i<MAX_BUSINESS; i++)
  343. {
  344. format(biz,sizeof(biz),"%iX",i);
  345. x = dini_Float("Business.ini",biz);
  346. format(biz,sizeof(biz),"%iY",i);
  347. y = dini_Float("Business.ini",biz);
  348. format(biz,sizeof(biz),"%iZ",i);
  349. z = dini_Float("Business.ini",biz);
  350. format(biz,sizeof(biz),"%sOwnerName",i);
  351. name = dini_Get("Business.ini",biz);
  352. GetPlayerName(playerid,pname,sizeof(pname));
  353. if(IsPlayerInRangeOfPoint(playerid,4,x,y,z) && strcmp(name,pname,false) == 0)
  354. {
  355. range = i;
  356. }
  357. }
  358. return range;
  359. }
  360.  
  361. stock GetBusinessCashAmmount(businessid)
  362. {
  363. new cash;
  364. new biz[50];
  365. format(biz,sizeof(biz),"%iCash",businessid);
  366. cash = dini_Int("Business.ini",biz);
  367. return cash;
  368. }
  369.  
  370. public AntiSpam(playerid)
  371. {
  372. antispam[playerid] = 0;
  373. return 1;
  374. }
  375.  
  376.  
  377.  
  378. stock sscanf(string[], format[], {Float,_}:...)
  379. {
  380. #if defined isnull
  381. if (isnull(string))
  382. #else
  383. if (string[0] == 0 || (string[0] == 1 && string[1] == 0))
  384. #endif
  385. {
  386. return format[0];
  387. }
  388. #pragma tabsize 4
  389. new
  390. formatPos = 0,
  391. stringPos = 0,
  392. paramPos = 2,
  393. paramCount = numargs(),
  394. delim = ' ';
  395. while (string[stringPos] && string[stringPos] <= ' ')
  396. {
  397. stringPos++;
  398. }
  399. while (paramPos < paramCount && string[stringPos])
  400. {
  401. switch (format[formatPos++])
  402. {
  403. case '\0':
  404. {
  405. return 0;
  406. }
  407. case 'i', 'd':
  408. {
  409. new
  410. neg = 1,
  411. num = 0,
  412. ch = string[stringPos];
  413. if (ch == '-')
  414. {
  415. neg = -1;
  416. ch = string[++stringPos];
  417. }
  418. do
  419. {
  420. stringPos++;
  421. if ('0' <= ch <= '9')
  422. {
  423. num = (num * 10) + (ch - '0');
  424. }
  425. else
  426. {
  427. return -1;
  428. }
  429. }
  430. while ((ch = string[stringPos]) > ' ' && ch != delim);
  431. setarg(paramPos, 0, num * neg);
  432. }
  433. case 'h', 'x':
  434. {
  435. new
  436. num = 0,
  437. ch = string[stringPos];
  438. do
  439. {
  440. stringPos++;
  441. switch (ch)
  442. {
  443. case 'x', 'X':
  444. {
  445. num = 0;
  446. continue;
  447. }
  448. case '0' .. '9':
  449. {
  450. num = (num << 4) | (ch - '0');
  451. }
  452. case 'a' .. 'f':
  453. {
  454. num = (num << 4) | (ch - ('a' - 10));
  455. }
  456. case 'A' .. 'F':
  457. {
  458. num = (num << 4) | (ch - ('A' - 10));
  459. }
  460. default:
  461. {
  462. return -1;
  463. }
  464. }
  465. }
  466. while ((ch = string[stringPos]) > ' ' && ch != delim);
  467. setarg(paramPos, 0, num);
  468. }
  469. case 'c':
  470. {
  471. setarg(paramPos, 0, string[stringPos++]);
  472. }
  473. case 'f':
  474. {
  475. setarg(paramPos, 0, _:floatstr(string[stringPos]));
  476. }
  477. case 'p':
  478. {
  479. delim = format[formatPos++];
  480. continue;
  481. }
  482. case '\'':
  483. {
  484. new
  485. end = formatPos - 1,
  486. ch;
  487. while ((ch = format[++end]) && ch != '\'') {}
  488. if (!ch)
  489. {
  490. return -1;
  491. }
  492. format[end] = '\0';
  493. if ((ch = strfind(string, format[formatPos], false, stringPos)) == -1)
  494. {
  495. if (format[end + 1])
  496. {
  497. return -1;
  498. }
  499. return 0;
  500. }
  501. format[end] = '\'';
  502. stringPos = ch + (end - formatPos);
  503. formatPos = end + 1;
  504. }
  505. case 'u':
  506. {
  507. new
  508. end = stringPos - 1,
  509. id = 0,
  510. bool:num = true,
  511. ch;
  512. while ((ch = string[++end]) && ch != delim)
  513. {
  514. if (num)
  515. {
  516. if ('0' <= ch <= '9')
  517. {
  518. id = (id * 10) + (ch - '0');
  519. }
  520. else
  521. {
  522. num = false;
  523. }
  524. }
  525. }
  526. if (num && IsPlayerConnected(id))
  527. {
  528. setarg(paramPos, 0, id);
  529. }
  530. else
  531. {
  532. #if !defined foreach
  533. #define foreach(%1,%2) for (new %2 = 0; %2 < MAX_PLAYERS; %2++) if (IsPlayerConnected(%2))
  534. #define __SSCANF_FOREACH__
  535. #endif
  536. string[end] = '\0';
  537. num = false;
  538. new
  539. name[MAX_PLAYER_NAME];
  540. id = end - stringPos;
  541. foreach (Player, playerid)
  542. {
  543. GetPlayerName(playerid, name, sizeof (name));
  544. if (!strcmp(name, string[stringPos], true, id))
  545. {
  546. setarg(paramPos, 0, playerid);
  547. num = true;
  548. break;
  549. }
  550. }
  551. if (!num)
  552. {
  553. setarg(paramPos, 0, INVALID_PLAYER_ID);
  554. }
  555. string[end] = ch;
  556. #if defined __SSCANF_FOREACH__
  557. #undef foreach
  558. #undef __SSCANF_FOREACH__
  559. #endif
  560. }
  561. stringPos = end;
  562. }
  563. case 's', 'z':
  564. {
  565. new
  566. i = 0,
  567. ch;
  568. if (format[formatPos])
  569. {
  570. while ((ch = string[stringPos++]) && ch != delim)
  571. {
  572. setarg(paramPos, i++, ch);
  573. }
  574. if (!i)
  575. {
  576. return -1;
  577. }
  578. }
  579. else
  580. {
  581. while ((ch = string[stringPos++]))
  582. {
  583. setarg(paramPos, i++, ch);
  584. }
  585. }
  586. stringPos--;
  587. setarg(paramPos, i, '\0');
  588. }
  589. default:
  590. {
  591. continue;
  592. }
  593. }
  594. while (string[stringPos] && string[stringPos] != delim && string[stringPos] > ' ')
  595. {
  596. stringPos++;
  597. }
  598. while (string[stringPos] && (string[stringPos] == delim || string[stringPos] <= ' '))
  599. {
  600. stringPos++;
  601. }
  602. paramPos++;
  603. }
  604. do
  605. {
  606. if ((delim = format[formatPos++]) > ' ')
  607. {
  608. if (delim == '\'')
  609. {
  610. while ((delim = format[formatPos++]) && delim != '\'') {}
  611. }
  612. else if (delim != 'z')
  613. {
  614. return delim;
  615. }
  616. }
  617. }
  618. while (delim > ' ');
  619. return 0;
  620. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement