Advertisement
Guest User

Wyzcrak

a guest
Dec 8th, 2008
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <amxmodx>
  2. #include <amxmisc>
  3. #include <ns2amx>
  4. #include <engine>
  5.  
  6. #define PLUGIN "Captains Game"
  7. #define VERSION "0.1"
  8. #define AUTHOR "Wyzcrak"
  9.  
  10. #define CHAT_TAG "[CAPTAINS]"
  11. #define HUD_CHANNEL 2   // 1-4 imessage(1) ScrollMsg(2) AlienUpgInfo(3)
  12. #define REFRESH_FREQ    1
  13.  
  14. #define HURRYSECONDS 180
  15.  
  16. #define REFRESHHURRYMARINES 1
  17. #define REFRESHHURRYALIENS 2
  18. #define REFRESHSOHWNOTES 3
  19.  
  20. new allowNotesDisplay = 1
  21. new captain1id
  22. new captain2id
  23. new g_maxPlayers
  24.  
  25. new g_Team[33]
  26. new notes[33][21]
  27. new taskId = 22337
  28. new preGameTimeleft
  29. new bool:isRoundTwo
  30. new refresh
  31.  
  32. public plugin_init() {
  33.     register_plugin(PLUGIN, VERSION, AUTHOR)
  34.     captain1id = -1
  35.     captain2id = -1
  36.     register_clcmd("say","handleSay")
  37.     register_clcmd("say_team","handleSayTeam")
  38.    
  39.     register_concmd("captains","config",ADMIN_KICK,"- configures the server for Captains Games")
  40.     register_event("Countdown", "do_roundbegin", "a")
  41.     register_event("GameStatus", "do_roundend","ab","1=2")
  42.    
  43.     g_maxPlayers = get_maxplayers()
  44.     isRoundTwo = false
  45.    
  46.     return PLUGIN_CONTINUE
  47. }
  48.  
  49. public refreshWhatever() {
  50.     if (refresh == REFRESHHURRYMARINES) hurryMarines()
  51.     else if (refresh == REFRESHHURRYALIENS) hurryAliens()
  52.     else showNotes()
  53. }
  54.  
  55. public handleSay(id) {
  56.     if (isCaptainsMode() && allowNotesDisplay == 1) {
  57.         new saytext[80]
  58.         read_args(saytext, 79)
  59.         remove_quotes(saytext)
  60.         if (equal(saytext, "<", 1) || contain(saytext, "/note ") == 0 || contain(saytext, "/notes") == 0) {
  61.             client_print(id, print_chat, "%s Manage notes with teamsay.", CHAT_TAG)
  62.             return PLUGIN_HANDLED
  63.         }
  64.         else if (contain(saytext, "/captain") == 0) {
  65.             makeCaptain(id)
  66.             return PLUGIN_CONTINUE
  67.         }
  68.         else if (contain(saytext, "ready") == 0) {
  69.             if ((captain1id != id) && (captain2id != id)) {
  70.                 client_print(id, print_chat, "%s Only the team captain should ready/notready the team.", CHAT_TAG)
  71.                 return PLUGIN_HANDLED
  72.             }
  73.             if (preGameTimeleft == HURRYSECONDS) {
  74.                 if (g_Team[id]==1) hurryTeam(2, id)
  75.                 else if (g_Team[id]==2) hurryTeam(1, id)
  76.             }
  77.             return PLUGIN_CONTINUE
  78.         }
  79.         else if (contain(saytext, "notready") == 0) {
  80.             if ((captain1id != id) && (captain2id != id)) {
  81.                 client_print(id, print_chat, "%s Only the team captain should ready/notready the team.", CHAT_TAG)
  82.                 return PLUGIN_HANDLED
  83.             }
  84.             if (g_Team[id]==1) unhurryTeam(2)
  85.             else if (g_Team[id]==2) unhurryTeam(1)
  86.             return PLUGIN_CONTINUE
  87.         }
  88.         else {
  89.             return PLUGIN_CONTINUE
  90.         }
  91.     }
  92.     return PLUGIN_CONTINUE
  93. }
  94.  
  95. public hurryTeam(team, id) {
  96.     remove_task(taskId)
  97.     if (team == 1) {
  98.         refresh = REFRESHHURRYMARINES
  99.     }
  100.     else if (team == 2) {
  101.         refresh = REFRESHHURRYALIENS
  102.     }
  103. }
  104.  
  105. public unhurryTeam(team) {
  106.     remove_task(taskId)
  107.     preGameTimeleft = HURRYSECONDS
  108.     showNotes()
  109. }
  110.  
  111. public hurryMarines() {
  112.     preGameTimeleft = preGameTimeleft - 1
  113.     showNotes()
  114. }
  115.  
  116. public hurryAliens() {
  117.     preGameTimeleft = preGameTimeleft - 1
  118.     showNotes()
  119. }
  120.  
  121. public handleSayTeam(id) {
  122.     if (isCaptainsMode()) {
  123.         new saytext[80]
  124.         read_args(saytext, 79)
  125.         remove_quotes(saytext)
  126.         if (equal(saytext, "<", 1)) {
  127.             replace(saytext, 254, "<", "")
  128.             trim(saytext)
  129.             new playername[80]
  130.             get_user_name(id, playername, 79)
  131.             assignNote(id, playername, saytext)
  132.             return PLUGIN_HANDLED
  133.         }
  134.         if (contain(saytext, "/note ") == 0) {
  135.             replace(saytext, 254, "/note ", "")
  136.             new playername[80], note[21]
  137.             new firstspace = contain(saytext," ")
  138.             strbreak(saytext, playername, firstspace, note, 20)
  139.             assignNote(id, playername, note)
  140.             return PLUGIN_HANDLED
  141.         }
  142.         else if (contain(saytext, "/captain") == 0) {
  143.             makeCaptain(id)
  144.             return PLUGIN_CONTINUE
  145.         }
  146.         else if (contain(saytext, "/notes") == 0) {
  147.             showTeamNotes(id, g_Team[id], 15)
  148.             return PLUGIN_HANDLED
  149.         }
  150.         else if (contain(saytext, "ready") == 0) {
  151.             if ((captain1id != id) && (captain2id != id)) {
  152.                 client_print(id, print_chat, "[CAPTAINS] Only the team captain should ready/notready the team.")
  153.                 return PLUGIN_HANDLED
  154.             }
  155.             return PLUGIN_CONTINUE
  156.         }
  157.         else if (contain(saytext, "notready") == 0) {
  158.             if ((captain1id != id) && (captain2id != id)) {
  159.                 client_print(id, print_chat, "[CAPTAINS] Only the team captain should ready/notready the team.")
  160.                 return PLUGIN_HANDLED
  161.             }
  162.             if (g_Team[id]==1) unhurryTeam(2)
  163.             else if (g_Team[id]==2) unhurryTeam(1)
  164.             return PLUGIN_CONTINUE
  165.         }
  166.         else {
  167.             return PLUGIN_CONTINUE
  168.         }
  169.     }
  170.     return PLUGIN_CONTINUE
  171. }
  172.  
  173. public assignNote(id, target[], note[]) {
  174.     if (isCaptainsMode()) {
  175.         if (g_Team[id] != 0) {
  176.             new player = cmd_target(id,target,1)
  177.             if (player && (g_Team[id] == g_Team[player])) {
  178.                 if (player == id || isCaptain(id)) {
  179.                     format(notes[player], 20, "%s", note)
  180.                 }
  181.                 else {
  182.                     client_print(id, print_chat, "%s Only captains may set others' notes.  You may only set your own.")
  183.                 }
  184.             }
  185.             else {
  186.                 client_print(id, print_chat, "%s '%s' does not uniquely match a teammate.  Try again.", CHAT_TAG, target)
  187.             }
  188.            
  189.         }
  190.         else {
  191.             client_print(id, print_chat, "%s You must be on a team to use this command.")
  192.         }
  193.     }
  194.     else {
  195.         client_print(id, print_chat, "%s Captains mode is not enabled.")
  196.     }
  197. }
  198.  
  199. public makeCaptain(id) {
  200.     if (isCaptainsMode()) {
  201.         if (g_Team[id] == 0) {
  202.             if (isCaptain(id)) {
  203.                 client_print(id, print_chat, "%s You are already a captain.", CHAT_TAG)
  204.             }
  205.             else {
  206.                 if (captain1id  == -1) {
  207.                     captain1id = id
  208.                 }
  209.                 else if (captain2id  == -1) {
  210.                     captain2id = id
  211.                 }
  212.                 if (isCaptain(id)) {
  213.                     new name[40]
  214.                     get_user_name(id, name, 39)
  215.                     client_print(0, print_chat, "%s %s is a captain.", CHAT_TAG, name)
  216.                 }
  217.                 else {
  218.                     client_print(id, print_chat, "%s Two captains already exist.  You are not a captain.", CHAT_TAG)
  219.                 }
  220.             }
  221.         }
  222.         else {
  223.             client_print(id, print_chat, "%s This command must be used from the readyroom", CHAT_TAG)
  224.         }
  225.     }
  226.     else {
  227.         client_print(id, print_chat, "%s Captains mode is not enabled.")
  228.     }
  229. }
  230.  
  231. public isCaptain(id) {
  232.     return (captain1id == id || captain2id == id)
  233. }
  234.  
  235. public do_roundbegin() {
  236.     remove_task(taskId)
  237.     if (isCaptainsMode()) {
  238.         allowNotesDisplay = 0
  239.         hideNotes()
  240.     }
  241. }
  242.  
  243. public do_roundend() {
  244.     if (isCaptainsMode()) {
  245.         remove_task(taskId)
  246.         set_task(12.0, "config", taskId)
  247.         isRoundTwo = true
  248.     }
  249. }
  250.  
  251. public config(id, level, cid) {
  252.     if (!cmd_access(id,level,cid,1)) {
  253.         return PLUGIN_HANDLED
  254.     }
  255.     if (ns_is_combat()) {
  256.         console_print(id, "%s This command cannot be used on CO maps.")
  257.         return PLUGIN_HANDLED
  258.     }
  259.     preGameTimeleft = HURRYSECONDS
  260.     refresh = REFRESHSOHWNOTES
  261.     set_task(float(REFRESH_FREQ),"refreshWhatever",taskId,_,_,"b")
  262.     server_cmd("mp_tournamentmode 1")
  263.     server_cmd("mp_countdowntime .20")
  264.     server_cmd("mp_timelimit 45")
  265.     server_cmd("meta unload Oddman.dll")
  266.     if (isRoundTwo) server_cmd("amx_att Captains Game: return to the readyroom to pick teams.")
  267.     return PLUGIN_HANDLED
  268. }
  269.  
  270. public client_authorized(id){
  271.     g_Team[id] = 0
  272. }
  273.  
  274. public client_putinserver(id) {
  275.     if (isCaptainsMode()) {
  276.         client_print(id, print_chat, "[CAPTAINS] You're joining a captains game.  Please ASK FOR ORDERS when you join a team.")
  277.     }
  278. }
  279.  
  280. public client_disconnect(id) {
  281.     if (isCaptainsMode()) {
  282.         if (g_Team[id] != 0) {
  283.             for (new i = 1; i <= g_maxPlayers; ++i) {
  284.                 if (is_user_connected(i) && g_Team[id] == g_Team[i] && strlen(notes[id]) > 0) {
  285.                     client_print(i, print_chat, "%s Teammate with note '%s' has left the server.", CHAT_TAG, notes[id])
  286.                 }
  287.             }
  288.         }
  289.         g_Team[id] = -1
  290.         if (captain1id == id) {
  291.             captain1id = -1
  292.             announceCaptDisc()
  293.         }
  294.         else if (captain2id == id) {
  295.             captain2id = -1
  296.             announceCaptDisc()
  297.         }
  298.     }
  299. }
  300.  
  301. public announceCaptDisc() {
  302.     client_print(0, print_chat, "%s A captain has left the server.", CHAT_TAG)
  303. }
  304.  
  305. public client_changeteam(id,newteam,oldteam) {
  306.     g_Team[id] = newteam
  307.     if (isCaptain(id) && g_Team[id] != 0 && allowAttack == 0) {
  308.         allowNotesDisplay = 1
  309.     }
  310.     format(notes[id], 20, "")
  311. }
  312.  
  313. public isCaptainsMode() {
  314.     return get_cvar_num("mp_tournamentmode")
  315. }
  316.  
  317. public showNotes() {
  318.     if (allowNotesDisplay == 1 && isCaptainsMode()) {
  319.         for (new i = 1; i <= g_maxPlayers; ++i) {
  320.             if (is_user_connected(i)) {
  321.                 showTeamNotes(i, g_Team[i], 9999)
  322.             }
  323.         }
  324.     }
  325. }
  326.  
  327. public hideNotes() {
  328.     for (new i = 1; i <= g_maxPlayers; ++i) {
  329.         if (is_user_connected(i)) {
  330.             client_print(i, print_chat, "%s Say /notes to view the captain's notes.", CHAT_TAG)
  331.             set_hudmessage(0,255,0, 0.028, 0.15, 0, 0.5, 1.0, 0.5, 0.5, HUD_CHANNEL)
  332.             show_hudmessage(i, " ")
  333.         }
  334.     }
  335. }
  336.  
  337. public showTeamNotes(id, team, duration) {
  338.     if (team == 0) {
  339.         showCaptains(id, duration)
  340.     }
  341.     else {
  342.         new notes[254]
  343.         buildTeamNotes(team, notes)
  344.         set_hudmessage(0,255,0, 0.028, 0.15, 0, 0.5, float(duration), 0.5, 0.5, HUD_CHANNEL)
  345.         show_hudmessage(id, notes)
  346.     }
  347. }
  348.  
  349. public showCaptains(id, duration) {
  350.     if (g_Team[id] == 0) {
  351.         new notes[254] = "", playername[35]
  352.         for (new i = 1; i <= g_maxPlayers; ++i) {
  353.             if (isCaptain(i)) {
  354.                 get_user_name(i, playername, 33)
  355.                 format(playername, 34, "%s*", playername)
  356.                 format(notes, 250, "%s%s", notes, playername)
  357.                 trim(notes)
  358.                 format(notes, 250, "%s^n", notes)
  359.             }
  360.         }
  361.         set_hudmessage(0,255,0, 0.028, 0.35, 0, 0.5, float(duration), 0.5, 0.5, HUD_CHANNEL)
  362.         show_hudmessage(id, notes)
  363.     }
  364. }
  365.  
  366. public buildTeamNotes(team, notesTable[]) {
  367.     new playername[16]
  368.     new notesLine[37]
  369.     for (new i = 1; i <= g_maxPlayers; ++i) {
  370.         if (g_Team[i] == team) {
  371.             get_user_name(i, playername, 14)
  372.             if (isCaptain(i)) {
  373.                 format(playername, 15, "%s*", playername)
  374.             }
  375.             format(notesLine, 35, "%s: %s", playername, notes[i])
  376.             trim(notesLine)
  377.             format(notesLine, 36, "%s^n", notesLine)
  378.             add(notesTable, 254, notesLine, 254-strlen(notesLine))
  379.         }
  380.     }
  381.     if (allowAttack == 0) {
  382.         new timeleft[8], seconds
  383.         if (team == 1) seconds = preGameTimeleft
  384.         else if (team == 2) seconds = preGameTimeleft
  385.         if (seconds >= HURRYSECONDS) format(timeleft, 7, "unknown")
  386.         else if (seconds > 0) {
  387.             new minutes
  388.             minutes = seconds / 60
  389.             seconds = seconds - (minutes * 60)
  390.             format(timeleft, 7, "%dm%ds", minutes, seconds)
  391.         }
  392.         else {
  393.             format(timeleft, 7, "unknown")
  394.             readyTeam(team)
  395.         }
  396.         format(notesLine, 35, "Pre-game time remaining: %s", timeleft)
  397.         trim(notesLine)
  398.         format(notesLine, 36, "%s^n", notesLine)
  399.         add(notesTable, 254, notesLine, 254-strlen(notesLine))
  400.     }
  401. }
  402.  
  403. public readyTeam(team) {
  404.     if (team==1) client_cmd(captain1id, "say ready")
  405.     else if (team==2) client_cmd(captain2id, "say ready")
  406.     remove_task(taskId)
  407. }
  408.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement