Код
/* last update: 2/25/2014
*
* Attention: setting hp during knife round (if enabled) to bots are NOT supported!
*
* Credits:
* - Subb98 for the idea & prototype
* - ConnorMcLeod for code that forces spawning of newly connected players
* https://forums.alliedmods.net/showthread.php?p=1820862#post1820862
*
* Thanks to eX-test from CS Support Community http://c-s.net.ua/ for testing
*/
#include <amxmodx>
#include <cstrike>
#include <fakemeta>
#include <hamsandwich>
#define PLUGIN "Simple WarmUp"
#define VERSION "0.50"
#define AUTHOR "Safety1st"
// *** customizable parameters
//#define RESTART_AFTER // comment to disable restart round after warmup end
//#define KNIFE_ROUND_ONLY // uncomment to enable knife warmup round only
//#define _35HP_FOR_KNIFE_ROUND // uncomment to enable 35 hp during knife round
// *** end of customizable parameters
#define TT 1
#define CT 2
new giRoundCounter
new gMsgStatusIconReg, gMsgStatusIcon, gMsgCurWeapon
new HamHook:g_iHhCBasePlayerSpawn, HamHook:g_iHhCBasePlayerPreThink
new bool:gbWarmupActive
#if defined RESTART_AFTER
new bool:gbIgnoreRestart
#endif
// offsets
#define m_fClientMapZone 235
#define MAPZONE_BUYZONE ( 1<<0 )
enum {
ROUND_NONE,
ROUND_KNIFE,
ROUND_PISTOL
}
const m_iJoinedState = 121
const m_iMenu = 205
const MENU_CHOOSEAPPEARANCE = 3
const STATE_PICKINGCLASS = 4
public plugin_init() {
register_plugin( PLUGIN, VERSION, AUTHOR )
register_event( "TextMsg", "EventNewGame", "a", "2=#Game_will_restart_in", "2=#Game_Commencing" )
register_event( "HLTV", "EventNewRound", "a", "1=0", "2=0" )
register_event( "CurWeapon", "EventCurWeapon", "be", "1=1", "2!29" ) // specified, call if is send to alive player only
register_logevent( "EventRoundEnd", 2, "1=Round_End" )
gMsgStatusIcon = get_user_msgid( "StatusIcon" )
gMsgCurWeapon = get_user_msgid( "CurWeapon" )
DisableHamForward( g_iHhCBasePlayerSpawn = RegisterHam( Ham_Spawn, "player", "OnCBasePlayer_Spawn_Post", 1 ) )
DisableHamForward( g_iHhCBasePlayerPreThink = RegisterHam( Ham_Player_PreThink, "player", "OnCBasePlayer_PreThink_Post", 1 ) )
register_clcmd( "menuselect", "ClCmd_MenuSelect_JoinClass" )
register_clcmd( "joinclass", "ClCmd_MenuSelect_JoinClass" )
}
public EventNewGame() {
#if defined RESTART_AFTER
if( gbIgnoreRestart ) {
// it is planned
gbIgnoreRestart = false
return
}
#endif
if( !gbWarmupActive ) {
// we don't have active 'hooks' for now
gMsgStatusIconReg = register_message( gMsgStatusIcon, "MessageStatusIcon" )
EnableHamForward( g_iHhCBasePlayerSpawn )
gbWarmupActive = true
}
giRoundCounter = ROUND_NONE
}
public EventNewRound() {
if( !gbWarmupActive )
return
giRoundCounter++
}
public OnCBasePlayer_Spawn_Post(id) {
if( !is_user_alive(id) )
return
switch( giRoundCounter ) {
#if defined _35HP_FOR_KNIFE_ROUND
case ROUND_KNIFE : set_pev( id, pev_health, 35.0 )
#endif
case ROUND_PISTOL: {
switch( get_user_team(id) ) {
case TT: cs_set_user_bpammo( id, CSW_GLOCK18, 120 )
case CT: cs_set_user_bpammo( id, CSW_USP, 100 )
}
}
}
}
public EventCurWeapon(id) {
if( !gbWarmupActive )
return
switch( giRoundCounter ) {
case ROUND_KNIFE : {
if( read_data(2) /* weapon id */ != CSW_C4 )
SetKnife(id)
}
case ROUND_PISTOL: {
switch( read_data(2) ) {
case CSW_GLOCK18, CSW_USP, CSW_C4 : return
}
SetKnife(id)
}
}
}
SetKnife(id) {
engclient_cmd( id, "weapon_knife" )
// update info about weapon
emessage_begin( MSG_ONE, gMsgCurWeapon, _, id )
ewrite_byte(1) // active
ewrite_byte(CSW_KNIFE) // weapon
ewrite_byte(-1) // clip
emessage_end()
}
public MessageStatusIcon( msgid, dest, receiver ) { // Exolent[jNr]'s code
// check if status is to be shown
if( get_msg_arg_int(1) ) {
static const buyzone[] = "buyzone"
// grab what icon is being shown
new icon[ sizeof( buyzone ) + 1 ]
get_msg_arg_string( 2, icon, charsmax(icon) )
// check if buyzone icon
if( !strcmp( icon, buyzone ) ) {
// remove player's buyzone bit for the map zones
set_pdata_int( receiver, m_fClientMapZone, get_pdata_int( receiver, m_fClientMapZone ) &~ MAPZONE_BUYZONE )
// block buyzone icon
return PLUGIN_HANDLED
}
}
return PLUGIN_CONTINUE
}
public EventRoundEnd() {
if( !gbWarmupActive )
return
// remember: Round_End is fired right after Game_Commencing too
switch( giRoundCounter ) {
case ROUND_NONE: return
#if !defined KNIFE_ROUND_ONLY
case ROUND_KNIFE : return
#endif
}
gbWarmupActive = false
unregister_message( gMsgStatusIcon, gMsgStatusIconReg )
DisableHamForward( g_iHhCBasePlayerSpawn )
#if defined RESTART_AFTER
gbIgnoreRestart = true
set_cvar_num( "sv_restart", 1 )
#endif
}
public ClCmd_MenuSelect_JoinClass(id) {
if( !gbWarmupActive )
return
if( get_pdata_int(id, m_iMenu) == MENU_CHOOSEAPPEARANCE && get_pdata_int(id, m_iJoinedState) == STATE_PICKINGCLASS )
EnableHamForward( g_iHhCBasePlayerPreThink )
}
public OnCBasePlayer_PreThink_Post(id) {
DisableHamForward( g_iHhCBasePlayerPreThink )
if( !is_user_alive(id) )
ExecuteHam( Ham_Spawn, id )
}