HLMOD.HU Forrás Megtekintés - www.hlmod.hu
  1. /*================================================================================
  2.  
  3. --------------------------------------
  4. -*- [ZP] Sub-Plugin: Ultimate Bank -*-
  5. --------------------------------------
  6.  
  7. ~~~~~~~~~~~~~~~
  8. - Description -
  9. ~~~~~~~~~~~~~~~
  10.  
  11. This plug-in offers the clients the possibility to save their
  12. ammo packs in a bank account and retrieve them when needed.
  13. Everything is configurable by cvar values.
  14. This bank has absolutely NO BUGS.
  15. This plug-in also has new features such as auto saving,
  16. auto withdrawing, ML and bot support.
  17. Enjoy it and have fun!
  18.  
  19. Original forum thread: http://forums.alliedmods.net/showthread.php?t=132326
  20.  
  21. ~~~~~~~~~~~~~
  22. - Thanks to -
  23. ~~~~~~~~~~~~~
  24.  
  25. MeRcyLeZZ - For such an awesome mod like Zombie Plague
  26. and for some code i used from it...once again
  27. Random1 - For the original plug-in
  28. abdul-rehman - For suggesting removal of entity for ads
  29. and providing a option to replace it
  30. dorin2oo7 - For his pictures i used to style up my post
  31.  
  32. ~~~~~~~~~~~~~~~~~
  33. - Multi-lingual -
  34. ~~~~~~~~~~~~~~~~~
  35.  
  36. EN: Me (http://forums.alliedmods.net/member.php?u=42526)
  37. RO: Me (http://forums.alliedmods.net/member.php?u=42526)
  38. ES: DJHD! (http://forums.alliedmods.net/member.php?u=65176),
  39. lNeedHelp (http://forums.alliedmods.net/member.php?u=82951)
  40. RU: GAARA54 (http://forums.alliedmods.net/member.php?u=62855)
  41. BR: BRDominik (http://forums.alliedmods.net/member.php?u=80474)
  42. TR: AnqeL' (http://forums.alliedmods.net/member.php?u=83506)
  43. LV: Zyhm (http://forums.alliedmods.net/member.php?u=55789)
  44. PL: artos (http://forums.alliedmods.net/member.php?u=73986)
  45.  
  46. ~~~~~~~~~~~~~~
  47. - To do list -
  48. ~~~~~~~~~~~~~~
  49.  
  50. * Add donate
  51. * Add SQL support
  52.  
  53. ~~~~~~~~~~~~~
  54. - Changelog -
  55. ~~~~~~~~~~~~~
  56.  
  57. * v1.0 (11 Jul 2010)
  58. - First release
  59. - Added ML, auto-depositing/withdrawing,
  60. bot, steamid, ip, name saving support
  61. - Fixed all the bugs up to date
  62.  
  63. * v1.1 (25 Sep 2010)
  64. - Fixed ML not displaying correctly when
  65. depositing a certain ammount of ammo packs
  66. - Fixed auto-withdraw bug which was
  67. giving players extra ammo packs
  68. - Replaced ad entity with a task
  69. - Added reseting the bank limit if it's
  70. set to a value lower than 1
  71. - Ads display now only the active options
  72. - Removed FakeMeta
  73.  
  74. ================================================================================*/
  75.  
  76. #include <amxmodx>
  77. #include <nvault>
  78. #include <zombieplague>
  79.  
  80. #define CMDTARGET_OBEY_IMMUNITY (1<<0)
  81. #define CMDTARGET_ALLOW_SELF (1<<1)
  82. #define CMDTARGET_ONLY_ALIVE (1<<2)
  83. #define CMDTARGET_NO_BOTS (1<<3)
  84.  
  85. enum pcvar
  86. {
  87. enable = 0,
  88. cap,
  89. start,
  90. advertise,
  91. deposit,
  92. withdraw,
  93. account,
  94. savetype,
  95. bot
  96. }
  97.  
  98. new gvault, g_msgSayText, pcvars[pcvar], bankstorage[33]
  99.  
  100. public plugin_init()
  101. {
  102. register_plugin("[ZP] Sub Plugin: Ultimate Bank", "1.1", "93()|29!/<, Random1");
  103. register_dictionary("zp_bank.txt")
  104.  
  105. gvault = nvault_open("Zombie Bank Ultimate");
  106. g_msgSayText = get_user_msgid("SayText")
  107.  
  108. pcvars[enable] = register_cvar("zp_bank", "1");
  109. pcvars[cap] = register_cvar("zp_bank_limit", "757");
  110. pcvars[start] = register_cvar("zp_bank_blockstart", "0");
  111. pcvars[advertise] = register_cvar("zp_bank_ad_delay", "275.7")
  112. pcvars[deposit] = register_cvar("zp_bank_deposit", "1")
  113. pcvars[withdraw] = register_cvar("zp_bank_withdraw", "1")
  114. pcvars[account] = register_cvar("zp_bank_account", "1")
  115. pcvars[savetype] = register_cvar("zp_bank_save_type", "1")
  116. pcvars[bot] = register_cvar("zp_bank_bot_support", "1")
  117.  
  118. if (get_pcvar_num(pcvars[cap]) > 2147483646)
  119. {
  120. set_pcvar_num(pcvars[cap], 2147483646);
  121. server_print("[%L] %L", LANG_PLAYER, "BANK_PREFIX", LANG_PLAYER, "BANK_LIMIT");
  122. }
  123. else if (get_pcvar_num(pcvars[cap]) < 1)
  124. set_pcvar_num(pcvars[cap], 1);
  125.  
  126. register_clcmd("say", "handle_say");
  127. register_clcmd("say_team", "handle_say");
  128.  
  129. if (get_pcvar_num(pcvars[advertise]))
  130. set_task(get_pcvar_float(pcvars[advertise]), "advertise_loop");
  131. }
  132.  
  133. public plugin_cfg()
  134. {
  135. // Plugin is disabled
  136. if (!get_pcvar_num(pcvars[enable]))
  137. return;
  138.  
  139. // Get configs dir
  140. new cfgdir[32]
  141. get_configsdir(cfgdir, charsmax(cfgdir))
  142.  
  143. // Execute config file (zp_rewards.cfg)
  144. server_cmd("exec %s/zp_bank.cfg", cfgdir)
  145. }
  146.  
  147. public advertise_loop()
  148. {
  149. if (!get_pcvar_num(pcvars[enable]) || !get_pcvar_float(pcvars[advertise]))
  150. {
  151. remove_task()
  152.  
  153. return;
  154. }
  155.  
  156. if (get_pcvar_num(pcvars[cap]))
  157. zp_colored_print(0, "^x04[%L]^x01 %L", LANG_PLAYER, "BANK_PREFIX", LANG_PLAYER, "BANK_INFO1", get_pcvar_num(pcvars[cap]));
  158.  
  159. if (get_pcvar_num(pcvars[deposit]))
  160. zp_colored_print(0, "^x04[%L]^x01 %L", LANG_PLAYER, "BANK_PREFIX", LANG_PLAYER, "BANK_INFO_DPS");
  161. else
  162. zp_colored_print(0, "^x04[%L]^x01 %L", LANG_PLAYER, "BANK_PREFIX", LANG_PLAYER, "BANK_INFO_AS");
  163.  
  164. if (get_pcvar_num(pcvars[withdraw]))
  165. zp_colored_print(0, "^x04[%L]^x01 %L", LANG_PLAYER, "BANK_PREFIX", LANG_PLAYER, "BANK_INFO_WD");
  166.  
  167. set_task(get_pcvar_float(pcvars[advertise]), "advertise_loop");
  168. }
  169.  
  170. public plugin_end()
  171. nvault_close(gvault);
  172.  
  173. public handle_say(id)
  174. {
  175. if (!get_pcvar_num(pcvars[enable]))
  176. return PLUGIN_CONTINUE;
  177.  
  178. new text[70], arg1[32], arg2[32], arg3[6];
  179. read_args(text, sizeof(text) - 1);
  180. remove_quotes(text);
  181. arg1[0] = '^0';
  182. arg2[0] = '^0';
  183. arg3[0] = '^0';
  184. parse(text, arg1, sizeof(arg1) - 1, arg2, sizeof(arg2) - 1, arg3, sizeof(arg3) - 1);
  185.  
  186. //strip forward slash if present
  187. if (equali(arg1, "/", 1))
  188. format(arg1, 31, arg1[1]);
  189.  
  190. // if the chat line has more than 2 words, we're not interested at all
  191. if (arg3[0])
  192. return PLUGIN_CONTINUE;
  193.  
  194. if (equali(arg1, "berak", 7) || equali(arg1, "betesz", 4) || equali(arg1, "save", 5))
  195. {
  196. if (!get_pcvar_num(pcvars[deposit]))
  197. {
  198. zp_colored_print(id, "^x04[%L]^x01 %L", id, "BANK_PREFIX", id, "BANK_DNA");
  199.  
  200. return PLUGIN_CONTINUE;
  201. }
  202.  
  203. if (isdigit(arg2[0]) || arg2[0] == '-' && isdigit(arg2[1]))
  204. {
  205. new amount = str_to_num(arg2);
  206. if (amount <= 0)
  207. {
  208. zp_colored_print(id, "^x04[%L]^x01 %L", id, "BANK_PREFIX", id, "BANK_VGZ");
  209.  
  210. return PLUGIN_CONTINUE;
  211. }
  212. store_packs(id, amount);
  213.  
  214. return PLUGIN_HANDLED;
  215. }
  216. else if (equali(arg2, "all"))
  217. {
  218. store_packs(id, 0);
  219.  
  220. return PLUGIN_HANDLED;
  221. }
  222. else if (!arg2[0])
  223. {
  224. zp_colored_print(id, "^x04[%L]^x01 %L", id, "BANK_PREFIX", id, "BANK_HELP_DPS");
  225.  
  226. return PLUGIN_CONTINUE;
  227. }
  228.  
  229. return PLUGIN_CONTINUE;
  230. }
  231. else if (equali(arg1, "kivesz", 8) || equali(arg1, "kiszed", 4) || equali(arg1, "retrieve", 8))
  232. {
  233. if (!get_pcvar_num(pcvars[withdraw]))
  234. {
  235. zp_colored_print(id, "^x04[%L]^x01 %L", id, "BANK_PREFIX", id, "BANK_WNA");
  236.  
  237. return PLUGIN_CONTINUE;
  238. }
  239.  
  240. if (isdigit(arg2[0]) || arg2[0] == '-' && isdigit(arg2[1]))
  241. {
  242. new amount = str_to_num(arg2);
  243. if (amount <= 0)
  244. {
  245. zp_colored_print(id, "^x04[%L]^x01 %L", id, "BANK_PREFIX", id, "BANK_VGZ");
  246.  
  247. return PLUGIN_CONTINUE;
  248. }
  249. take_packs(id, amount);
  250.  
  251. return PLUGIN_HANDLED;
  252. }
  253. else if (equali(arg2, "all", 3) || equali(arg2, "everything", 10))
  254. {
  255. take_packs(id, 0);
  256.  
  257. return PLUGIN_HANDLED;
  258. }
  259. else if (!arg2[0])
  260. {
  261. zp_colored_print(id, "^x04[%L]^x01 %L", id, "BANK_PREFIX", id, "BANK_HELP_WD");
  262.  
  263. return PLUGIN_CONTINUE;
  264. }
  265.  
  266. return PLUGIN_CONTINUE;
  267. }
  268. else if (equali(arg1, "packs", 6) || equali(arg1, "account", 7) || equali(arg1, "bank", 4))
  269. {
  270. if (!arg2[0])
  271. {
  272. zp_colored_print(id, "^x04[%L]^x01 %L", id, "BANK_PREFIX", id, "BANK_INFO_CHK1", bankstorage[id]);
  273.  
  274. return PLUGIN_HANDLED;
  275. }
  276. else
  277. {
  278. new id2 = cmd_target(id, arg2, 2);
  279. if (!id2)
  280. return PLUGIN_CONTINUE;
  281.  
  282. static id2name[32];
  283. get_user_name(id2, id2name, 31);
  284. zp_colored_print(id, "^x04[%L]^x01 %L", id, "BANK_PREFIX", id, "BANK_INFO_CHK2", id2name, bankstorage[id2]);
  285.  
  286. return PLUGIN_HANDLED;
  287. }
  288.  
  289. return PLUGIN_CONTINUE;
  290. }
  291.  
  292. return PLUGIN_CONTINUE;
  293. }
  294.  
  295. //public zp_user_disconnect_pre(id)
  296. public client_disconnect(id)
  297. {
  298. if (!get_pcvar_num(pcvars[enable]))
  299. return;
  300.  
  301. if (is_user_bot(id) && !get_pcvar_num(pcvars[bot]) || !zp_get_user_ammo_packs(id))
  302. return;
  303. else
  304. store_packs(id, 0);
  305.  
  306. if (bankstorage[id] > 0)
  307. save_data(id);
  308. }
  309.  
  310. //public zp_user_connect_post(id)
  311. public client_putinserver(id)
  312. {
  313. if (!get_pcvar_num(pcvars[enable]))
  314. return;
  315.  
  316. bankstorage[id] = 0; //clear residual before loading
  317. retrieve_data(id);
  318. if (!get_pcvar_num(pcvars[withdraw]))
  319. {
  320. if (!bankstorage[id] || is_user_bot(id) && !get_pcvar_num(pcvars[bot]))
  321. return;
  322.  
  323. take_packs(id, 0)
  324. }
  325. }
  326.  
  327. store_packs(id, amnt)
  328. {
  329. if (!get_pcvar_num(pcvars[enable]))
  330. return;
  331.  
  332. new temp = zp_get_user_ammo_packs(id);
  333. new limit = get_pcvar_num(pcvars[cap]);
  334. new fill = limit - bankstorage[id];
  335.  
  336. if (!temp)
  337. {
  338. zp_colored_print(id, "^x04[%L]^x01 %L", id, "BANK_PREFIX", id, "BANK_NAPTD")
  339.  
  340. return;
  341. }
  342.  
  343. if (amnt == 0)
  344. {
  345. if (bankstorage[id] + temp <= limit)
  346. {
  347. bankstorage[id] += temp;
  348. zp_colored_print(id, "^x04[%L]^x01 %L", id, "BANK_PREFIX", id, "BANK_DPST", temp)
  349. zp_set_user_ammo_packs(id, 0);
  350. }
  351. else
  352. {
  353. zp_colored_print(id, "^x04[%L]^x01 %L", id, "BANK_PREFIX", id, "BANK_CPCT", limit);
  354. if (!fill)
  355. {
  356. zp_colored_print(id, "^x04[%L]^x01 %L", id, "BANK_PREFIX", id, "BANK_NDPST");
  357.  
  358. return;
  359. }
  360. else
  361. {
  362. bankstorage[id] += fill
  363. zp_set_user_ammo_packs(id, temp - fill);
  364. zp_colored_print(id, "^x04[%L]^x01 %L", id, "BANK_PREFIX", id, "BANK_PADPST", fill);
  365. }
  366. }
  367. checkmax(id);
  368. }
  369. else if (amnt > 0)
  370. {
  371. if (temp >= amnt)
  372. {
  373. if (bankstorage[id] + amnt <= limit)
  374. {
  375. bankstorage[id] += amnt
  376. zp_set_user_ammo_packs(id, temp - amnt);
  377. zp_colored_print(id, "^x04[%L]^x01 %L", id, "BANK_PREFIX", id, "BANK_DPST", amnt)
  378. }
  379. else
  380. {
  381. zp_colored_print(id, "^x04[%L]^x01 %L", id, "BANK_PREFIX", id, "BANK_CPCT", limit);
  382. if (!fill)
  383. {
  384. zp_colored_print(id, "^x04[%L]^x01 %L", id, "BANK_PREFIX", id, "BANK_NDPST");
  385.  
  386. return;
  387. }
  388. else
  389. {
  390. bankstorage[id] += fill
  391. zp_set_user_ammo_packs(id, temp - fill);
  392. zp_colored_print(id, "^x04[%L]^x01 %L", id, "BANK_PREFIX", id, "BANK_PDPST", fill, amnt);
  393. }
  394. }
  395. }
  396. else
  397. {
  398. zp_colored_print(id, "^x04[%L]^x01 %L", id, "BANK_PREFIX", id, "BANK_ASTDG", amnt, temp);
  399.  
  400. return;
  401. }
  402. }
  403. }
  404.  
  405. take_packs(id, amnt)
  406. {
  407. if (!get_pcvar_num(pcvars[enable]))
  408. return;
  409.  
  410. if (!bankstorage[id])
  411. {
  412. zp_colored_print(id, "^x04[%L]^x01 %L", id, "BANK_PREFIX", id, "BANK_NPIA")
  413.  
  414. return;
  415. }
  416.  
  417. if (amnt == 0)
  418. {
  419. zp_set_user_ammo_packs(id, zp_get_user_ammo_packs(id) + bankstorage[id])
  420. zp_colored_print(id, "^x04[%L]^x01 %L", id, "BANK_PREFIX", id, "BANK_WALL", bankstorage[id])
  421. bankstorage[id] = 0;
  422. }
  423. else if (amnt > 0)
  424. {
  425. if (bankstorage[id] >= amnt)
  426. {
  427. zp_set_user_ammo_packs(id, zp_get_user_ammo_packs(id) + amnt);
  428. bankstorage[id] -= amnt;
  429. zp_colored_print(id, "^x04[%L]^x01 %L", id, "BANK_PREFIX", id, "BANK_WAM", amnt)
  430. }
  431. else
  432. {
  433. zp_colored_print(id, "^x04[%L]^x01 %L", id, "BANK_PREFIX", id, "BANK_ASGB", amnt, bankstorage[id]);
  434.  
  435. return;
  436. }
  437. }
  438. }
  439.  
  440. save_data(id)
  441. {
  442. new vaultkey[40], vaultdata[13];
  443.  
  444. switch (get_pcvar_num(pcvars[savetype]))
  445. {
  446. case 1:
  447. {
  448. new AuthID[33];
  449. get_user_authid(id, AuthID, 32);
  450.  
  451. formatex(vaultkey, 39, "__%s__", AuthID);
  452. }
  453. case 2:
  454. {
  455. new IP[33];
  456. get_user_ip(id, IP, 32);
  457.  
  458. formatex(vaultkey, 39, "__%s__", IP);
  459. }
  460. case 3:
  461. {
  462. new Name[33];
  463. get_user_name(id, Name, 32);
  464.  
  465. formatex(vaultkey, 39, "__%s__", Name);
  466. }
  467. }
  468. formatex(vaultdata, 12, "%i", bankstorage[id]);
  469. nvault_set(gvault, vaultkey, vaultdata);
  470. }
  471.  
  472. retrieve_data(id)
  473. {
  474. new vaultkey[40], vaultdata[13];
  475.  
  476. switch (get_pcvar_num(pcvars[savetype]))
  477. {
  478. case 1:
  479. {
  480. new AuthID[33];
  481. get_user_authid(id, AuthID, 32);
  482.  
  483. formatex(vaultkey, 39, "__%s__", AuthID);
  484. }
  485. case 2:
  486. {
  487. new IP[33];
  488. get_user_ip(id, IP, 32);
  489.  
  490. formatex(vaultkey, 39, "__%s__", IP);
  491. }
  492. case 3:
  493. {
  494. new Name[33];
  495. get_user_name(id, Name, 32);
  496.  
  497. formatex(vaultkey, 39, "__%s__", Name);
  498. }
  499. }
  500. nvault_get(gvault, vaultkey, vaultdata, 12);
  501.  
  502. bankstorage[id] = str_to_num(vaultdata);
  503. checkmax(id);
  504.  
  505. // If they have an account don't allow zombie mod to give them 5 ammo packs at beggining
  506. if (get_pcvar_num(pcvars[start]) && bankstorage[id] > 0)
  507. zp_set_user_ammo_packs(id, 0);
  508. }
  509.  
  510. checkmax(id)
  511. {
  512. if (bankstorage[id] > get_pcvar_num(pcvars[cap]))
  513. bankstorage[id] = get_pcvar_num(pcvars[cap]);
  514. else if (bankstorage[id] < 0)
  515. bankstorage[id] = 0;
  516. }
  517.  
  518. // Colored chat print by MeRcyLeZZ
  519. zp_colored_print(target, const message[], any:...)
  520. {
  521. static buffer[512], i, argscount
  522. argscount = numargs()
  523.  
  524. // Send to everyone
  525. if (!target)
  526. {
  527. static player
  528. for (player = 1; player <= get_maxplayers(); player++)
  529. {
  530. // Not connected
  531. if (!is_user_connected(player))
  532. continue;
  533.  
  534. // Remember changed arguments
  535. static changed[5], changedcount // [5] = max LANG_PLAYER occurencies
  536. changedcount = 0
  537.  
  538. // Replace LANG_PLAYER with player id
  539. for (i = 2; i < argscount; i++)
  540. {
  541. if (getarg(i) == LANG_PLAYER)
  542. {
  543. setarg(i, 0, player)
  544. changed[changedcount] = i
  545. changedcount++
  546. }
  547. }
  548.  
  549. // Format message for player
  550. vformat(buffer, charsmax(buffer), message, 3)
  551.  
  552. // Send it
  553. message_begin(MSG_ONE_UNRELIABLE, g_msgSayText, _, player)
  554. write_byte(player)
  555. write_string(buffer)
  556. message_end()
  557.  
  558. // Replace back player id's with LANG_PLAYER
  559. for (i = 0; i < changedcount; i++)
  560. setarg(changed[i], 0, LANG_PLAYER)
  561. }
  562. }
  563. // Send to specific target
  564. else
  565. {
  566. // Format message for player
  567. vformat(buffer, charsmax(buffer), message, 3)
  568.  
  569. // Send it
  570. message_begin(MSG_ONE, g_msgSayText, _, target)
  571. write_byte(target)
  572. write_string(buffer)
  573. message_end()
  574. }
  575. }
  576.  
  577. // Stock from AmxMisc
  578. stock get_configsdir(name[], len)
  579. return get_localinfo("amxx_configsdir", name, len);
  580.  
  581. stock cmd_target(id,const arg[],flags = CMDTARGET_OBEY_IMMUNITY)
  582. {
  583. new player = find_player("bl",arg);
  584. if (player)
  585. {
  586. if ( player != find_player("blj",arg) )
  587. {
  588. #if defined AMXMOD_BCOMPAT
  589. console_print(id, SIMPLE_T("There are more clients matching to your argument"));
  590. #else
  591. console_print(id,"%L",id,"MORE_CL_MATCHT");
  592. #endif
  593. return 0;
  594. }
  595. }
  596. else if ( ( player = find_player("c",arg) )==0 && arg[0]=='#' && arg[1] )
  597. {
  598. player = find_player("k",str_to_num(arg[1]));
  599. }
  600. if (!player)
  601. {
  602. #if defined AMXMOD_BCOMPAT
  603. console_print(id, SIMPLE_T("Client with that name or userid not found"));
  604. #else
  605. console_print(id,"%L",id,"CL_NOT_FOUND");
  606. #endif
  607. return 0;
  608. }
  609. if (flags & CMDTARGET_OBEY_IMMUNITY)
  610. {
  611. if ((get_user_flags(player) & ADMIN_IMMUNITY) &&
  612. ((flags & CMDTARGET_ALLOW_SELF) ? (id != player) : true) )
  613. {
  614. new imname[32];
  615. get_user_name(player,imname,31);
  616. #if defined AMXMOD_BCOMPAT
  617. console_print(id, SIMPLE_T("Client ^"%s^" has immunity"), imname);
  618. #else
  619. console_print(id,"%L",id,"CLIENT_IMM",imname);
  620. #endif
  621. return 0;
  622. }
  623. }
  624. if (flags & CMDTARGET_ONLY_ALIVE)
  625. {
  626. if (!is_user_alive(player))
  627. {
  628. new imname[32];
  629. get_user_name(player,imname,31);
  630. #if defined AMXMOD_BCOMPAT
  631. console_print(id, SIMPLE_T("That action can't be performed on dead client ^"%s^""), imname);
  632. #else
  633. console_print(id,"%L",id,"CANT_PERF_DEAD",imname);
  634. #endif
  635. return 0;
  636. }
  637. }
  638. if (flags & CMDTARGET_NO_BOTS)
  639. {
  640. if (is_user_bot(player))
  641. {
  642. new imname[32];
  643. get_user_name(player,imname,31);
  644. #if defined AMXMOD_BCOMPAT
  645. console_print(id, SIMPLE_T("That action can't be performed on bot ^"%s^""), imname);
  646. #else
  647. console_print(id,"%L",id,"CANT_PERF_BOT",imname);
  648. #endif
  649. return 0;
  650. }
  651. }
  652. return player;
  653. }
  654.