Advertisement
Guest User

Untitled

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