hlmod.hu

Magyar Half-Life Mód közösség!
Pontos idő: 2024.04.19. 13:26



Jelenlévő felhasználók

Jelenleg 213 felhasználó van jelen :: 1 regisztrált, 0 rejtett és 212 vendég

A legtöbb felhasználó (1565 fő) 2020.11.21. 11:26-kor tartózkodott itt.

Regisztrált felhasználók: Bing [Bot] az elmúlt 5 percben aktív felhasználók alapján

Utoljára aktív
Ahhoz hogy lásd ki volt utoljára aktív, be kell jelentkezned.



Az oldal teljeskörű
használatához regisztrálj.

Regisztráció

Kereső


Új téma nyitása  Hozzászólás a témához  [ 3 hozzászólás ] 
Szerző Üzenet
 Hozzászólás témája: stock ChatColor
HozzászólásElküldve: 2012.09.11. 13:53 
Offline
Őskövület
Avatar

Csatlakozott: 2011.09.17. 17:54
Hozzászólások: 2350
Megköszönt másnak: 40 alkalommal
Megköszönték neki: 57 alkalommal
Valaki csinálja meg erre a kódra,hogy jó legyen,hogy langból tudjam használni a színeket,nem sikerül mindig errort dob !

Kód:
SMA Forráskód: [ Mindet kijelol ]
  1.  
  2. #include <amxmodx>
  3. #include <amxmisc>
  4. #include <zombieplague>
  5. #include <vault>
  6.  
  7. stock const ZP_BANK_FMT[] = "^x04[AC] %L"
  8. stock const zplog[] = "zp_bank_activity.log"
  9.  
  10. new g_iAmmoPacks[33]
  11. new g_iSessionMovement[33]
  12. new g_iWithdrawLimit[33]
  13. new g_szAuth[33][32]
  14. new cvAnnounceTime
  15. new cvBankMax
  16. new cvDepositMin
  17. new cvWithdrawMax
  18. new cvWithdrawLimit
  19. new cvBankSaveDays
  20. new cvAutoSave
  21. new cvDeBug
  22.  
  23. // Temporary Database vars (used to restore players stats in case they get disconnected)
  24. new db_playerip[64][32] // player name
  25. new db_wlimit[64] // withdraw limit
  26. new db_slot_i // additional saved slots counter (should start on maxplayers+1)
  27.  
  28. // Temporary save player's stats to database
  29. Tmp_Save(id)
  30. {
  31. new PIP[32]
  32. get_user_ip(id, PIP, 31, 1)
  33.  
  34. // Check whether there is another record already in that slot
  35. if (db_playerip[id][0] && !equal(PIP, db_playerip[id]))
  36. {
  37. // If DB size is exceeded, write over old records
  38. if (db_slot_i >= sizeof db_playerip)
  39. db_slot_i = get_maxplayers()+1
  40.  
  41. // Move previous record onto an additional save slot
  42. copy(db_playerip[db_slot_i], charsmax(db_playerip[]), db_playerip[id])
  43. db_wlimit[db_slot_i] = db_wlimit[id]
  44. db_slot_i++
  45. }
  46.  
  47. copy(db_playerip[id], charsmax(db_playerip[]), PIP) // name
  48. db_wlimit[id] = g_iWithdrawLimit[id] // withdraw limit
  49. }
  50.  
  51. // Load temporary saved player's stats from database (if a record is found)
  52. Tmp_Load(id)
  53. {
  54. new PIP[32]
  55. get_user_ip(id, PIP, 31, 1)
  56.  
  57. // Look for a matching record
  58. static i
  59. for (i = 0; i < sizeof db_playerip; i++)
  60. {
  61. if (equal(PIP, db_playerip[i]))
  62. {
  63. // Bingo!
  64. g_iWithdrawLimit[id] = db_wlimit[i]
  65. return;
  66. }
  67. }
  68. }
  69.  
  70. LoadClient(id, szAuth[])
  71. {
  72. static szValue[11]
  73. new iValue = 0
  74. new key[38], vaultdata[56], name[34], timestamp[11]
  75.  
  76. // Little memory cleanup
  77. szValue[0] = '^0'
  78. key[0] = '^0'
  79. vaultdata[0] = '^0'
  80. name[0] = '^0'
  81. timestamp[0] = '^0'
  82.  
  83. format(key,37,"ZBANK.%s",szAuth)
  84.  
  85. get_vaultdata(key,vaultdata,55)
  86. parse(vaultdata,name,33,timestamp,10,szValue,10)
  87. remove_quotes(name)
  88.  
  89. if (strlen(szValue) > 0)
  90. {
  91. iValue = (g_iAmmoPacks[id] = str_to_num(szValue))
  92. }
  93.  
  94. SayText(id, id, ZP_BANK_FMT, id, "ZP_BANK_LOAD", iValue, szAuth, (get_pcvar_num(cvWithdrawLimit) - g_iWithdrawLimit[id]))
  95.  
  96. if (get_pcvar_num(cvDeBug) >= 2)
  97. {
  98. if (iValue != 0)
  99. {
  100. log_to_file(zplog,"[ZP] DBLoad: loaded ^"%d^" ammovalue for (Player ^"%s^") (IP ^"%s^")",iValue,name,szAuth)
  101. }
  102. else
  103. {
  104. log_to_file(zplog,"[ZP] DBLoad: nothing to load for (IP ^"%s^"). So sad.",szAuth)
  105. }
  106.  
  107. }
  108. }
  109.  
  110. SaveClient(id, szAuth[])
  111. {
  112. static szValue[11]
  113. new key[38], vaultdata[56], name[32]
  114.  
  115. // Little memory cleanup
  116. szValue[0] = '^0'
  117. key[0] = '^0'
  118. vaultdata[0] = '^0'
  119. name[0] = '^0'
  120.  
  121. num_to_str(g_iAmmoPacks[id] + g_iSessionMovement[id], szValue, charsmax(szValue))
  122. get_user_name(id, name, 31)
  123. format(key,37,"ZBANK.%s",szAuth)
  124. format(vaultdata,55,"^"%s^" %d %s",name,get_systime(),szValue)
  125.  
  126. if (str_to_num(szValue) <= 0)
  127. {
  128. remove_vaultdata(key)
  129. }
  130. else
  131. {
  132. set_vaultdata(key,vaultdata)
  133. }
  134.  
  135. if (get_pcvar_num(cvDeBug) >= 2)
  136. {
  137. if (str_to_num(szValue) > 0)
  138. {
  139. log_to_file(zplog,"[ZP] DBSave: saved ^"%s^" ammovalue for (Player ^"%s^") (IP ^"%s^")",szValue,name,szAuth)
  140. }
  141. else
  142. {
  143. log_to_file(zplog,"[ZP] DBSave: nothing to save for (IP ^"%s^"). So sad.",szAuth)
  144. }
  145. }
  146. }
  147.  
  148. MemClr(id)
  149. {
  150. g_szAuth[id][0] = '^0'
  151. g_iAmmoPacks[id] = 0
  152. g_iSessionMovement[id] = 0
  153. g_iWithdrawLimit[id] = 0
  154. }
  155.  
  156. cleanDB()
  157. {
  158. // Open up the vault file - read line by line
  159. // Use vault to delete to any data over a certain age
  160. new gVaultFile[128]
  161. if ( !file_exists(gVaultFile) ) return
  162. get_localinfo("amxx_vault", gVaultFile, 127)
  163.  
  164. new ammoSaveDays = get_pcvar_num(cvBankSaveDays)
  165.  
  166. if ( ammoSaveDays < 0) return
  167.  
  168. if (get_pcvar_num(cvDeBug) >= 1)
  169. {
  170. log_to_file(zplog,"[ZP] DBClean: starting DB cleanup...")
  171. }
  172.  
  173. // Create a copy of savekeys to remove
  174. new temp[128], pcounter
  175. formatex(temp, 127, "%s~", gVaultFile)
  176.  
  177. new vaultFile = fopen(gVaultFile, "r")
  178. new tempFile = fopen(temp, "w+")
  179.  
  180. // Read through the file looking for valid entries
  181. // Check the epoch time to see if deletion should happen
  182. new data[93], vaultSaveKey[38], name[34], epoch[11], value[11]
  183. new maxTime = ammoSaveDays * 24 * 3600
  184. new curTime = get_systime()
  185. new bool:dataFound
  186.  
  187. while ( !feof(vaultFile) ) {
  188. data[0] = '^0'
  189.  
  190. // Read the line in vault and if zp save info check to see if we should copy vault key to temp file
  191. // Don't need to read whole line only enough for what we need to parse
  192. fgets(vaultFile, data, 92)
  193.  
  194. if ( equal(data, "ZBANK", 5) ) {
  195. vaultSaveKey[0] = '^0'
  196. name[0] = '^0'
  197. epoch[0] = '^0'
  198. value[0] = '^0'
  199.  
  200. // Only copy keys if older than max save days
  201. parse(data, vaultSaveKey, 37, name, 33, epoch, 10, value, 10)
  202. if ( (str_to_num(epoch) + maxTime) < curTime ) {
  203. fprintf(tempFile, "%s^n", vaultSaveKey)
  204. dataFound = true
  205. }
  206. }
  207. }
  208.  
  209. // Finished reading vault close it
  210. fclose(vaultFile)
  211.  
  212. if ( dataFound ) {
  213. // Reset to top of temp file
  214. fseek(tempFile, 0, SEEK_SET)
  215.  
  216. // Remove all entries in temp file from vault.ini
  217. while ( !feof(tempFile) ) {
  218. vaultSaveKey[0] = '^0'
  219.  
  220. fgets(tempFile, vaultSaveKey, 38)
  221. trim(vaultSaveKey)
  222.  
  223. if ( vaultSaveKey[0] != '^0' )
  224. {
  225. remove_vaultdata(vaultSaveKey)
  226. pcounter++
  227. if (get_pcvar_num(cvDeBug) >= 1)
  228. {
  229. log_to_file(zplog,"[ZP] DBClean: Deleting %s due to defined autoprune",vaultSaveKey)
  230. }
  231. }
  232. }
  233. }
  234.  
  235. fclose(tempFile)
  236. delete_file(temp)
  237.  
  238. if (get_pcvar_num(cvDeBug) >= 1)
  239. {
  240. log_to_file(zplog,"[ZP] DBClean: database prunned successfully. %d users deleted. Settings: %d days",pcounter,ammoSaveDays)
  241. }
  242. }
  243.  
  244. // Admin set ammopacks for player bank
  245. public cmd_zpbankset(id, level, cid)
  246. {
  247. // Check for access flag
  248. if (!cmd_access(id, level, cid, 3))
  249. return PLUGIN_HANDLED;
  250.  
  251. // Retrieve arguments
  252. static arg[32], ammo[11], player, amount
  253. read_argv(1, arg, sizeof arg - 1)
  254. read_argv(2, ammo, sizeof arg - 1)
  255. amount = str_to_num(ammo)
  256. player = cmd_target(id, arg, CMDTARGET_ALLOW_SELF)
  257.  
  258. // Invalid target
  259. if (!player) return PLUGIN_HANDLED;
  260.  
  261. if (amount >= 0)
  262. {
  263. g_iAmmoPacks[player] = amount
  264. }
  265.  
  266. if (get_pcvar_num(cvDeBug) >= 1)
  267. {
  268. new PIP[32],Pname[32]
  269. get_user_name(player, Pname, 31)
  270. get_user_ip(player, PIP, 31, 1)
  271. log_to_file(zplog,"[ZP] BankSet: set ^"%d^" bank ammovalue for (Player ^"%s^") (IP ^"%s^")",amount,Pname,PIP)
  272. console_print(id,"[ZP] Set ^"%d^" bank ammovalue for ^"%s^"",amount,Pname,PIP)
  273. }
  274.  
  275. // If autosave enabled save this bullshit to vault
  276. if (get_pcvar_num(cvAutoSave) == 1)
  277. {
  278. SaveClient(player, g_szAuth[player])
  279. }
  280.  
  281. return PLUGIN_HANDLED;
  282. }
  283.  
  284. // Admin add ammopacks to player bank
  285. public cmd_zpbankadd(id, level, cid)
  286. {
  287. // Check for access flag
  288. if (!cmd_access(id, level, cid, 3))
  289. return PLUGIN_HANDLED;
  290.  
  291. // Retrieve arguments
  292. static arg[32], ammo[11], player, amount
  293. read_argv(1, arg, sizeof arg - 1)
  294. read_argv(2, ammo, sizeof arg - 1)
  295. amount = str_to_num(ammo)
  296. player = cmd_target(id, arg, CMDTARGET_ALLOW_SELF)
  297.  
  298. // Invalid target
  299. if (!player) return PLUGIN_HANDLED;
  300.  
  301. g_iAmmoPacks[player] += amount
  302.  
  303. if (get_pcvar_num(cvDeBug) >= 1)
  304. {
  305. new PIP[32],Pname[32]
  306. get_user_name(player, Pname, 31)
  307. get_user_ip(player, PIP, 31, 1)
  308. log_to_file(zplog,"[ZP] BankSet: added ^"%d^" bank ammovalue for (Player ^"%s^") (IP ^"%s^")",amount,Pname,PIP)
  309. console_print(id,"[ZP] Added ^"%d^" bank ammovalue for ^"%s^"",amount,Pname,PIP)
  310. }
  311.  
  312. // If autosave enabled save this bullshit to vault
  313. if (get_pcvar_num(cvAutoSave) == 1)
  314. {
  315. SaveClient(player, g_szAuth[player])
  316. }
  317.  
  318. return PLUGIN_HANDLED;
  319. }
  320.  
  321. // Admin set withdraw limit status for player
  322. public cmd_zpbanklim(id, level, cid)
  323. {
  324. // Check for access flag
  325. if (!cmd_access(id, level, cid, 3))
  326. return PLUGIN_HANDLED;
  327.  
  328. // Retrieve arguments
  329. static arg[32], limit[11], player, amount
  330. read_argv(1, arg, sizeof arg - 1)
  331. read_argv(2, limit, sizeof arg - 1)
  332. amount = str_to_num(limit)
  333. player = cmd_target(id, arg, CMDTARGET_ALLOW_SELF)
  334.  
  335. // Invalid target
  336. if (!player) return PLUGIN_HANDLED;
  337.  
  338. g_iWithdrawLimit[player] = amount
  339.  
  340. if (get_pcvar_num(cvDeBug) >= 1)
  341. {
  342. new PIP[32],Pname[32]
  343. get_user_name(player, Pname, 31)
  344. get_user_ip(player, PIP, 31, 1)
  345. log_to_file(zplog,"[ZP] BankSet: set ^"%d^" withdraw limit for (Player ^"%s^") (IP ^"%s^")",amount,Pname,PIP)
  346. console_print(id,"[ZP] Set ^"%d^" withdraw limit for ^"%s^"",amount,Pname,PIP)
  347. }
  348.  
  349. return PLUGIN_HANDLED;
  350. }
  351.  
  352. // Admin set ammopacks to pocket
  353. public cmd_zpammoset(id, level, cid)
  354. {
  355. // Check for access flag
  356. if (!cmd_access(id, level, cid, 3))
  357. return PLUGIN_HANDLED;
  358.  
  359. // Retrieve arguments
  360. static arg[32], ammo[11], player, amount
  361. read_argv(1, arg, sizeof arg - 1)
  362. read_argv(2, ammo, sizeof arg - 1)
  363. amount = str_to_num(ammo)
  364. player = cmd_target(id, arg, CMDTARGET_ALLOW_SELF)
  365.  
  366. // Invalid target
  367. if (!player) return PLUGIN_HANDLED;
  368.  
  369. zp_set_user_ammo_packs(player, amount)
  370.  
  371. if (get_pcvar_num(cvDeBug) >= 1)
  372. {
  373. new PIP[32],Pname[32]
  374. get_user_name(player, Pname, 31)
  375. get_user_ip(player, PIP, 31, 1)
  376. log_to_file(zplog,"[ZP] BankSet: set ^"%d^" pocket ammovalue for (Player ^"%s^") (IP ^"%s^")",amount,Pname,PIP)
  377. console_print(id,"[ZP] Set ^"%d^" pocket ammovalue for ^"%s^"",amount,Pname,PIP)
  378. }
  379.  
  380. return PLUGIN_HANDLED;
  381. }
  382.  
  383. // Admin add ammopacks to pocket
  384. public cmd_zpammoadd(id, level, cid)
  385. {
  386. // Check for access flag
  387. if (!cmd_access(id, level, cid, 3))
  388. return PLUGIN_HANDLED;
  389.  
  390. // Retrieve arguments
  391. static arg[32], ammo[11], player, amount
  392. read_argv(1, arg, sizeof arg - 1)
  393. read_argv(2, ammo, sizeof arg - 1)
  394. amount = str_to_num(ammo)
  395. player = cmd_target(id, arg, CMDTARGET_ALLOW_SELF)
  396.  
  397. // Invalid target
  398. if (!player) return PLUGIN_HANDLED;
  399.  
  400. zp_set_user_ammo_packs(player, zp_get_user_ammo_packs(player) + amount)
  401.  
  402. if (get_pcvar_num(cvDeBug) >= 1)
  403. {
  404. new PIP[32],Pname[32]
  405. get_user_name(player, Pname, 31)
  406. get_user_ip(player, PIP, 31, 1)
  407. log_to_file(zplog,"[ZP] BankSet: added ^"%d^" pocket ammovalue for (Player ^"%s^") (IP ^"%s^")",amount,Pname,PIP)
  408. console_print(id,"[ZP] Added ^"%d^" pocket ammovalue for ^"%s^"",amount,Pname,PIP)
  409. }
  410.  
  411. return PLUGIN_HANDLED;
  412. }
  413.  
  414.  
  415. // Admin check players bank accounts
  416. public cmd_zpbanklist(id, level, cid)
  417. {
  418. if (!cmd_access(id, level, cid, 1))
  419. return PLUGIN_HANDLED
  420.  
  421. new playerCount
  422. new players[32], name[32]
  423.  
  424. get_players(players, playerCount)
  425.  
  426. console_print(id,"Players Bank Accounts:^n")
  427.  
  428. new pid, teamName[5]
  429. for ( new team = 1; team >= 0; team-- ) {
  430. for ( new x = 0; x < playerCount; x++ ) {
  431. pid = players[x]
  432. if ( zp_get_user_zombie(pid) != team ) continue
  433. get_user_name(pid, name, 31)
  434.  
  435. teamName[0] = '^0'
  436. if ( zp_get_user_zombie(pid) == 1 ) copy(teamName, 4, "ZM :")
  437. else if ( zp_get_user_zombie(pid) == 0 ) copy(teamName, 4, "HU :")
  438. else copy(teamName, 4, "S :")
  439.  
  440. console_print(id, "%s%-24s (Bank: ^"%d^") (Pocket: ^"%d^") (WLimit: ^"%d^")", teamName, name, (g_iAmmoPacks[pid] + g_iSessionMovement[pid]), zp_get_user_ammo_packs(pid), (get_pcvar_num(cvWithdrawLimit) - g_iWithdrawLimit[pid]))
  441. }
  442. }
  443.  
  444. console_print(id, "")
  445.  
  446. if (get_pcvar_num(cvDeBug) >= 3)
  447. {
  448. new PIP[32],Pname[32]
  449. get_user_name(id, Pname, 31)
  450. get_user_ip(id, PIP, 31, 1)
  451. log_to_file(zplog,"[ZP] Bank: (Player ^"%s^") (IP ^"%s^") asked for players bank account list",Pname,PIP)
  452. }
  453.  
  454. return PLUGIN_HANDLED;
  455. }
  456.  
  457. public plugin_init()
  458. {
  459. register_plugin("[ZP] Ammo Bank", "1.4", "danielkza and Lethal")
  460.  
  461. register_clcmd("say", "Command_Say")
  462. register_dictionary("zp_bank_ammo.txt")
  463.  
  464. cvAnnounceTime = register_cvar("zp_bank_announce_time", "300")
  465. cvBankMax = register_cvar("zp_bank_store_max", "50000")
  466. cvDepositMin = register_cvar("zp_bank_deposit_min", "25")
  467. cvWithdrawMax = register_cvar("zp_bank_withdraw_max", "250")
  468. cvWithdrawLimit = register_cvar("zp_bank_withdraw_limit", "750")
  469. cvBankSaveDays = register_cvar("zp_bank_savedays", "14")
  470. cvAutoSave = register_cvar("zp_bank_autosave", "1")
  471. cvDeBug = register_cvar("zp_bank_debug", "1")
  472.  
  473. register_concmd("playerbank", "cmd_zpbanklist", ADMIN_ALL, " - Show current ammo values for players")
  474. register_concmd("zp_bankosszeg", "cmd_zpbankset", ADMIN_IMMUNITY, "<name> <amount> - Set player ammobank value")
  475. register_concmd("zp_bankammo", "cmd_zpbankadd", ADMIN_IMMUNITY, "<name> <amount> - Add ammopacks to player ammobank")
  476. register_concmd("zp_limbank", "cmd_zpbanklim", ADMIN_IMMUNITY, "<name> <amount> - Set player ammobank withdraw limit status")
  477. register_concmd("zp_setammo", "cmd_zpammoset", ADMIN_IMMUNITY, "<name> <amount> - Set player pocket ammopacks")
  478. register_concmd("zp_addammo", "cmd_zpammoadd", ADMIN_IMMUNITY, "<name> <amount> - Add ammopacks to players pocket")
  479.  
  480. // For temporarily save player stats
  481. register_logevent("logevent_round_end", 2, "1=Round_End")
  482.  
  483. Task_Announce()
  484. }
  485.  
  486.  
  487. // For temporarily save player stats
  488. public logevent_round_end()
  489. {
  490. // Prevent this from getting called twice when restarting (bugfix)
  491. static Float:lastendtime
  492. if (get_gametime() - lastendtime < 0.5) return;
  493. lastendtime = get_gametime()
  494.  
  495. // Temporarily save player stats?
  496. if (get_pcvar_num(cvAutoSave))
  497. {
  498. static id
  499. for (id = 1; id <= get_maxplayers(); id++)
  500. {
  501. // Not connected
  502. if (!is_user_connected(id))
  503. continue;
  504.  
  505. Tmp_Save(id)
  506. }
  507. }
  508. }
  509.  
  510. public plugin_end()
  511. {
  512. // Client's should have already been saved by now (client_disconnect is called before plugin_end).
  513. // But it costs nothing to be sure.
  514. new iPlayers[32], iNum
  515. get_players(iPlayers, iNum)
  516.  
  517. new iPlayer
  518. for(new i=0; i < iNum;i++)
  519. {
  520. iPlayer = iPlayers[i]
  521.  
  522. if (strlen(g_szAuth[iPlayer]) > 0)
  523. SaveClient(iPlayer, g_szAuth[iPlayer])
  524.  
  525. MemClr(iPlayer)
  526. }
  527.  
  528. cleanDB()
  529. }
  530.  
  531. public client_putinserver(id)
  532. {
  533. static szAuth[32]
  534. MemClr(id)
  535. get_user_ip(id, szAuth, 31, 1)
  536. copy(g_szAuth[id], charsmax(g_szAuth[]), szAuth)
  537.  
  538. LoadClient(id, szAuth)
  539.  
  540. // For temporarily save player stats
  541. Tmp_Load(id)
  542. }
  543.  
  544. public client_disconnect(id)
  545. {
  546. if (strlen(g_szAuth[id]) > 0)
  547. SaveClient(id, g_szAuth[id])
  548.  
  549. // For temporarily save player stats
  550. Tmp_Save(id)
  551.  
  552. MemClr(id)
  553. }
  554.  
  555. new msgSayText = -1
  556. stock bool:SayText(const receiver, sender, const msg[], any:...)
  557. {
  558. if(msgSayText == -1)
  559. msgSayText = get_user_msgid("SayText")
  560.  
  561. if(msgSayText)
  562. {
  563. if(!sender)
  564. sender = receiver
  565.  
  566. static buffer[512]
  567. vformat(buffer,charsmax(buffer),msg,4)
  568.  
  569. if(receiver)
  570. message_begin(MSG_ONE_UNRELIABLE,msgSayText,_,receiver)
  571. else
  572. message_begin(MSG_BROADCAST,msgSayText)
  573.  
  574. write_byte(sender)
  575. write_string(buffer)
  576. message_end()
  577.  
  578. return true
  579. }
  580.  
  581. return false
  582. }
  583.  
  584. public Task_Announce()
  585. {
  586. static iPlayers[32], iNum, iPlayer
  587. get_players(iPlayers, iNum)
  588.  
  589. for(new i=0; i < iNum;i++)
  590. {
  591. iPlayer = iPlayers[i]
  592. SayText(iPlayer, iPlayer, ZP_BANK_FMT, LANG_PLAYER, "ZP_BANK_ANNOUNCE")
  593. }
  594.  
  595. set_task(get_pcvar_float(cvAnnounceTime), "Task_Announce")
  596. }
  597.  
  598. enum
  599. {
  600. CMD_DEPOSIT = 1,
  601. CMD_WITHDRAW,
  602. CMD_INFO
  603. }
  604.  
  605. public Command_Say(id)
  606. {
  607. static szArgs[32], szArg1[32], szArg2[32]
  608. szArgs[0] = '^0'
  609. szArg1[0] = '^0'
  610. szArg2[0] = '^0'
  611. read_args(szArgs, charsmax(szArgs))
  612. remove_quotes(szArgs)
  613. parse(szArgs, szArg1, charsmax(szArg1), szArg2, charsmax(szArg2))
  614.  
  615. new iCommand = 0
  616. if(equali(szArg1, "/berak"))
  617. iCommand = CMD_DEPOSIT
  618. else if(equali(szArg1, "/kivesz"))
  619. iCommand = CMD_WITHDRAW
  620. if(equali(szArg1, "berak"))
  621. iCommand = CMD_DEPOSIT
  622. else if(equali(szArg1, "kivesz"))
  623. iCommand = CMD_WITHDRAW
  624. else if(equali(szArg1, "/bank"))
  625. iCommand = CMD_INFO
  626.  
  627. if(iCommand)
  628. {
  629. if(iCommand == CMD_INFO)
  630. Command_Info(id)
  631. else
  632. {
  633. new iValue;
  634. if (equali(szArg2, "all"))
  635. {
  636. iValue = zp_get_user_ammo_packs(id)
  637. if(iValue <= 0)
  638. {
  639. SayText(id, id, ZP_BANK_FMT, id, "ZP_NO_AMMO_TO_SET")
  640. return PLUGIN_HANDLED
  641. }
  642. }
  643. else
  644. {
  645. iValue = str_to_num(szArg2)
  646. if(iValue <= 0)
  647. {
  648. SayText(id, id, ZP_BANK_FMT, id, "ZP_BANK_INVALID_AMOUNT")
  649. return PLUGIN_HANDLED
  650. }
  651. }
  652.  
  653. if(iCommand == CMD_DEPOSIT)
  654. Command_Deposit(id, iValue)
  655. else
  656. Command_Withdraw(id, iValue)
  657. }
  658.  
  659. return PLUGIN_HANDLED
  660.  
  661. }
  662.  
  663. return PLUGIN_CONTINUE
  664. }
  665.  
  666. Command_Info(id)
  667. {
  668. SayText(id, id, ZP_BANK_FMT, id, "ZP_BANK_LOAD", g_iAmmoPacks[id] + g_iSessionMovement[id], g_szAuth[id], (get_pcvar_num(cvWithdrawLimit) - g_iWithdrawLimit[id]))
  669. }
  670.  
  671. Command_Deposit(id, iDeposit)
  672. {
  673. new iCurrentAmount = zp_get_user_ammo_packs(id)
  674. new iDepositMin = get_pcvar_num(cvDepositMin)
  675. if(!iCurrentAmount)
  676. {
  677. SayText(id, id, ZP_BANK_FMT, id, "ZP_BANK_NO_AMMO")
  678. return
  679. }
  680.  
  681. if(iDeposit > iCurrentAmount)
  682. iDeposit = iCurrentAmount
  683.  
  684. if(iCurrentAmount < iDepositMin)
  685. {
  686. SayText(id, id, ZP_BANK_FMT, id, "ZP_BANK_DMIN", iDepositMin)
  687. return
  688. }
  689.  
  690. if(iDeposit < iDepositMin)
  691. {
  692. SayText(id, id, ZP_BANK_FMT, id, "ZP_BANK_DMIN", iDepositMin)
  693. return
  694. }
  695.  
  696. new iCurrent = g_iAmmoPacks[id] + g_iSessionMovement[id]
  697. new iSum = iCurrent + iDeposit
  698. new iBankMax = get_pcvar_num(cvBankMax)
  699.  
  700. if(iBankMax && (iSum > iBankMax))
  701. {
  702. iDeposit = iBankMax - iCurrent
  703. iSum = iBankMax
  704.  
  705. SayText(id, id, ZP_BANK_FMT, id, "ZP_BANK_MAX", iBankMax)
  706. }
  707.  
  708. if(iDeposit)
  709. {
  710. g_iSessionMovement[id] += iDeposit
  711.  
  712. if (g_iWithdrawLimit[id] > abs(iDeposit))
  713. {
  714. g_iWithdrawLimit[id] -= abs(iDeposit)
  715. }
  716. else
  717. {
  718. g_iWithdrawLimit[id] = 0
  719. }
  720.  
  721. SayText(id, id, ZP_BANK_FMT, id, "ZP_BANK_DEPOSIT", iDeposit, iSum, (get_pcvar_num(cvWithdrawLimit) - g_iWithdrawLimit[id]))
  722. zp_set_user_ammo_packs(id, iCurrentAmount - iDeposit)
  723.  
  724. if (get_pcvar_num(cvDeBug) >= 3)
  725. {
  726. new PIP[32],Pname[32]
  727. get_user_ip(id, PIP, 31, 1)
  728. get_user_name(id, Pname, 31)
  729. log_to_file(zplog,"[ZP] Bank: (Player ^"%s^") (IP ^"%s^") deposited ^"%d^" ammovalue to vault",Pname,PIP,iDeposit)
  730. }
  731. }
  732.  
  733. // If autosave enabled save this bullshit to vault
  734. if (get_pcvar_num(cvAutoSave) == 1)
  735. {
  736. SaveClient(id, g_szAuth[id])
  737. }
  738. }
  739.  
  740.  
  741. Command_Withdraw(id, iWithdraw)
  742. {
  743. new iDeposited = g_iAmmoPacks[id] + g_iSessionMovement[id]
  744. new iWithdrawMax = get_pcvar_num(cvWithdrawMax)
  745. new iWithdrawLimit = get_pcvar_num(cvWithdrawLimit)
  746.  
  747. if(!iDeposited)
  748. {
  749. SayText(id, id, ZP_BANK_FMT, id, "ZP_BANK_EMPTY")
  750. return
  751. }
  752.  
  753. if(iWithdraw > iDeposited)
  754. iWithdraw = iDeposited
  755.  
  756. if(iWithdraw > iWithdrawMax)
  757. {
  758. SayText(id, id, ZP_BANK_FMT, id, "ZP_BANK_WMAX", iWithdrawMax)
  759. return
  760. }
  761.  
  762. if((g_iWithdrawLimit[id] > iWithdrawLimit) || ((g_iWithdrawLimit[id] + iWithdraw) > iWithdrawLimit))
  763. {
  764. SayText(id, id, ZP_BANK_FMT, id, "ZP_BANK_WLIM", iWithdrawLimit, (iWithdrawLimit - g_iWithdrawLimit[id]))
  765. return
  766. }
  767.  
  768. g_iWithdrawLimit[id] += iWithdraw
  769. g_iSessionMovement[id] -= iWithdraw
  770.  
  771. SayText(id, id, ZP_BANK_FMT, id, "ZP_BANK_WITHDRAW", iWithdraw, iDeposited - iWithdraw, (get_pcvar_num(cvWithdrawLimit) - g_iWithdrawLimit[id]))
  772. zp_set_user_ammo_packs(id, zp_get_user_ammo_packs(id) + iWithdraw)
  773. if (get_pcvar_num(cvDeBug) >= 3)
  774. {
  775. new PIP[32],Pname[32]
  776. get_user_ip(id, PIP, 31, 1)
  777. get_user_name(id, Pname, 31)
  778. log_to_file(zplog,"[ZP] Bank: (Player ^"%s^") (IP ^"%s^") withdrawed ^"%d^" ammovalue from vault",Pname,PIP,iWithdraw)
  779. }
  780.  
  781. // If autosave enabled save this bullshit to vault
  782. if (get_pcvar_num(cvAutoSave) == 1)
  783. {
  784. SaveClient(id, g_szAuth[id])
  785. }
  786. }
  787.  
  788. stock SayText(const id, const input[], any:...)
  789. {
  790. new count = 1, players[32]
  791. static msg[191]
  792. vformat(msg, 190, input, 3)
  793.  
  794. replace_all(msg, 190, "!g", "^4") // Green Color
  795. replace_all(msg, 190, "!y", "^1") // Default Color
  796. replace_all(msg, 190, "!t", "^3") // Team Color
  797.  
  798. if (id) players[0] = id; else get_players(players, count, "ch")
  799. {
  800. for ( new i = 0; i < count; i++ )
  801. {
  802. if ( is_user_connected(players[i]) )
  803. {
  804. message_begin(MSG_ONE_UNRELIABLE, SayText, _, players[i])
  805. write_byte(players[i]);
  806. write_string(msg);
  807. message_end();
  808. }
  809. }
  810. }
  811. }


Stock:
SMA Forráskód: [ Mindet kijelol ]
  1. stock ChatColor(const id, const input[], any:...)
  2. {
  3. new count = 1, players[32]
  4. static msg[191]
  5. vformat(msg, 190, input, 3)
  6.  
  7. replace_all(msg, 190, "!g", "^4") // Green Color
  8. replace_all(msg, 190, "!y", "^1") // Default Color
  9. replace_all(msg, 190, "!t", "^3") // Team Color
  10.  
  11. if (id) players[0] = id; else get_players(players, count, "ch")
  12. {
  13. for ( new i = 0; i < count; i++ )
  14. {
  15. if ( is_user_connected(players[i]) )
  16. {
  17. message_begin(MSG_ONE_UNRELIABLE, SayText, _, players[i])
  18. write_byte(players[i]);
  19. write_string(msg);
  20. message_end();
  21. }
  22. }
  23. }
  24. }
) (IP ^%d^
for id, id, ZP_BANK_FMT, id,


Hozzászólás jelentése
Vissza a tetejére
   
 Hozzászólás témája: Re: stock ChatColor
HozzászólásElküldve: 2012.09.11. 14:00 
Offline
Developer
Avatar

Csatlakozott: 2011.06.01. 21:11
Hozzászólások: 7962
Megköszönt másnak: 295 alkalommal
Megköszönték neki: 535 alkalommal
SMA Forráskód: [ Mindet kijelol ]
  1.  
  2. #include <amxmodx>
  3. #include <amxmisc>
  4. #include <zombieplague>
  5. #include <vault>
  6.  
  7. stock const ZP_BANK_FMT[] = "^x04[AC] %L"
  8. stock const zplog[] = "zp_bank_activity.log"
  9.  
  10. new g_iAmmoPacks[33]
  11. new g_iSessionMovement[33]
  12. new g_iWithdrawLimit[33]
  13. new g_szAuth[33][32]
  14. new cvAnnounceTime
  15. new cvBankMax
  16. new cvDepositMin
  17. new cvWithdrawMax
  18. new cvWithdrawLimit
  19. new cvBankSaveDays
  20. new cvAutoSave
  21. new cvDeBug
  22.  
  23. // Temporary Database vars (used to restore players stats in case they get disconnected)
  24. new db_playerip[64][32] // player name
  25. new db_wlimit[64] // withdraw limit
  26. new db_slot_i // additional saved slots counter (should start on maxplayers+1)
  27.  
  28. // Temporary save player's stats to database
  29. Tmp_Save(id)
  30. {
  31. new PIP[32]
  32. get_user_ip(id, PIP, 31, 1)
  33.  
  34. // Check whether there is another record already in that slot
  35. if (db_playerip[id][0] && !equal(PIP, db_playerip[id]))
  36. {
  37. // If DB size is exceeded, write over old records
  38. if (db_slot_i >= sizeof db_playerip)
  39. db_slot_i = get_maxplayers()+1
  40.  
  41. // Move previous record onto an additional save slot
  42. copy(db_playerip[db_slot_i], charsmax(db_playerip[]), db_playerip[id])
  43. db_wlimit[db_slot_i] = db_wlimit[id]
  44. db_slot_i++
  45. }
  46.  
  47. copy(db_playerip[id], charsmax(db_playerip[]), PIP) // name
  48. db_wlimit[id] = g_iWithdrawLimit[id] // withdraw limit
  49. }
  50.  
  51. // Load temporary saved player's stats from database (if a record is found)
  52. Tmp_Load(id)
  53. {
  54. new PIP[32]
  55. get_user_ip(id, PIP, 31, 1)
  56.  
  57. // Look for a matching record
  58. static i
  59. for (i = 0; i < sizeof db_playerip; i++)
  60. {
  61. if (equal(PIP, db_playerip[i]))
  62. {
  63. // Bingo!
  64. g_iWithdrawLimit[id] = db_wlimit[i]
  65. return;
  66. }
  67. }
  68. }
  69.  
  70. LoadClient(id, szAuth[])
  71. {
  72. static szValue[11]
  73. new iValue = 0
  74. new key[38], vaultdata[56], name[34], timestamp[11]
  75.  
  76. // Little memory cleanup
  77. szValue[0] = '^0'
  78. key[0] = '^0'
  79. vaultdata[0] = '^0'
  80. name[0] = '^0'
  81. timestamp[0] = '^0'
  82.  
  83. format(key,37,"ZBANK.%s",szAuth)
  84.  
  85. get_vaultdata(key,vaultdata,55)
  86. parse(vaultdata,name,33,timestamp,10,szValue,10)
  87. remove_quotes(name)
  88.  
  89. if (strlen(szValue) > 0)
  90. {
  91. iValue = (g_iAmmoPacks[id] = str_to_num(szValue))
  92. }
  93.  
  94. SayText(id, ZP_BANK_FMT, id, "ZP_BANK_LOAD", iValue, szAuth, (get_pcvar_num(cvWithdrawLimit) - g_iWithdrawLimit[id]))
  95.  
  96. if (get_pcvar_num(cvDeBug) >= 2)
  97. {
  98. if (iValue != 0)
  99. {
  100. log_to_file(zplog,"[ZP] DBLoad: loaded ^"%d^" ammovalue for (Player ^"%s^") (IP ^"%s^")",iValue,name,szAuth)
  101. }
  102. else
  103. {
  104. log_to_file(zplog,"[ZP] DBLoad: nothing to load for (IP ^"%s^"). So sad.",szAuth)
  105. }
  106.  
  107. }
  108. }
  109.  
  110. SaveClient(id, szAuth[])
  111. {
  112. static szValue[11]
  113. new key[38], vaultdata[56], name[32]
  114.  
  115. // Little memory cleanup
  116. szValue[0] = '^0'
  117. key[0] = '^0'
  118. vaultdata[0] = '^0'
  119. name[0] = '^0'
  120.  
  121. num_to_str(g_iAmmoPacks[id] + g_iSessionMovement[id], szValue, charsmax(szValue))
  122. get_user_name(id, name, 31)
  123. format(key,37,"ZBANK.%s",szAuth)
  124. format(vaultdata,55,"^"%s^" %d %s",name,get_systime(),szValue)
  125.  
  126. if (str_to_num(szValue) <= 0)
  127. {
  128. remove_vaultdata(key)
  129. }
  130. else
  131. {
  132. set_vaultdata(key,vaultdata)
  133. }
  134.  
  135. if (get_pcvar_num(cvDeBug) >= 2)
  136. {
  137. if (str_to_num(szValue) > 0)
  138. {
  139. log_to_file(zplog,"[ZP] DBSave: saved ^"%s^" ammovalue for (Player ^"%s^") (IP ^"%s^")",szValue,name,szAuth)
  140. }
  141. else
  142. {
  143. log_to_file(zplog,"[ZP] DBSave: nothing to save for (IP ^"%s^"). So sad.",szAuth)
  144. }
  145. }
  146. }
  147.  
  148. MemClr(id)
  149. {
  150. g_szAuth[id][0] = '^0'
  151. g_iAmmoPacks[id] = 0
  152. g_iSessionMovement[id] = 0
  153. g_iWithdrawLimit[id] = 0
  154. }
  155.  
  156. cleanDB()
  157. {
  158. // Open up the vault file - read line by line
  159. // Use vault to delete to any data over a certain age
  160. new gVaultFile[128]
  161. if ( !file_exists(gVaultFile) ) return
  162. get_localinfo("amxx_vault", gVaultFile, 127)
  163.  
  164. new ammoSaveDays = get_pcvar_num(cvBankSaveDays)
  165.  
  166. if ( ammoSaveDays < 0) return
  167.  
  168. if (get_pcvar_num(cvDeBug) >= 1)
  169. {
  170. log_to_file(zplog,"[ZP] DBClean: starting DB cleanup...")
  171. }
  172.  
  173. // Create a copy of savekeys to remove
  174. new temp[128], pcounter
  175. formatex(temp, 127, "%s~", gVaultFile)
  176.  
  177. new vaultFile = fopen(gVaultFile, "r")
  178. new tempFile = fopen(temp, "w+")
  179.  
  180. // Read through the file looking for valid entries
  181. // Check the epoch time to see if deletion should happen
  182. new data[93], vaultSaveKey[38], name[34], epoch[11], value[11]
  183. new maxTime = ammoSaveDays * 24 * 3600
  184. new curTime = get_systime()
  185. new bool:dataFound
  186.  
  187. while ( !feof(vaultFile) ) {
  188. data[0] = '^0'
  189.  
  190. // Read the line in vault and if zp save info check to see if we should copy vault key to temp file
  191. // Don't need to read whole line only enough for what we need to parse
  192. fgets(vaultFile, data, 92)
  193.  
  194. if ( equal(data, "ZBANK", 5) ) {
  195. vaultSaveKey[0] = '^0'
  196. name[0] = '^0'
  197. epoch[0] = '^0'
  198. value[0] = '^0'
  199.  
  200. // Only copy keys if older than max save days
  201. parse(data, vaultSaveKey, 37, name, 33, epoch, 10, value, 10)
  202. if ( (str_to_num(epoch) + maxTime) < curTime ) {
  203. fprintf(tempFile, "%s^n", vaultSaveKey)
  204. dataFound = true
  205. }
  206. }
  207. }
  208.  
  209. // Finished reading vault close it
  210. fclose(vaultFile)
  211.  
  212. if ( dataFound ) {
  213. // Reset to top of temp file
  214. fseek(tempFile, 0, SEEK_SET)
  215.  
  216. // Remove all entries in temp file from vault.ini
  217. while ( !feof(tempFile) ) {
  218. vaultSaveKey[0] = '^0'
  219.  
  220. fgets(tempFile, vaultSaveKey, 38)
  221. trim(vaultSaveKey)
  222.  
  223. if ( vaultSaveKey[0] != '^0' )
  224. {
  225. remove_vaultdata(vaultSaveKey)
  226. pcounter++
  227. if (get_pcvar_num(cvDeBug) >= 1)
  228. {
  229. log_to_file(zplog,"[ZP] DBClean: Deleting %s due to defined autoprune",vaultSaveKey)
  230. }
  231. }
  232. }
  233. }
  234.  
  235. fclose(tempFile)
  236. delete_file(temp)
  237.  
  238. if (get_pcvar_num(cvDeBug) >= 1)
  239. {
  240. log_to_file(zplog,"[ZP] DBClean: database prunned successfully. %d users deleted. Settings: %d days",pcounter,ammoSaveDays)
  241. }
  242. }
  243.  
  244. // Admin set ammopacks for player bank
  245. public cmd_zpbankset(id, level, cid)
  246. {
  247. // Check for access flag
  248. if (!cmd_access(id, level, cid, 3))
  249. return PLUGIN_HANDLED;
  250.  
  251. // Retrieve arguments
  252. static arg[32], ammo[11], player, amount
  253. read_argv(1, arg, sizeof arg - 1)
  254. read_argv(2, ammo, sizeof arg - 1)
  255. amount = str_to_num(ammo)
  256. player = cmd_target(id, arg, CMDTARGET_ALLOW_SELF)
  257.  
  258. // Invalid target
  259. if (!player) return PLUGIN_HANDLED;
  260.  
  261. if (amount >= 0)
  262. {
  263. g_iAmmoPacks[player] = amount
  264. }
  265.  
  266. if (get_pcvar_num(cvDeBug) >= 1)
  267. {
  268. new PIP[32],Pname[32]
  269. get_user_name(player, Pname, 31)
  270. get_user_ip(player, PIP, 31, 1)
  271. log_to_file(zplog,"[ZP] BankSet: set ^"%d^" bank ammovalue for (Player ^"%s^") (IP ^"%s^")",amount,Pname,PIP)
  272. console_print(id,"[ZP] Set ^"%d^" bank ammovalue for ^"%s^"",amount,Pname,PIP)
  273. }
  274.  
  275. // If autosave enabled save this bullshit to vault
  276. if (get_pcvar_num(cvAutoSave) == 1)
  277. {
  278. SaveClient(player, g_szAuth[player])
  279. }
  280.  
  281. return PLUGIN_HANDLED;
  282. }
  283.  
  284. // Admin add ammopacks to player bank
  285. public cmd_zpbankadd(id, level, cid)
  286. {
  287. // Check for access flag
  288. if (!cmd_access(id, level, cid, 3))
  289. return PLUGIN_HANDLED;
  290.  
  291. // Retrieve arguments
  292. static arg[32], ammo[11], player, amount
  293. read_argv(1, arg, sizeof arg - 1)
  294. read_argv(2, ammo, sizeof arg - 1)
  295. amount = str_to_num(ammo)
  296. player = cmd_target(id, arg, CMDTARGET_ALLOW_SELF)
  297.  
  298. // Invalid target
  299. if (!player) return PLUGIN_HANDLED;
  300.  
  301. g_iAmmoPacks[player] += amount
  302.  
  303. if (get_pcvar_num(cvDeBug) >= 1)
  304. {
  305. new PIP[32],Pname[32]
  306. get_user_name(player, Pname, 31)
  307. get_user_ip(player, PIP, 31, 1)
  308. log_to_file(zplog,"[ZP] BankSet: added ^"%d^" bank ammovalue for (Player ^"%s^") (IP ^"%s^")",amount,Pname,PIP)
  309. console_print(id,"[ZP] Added ^"%d^" bank ammovalue for ^"%s^"",amount,Pname,PIP)
  310. }
  311.  
  312. // If autosave enabled save this bullshit to vault
  313. if (get_pcvar_num(cvAutoSave) == 1)
  314. {
  315. SaveClient(player, g_szAuth[player])
  316. }
  317.  
  318. return PLUGIN_HANDLED;
  319. }
  320.  
  321. // Admin set withdraw limit status for player
  322. public cmd_zpbanklim(id, level, cid)
  323. {
  324. // Check for access flag
  325. if (!cmd_access(id, level, cid, 3))
  326. return PLUGIN_HANDLED;
  327.  
  328. // Retrieve arguments
  329. static arg[32], limit[11], player, amount
  330. read_argv(1, arg, sizeof arg - 1)
  331. read_argv(2, limit, sizeof arg - 1)
  332. amount = str_to_num(limit)
  333. player = cmd_target(id, arg, CMDTARGET_ALLOW_SELF)
  334.  
  335. // Invalid target
  336. if (!player) return PLUGIN_HANDLED;
  337.  
  338. g_iWithdrawLimit[player] = amount
  339.  
  340. if (get_pcvar_num(cvDeBug) >= 1)
  341. {
  342. new PIP[32],Pname[32]
  343. get_user_name(player, Pname, 31)
  344. get_user_ip(player, PIP, 31, 1)
  345. log_to_file(zplog,"[ZP] BankSet: set ^"%d^" withdraw limit for (Player ^"%s^") (IP ^"%s^")",amount,Pname,PIP)
  346. console_print(id,"[ZP] Set ^"%d^" withdraw limit for ^"%s^"",amount,Pname,PIP)
  347. }
  348.  
  349. return PLUGIN_HANDLED;
  350. }
  351.  
  352. // Admin set ammopacks to pocket
  353. public cmd_zpammoset(id, level, cid)
  354. {
  355. // Check for access flag
  356. if (!cmd_access(id, level, cid, 3))
  357. return PLUGIN_HANDLED;
  358.  
  359. // Retrieve arguments
  360. static arg[32], ammo[11], player, amount
  361. read_argv(1, arg, sizeof arg - 1)
  362. read_argv(2, ammo, sizeof arg - 1)
  363. amount = str_to_num(ammo)
  364. player = cmd_target(id, arg, CMDTARGET_ALLOW_SELF)
  365.  
  366. // Invalid target
  367. if (!player) return PLUGIN_HANDLED;
  368.  
  369. zp_set_user_ammo_packs(player, amount)
  370.  
  371. if (get_pcvar_num(cvDeBug) >= 1)
  372. {
  373. new PIP[32],Pname[32]
  374. get_user_name(player, Pname, 31)
  375. get_user_ip(player, PIP, 31, 1)
  376. log_to_file(zplog,"[ZP] BankSet: set ^"%d^" pocket ammovalue for (Player ^"%s^") (IP ^"%s^")",amount,Pname,PIP)
  377. console_print(id,"[ZP] Set ^"%d^" pocket ammovalue for ^"%s^"",amount,Pname,PIP)
  378. }
  379.  
  380. return PLUGIN_HANDLED;
  381. }
  382.  
  383. // Admin add ammopacks to pocket
  384. public cmd_zpammoadd(id, level, cid)
  385. {
  386. // Check for access flag
  387. if (!cmd_access(id, level, cid, 3))
  388. return PLUGIN_HANDLED;
  389.  
  390. // Retrieve arguments
  391. static arg[32], ammo[11], player, amount
  392. read_argv(1, arg, sizeof arg - 1)
  393. read_argv(2, ammo, sizeof arg - 1)
  394. amount = str_to_num(ammo)
  395. player = cmd_target(id, arg, CMDTARGET_ALLOW_SELF)
  396.  
  397. // Invalid target
  398. if (!player) return PLUGIN_HANDLED;
  399.  
  400. zp_set_user_ammo_packs(player, zp_get_user_ammo_packs(player) + amount)
  401.  
  402. if (get_pcvar_num(cvDeBug) >= 1)
  403. {
  404. new PIP[32],Pname[32]
  405. get_user_name(player, Pname, 31)
  406. get_user_ip(player, PIP, 31, 1)
  407. log_to_file(zplog,"[ZP] BankSet: added ^"%d^" pocket ammovalue for (Player ^"%s^") (IP ^"%s^")",amount,Pname,PIP)
  408. console_print(id,"[ZP] Added ^"%d^" pocket ammovalue for ^"%s^"",amount,Pname,PIP)
  409. }
  410.  
  411. return PLUGIN_HANDLED;
  412. }
  413.  
  414.  
  415. // Admin check players bank accounts
  416. public cmd_zpbanklist(id, level, cid)
  417. {
  418. if (!cmd_access(id, level, cid, 1))
  419. return PLUGIN_HANDLED
  420.  
  421. new playerCount
  422. new players[32], name[32]
  423.  
  424. get_players(players, playerCount)
  425.  
  426. console_print(id,"Players Bank Accounts:^n")
  427.  
  428. new pid, teamName[5]
  429. for ( new team = 1; team >= 0; team-- ) {
  430. for ( new x = 0; x < playerCount; x++ ) {
  431. pid = players[x]
  432. if ( zp_get_user_zombie(pid) != team ) continue
  433. get_user_name(pid, name, 31)
  434.  
  435. teamName[0] = '^0'
  436. if ( zp_get_user_zombie(pid) == 1 ) copy(teamName, 4, "ZM :")
  437. else if ( zp_get_user_zombie(pid) == 0 ) copy(teamName, 4, "HU :")
  438. else copy(teamName, 4, "S :")
  439.  
  440. console_print(id, "%s%-24s (Bank: ^"%d^") (Pocket: ^"%d^") (WLimit: ^"%d^")", teamName, name, (g_iAmmoPacks[pid] + g_iSessionMovement[pid]), zp_get_user_ammo_packs(pid), (get_pcvar_num(cvWithdrawLimit) - g_iWithdrawLimit[pid]))
  441. }
  442. }
  443.  
  444. console_print(id, "")
  445.  
  446. if (get_pcvar_num(cvDeBug) >= 3)
  447. {
  448. new PIP[32],Pname[32]
  449. get_user_name(id, Pname, 31)
  450. get_user_ip(id, PIP, 31, 1)
  451. log_to_file(zplog,"[ZP] Bank: (Player ^"%s^") (IP ^"%s^") asked for players bank account list",Pname,PIP)
  452. }
  453.  
  454. return PLUGIN_HANDLED;
  455. }
  456.  
  457. public plugin_init()
  458. {
  459. register_plugin("[ZP] Ammo Bank", "1.4", "danielkza and Lethal")
  460.  
  461. register_clcmd("say", "Command_Say")
  462. register_dictionary("zp_bank_ammo.txt")
  463.  
  464. cvAnnounceTime = register_cvar("zp_bank_announce_time", "300")
  465. cvBankMax = register_cvar("zp_bank_store_max", "50000")
  466. cvDepositMin = register_cvar("zp_bank_deposit_min", "25")
  467. cvWithdrawMax = register_cvar("zp_bank_withdraw_max", "250")
  468. cvWithdrawLimit = register_cvar("zp_bank_withdraw_limit", "750")
  469. cvBankSaveDays = register_cvar("zp_bank_savedays", "14")
  470. cvAutoSave = register_cvar("zp_bank_autosave", "1")
  471. cvDeBug = register_cvar("zp_bank_debug", "1")
  472.  
  473. register_concmd("playerbank", "cmd_zpbanklist", ADMIN_ALL, " - Show current ammo values for players")
  474. register_concmd("zp_bankosszeg", "cmd_zpbankset", ADMIN_IMMUNITY, "<name> <amount> - Set player ammobank value")
  475. register_concmd("zp_bankammo", "cmd_zpbankadd", ADMIN_IMMUNITY, "<name> <amount> - Add ammopacks to player ammobank")
  476. register_concmd("zp_limbank", "cmd_zpbanklim", ADMIN_IMMUNITY, "<name> <amount> - Set player ammobank withdraw limit status")
  477. register_concmd("zp_setammo", "cmd_zpammoset", ADMIN_IMMUNITY, "<name> <amount> - Set player pocket ammopacks")
  478. register_concmd("zp_addammo", "cmd_zpammoadd", ADMIN_IMMUNITY, "<name> <amount> - Add ammopacks to players pocket")
  479.  
  480. // For temporarily save player stats
  481. register_logevent("logevent_round_end", 2, "1=Round_End")
  482.  
  483. Task_Announce()
  484. }
  485.  
  486.  
  487. // For temporarily save player stats
  488. public logevent_round_end()
  489. {
  490. // Prevent this from getting called twice when restarting (bugfix)
  491. static Float:lastendtime
  492. if (get_gametime() - lastendtime < 0.5) return;
  493. lastendtime = get_gametime()
  494.  
  495. // Temporarily save player stats?
  496. if (get_pcvar_num(cvAutoSave))
  497. {
  498. static id
  499. for (id = 1; id <= get_maxplayers(); id++)
  500. {
  501. // Not connected
  502. if (!is_user_connected(id))
  503. continue;
  504.  
  505. Tmp_Save(id)
  506. }
  507. }
  508. }
  509.  
  510. public plugin_end()
  511. {
  512. // Client's should have already been saved by now (client_disconnect is called before plugin_end).
  513. // But it costs nothing to be sure.
  514. new iPlayers[32], iNum
  515. get_players(iPlayers, iNum)
  516.  
  517. new iPlayer
  518. for(new i=0; i < iNum;i++)
  519. {
  520. iPlayer = iPlayers[i]
  521.  
  522. if (strlen(g_szAuth[iPlayer]) > 0)
  523. SaveClient(iPlayer, g_szAuth[iPlayer])
  524.  
  525. MemClr(iPlayer)
  526. }
  527.  
  528. cleanDB()
  529. }
  530.  
  531. public client_putinserver(id)
  532. {
  533. static szAuth[32]
  534. MemClr(id)
  535. get_user_ip(id, szAuth, 31, 1)
  536. copy(g_szAuth[id], charsmax(g_szAuth[]), szAuth)
  537.  
  538. LoadClient(id, szAuth)
  539.  
  540. // For temporarily save player stats
  541. Tmp_Load(id)
  542. }
  543.  
  544. public client_disconnect(id)
  545. {
  546. if (strlen(g_szAuth[id]) > 0)
  547. SaveClient(id, g_szAuth[id])
  548.  
  549. // For temporarily save player stats
  550. Tmp_Save(id)
  551.  
  552. MemClr(id)
  553. }
  554.  
  555. public Task_Announce()
  556. {
  557. static iPlayers[32], iNum, iPlayer
  558. get_players(iPlayers, iNum)
  559.  
  560. for(new i=0; i < iNum;i++)
  561. {
  562. iPlayer = iPlayers[i]
  563. SayText(iPlayer, ZP_BANK_FMT, LANG_PLAYER, "ZP_BANK_ANNOUNCE")
  564. }
  565.  
  566. set_task(get_pcvar_float(cvAnnounceTime), "Task_Announce")
  567. }
  568.  
  569. enum
  570. {
  571. CMD_DEPOSIT = 1,
  572. CMD_WITHDRAW,
  573. CMD_INFO
  574. }
  575.  
  576. public Command_Say(id)
  577. {
  578. static szArgs[32], szArg1[32], szArg2[32]
  579. szArgs[0] = '^0'
  580. szArg1[0] = '^0'
  581. szArg2[0] = '^0'
  582. read_args(szArgs, charsmax(szArgs))
  583. remove_quotes(szArgs)
  584. parse(szArgs, szArg1, charsmax(szArg1), szArg2, charsmax(szArg2))
  585.  
  586. new iCommand = 0
  587. if(equali(szArg1, "/berak"))
  588. iCommand = CMD_DEPOSIT
  589. else if(equali(szArg1, "/kivesz"))
  590. iCommand = CMD_WITHDRAW
  591. if(equali(szArg1, "berak"))
  592. iCommand = CMD_DEPOSIT
  593. else if(equali(szArg1, "kivesz"))
  594. iCommand = CMD_WITHDRAW
  595. else if(equali(szArg1, "/bank"))
  596. iCommand = CMD_INFO
  597.  
  598. if(iCommand)
  599. {
  600. if(iCommand == CMD_INFO)
  601. Command_Info(id)
  602. else
  603. {
  604. new iValue;
  605. if (equali(szArg2, "all"))
  606. {
  607. iValue = zp_get_user_ammo_packs(id)
  608. if(iValue <= 0)
  609. {
  610. SayText(id, ZP_BANK_FMT, id, "ZP_NO_AMMO_TO_SET")
  611. return PLUGIN_HANDLED
  612. }
  613. }
  614. else
  615. {
  616. iValue = str_to_num(szArg2)
  617. if(iValue <= 0)
  618. {
  619. SayText(id, ZP_BANK_FMT, id, "ZP_BANK_INVALID_AMOUNT")
  620. return PLUGIN_HANDLED
  621. }
  622. }
  623.  
  624. if(iCommand == CMD_DEPOSIT)
  625. Command_Deposit(id, iValue)
  626. else
  627. Command_Withdraw(id, iValue)
  628. }
  629.  
  630. return PLUGIN_HANDLED
  631.  
  632. }
  633.  
  634. return PLUGIN_CONTINUE
  635. }
  636.  
  637. Command_Info(id)
  638. {
  639. SayText(id, ZP_BANK_FMT, id, "ZP_BANK_LOAD", g_iAmmoPacks[id] + g_iSessionMovement[id], g_szAuth[id], (get_pcvar_num(cvWithdrawLimit) - g_iWithdrawLimit[id]))
  640. }
  641.  
  642. Command_Deposit(id, iDeposit)
  643. {
  644. new iCurrentAmount = zp_get_user_ammo_packs(id)
  645. new iDepositMin = get_pcvar_num(cvDepositMin)
  646. if(!iCurrentAmount)
  647. {
  648. SayText(id, ZP_BANK_FMT, id, "ZP_BANK_NO_AMMO")
  649. return
  650. }
  651.  
  652. if(iDeposit > iCurrentAmount)
  653. iDeposit = iCurrentAmount
  654.  
  655. if(iCurrentAmount < iDepositMin)
  656. {
  657. SayText(id, ZP_BANK_FMT, id, "ZP_BANK_DMIN", iDepositMin)
  658. return
  659. }
  660.  
  661. if(iDeposit < iDepositMin)
  662. {
  663. SayText(id, ZP_BANK_FMT, id, "ZP_BANK_DMIN", iDepositMin)
  664. return
  665. }
  666.  
  667. new iCurrent = g_iAmmoPacks[id] + g_iSessionMovement[id]
  668. new iSum = iCurrent + iDeposit
  669. new iBankMax = get_pcvar_num(cvBankMax)
  670.  
  671. if(iBankMax && (iSum > iBankMax))
  672. {
  673. iDeposit = iBankMax - iCurrent
  674. iSum = iBankMax
  675.  
  676. SayText(id, ZP_BANK_FMT, id, "ZP_BANK_MAX", iBankMax)
  677. }
  678.  
  679. if(iDeposit)
  680. {
  681. g_iSessionMovement[id] += iDeposit
  682.  
  683. if (g_iWithdrawLimit[id] > abs(iDeposit))
  684. {
  685. g_iWithdrawLimit[id] -= abs(iDeposit)
  686. }
  687. else
  688. {
  689. g_iWithdrawLimit[id] = 0
  690. }
  691.  
  692. SayText(id, ZP_BANK_FMT, id, "ZP_BANK_DEPOSIT", iDeposit, iSum, (get_pcvar_num(cvWithdrawLimit) - g_iWithdrawLimit[id]))
  693. zp_set_user_ammo_packs(id, iCurrentAmount - iDeposit)
  694.  
  695. if (get_pcvar_num(cvDeBug) >= 3)
  696. {
  697. new PIP[32],Pname[32]
  698. get_user_ip(id, PIP, 31, 1)
  699. get_user_name(id, Pname, 31)
  700. log_to_file(zplog,"[ZP] Bank: (Player ^"%s^") (IP ^"%s^") deposited ^"%d^" ammovalue to vault",Pname,PIP,iDeposit)
  701. }
  702. }
  703.  
  704. // If autosave enabled save this bullshit to vault
  705. if (get_pcvar_num(cvAutoSave) == 1)
  706. {
  707. SaveClient(id, g_szAuth[id])
  708. }
  709. }
  710.  
  711.  
  712. Command_Withdraw(id, iWithdraw)
  713. {
  714. new iDeposited = g_iAmmoPacks[id] + g_iSessionMovement[id]
  715. new iWithdrawMax = get_pcvar_num(cvWithdrawMax)
  716. new iWithdrawLimit = get_pcvar_num(cvWithdrawLimit)
  717.  
  718. if(!iDeposited)
  719. {
  720. SayText(id, ZP_BANK_FMT, id, "ZP_BANK_EMPTY")
  721. return
  722. }
  723.  
  724. if(iWithdraw > iDeposited)
  725. iWithdraw = iDeposited
  726.  
  727. if(iWithdraw > iWithdrawMax)
  728. {
  729. SayText(id, ZP_BANK_FMT, id, "ZP_BANK_WMAX", iWithdrawMax)
  730. return
  731. }
  732.  
  733. if((g_iWithdrawLimit[id] > iWithdrawLimit) || ((g_iWithdrawLimit[id] + iWithdraw) > iWithdrawLimit))
  734. {
  735. SayText(id, ZP_BANK_FMT, id, "ZP_BANK_WLIM", iWithdrawLimit, (iWithdrawLimit - g_iWithdrawLimit[id]))
  736. return
  737. }
  738.  
  739. g_iWithdrawLimit[id] += iWithdraw
  740. g_iSessionMovement[id] -= iWithdraw
  741.  
  742. SayText(id, ZP_BANK_FMT, id, "ZP_BANK_WITHDRAW", iWithdraw, iDeposited - iWithdraw, (get_pcvar_num(cvWithdrawLimit) - g_iWithdrawLimit[id]))
  743. zp_set_user_ammo_packs(id, zp_get_user_ammo_packs(id) + iWithdraw)
  744. if (get_pcvar_num(cvDeBug) >= 3)
  745. {
  746. new PIP[32],Pname[32]
  747. get_user_ip(id, PIP, 31, 1)
  748. get_user_name(id, Pname, 31)
  749. log_to_file(zplog,"[ZP] Bank: (Player ^"%s^") (IP ^"%s^") withdrawed ^"%d^" ammovalue from vault",Pname,PIP,iWithdraw)
  750. }
  751.  
  752. // If autosave enabled save this bullshit to vault
  753. if (get_pcvar_num(cvAutoSave) == 1)
  754. {
  755. SaveClient(id, g_szAuth[id])
  756. }
  757. }
  758.  
  759. stock SayText(const id, const input[], any:...)
  760. {
  761. new count = 1, players[32]
  762. static msg[191]
  763. vformat(msg, 190, input, 3)
  764.  
  765. replace_all(msg, 190, "!g", "^4") // Green Color
  766. replace_all(msg, 190, "!y", "^1") // Default Color
  767. replace_all(msg, 190, "!t", "^3") // Team Color
  768.  
  769. if (id) players[0] = id; else get_players(players, count, "ch")
  770. {
  771. for ( new i = 0; i < count; i++ )
  772. {
  773. if ( is_user_connected(players[i]) )
  774. {
  775. message_begin(MSG_ONE_UNRELIABLE, get_user_msgid("SayText"), _, players[i])
  776. write_byte(players[i]);
  777. write_string(msg);
  778. message_end();
  779. }
  780. }
  781. }
  782. }
  783.  

_________________
http://www.easyrankup.eu

Ők köszönték meg kiki nek ezt a hozzászólást: VirTuaL ~` (2012.09.11. 14:08)
  Népszerűség: 2.27%


Hozzászólás jelentése
Vissza a tetejére
   
 Hozzászólás témája: Re: stock ChatColor
HozzászólásElküldve: 2012.09.11. 14:08 
Offline
Őskövület
Avatar

Csatlakozott: 2011.09.17. 17:54
Hozzászólások: 2350
Megköszönt másnak: 40 alkalommal
Megköszönték neki: 57 alkalommal
Thx,mostmár jó :D


Hozzászólás jelentése
Vissza a tetejére
   
Hozzászólások megjelenítése:  Rendezés  
Új téma nyitása  Hozzászólás a témához  [ 3 hozzászólás ] 


Ki van itt

Jelenlévő fórumozók: nincs regisztrált felhasználó valamint 18 vendég


Nyithatsz új témákat ebben a fórumban.
Válaszolhatsz egy témára ebben a fórumban.
Nem szerkesztheted a hozzászólásaidat ebben a fórumban.
Nem törölheted a hozzászólásaidat ebben a fórumban.
Nem küldhetsz csatolmányokat ebben a fórumban.

Keresés:
Ugrás:  
Powered by phpBB® Forum Software © phpBB Limited
Magyar fordítás © Magyar phpBB Közösség
Portal: Kiss Portal Extension © Michael O'Toole