PHP Code:
#include <amxmodx>
#include <objective_reset>
#define PLUGIN "Pause Round"
#define VERSION "1.0"
#define AUTHOR "author"
#define TASK_PAUSE 2301031
new bool:g_bPaused, bool:g_bPauseAsked, g_bIsFreezeTime
new g_iPauses[2], g_iLastPause[2], g_iTeam, g_iCountDown
new pCvarPauseTime, pCvarMaxPauses, pCvarPauseDelay
public plugin_init()
{
register_plugin(PLUGIN, VERSION, AUTHOR)
pCvarMaxPauses = register_cvar("pause_maxpauses_perteam", "3")
pCvarPauseTime = register_cvar("pause_pausetime", "60")
pCvarPauseDelay = register_cvar("pause_pausedelay", "120")
register_logevent("RoundStart", 2, "1=Round_Start")
register_event("HLTV", "NewRound", "a", "1=0", "2=0")
register_clcmd("say /pause", "cmdPause")
register_clcmd("say /unpause", "cmdUnpause")
}
public RoundStart()
{
g_bIsFreezeTime = false
}
public NewRound()
{
g_bIsFreezeTime = true
if(g_bPauseAsked)
{
pauseGame()
}
}
public cmdPause(id)
{
new iUserTeam = get_user_team(id), iTeam = (iUserTeam - 1)
if(iUserTeam >= 3)
{
client_print(id, print_chat, "[AMXX]: You cannot use this command while spectating.")
return PLUGIN_HANDLED
}
if(g_bPaused)
{
client_print(id, print_chat, "[AMXX]: The game is already paused.")
return PLUGIN_HANDLED
}
if(g_bPauseAsked)
{
client_print(id, print_chat, "[AMXX]: The %s already asked the pause.", g_iTeam ? "Counter-Terrorists" : "Terrorists")
return PLUGIN_HANDLED
}
if(g_iPauses[(g_iTeam = iTeam)] == get_pcvar_num(pCvarMaxPauses))
{
client_print(id, print_chat, "[AMXX]: Your team cannot pause anymore.")
return PLUGIN_HANDLED
}
new iSystime = get_systime()
if(iSystime < g_iLastPause[iTeam])
{
new iMath = (g_iLastPause[iTeam] - iSystime)
if(iMath < get_pcvar_num(pCvarPauseDelay))
{
client_print(id, print_chat, "[AMXX]: Your team must wait %d second%s to ask a pause again.", iMath, (iMath > 1) ? "s" : "")
return PLUGIN_HANDLED
}
}
new szName[32]
get_user_name(id, szName, charsmax(szName))
client_print(id, print_chat, "[AMXX]: Player %s wants to pause the game.", szName)
g_bPauseAsked = true
if(g_bIsFreezeTime)
{
pauseGame()
}
else
{
client_print(id, print_chat, "[AMXX]: The game will be paused during the freezetime.")
}
return PLUGIN_HANDLED
}
public cmdUnpause(id)
{
if(get_user_team(id) > 2)
{
client_print(id, print_chat, "[AMXX]: You cannot use this command while spectating.")
return PLUGIN_HANDLED
}
if(!g_bPaused)
{
client_print(id, print_chat, "[AMXX]: The game is not paused.")
return PLUGIN_HANDLED
}
new szName[32]
get_user_name(id, szName, charsmax(szName))
client_print(id, print_chat, "[AMXX]: Player %s unpaused the game.", szName)
unpauseGame()
return PLUGIN_HANDLED
}
pauseGame()
{
new iCvarPauseTime = get_pcvar_num(pCvarPauseTime), iCvarMaxPauses = get_pcvar_num(pCvarMaxPauses)
g_bPaused = true
g_bPauseAsked = false
g_iPauses[g_iTeam]++
g_iCountDown = iCvarPauseTime
new szTeam[19];szTeam = g_iTeam ? "Counter-Terrorists" : "Terrorists"
client_print(0, print_chat, "[AMXX]: Game paused by %s.", szTeam)
new szMessage[32]
if(g_iPauses[g_iTeam] < iCvarMaxPauses)
{
formatex(szMessage, charsmax(szMessage), "They still have %d pauses left.", (iCvarMaxPauses - g_iPauses[g_iTeam]))
}
else
{
formatex(szMessage, charsmax(szMessage), "They have not pauses to ask anymore.")
}
client_print(0, print_chat, "[AMXX]: %s", szMessage)
client_print(0, print_chat, "[AMXX]: The %s have %d second%s to unpause the game.", szTeam, iCvarPauseTime, (iCvarPauseTime > 1) ? "s" : "")
set_task(1.0, "setPause", TASK_PAUSE, .flags = "b")
}
unpauseGame()
{
g_iLastPause[g_iTeam] = get_systime() + get_pcvar_num(pCvarPauseDelay)
g_bPaused = false
g_iTeam = 0
g_iCountDown = 0
remove_task(TASK_PAUSE)
}
public setPause()
{
set_hudmessage(255, 255, 255, -1.0, 0.3, 0, 1.0, 1.0)
show_hudmessage(0, "GAME PAUSED")
SetRoundTime(1, 1)
new szTeam[19];szTeam = g_iTeam ? "Counter-Terrorists" : "Terrorists"
if(g_iCountDown == (get_pcvar_num(pCvarPauseTime) / 2))
{
client_print(0, print_chat, "[AMXX]: The %s team have %d seconds left to unpause.", szTeam, (get_pcvar_num(pCvarPauseTime) / 2))
}
else if(g_iCountDown == 0)
{
unpauseGame()
client_print(0, print_chat, "[AMXX]: The %s team pause time has ended.", szTeam)
}
g_iCountDown--
}