HLMOD.HU Forrás Megtekintés - www.hlmod.hu
  1. /////////////////////////////////////////////////////////////////////
  2. /// DESCRIPTION ///
  3. /////////////////////////////////////////////////////////////////////
  4.  
  5. /* Made by Filip Vilicic. */
  6. /* Plugin link: http://forums.alliedmods.net/showthread.php?p=1060370 */
  7.  
  8. /* Special thanks to ConnorMcLeod (https://forums.alliedmods.net/member.php?u=18946)
  9.   for granting source and permision to use his seconds left
  10.   (http://forums.alliedmods.net/showpost.php?p=540426&postcount=5) plugin */
  11.  
  12. /* Description: Plugin that allows users to bet using chat. */
  13.  
  14. /* If you make translation to your language please give it to me as a reply to forum thread which
  15.   link is mentioned above. Thanks! */
  16. /* List of missing tranlsations: */
  17. /*
  18.   * Turkish (tr)
  19.   * French (fr)
  20.   * Swedish (sv)
  21.   * Danish (da)
  22.   * Poland (pl)
  23.   * Spanish (es)
  24.   * Brazil Portuguese (bp)
  25.   * Finish (fi)
  26.   * l33t (ls)
  27.   * Bulgarian (bg)
  28.   * Hungarian (hu)
  29.   * Lithuania (lt)
  30.   * Macedonian (mk)
  31. */
  32. /* There is no special license to this file except the following: */
  33. /*
  34.   * You must not use whole code, mod it a little and make it as your plugin! Rather post a
  35.   suggestion to link mentioned above.
  36.   * You can use part of a code for your plugin (WITH DIFFERENT PURPOSE!), this is sort of
  37.   educational purpose, and that's the point of whole community and all plugins!
  38.  
  39. Fordította: BBk
  40. */
  41.  
  42.  
  43.  
  44. /////////////////////////////////////////////////////
  45. /// INCLUDES & PLUGIN INFO ///
  46. /////////////////////////////////////////////////////
  47.  
  48. #include <amxmodx>
  49. #include <amxmisc>
  50. #include <cstrike>
  51. #include <fakemeta_util>
  52.  
  53. #define PLUGIN "Bet"
  54. #define VERSION "2.2"
  55. #define AUTHOR "Filip Vilicic"
  56.  
  57.  
  58.  
  59. /////////////////////////////////////////////////////
  60. /// CONSTANTS ///
  61. /////////////////////////////////////////////////////
  62.  
  63. //const strings for comparing
  64. new const CT[3] = "ct"
  65. new const T[2] = "t"
  66. new const ALL[4] = "all"
  67. new const HALF[5] = "half"
  68. new const BET[4] = "bet"
  69. new const ODDS[5] = "odds"
  70. //const string for client_print
  71. new const BET_PREFIX[9] = "[Bet] %L"
  72.  
  73. //Lookup table
  74. new const MessagesTable[15][] = {
  75. "TEAM_DEAD",
  76. "TEAM_DEAD_ODDS",
  77. "SAME_ODDS",
  78. "DIFF_ODDS",
  79. "BET_HELP",
  80. "NO_AMOUNT",
  81. "INVALID_TEAM",
  82. "NO_MONEY",
  83. "INVALID_AMOUNT",
  84. "BIGGER_BET",
  85. "PLAYER_ALIVE",
  86. "ALREADY_PLACED",
  87. "BET_PLACED",
  88. "BET_WIN",
  89. "BET_LOST"
  90. };
  91.  
  92.  
  93.  
  94. /////////////////////////////////////////////////////////////////////
  95. /// VARIABLES ///
  96. /////////////////////////////////////////////////////////////////////
  97.  
  98. //variables for storing bet information
  99. new pos = 0
  100. static betTeam[32], betUserId[32], betAmount[32], betWin[32] //we use auth if some player exited and another came to his place
  101.  
  102. //ads
  103. new gmsgSayText;
  104. static const message[] = "^x01 ^x03 **Ird be ^x04 ^"bet^" ^x03 segitseg a fogadashoz! Ird be ^x04 ^"odds^" ^x03 a nyeresi esely megtekintesehez! **"
  105. new taskID = 1555
  106. //end ads
  107.  
  108. //Advanced odds time calculation -> Thanks to ConnorMcLeod
  109. new Float:g_newround_time,
  110. Float:g_roundstart_time,
  111. Float:g_bombplanted_time
  112.  
  113. new Float:g_freezetime,
  114. Float:g_roundtime,
  115. Float:g_c4timer
  116.  
  117. new g_playtime = 1
  118.  
  119. new pcvar_roundtime, pcvar_freezetime, pcvar_c4timer
  120. //End of advanced odds time calculation
  121.  
  122.  
  123. /////////////////////////////////////////////////////////////
  124. /// CVAR HANDLING ///
  125. /////////////////////////////////////////////////////////////
  126.  
  127. new cvar_chatEnabled //pointer to cvar handle
  128. new bool:g_chatEnabled //stores last cvar value
  129. #define GetChatEnabled() bool:get_pcvar_num(cvar_chatEnabled)
  130.  
  131. new cvar_adsEnabled
  132. #define GetAdsEnabled() bool:get_pcvar_num(cvar_adsEnabled)
  133.  
  134. new cvar_aliveEnabled
  135. #define GetAliveEnabled() bool:get_pcvar_num(cvar_aliveEnabled)
  136.  
  137. new cvar_newOddsEnabled
  138. #define GetNewOddsEnabled() bool:get_pcvar_num(cvar_newOddsEnabled)
  139.  
  140.  
  141.  
  142. /////////////////////////////////////////////////////
  143. /// PLUGIN INITIALIZATION ///
  144. /////////////////////////////////////////////////////
  145.  
  146. public plugin_init() {
  147. register_plugin(PLUGIN, VERSION, AUTHOR)
  148.  
  149. // Add your code here...
  150. register_clcmd("say", "sayBet", ADMIN_USER, "- segitseg mutatasa a fogadashoz es a hasznatlahoz")
  151. register_concmd("amx_advertisebet", "cmdAd", ADMIN_CVAR, " - hirdetes mutatasa minden jatekos szamara")
  152. register_clcmd("say /advertisebet", "cmdAd", ADMIN_CVAR, " - hirdetes mutatasa minden jatekos szamara")
  153.  
  154. register_event("SendAudio", "t_win", "a", "2&%!MRAD_terwin")
  155. register_event("SendAudio", "ct_win", "a", "2&%!MRAD_ctwin")
  156.  
  157. //ads
  158. gmsgSayText = get_user_msgid("SayText");
  159. register_event("DeathMsg", "hook_death", "a") //advertises script on death (only for 1 player)
  160. //end ads
  161.  
  162. //dictionary
  163. register_dictionary("bet.txt")
  164.  
  165. //cvars
  166. cvar_chatEnabled = register_cvar("bet_chatenabled", "1")
  167. g_chatEnabled = GetChatEnabled()
  168. cvar_adsEnabled = register_cvar("bet_adsenabled", "1")
  169. cvar_aliveEnabled = register_cvar("bet_mustbedead", "1")
  170. cvar_newOddsEnabled = register_cvar("bet_oddssystem", "1")
  171.  
  172. //Advanced odds time calculation -> Thanks to ConnorMcLeod
  173. register_event("TextMsg", "eRestart", "a", "2&#Game_C", "2&#Game_w")
  174. register_logevent("eRoundEnd", 2, "1=Round_End")
  175.  
  176. register_event("HLTV", "eNewRound", "a", "1=0", "2=0")
  177. register_logevent("eRoundStart", 2, "1=Round_Start")
  178. register_event("SendAudio","eSendAudio","a","2=%!MRAD_BOMBPL")
  179.  
  180. pcvar_roundtime = get_cvar_pointer("mp_roundtime")
  181. pcvar_freezetime = get_cvar_pointer("mp_freezetime")
  182. pcvar_c4timer = get_cvar_pointer("mp_c4timer")
  183. //End of advanced odds time calculation
  184. }
  185.  
  186.  
  187.  
  188. /////////////////////////////////////////////////////////////////////
  189. /// ADVERTISING ///
  190. /////////////////////////////////////////////////////////////////////
  191.  
  192. public hook_death()
  193. {
  194. if (!GetAdsEnabled())
  195. return PLUGIN_HANDLED
  196. new Victim[1]
  197. Victim[0] = read_data(2)
  198. set_task(1.5, "showAd", taskID, Victim, 1)
  199. taskID++
  200. if (taskID > 1655) taskID = 1555
  201. return PLUGIN_HANDLED
  202. }
  203.  
  204. public showAd(args[])
  205. {
  206. new player = args[0]
  207. message_begin(MSG_ONE, gmsgSayText, {0,0,0}, player);
  208. write_byte(player);
  209. write_string(message);
  210. message_end();
  211. }
  212.  
  213. public cmdAd(id, level, cid)
  214. {
  215. if (!cmd_access(id, level, cid, 1)) //check access
  216. return PLUGIN_HANDLED
  217.  
  218. new plist[32], playernum, player;
  219. get_players(plist, playernum, "c");
  220. for(new i = 0; i < playernum; i++)
  221. {
  222. player = plist[i];
  223.  
  224. message_begin(MSG_ONE, gmsgSayText, {0,0,0}, player);
  225. write_byte(player);
  226. write_string(message);
  227. message_end();
  228. }
  229. return PLUGIN_HANDLED
  230. }
  231. //end ads
  232.  
  233.  
  234.  
  235. /////////////////////////////////////////////////////////////
  236. /// BET FUNCTIONS ///
  237. /////////////////////////////////////////////////////////////
  238.  
  239. //say hook
  240. public sayBet(id, level, cid)
  241. {
  242. new argCheck[32]
  243. read_argv(1,argCheck,31)
  244. //get args
  245. new argCmd[5], arg1[8], arg2[8]
  246. new numOfArgs = 3
  247. parse(argCheck, argCmd, 4, arg1, 2, arg2, 5)
  248. //update is chat enabled
  249. g_chatEnabled = GetChatEnabled()
  250. if(!equali(argCmd,BET)) //not bet prefix
  251. {
  252. if (equali(argCmd, ODDS))
  253. {
  254. //its odds request
  255. //handle odds request
  256. new alT, alCT
  257. if(!FindOdds(alT, alCT))
  258. {
  259. client_print(id, print_chat, BET_PREFIX, id, MessagesTable[1])
  260. } else if (alT==alCT) { //same odds
  261. client_print(id, print_chat, BET_PREFIX, id, MessagesTable[2], alT, alCT)
  262. } else { //different odds
  263. client_print(id, print_chat, BET_PREFIX, id, MessagesTable[3], alT, alCT)
  264. }
  265. //odds request. Test should I print?
  266. return whatToReturn()
  267. }
  268. //normal chat
  269. return PLUGIN_CONTINUE
  270.  
  271. }
  272. if (is_user_alive(id) && GetAliveEnabled())
  273. {
  274. client_print(id, print_chat, BET_PREFIX, id, MessagesTable[10])
  275. return whatToReturn()
  276. }
  277. if (arg2[0] == 0){ //no amount
  278. numOfArgs = 2
  279. }
  280. if (arg1[0] == 0) { //no team
  281. numOfArgs = 1
  282. }
  283. switch (numOfArgs)
  284. {
  285. case 1:
  286. {
  287. //bet help
  288. client_print(id, print_chat, BET_PREFIX, id, MessagesTable[4])
  289. }
  290. case 2:
  291. {
  292. //no amount
  293. client_print(id, print_chat, BET_PREFIX, id, MessagesTable[5])
  294. }
  295. case 3:
  296. {
  297. //all parameters accepted lets test them...
  298. new TeamReturnFunc = checkTeam(arg1)
  299. if(TeamReturnFunc > 0)
  300. {
  301. //good team
  302. //value is stored in TeamReturnFunc and it will be passed to Bet function
  303. } else {
  304. //Not good team
  305. client_print(id, print_chat, BET_PREFIX, id, MessagesTable[6], arg1)
  306. return whatToReturn()
  307. }
  308. new arg2Num = str_to_num(arg2)
  309. new AmountFuncReturn = checkAmount(arg2)
  310.  
  311. new userMoney = cs_get_user_money(id)
  312. if(AmountFuncReturn > 0)
  313. {
  314. //good text
  315. //get text and bet that amount
  316. if (userMoney == 0)
  317. {
  318. client_print(id, print_chat, BET_PREFIX, id, MessagesTable[7], arg2)
  319. return whatToReturn()
  320. }
  321. if (AmountFuncReturn == 1)
  322. {
  323. arg2Num = userMoney
  324. } else if (AmountFuncReturn == 2) {
  325. arg2Num = userMoney/2
  326. } else { //note: code should never enter this code block
  327. client_print(id, print_chat, BET_PREFIX, id, MessagesTable[8], arg2)
  328. return whatToReturn()
  329. }
  330. //do the job
  331. Bet(id,TeamReturnFunc,arg2Num)
  332. } else if (arg2Num > 0 && arg2Num < 16000) { //it isn't textual
  333. //good num
  334. if (userMoney == 0)
  335. {
  336. client_print(id, print_chat, BET_PREFIX, id, MessagesTable[7], arg2)
  337. return whatToReturn()
  338. }
  339. if (userMoney < arg2Num)
  340. {
  341. client_print(id, print_chat, BET_PREFIX, id, MessagesTable[9], userMoney, arg2Num)
  342. return whatToReturn()
  343. }
  344. //do the job
  345. Bet(id,TeamReturnFunc,arg2Num)
  346. } else {
  347. //bad
  348. client_print(id, print_chat, BET_PREFIX, id, MessagesTable[8], arg2)
  349. } //if block
  350. } //case 3
  351. }//switch
  352. return whatToReturn()
  353. }
  354. //end of say hook
  355.  
  356. //place bet
  357. public Bet(id, team, amount) // 1 for T and 2 for CT
  358. {
  359. new alT, alCT, possWin
  360. if(findPos(get_user_userid(id)) != -1)
  361. {
  362. client_print(id, print_chat, BET_PREFIX, id, MessagesTable[11])
  363. return whatToReturn()
  364. }
  365. if(!FindOdds(alT, alCT))
  366. {
  367. client_print(id, print_chat, BET_PREFIX, id, MessagesTable[0])
  368. return whatToReturn()
  369. }
  370. if(team == 1) //T
  371. {
  372. possWin = amount * alCT / alT
  373. client_print(id, print_chat, BET_PREFIX, id, MessagesTable[12], alT,alCT,possWin,amount)
  374. } else { //CT
  375. possWin = amount * alT / alCT
  376. client_print(id, print_chat, BET_PREFIX, id, MessagesTable[12], alCT,alT,possWin,amount)
  377. }
  378. new money = cs_get_user_money(id) - amount
  379. //set to change money after end of round
  380. betTeam[pos] = team
  381. betUserId[pos] = get_user_userid(id)
  382. betAmount[pos] = amount
  383. betWin[pos] = amount + possWin + money
  384. pos++
  385. cs_set_user_money(id, cs_get_user_money(id) - amount) //take money
  386. return whatToReturn()
  387. }
  388. //end of place bet
  389.  
  390.  
  391.  
  392. /////////////////////////////////////////////////////////////
  393. /// PAYOFF FUNCTIONS ///
  394. /////////////////////////////////////////////////////////////
  395.  
  396. //hooks on terrorist win event
  397. public t_win()
  398. {
  399. giveMoney(1)
  400. }
  401.  
  402. //hooks on ct win event
  403. public ct_win()
  404. {
  405. giveMoney(2)
  406. }
  407.  
  408. //gives money after round end
  409. public giveMoney(team) // 1 for T and 2 for CT
  410. {
  411. new Players[32]
  412. new playerCount, id, userid, position
  413. get_players(Players, playerCount, "c")
  414. for (new i=0; i<playerCount; i++)
  415. {
  416. id = Players[i]
  417. userid = get_user_userid(id)
  418. //find pos for this userid
  419. position = findPos(userid)
  420. if (position != -1) //did he placed bet?
  421. {
  422. if (betTeam[position] == team) //did he won?
  423. {
  424. client_print(id, print_chat, BET_PREFIX, id, MessagesTable[13], betWin[position] - cs_get_user_money(id))
  425. cs_set_user_money(id, betWin[position])
  426. } else {
  427. client_print(id, print_chat, BET_PREFIX, id, MessagesTable[14], betAmount[position])
  428. }
  429. }
  430. }
  431. for(new b=0; b<pos; b++)
  432. {
  433. betAmount[b] = 0
  434. betTeam[b] = 0
  435. betUserId[b] = 0
  436. betWin[b] = 0
  437. }
  438. pos = 0
  439. }
  440.  
  441.  
  442.  
  443. /////////////////////////////////////////////////////////////
  444. /// ODDS FUNCTIONS ///
  445. /////////////////////////////////////////////////////////////
  446.  
  447. bool:FindOdds(&One, &Two)
  448. {
  449. if (GetNewOddsEnabled()) return FindOddsNew(One, Two)
  450.  
  451. return FindOddsOld(One, Two)
  452. }
  453.  
  454. bool:FindOddsOld(&One, &Two)
  455. {
  456. new Players[32]
  457. new playerCount
  458. new aliveT, aliveCT
  459. aliveT = 0
  460. aliveCT = 0
  461. get_players(Players, playerCount, "a") //get all alive players
  462. for (new i=0; i<playerCount; i++)
  463. {
  464. switch(cs_get_user_team(Players[i]))
  465. {
  466. case CS_TEAM_T:
  467. {
  468. aliveT++
  469. }
  470. case CS_TEAM_CT:
  471. {
  472. aliveCT++
  473. }
  474. }
  475. }
  476.  
  477. One = aliveT
  478. Two = aliveCT
  479. if(aliveT == 0 || aliveCT == 0) {
  480. return false //one (or more) team is dead
  481. }
  482. return true //both teams are alive
  483. }
  484.  
  485. bool:FindOddsNew(&One, &Two)
  486. {
  487. new Players[32]
  488. new playerCount
  489. new Float:aliveT, Float:aliveCT
  490. aliveT = 0.0
  491. aliveCT = 0.0
  492. get_players(Players, playerCount, "a") //get all alive players
  493. for (new i=0; i<playerCount; i++)
  494. {
  495. new player = Players[i]
  496. new CsTeams:team = cs_get_user_team(player)
  497. if (team == CS_TEAM_SPECTATOR) continue
  498. new Float:addToOdd
  499. new frags, deaths
  500. frags = get_user_frags(player)
  501. deaths = get_user_deaths(player)
  502. if (frags > 0) {
  503. if (frags + deaths > 4) {
  504. addToOdd = floatdiv(Float:frags, Float:(deaths+1))
  505. } else {
  506. addToOdd = 1.0
  507. }
  508. } else {
  509. addToOdd = 0.0
  510. }
  511. new health = get_user_health(player)
  512. if (health < 11) {
  513. addToOdd = floatmul(addToOdd, 0.25)
  514. goto next
  515. }
  516. if (health < 21) {
  517. addToOdd = floatmul(addToOdd, 0.35)
  518. goto next
  519. }
  520. if (health < 41) {
  521. addToOdd = floatmul(addToOdd, 0.5)
  522. goto next
  523. }
  524. if (health < 61) {
  525. addToOdd = floatmul(addToOdd, 0.75)
  526. goto next
  527. }
  528. //60 < health < 81 - multiplies by 1 - do nothing
  529. if (health > 80) {
  530. addToOdd = floatmul(addToOdd, 1.25)
  531. }
  532. next:
  533. if (floatcmp(addToOdd, 0.5) == -1) addToOdd = 0.5
  534. if (floatcmp(addToOdd, 2.0) == 1) addToOdd = 2.0
  535. switch(team)
  536. {
  537. case CS_TEAM_T:
  538. {
  539. aliveT += addToOdd
  540. }
  541. case CS_TEAM_CT:
  542. {
  543. aliveCT += addToOdd
  544. }
  545. }//switch(team)
  546. }//for
  547.  
  548. One = floatround(aliveT)
  549. Two = floatround(aliveCT)
  550. if(One == 0 || Two == 0) {
  551. return false //one (or more) team is dead
  552. }
  553.  
  554. //passes floats!
  555. AdvancedOdds(aliveT, aliveCT)
  556.  
  557. One = floatround(aliveT)
  558. Two = floatround(aliveCT)
  559. //test again since advanced odds may set this to zeros
  560. if(One == 0 || Two == 0) {
  561. return false //one (or more) team is dead
  562. }
  563.  
  564. //If odds have common divisor (other than 1)
  565. new divisor = gcd(One, Two)
  566. if (divisor > 1) {
  567. One /= divisor
  568. Two /= divisor
  569. }
  570.  
  571. return true //both teams are alive
  572. }
  573.  
  574. //changes odds acording to round time, c4 time etc.
  575. //Point of this odds changing is to prevent "cheating". Eg:
  576. //10 Ts vs 2 CTs and 2 sec to end of round and bomb isn't even near the site
  577. //So if you bet for CTs you get 5 times your money for nothing :)
  578. public AdvancedOdds(&Float:TOdd, &Float:CTOdd)
  579. {
  580. if (g_playtime <= 1) return //no changes if end of round or freeze time
  581. new remaining = get_remaining_seconds() //Thanks to ConnorMcLeod
  582. if (remaining <= 0) return //0 or less remaining -> no changes
  583. if (fm_find_ent_by_class(-1, "func_bomb_target") || fm_find_ent_by_class(-1, "info_bomb_target"))
  584. {
  585. //map has c4 site(s)
  586. if (g_playtime == 3)
  587. {
  588. //bomb planted
  589. //TODO: test how many Ts and CTs on site and if defusing started
  590. if (remaining < 6) //bomb is defused in 6secs with defuse kit
  591. {
  592. //Very little time (it can be defused if already started def process)
  593. TOdd = floatmul(TOdd, 2.0)
  594. return
  595. }
  596. if (remaining < 11)
  597. {
  598. //Little time -> give T more chances
  599. TOdd = floatmul(TOdd, 1.5)
  600. }
  601. if (remaining > 25)
  602. {
  603. //plenty of time -> give CT more chances
  604. CTOdd = floatmul(CTOdd, 1.2)
  605. }
  606. } else {
  607. //bomb not planted
  608. //TODO: test if bomb on site
  609. if (remaining < 6)
  610. {
  611. CTOdd = floatmul(CTOdd, 5.0)
  612. goto next
  613. }
  614. if (remaining < 11)
  615. {
  616. CTOdd = floatmul(CTOdd, 2.0)
  617. goto next
  618. }
  619. if (remaining < 16)
  620. {
  621. CTOdd = floatmul(CTOdd, 1.5)
  622. goto next
  623. }
  624. if (remaining < 31)
  625. {
  626. CTOdd = floatmul(CTOdd, 1.15)
  627. }
  628. next:
  629. }
  630. } else {
  631. //map doesn't have c4 site(s)
  632. //TODO: Make tests for hostages and other map types
  633. if (remaining < 6)
  634. {
  635. CTOdd = floatmul(CTOdd, 5.0)
  636. goto next2
  637. }
  638. if (remaining < 11)
  639. {
  640. CTOdd = floatmul(CTOdd, 2.0)
  641. goto next2
  642. }
  643. if (remaining < 16)
  644. {
  645. CTOdd = floatmul(CTOdd, 1.5)
  646. goto next2
  647. }
  648. if (remaining < 31)
  649. {
  650. CTOdd = floatmul(CTOdd, 1.15)
  651. }
  652. next2:
  653. }
  654. }
  655.  
  656.  
  657.  
  658. /////////////////////////////////////////////////////////////
  659. /// HELPER FUNCTIONS ///
  660. /////////////////////////////////////////////////////////////
  661.  
  662. //checks if string represents a team (t or ct)
  663. checkTeam(input[])
  664. {
  665. if (equali(input,T))
  666. {
  667. return 1
  668. } else if (equali(input,CT)) {
  669. return 2
  670. }
  671. return 0
  672. }
  673.  
  674. //checks if string represents textual amount (all or half)
  675. checkAmount(input[])
  676. {
  677. if (equali(input,ALL))
  678. {
  679. return 1
  680. } else if (equali(input, HALF)) {
  681. return 2
  682. }
  683. return 0
  684. }
  685.  
  686. findPos(userid)
  687. {
  688. for(new b=0; b<32; b++)
  689. {
  690. if (betUserId[b] == userid)
  691. {
  692. return b
  693. }
  694. }
  695. return -1
  696. }
  697.  
  698. public whatToReturn()
  699. {
  700. if(g_chatEnabled)
  701. return PLUGIN_CONTINUE
  702.  
  703. return PLUGIN_HANDLED
  704. }
  705.  
  706. public gcd(a, b)
  707. {
  708. if (b==0)
  709. return a;
  710.  
  711. return gcd(b, a % b)
  712. }
  713. //end of misc functions
  714.  
  715.  
  716.  
  717. /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  718. /// REMAINING TIME CALCULATION - Whole code written by: ConnorMcLeod (https://forums.alliedmods.net/member.php?u=18946) ///
  719. /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  720.  
  721. public eRestart() {
  722. g_playtime = 0
  723. }
  724.  
  725. public eRoundEnd() {
  726. g_playtime = 0
  727. }
  728.  
  729. public eNewRound() {
  730. g_playtime = 1
  731.  
  732. new Float:freezetime = get_pcvar_float(pcvar_freezetime)
  733. if(freezetime)
  734. {
  735. g_newround_time = get_gametime()
  736. g_freezetime = freezetime
  737. }
  738. g_c4timer = get_pcvar_float(pcvar_c4timer)
  739. g_roundtime = floatmul(get_pcvar_float(pcvar_roundtime), 60.0) - 1.0
  740. }
  741.  
  742. public eRoundStart() {
  743. g_playtime = 2
  744.  
  745. g_roundstart_time = get_gametime()
  746. }
  747.  
  748. public eSendAudio() {
  749. g_playtime = 3
  750.  
  751. g_bombplanted_time = get_gametime()
  752. }
  753.  
  754. public get_remaining_seconds() {
  755. switch(g_playtime)
  756. {
  757. case 0: return 0
  758. case 1: return floatround( ( get_gametime() - g_newround_time ) - g_freezetime , floatround_ceil )
  759. case 2: return floatround( g_roundtime - ( get_gametime() - g_roundstart_time ) , floatround_ceil )
  760. case 3: return floatround( g_c4timer - ( get_gametime() - g_bombplanted_time ) , floatround_ceil )
  761. }
  762. return 0
  763. }