Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <amxmodx>
- #include <amxmisc>
- #include <ns2amx>
- #include <engine>
- #define PLUGIN "Captains Game"
- #define VERSION "0.1"
- #define AUTHOR "Wyzcrak"
- #define CHAT_TAG "[CAPTAINS]"
- #define HUD_CHANNEL 2 // 1-4 imessage(1) ScrollMsg(2) AlienUpgInfo(3)
- #define REFRESH_FREQ 1
- #define HURRYSECONDS 180
- #define REFRESHHURRYMARINES 1
- #define REFRESHHURRYALIENS 2
- #define REFRESHSOHWNOTES 3
- new allowNotesDisplay = 1
- new captain1id
- new captain2id
- new g_maxPlayers
- new g_Team[33]
- new notes[33][21]
- new taskId = 22337
- new preGameTimeleft
- new bool:isRoundTwo
- new refresh
- public plugin_init() {
- register_plugin(PLUGIN, VERSION, AUTHOR)
- captain1id = -1
- captain2id = -1
- register_clcmd("say","handleSay")
- register_clcmd("say_team","handleSayTeam")
- register_concmd("captains","config",ADMIN_KICK,"- configures the server for Captains Games")
- register_event("Countdown", "do_roundbegin", "a")
- register_event("GameStatus", "do_roundend","ab","1=2")
- g_maxPlayers = get_maxplayers()
- isRoundTwo = false
- return PLUGIN_CONTINUE
- }
- public refreshWhatever() {
- if (refresh == REFRESHHURRYMARINES) hurryMarines()
- else if (refresh == REFRESHHURRYALIENS) hurryAliens()
- else showNotes()
- }
- public handleSay(id) {
- if (isCaptainsMode() && allowNotesDisplay == 1) {
- new saytext[80]
- read_args(saytext, 79)
- remove_quotes(saytext)
- if (equal(saytext, "<", 1) || contain(saytext, "/note ") == 0 || contain(saytext, "/notes") == 0) {
- client_print(id, print_chat, "%s Manage notes with teamsay.", CHAT_TAG)
- return PLUGIN_HANDLED
- }
- else if (contain(saytext, "/captain") == 0) {
- makeCaptain(id)
- return PLUGIN_CONTINUE
- }
- else if (contain(saytext, "ready") == 0) {
- if ((captain1id != id) && (captain2id != id)) {
- client_print(id, print_chat, "%s Only the team captain should ready/notready the team.", CHAT_TAG)
- return PLUGIN_HANDLED
- }
- if (preGameTimeleft == HURRYSECONDS) {
- if (g_Team[id]==1) hurryTeam(2, id)
- else if (g_Team[id]==2) hurryTeam(1, id)
- }
- return PLUGIN_CONTINUE
- }
- else if (contain(saytext, "notready") == 0) {
- if ((captain1id != id) && (captain2id != id)) {
- client_print(id, print_chat, "%s Only the team captain should ready/notready the team.", CHAT_TAG)
- return PLUGIN_HANDLED
- }
- if (g_Team[id]==1) unhurryTeam(2)
- else if (g_Team[id]==2) unhurryTeam(1)
- return PLUGIN_CONTINUE
- }
- else {
- return PLUGIN_CONTINUE
- }
- }
- return PLUGIN_CONTINUE
- }
- public hurryTeam(team, id) {
- remove_task(taskId)
- if (team == 1) {
- refresh = REFRESHHURRYMARINES
- }
- else if (team == 2) {
- refresh = REFRESHHURRYALIENS
- }
- }
- public unhurryTeam(team) {
- remove_task(taskId)
- preGameTimeleft = HURRYSECONDS
- showNotes()
- }
- public hurryMarines() {
- preGameTimeleft = preGameTimeleft - 1
- showNotes()
- }
- public hurryAliens() {
- preGameTimeleft = preGameTimeleft - 1
- showNotes()
- }
- public handleSayTeam(id) {
- if (isCaptainsMode()) {
- new saytext[80]
- read_args(saytext, 79)
- remove_quotes(saytext)
- if (equal(saytext, "<", 1)) {
- replace(saytext, 254, "<", "")
- trim(saytext)
- new playername[80]
- get_user_name(id, playername, 79)
- assignNote(id, playername, saytext)
- return PLUGIN_HANDLED
- }
- if (contain(saytext, "/note ") == 0) {
- replace(saytext, 254, "/note ", "")
- new playername[80], note[21]
- new firstspace = contain(saytext," ")
- strbreak(saytext, playername, firstspace, note, 20)
- assignNote(id, playername, note)
- return PLUGIN_HANDLED
- }
- else if (contain(saytext, "/captain") == 0) {
- makeCaptain(id)
- return PLUGIN_CONTINUE
- }
- else if (contain(saytext, "/notes") == 0) {
- showTeamNotes(id, g_Team[id], 15)
- return PLUGIN_HANDLED
- }
- else if (contain(saytext, "ready") == 0) {
- if ((captain1id != id) && (captain2id != id)) {
- client_print(id, print_chat, "[CAPTAINS] Only the team captain should ready/notready the team.")
- return PLUGIN_HANDLED
- }
- return PLUGIN_CONTINUE
- }
- else if (contain(saytext, "notready") == 0) {
- if ((captain1id != id) && (captain2id != id)) {
- client_print(id, print_chat, "[CAPTAINS] Only the team captain should ready/notready the team.")
- return PLUGIN_HANDLED
- }
- if (g_Team[id]==1) unhurryTeam(2)
- else if (g_Team[id]==2) unhurryTeam(1)
- return PLUGIN_CONTINUE
- }
- else {
- return PLUGIN_CONTINUE
- }
- }
- return PLUGIN_CONTINUE
- }
- public assignNote(id, target[], note[]) {
- if (isCaptainsMode()) {
- if (g_Team[id] != 0) {
- new player = cmd_target(id,target,1)
- if (player && (g_Team[id] == g_Team[player])) {
- if (player == id || isCaptain(id)) {
- format(notes[player], 20, "%s", note)
- }
- else {
- client_print(id, print_chat, "%s Only captains may set others' notes. You may only set your own.")
- }
- }
- else {
- client_print(id, print_chat, "%s '%s' does not uniquely match a teammate. Try again.", CHAT_TAG, target)
- }
- }
- else {
- client_print(id, print_chat, "%s You must be on a team to use this command.")
- }
- }
- else {
- client_print(id, print_chat, "%s Captains mode is not enabled.")
- }
- }
- public makeCaptain(id) {
- if (isCaptainsMode()) {
- if (g_Team[id] == 0) {
- if (isCaptain(id)) {
- client_print(id, print_chat, "%s You are already a captain.", CHAT_TAG)
- }
- else {
- if (captain1id == -1) {
- captain1id = id
- }
- else if (captain2id == -1) {
- captain2id = id
- }
- if (isCaptain(id)) {
- new name[40]
- get_user_name(id, name, 39)
- client_print(0, print_chat, "%s %s is a captain.", CHAT_TAG, name)
- }
- else {
- client_print(id, print_chat, "%s Two captains already exist. You are not a captain.", CHAT_TAG)
- }
- }
- }
- else {
- client_print(id, print_chat, "%s This command must be used from the readyroom", CHAT_TAG)
- }
- }
- else {
- client_print(id, print_chat, "%s Captains mode is not enabled.")
- }
- }
- public isCaptain(id) {
- return (captain1id == id || captain2id == id)
- }
- public do_roundbegin() {
- remove_task(taskId)
- if (isCaptainsMode()) {
- allowNotesDisplay = 0
- hideNotes()
- }
- }
- public do_roundend() {
- if (isCaptainsMode()) {
- remove_task(taskId)
- set_task(12.0, "config", taskId)
- isRoundTwo = true
- }
- }
- public config(id, level, cid) {
- if (!cmd_access(id,level,cid,1)) {
- return PLUGIN_HANDLED
- }
- if (ns_is_combat()) {
- console_print(id, "%s This command cannot be used on CO maps.")
- return PLUGIN_HANDLED
- }
- preGameTimeleft = HURRYSECONDS
- refresh = REFRESHSOHWNOTES
- set_task(float(REFRESH_FREQ),"refreshWhatever",taskId,_,_,"b")
- server_cmd("mp_tournamentmode 1")
- server_cmd("mp_countdowntime .20")
- server_cmd("mp_timelimit 45")
- server_cmd("meta unload Oddman.dll")
- if (isRoundTwo) server_cmd("amx_att Captains Game: return to the readyroom to pick teams.")
- return PLUGIN_HANDLED
- }
- public client_authorized(id){
- g_Team[id] = 0
- }
- public client_putinserver(id) {
- if (isCaptainsMode()) {
- client_print(id, print_chat, "[CAPTAINS] You're joining a captains game. Please ASK FOR ORDERS when you join a team.")
- }
- }
- public client_disconnect(id) {
- if (isCaptainsMode()) {
- if (g_Team[id] != 0) {
- for (new i = 1; i <= g_maxPlayers; ++i) {
- if (is_user_connected(i) && g_Team[id] == g_Team[i] && strlen(notes[id]) > 0) {
- client_print(i, print_chat, "%s Teammate with note '%s' has left the server.", CHAT_TAG, notes[id])
- }
- }
- }
- g_Team[id] = -1
- if (captain1id == id) {
- captain1id = -1
- announceCaptDisc()
- }
- else if (captain2id == id) {
- captain2id = -1
- announceCaptDisc()
- }
- }
- }
- public announceCaptDisc() {
- client_print(0, print_chat, "%s A captain has left the server.", CHAT_TAG)
- }
- public client_changeteam(id,newteam,oldteam) {
- g_Team[id] = newteam
- if (isCaptain(id) && g_Team[id] != 0 && allowAttack == 0) {
- allowNotesDisplay = 1
- }
- format(notes[id], 20, "")
- }
- public isCaptainsMode() {
- return get_cvar_num("mp_tournamentmode")
- }
- public showNotes() {
- if (allowNotesDisplay == 1 && isCaptainsMode()) {
- for (new i = 1; i <= g_maxPlayers; ++i) {
- if (is_user_connected(i)) {
- showTeamNotes(i, g_Team[i], 9999)
- }
- }
- }
- }
- public hideNotes() {
- for (new i = 1; i <= g_maxPlayers; ++i) {
- if (is_user_connected(i)) {
- client_print(i, print_chat, "%s Say /notes to view the captain's notes.", CHAT_TAG)
- set_hudmessage(0,255,0, 0.028, 0.15, 0, 0.5, 1.0, 0.5, 0.5, HUD_CHANNEL)
- show_hudmessage(i, " ")
- }
- }
- }
- public showTeamNotes(id, team, duration) {
- if (team == 0) {
- showCaptains(id, duration)
- }
- else {
- new notes[254]
- buildTeamNotes(team, notes)
- set_hudmessage(0,255,0, 0.028, 0.15, 0, 0.5, float(duration), 0.5, 0.5, HUD_CHANNEL)
- show_hudmessage(id, notes)
- }
- }
- public showCaptains(id, duration) {
- if (g_Team[id] == 0) {
- new notes[254] = "", playername[35]
- for (new i = 1; i <= g_maxPlayers; ++i) {
- if (isCaptain(i)) {
- get_user_name(i, playername, 33)
- format(playername, 34, "%s*", playername)
- format(notes, 250, "%s%s", notes, playername)
- trim(notes)
- format(notes, 250, "%s^n", notes)
- }
- }
- set_hudmessage(0,255,0, 0.028, 0.35, 0, 0.5, float(duration), 0.5, 0.5, HUD_CHANNEL)
- show_hudmessage(id, notes)
- }
- }
- public buildTeamNotes(team, notesTable[]) {
- new playername[16]
- new notesLine[37]
- for (new i = 1; i <= g_maxPlayers; ++i) {
- if (g_Team[i] == team) {
- get_user_name(i, playername, 14)
- if (isCaptain(i)) {
- format(playername, 15, "%s*", playername)
- }
- format(notesLine, 35, "%s: %s", playername, notes[i])
- trim(notesLine)
- format(notesLine, 36, "%s^n", notesLine)
- add(notesTable, 254, notesLine, 254-strlen(notesLine))
- }
- }
- if (allowAttack == 0) {
- new timeleft[8], seconds
- if (team == 1) seconds = preGameTimeleft
- else if (team == 2) seconds = preGameTimeleft
- if (seconds >= HURRYSECONDS) format(timeleft, 7, "unknown")
- else if (seconds > 0) {
- new minutes
- minutes = seconds / 60
- seconds = seconds - (minutes * 60)
- format(timeleft, 7, "%dm%ds", minutes, seconds)
- }
- else {
- format(timeleft, 7, "unknown")
- readyTeam(team)
- }
- format(notesLine, 35, "Pre-game time remaining: %s", timeleft)
- trim(notesLine)
- format(notesLine, 36, "%s^n", notesLine)
- add(notesTable, 254, notesLine, 254-strlen(notesLine))
- }
- }
- public readyTeam(team) {
- if (team==1) client_cmd(captain1id, "say ready")
- else if (team==2) client_cmd(captain2id, "say ready")
- remove_task(taskId)
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement