SHARE
TWEET

Untitled

a guest Jan 9th, 2019 88 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. new const PLUGINNAME[] = "Roundsleft"
  2. new const VERSION[] = "0.2"
  3. new const AUTHOR[] = "JGHG"
  4. /*
  5. Copyleft 2003
  6. http://amxmod.net/forums/viewtopic.php?p=130419
  7.  
  8. ROUNDSLEFT
  9. ==========
  10. Allows the users to "say roundsleft" and remaining rounds will be displayed.
  11. This is useful if you are using default hlds cvar mp_maxrounds set to some value.
  12. Will respond with same answer if users "say timeleft" also.
  13. There is also a command "amx_roundsleft" to view remaining rounds in console.
  14.  
  15. /jghg
  16.  
  17. HOW TO INSTALL
  18. ==============
  19. 1. Name this file roundsleft.sma.
  20. 2. Compile it into roundsleft.amx.
  21. 3. Put roundsleft.amx into amx/plugins directory.
  22. 4. Open up amx/plugins/plugins.ini and add a line to the end saying: roundsleft.amx
  23. 5. Done. Type reload in your server.
  24.  
  25. HOW TO USE
  26. ==========
  27. say roundsleft, say timeleft, say /roundsleft, say /timeleft
  28. - all these will respond with remaining rounds if mp_maxrounds is set to anything higher than 0.
  29.  
  30. amx_roundsleft
  31. - displays remaining rounds in console. Works also from server console.
  32.  
  33. VERSIONS
  34. ========
  35. 040308   0.2            Rewritten to work with amxmodx. :-) (lol, I changed #include <amxmod> to #include <amxmodx>)
  36. ??????   0.1            First version
  37.  
  38. */
  39.  
  40. #include <amxmodx>
  41. #include <amxmisc>
  42. #include <engine>
  43.  
  44. // Globals below
  45. new g_teamScore[2]
  46. // Globals above
  47.  
  48. public sayRoundsLeft(id) {
  49.     new maxRounds = get_cvar_num("mp_maxrounds")
  50.     if (id) {
  51.         if (maxRounds == 0) {
  52.             client_print(0, print_chat, "No rounds limit.")
  53.         }
  54.         else {
  55.             new roundsleft = maxRounds - (g_teamScore[0] + g_teamScore[1])
  56.             client_print(0, print_chat, "Remaining rounds: %d", roundsleft)
  57.         }
  58.     }
  59.  
  60.     return PLUGIN_CONTINUE
  61. }
  62.  
  63. public conRoundsLeft(id) {
  64.     new maxRounds = get_cvar_num("mp_maxrounds")
  65.     if (id) console_print(id,"Remaining rounds: %d",maxRounds - (g_teamScore[0] + g_teamScore[1]))
  66.     else server_print("Remaining rounds: %d",maxRounds - (g_teamScore[0] + g_teamScore[1]))
  67.  
  68.     return PLUGIN_HANDLED
  69. }
  70.  
  71. public teamScore(id) {
  72.     new team[2]
  73.     read_data(1,team,1)
  74.     g_teamScore[(team[0]=='C')? 0 : 1] = read_data(2)
  75.  
  76.     return PLUGIN_CONTINUE
  77. }
  78.  
  79. /*
  80. public newround_event(id) {
  81.     if (is_user_bot(id))
  82.         return PLUGIN_CONTINUE
  83.  
  84.     new maxRounds = get_cvar_num("mp_maxrounds")
  85.     if (maxRounds) {
  86.         set_hudmessage(0, 100, 0, -1.0, 0.65, 2, 0.02, 10.0, 0.01, 0.1, 2)
  87.         show_hudmessage(id, "%d rounds remaining", maxRounds - (g_teamScore[0] + g_teamScore[1]))
  88.         client_print(id, print_chat, "%d rounds remaining", maxRounds - (g_teamScore[0] + g_teamScore[1]))
  89.     }
  90.  
  91.     return PLUGIN_CONTINUE
  92. }
  93. */
  94.  
  95. public endround_event() {
  96.     server_print("endround_event, %d entities in game", entity_count())
  97.     set_task(2.0, "endofroundspk")
  98.  
  99.     return PLUGIN_CONTINUE
  100. }
  101.  
  102. public endofroundspk() {
  103.     //server_print("endofroundspk")
  104.     new maxRounds = get_cvar_num("mp_maxrounds")
  105.     new roundsleft = maxRounds - (g_teamScore[0] + g_teamScore[1])
  106.     if (maxRounds) {
  107.         set_hudmessage(0, 100, 0, 0.65, 0.7, 2, 0.02, 10.0, 0.01, 0.1, random_num(346, 6715))
  108.         if (roundsleft > 0)
  109.             show_hudmessage(0, "%d round%s remaining", roundsleft, roundsleft > 1 ? "s" : "")
  110.         else {
  111.             new nextmap[64]
  112.             get_cvar_string("amx_nextmap", nextmap, 63)
  113.             show_hudmessage(0, "That was the final round, changing to %s...", nextmap)
  114.         }
  115.         //client_print(0, print_chat, "%d rounds remaining", roundsleft)
  116.     }
  117.  
  118.     if (roundsleft > 0) {
  119.         if (roundsleft == 1)
  120.             client_cmd(0, "spk ^"this is the final round^"")
  121.     }
  122. }
  123.  
  124. stock getnumbers(number, wordnumbers[], length) {
  125.     if (number < 0) {
  126.         format(wordnumbers, length, "error")
  127.         return
  128.     }
  129.  
  130.     new numberstr[20]
  131.     num_to_str(number, numberstr, 19)
  132.     new stlen = strlen(numberstr), bool:getzero = false, bool:jumpnext = false
  133.     if (stlen == 1)
  134.         getzero = true
  135.  
  136.     do {
  137.         if (jumpnext)
  138.             jumpnext = false
  139.         else if (numberstr[0] != '0') {
  140.             switch (stlen) {
  141.                 case 9: {
  142.                     if (getsingledigit(numberstr[0], wordnumbers, length))
  143.                         format(wordnumbers, length, "%s hundred%s", wordnumbers, numberstr[1] == '0' && numberstr[2] == '0' ? " million" : "")
  144.                 }
  145.                 case 8: {
  146.                     jumpnext = gettens(wordnumbers, length, numberstr)
  147.                     if (jumpnext)
  148.                         format(wordnumbers, length, "%s million", wordnumbers)
  149.                 }
  150.                 case 7: {
  151.                     getsingledigit(numberstr[0], wordnumbers, length)
  152.                     format(wordnumbers, length, "%s million", wordnumbers)
  153.                 }
  154.                 case 6: {
  155.                     if (getsingledigit(numberstr[0], wordnumbers, length))
  156.                         format(wordnumbers, length, "%s hundred%s", wordnumbers, numberstr[1] == '0' && numberstr[2] == '0' ? " thousand" : "")
  157.                 }
  158.                 case 5: {
  159.                     jumpnext = gettens(wordnumbers, length, numberstr)
  160.                     if (numberstr[0] == '1' || numberstr[1] == '0')
  161.                         format(wordnumbers, length, "%s thousand", wordnumbers)
  162.                 }
  163.                 case 4: {
  164.                     getsingledigit(numberstr[0], wordnumbers, length)
  165.                     format(wordnumbers, length, "%s thousand", wordnumbers)
  166.                 }
  167.                 case 3: {
  168.                     getsingledigit(numberstr[0], wordnumbers, length)
  169.                     format(wordnumbers, length, "%s hundred", wordnumbers)
  170.                 }
  171.                 case 2: jumpnext = gettens(wordnumbers, length, numberstr)
  172.                 case 1: {
  173.                     getsingledigit(numberstr[0], wordnumbers, length, getzero)
  174.                     break // could've trimmed, but of no use here
  175.                 }
  176.                 default: {
  177.                     format(wordnumbers, length, "%s TOO LONG", wordnumbers)
  178.                     break
  179.                 }
  180.             }
  181.         }
  182.  
  183.         jghg_trim(numberstr, length, 1)
  184.         stlen = strlen(numberstr)
  185.     }
  186.     while (stlen > 0)
  187.  
  188.     // Trim a char from left if first char is a space (very likely)
  189.     if (wordnumbers[0] == ' ')
  190.         jghg_trim(wordnumbers, length, 1)
  191. }
  192.  
  193. // Returns true if next char should be jumped
  194. stock bool:gettens(wordnumbers[], length, numberstr[]) {
  195.     new digitstr[11], bool:dont = false, bool:jumpnext = false
  196.     switch (numberstr[0]) {
  197.         case '1': {
  198.             jumpnext = true
  199.             switch (numberstr[1]) {
  200.                 case '0': digitstr = "ten"
  201.                 case '1': digitstr = "eleven"
  202.                 case '2': digitstr = "twelve"
  203.                 case '3': digitstr = "thirteen"
  204.                 case '4': digitstr = "fourteen"
  205.                 case '5': digitstr = "fifteen"
  206.                 case '6': digitstr = "sixteen"
  207.                 case '7': digitstr = "seventeen"
  208.                 case '8': digitstr = "eighteen"
  209.                 case '9': digitstr = "nineteen"
  210.                 default: digitstr = "TEENSERROR"
  211.             }
  212.         }
  213.         case '2': digitstr = "twenty"
  214.         case '3': digitstr = "thirty"
  215.         case '4': digitstr = "fourty"
  216.         case '5': digitstr = "fifty"
  217.         case '6': digitstr = "sixty"
  218.         case '7': digitstr = "seventy"
  219.         case '8': digitstr = "eighty"
  220.         case '9': digitstr = "ninety"
  221.         case '0': dont = true // do nothing
  222.         default : digitstr = "TENSERROR"
  223.     }
  224.     if (!dont)
  225.         format(wordnumbers, length, "%s %s", wordnumbers, digitstr)
  226.  
  227.     return jumpnext
  228. }
  229.  
  230. // Returns true when sets, else false
  231. stock getsingledigit(digit[], numbers[], length, bool:getzero = false) {
  232.     new digitstr[11]
  233.     switch (digit[0]) {
  234.         case '1': digitstr = "one"
  235.         case '2': digitstr = "two"
  236.         case '3': digitstr = "three"
  237.         case '4': digitstr = "four"
  238.         case '5': digitstr = "five"
  239.         case '6': digitstr = "six"
  240.         case '7': digitstr = "seven"
  241.         case '8': digitstr = "eight"
  242.         case '9': digitstr = "nine"
  243.         case '0': {
  244.             if (getzero)
  245.                 digitstr = "zero"
  246.             else
  247.                 return false
  248.         }
  249.         default : digitstr = "digiterror"
  250.     }
  251.     format(numbers, length, "%s %s", numbers, digitstr)
  252.  
  253.     return true
  254. }
  255.  
  256. stock jghg_trim(stringtotrim[], len, charstotrim, bool:fromleft = true) {
  257.     if (charstotrim <= 0)
  258.         return
  259.  
  260.     if (fromleft) {
  261.         new maxlen = strlen(stringtotrim)
  262.         if (charstotrim > maxlen)
  263.             charstotrim = maxlen
  264.  
  265.         format(stringtotrim, len, "%s", stringtotrim[charstotrim])
  266.     }
  267.     else {
  268.         new maxlen = strlen(stringtotrim) - charstotrim
  269.         if (maxlen < 0)
  270.             maxlen = 0
  271.  
  272.         format(stringtotrim, maxlen, "%s", stringtotrim)
  273.     }
  274. }
  275.  
  276. public addrounds(id, level, cid) {
  277.     if (!cmd_access(id, level, cid, 2))
  278.         return PLUGIN_HANDLED
  279.  
  280.     new arg[32]
  281.     read_argv(1, arg, 31)
  282.     new arglength = strlen(arg)
  283.     for (new i = 0; i < arglength; i++) {
  284.         if (!isdigit(arg[i])) {
  285.             if (i != 0 || arg[0] != '-') {
  286.                 console_print(id, "Error: Enter only numbers, ie ^"amx_addrounds 10^"")
  287.                 return PLUGIN_HANDLED
  288.             }
  289.         }
  290.     }
  291.  
  292.     new roundstoadd = str_to_num(arg)
  293.  
  294.     if (roundstoadd == 0) {
  295.         console_print(id, "Error: Well duuuh. Enter a positive or negative value, ie ^"amx_addrounds 10^"")
  296.         return PLUGIN_HANDLED
  297.     }
  298.  
  299.     new originalmaxrounds = get_cvar_num("mp_maxrounds")
  300.  
  301.     new newmaxrounds = originalmaxrounds + roundstoadd
  302.  
  303.     if (newmaxrounds < 1)
  304.         newmaxrounds = 1
  305.  
  306.     new roundschanged = newmaxrounds - originalmaxrounds
  307.  
  308.     new Float:displayrounds = float(roundschanged)
  309.     displayrounds *= displayrounds
  310.     displayrounds = floatsqroot(displayrounds)
  311.  
  312.     console_print(id, "%sing %d rounds...", roundschanged > 0 ? "Add" : "Remov", floatround(displayrounds))
  313.  
  314.     set_cvar_num("mp_maxrounds", newmaxrounds)
  315.  
  316.     conRoundsLeft(id)
  317.  
  318.     return PLUGIN_HANDLED
  319. }
  320.  
  321. public plugin_init() {
  322.     register_plugin(PLUGINNAME, VERSION, AUTHOR)
  323.     register_clcmd("say timeleft", "sayRoundsLeft")
  324.     register_clcmd("say roundsleft", "sayRoundsLeft", 0, "- displays remaining rounds")
  325.     register_concmd("amx_roundsleft", "conRoundsLeft", 0, "- displays remaining rounds")
  326.     register_concmd("amx_addrounds", "addrounds", ADMIN_CFG, "<rounds> - add/remove remaining rounds")
  327.     register_event("TeamScore", "teamScore", "ab")
  328.     //register_event("ResetHUD", "newround_event", "b")
  329.     /*
  330.     register_event("SendAudio","endround_event","a","2&%!MRAD_terwin","2&%!MRAD_ctwin","2&%!MRAD_rounddraw")
  331.     register_event("TextMsg","endround_event","a","2&#Game_C","2&#Game_w")
  332.     register_event("TextMsg","endround_event","a","2&#Game_will_restart_in")
  333.     */
  334.     /*
  335.     register_logevent("death_event",5,"1=killed","3=with")
  336.     // L 03/08/2004 - 13:32:34: "xian<2><BOT><CT>" killed "SuperKaka<1><BOT><TERRORIST>" with "usp"
  337.     // L 03/08/2004 - 13:32:34: World triggered "Round_End"
  338.     */
  339.     // L 03/08/2004 - 13:32:34: World triggered "Round_End"
  340.     /*register_logevent("endround_event", 3, "2=Round_End")
  341.     register_logevent("endround_event", 3, "1=Round_End")
  342.     register_logevent("endround_event", 3, "0=Round_End")
  343.     register_logevent("endround_event", 3, "3=Round_End")*/
  344.     register_logevent("endround_event", 2, "0=World triggered", "1=Round_End")
  345. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top