Код:
/* Formatright © 2009, ConnorMcLeod
DeathMatch ChooseTeam is free software;
you can redistribute it and/or modify it under the terms of the
GNU General Public License as published by the Free Software Foundation.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with DeathMatch ChooseTeam; if not, write to the
Free Software Foundation, Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA.
*/
#include <amxmodx>
#include <fakemeta>
#include <hamsandwich>
#define VERSION "0.0.1"
#define MAX_PLAYERS 32
#define OFFSET_CAN_CHOOSETEAM 125
const CANT_CHOOSETEAM = 1<<8
#define AllowPlayerChooseTeam(%1) set_pdata_int(%1, OFFSET_CAN_CHOOSETEAM, get_pdata_int(%1, OFFSET_CAN_CHOOSETEAM) & ~CANT_CHOOSETEAM)
#define m_fGameHUDInitialized 349
new g_pCvarChangeTeamDelay
new Float:g_fNextGameTimeChooseTeam[MAX_PLAYERS+1]
new gmsgTextMsg
new g_bPutInSpec[MAX_PLAYERS+1]
public plugin_init()
{
register_plugin("DeathMatch ChooseTeam", VERSION, "ConnorMcLeod")
g_pCvarChangeTeamDelay = register_cvar("csdm_changeteam_minspawns", "30")
register_clcmd("chooseteam", "ClientCommand_ChooseTeam")
register_clcmd("say /spec", "ClientCommand_GoSpec")
gmsgTextMsg = get_user_msgid("TextMsg")
RegisterHam(Ham_Spawn, "player", "Player_Spawn_Post", 1)
// register_event("ShowMenu", "Event_ShowMenu_TeamSelectSpect", "b", "1=51", "2=-1", "3=0", "4=#Team_Select_Spect")
// register_event("VGUIMenu", "Event_VGUIMenu_TeamSelectSpect", "b", "1=2", "2=51"/*, "3=-1", "4=0"*/)
}
/*message_begin(MSG_ONE, get_user_msgid("ShowMenu"), {0,0,0}, 1)
write_short(51)
write_char(-1)
write_byte(0)
write_string("#Team_Select_Spect")
message_end()*/
/*message_begin(MSG_ONE, get_user_msgid("VGUIMenu"), {0,0,0}, 1)
write_byte(2)
write_short(51)
write_char(-1)
write_byte(0)
write_string(" ")
message_end()*/
public Player_Spawn_Post( id )
{
if( is_user_alive(id) )
{
set_pdata_int(id, 509, 1)
}
}
public client_putinserver(id)
{
g_bPutInSpec[id] = false
// not really fine
g_fNextGameTimeChooseTeam[id] = get_gametime() + get_pcvar_float(g_pCvarChangeTeamDelay)
}
public ClientCommand_GoSpec(id)
{
new Float:fGameTime = get_gametime()
new Float:fTimeLeft = g_fNextGameTimeChooseTeam[id] - fGameTime
if( fTimeLeft <= 0.0 )
{
g_bPutInSpec[id] = true
new bVGUI = (get_pdata_int(id, 510) & (1<<0))
set_msg_block(gmsgTextMsg, BLOCK_ONCE) // attempt to block %playername% connected in players console
dllfunc(DLLFunc_ClientPutInServer, id)
set_pdata_int(id, m_fGameHUDInitialized, 1)
set_pev(id, pev_viewmodel, 0)
engclient_cmd(id, bVGUI ? "jointeam 6" : "menuselect 6")
new const szCommand[] = "slot6"
set_task(0.1, "Task_DelayedCommand", id, szCommand, charsmax(szCommand))
g_fNextGameTimeChooseTeam[id] = fGameTime + get_pcvar_float(g_pCvarChangeTeamDelay)
}
else
{
client_print(id, print_center, "You can spec in %.0f seconds", fTimeLeft)
return PLUGIN_HANDLED
}
return PLUGIN_CONTINUE
}
/*public Event_ShowMenu_TeamSelectSpect(id)
{
if( g_bPutInSpec[id] )
{
client_cmd(id, "menuselect 6")
new szCommand[] = "slot6"
set_task(0.1, "Task_DelayedCommand", id, szCommand, 12)
g_bPutInSpec[id] = false
}
}
public Event_VGUIMenu_TeamSelectSpect(id)
{
if( g_bPutInSpec[id] )
{
client_cmd(id, "jointeam 6")
new szCommand[] = "slot6"
set_task(0.1, "Task_DelayedCommand", id, szCommand, 12)
g_bPutInSpec[id] = false
}
}*/
public Task_DelayedCommand(const szCommand[], const id)
{
if( is_user_connected(id) )
{
client_cmd(id, szCommand)
}
}
public ClientCommand_ChooseTeam( id )
{
new Float:fGameTime = get_gametime()
new Float:fTimeLeft = g_fNextGameTimeChooseTeam[id] - fGameTime
if( fTimeLeft <= 0.0 )
{
AllowPlayerChooseTeam(id)
g_fNextGameTimeChooseTeam[id] = fGameTime + get_pcvar_float(g_pCvarChangeTeamDelay)
}
else
{
client_print(id, print_center, "You can choose a team in %.0f seconds", fTimeLeft)
return PLUGIN_HANDLED
}
return PLUGIN_CONTINUE
}