
/* AMX Mod script.
*
* (c) Copyright 2002, OLO
* This file is provided as is (no warranties).
*
*/

#include <amxmod>

/* To pause or unpause the server use amx_pause
*  on server console or in admin console with level "g"
*/

new pausable
new paused

public pause_success(){
	set_cvar_num("pausable",pausable)
	server_print("[AMX] Server %s", paused ? "unpaused" : "paused")
	paused = (paused) ? 0 : 1
	return PLUGIN_HANDLED
}

pause_server(id){
	pausable = get_cvar_num("pausable")
	if (!id) id = find_player("h")
	if (id){
		set_cvar_num("pausable",1)
		client_cmd(id,"pause;pause_loopback")
	}
	else
		server_print("[AMX] Server was unable to pause the game. Real players on server are needed.")
}

public admin_pause_cl(id){
	if (!(get_user_flags(id)&ADMIN_CVAR)){
		client_print(id,print_console,"[AMX] You have no access to that command")
		return PLUGIN_HANDLED
	}
	new authid[16],name[32]
	get_user_authid(id,authid,16)
	get_user_name(id,name,32)
	log_to_file("addons/amx/admin.log","^"%s<%d><%s><>^" %s server",
			name,get_user_userid(id),authid, paused ? "unpause" : "pause" )
	client_print(id,print_console,"[AMX] Server proceed pausing")
	pause_server(id)
	return PLUGIN_HANDLED
}

public admin_pause_sr()
	pause_server(0)

public plugin_init() {
	register_plugin("Admin Pause","0.6","default")
	register_clcmd("amx_pause","admin_pause_cl",ADMIN_CVAR,"amx_pause")
	register_srvcmd("amx_pause","admin_pause_sr")
	register_clcmd("pause_loopback","pause_success")
	return PLUGIN_CONTINUE
}

