/* Formatright © 2011, ConnorMcLeod
This plugin 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 this plugin; 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.2"
#define PLUGIN "Cut the right wire"
#if !defined Ham_CS_Player_ResetMaxSpeed
#define Ham_CS_Player_ResetMaxSpeed Ham_Item_PreFrame
#endif
#define m_iTeam 114
#define TEAM_CT 2
#define get_player_team(%0) get_pdata_int(%0,m_iTeam)
new g_iMaxPlayers
#define IsPlayer(%0) ( 1 <= %0 <= g_iMaxPlayers )
const g_iKeys = MENU_KEY_1|MENU_KEY_2|MENU_KEY_3|MENU_KEY_4|MENU_KEY_5
const HasDefuser = (1<<16)
#define has_user_defuser(%0) ( get_pdata_int(%0,193) & HasDefuser )
const IsDefusing = (1<<8)
#define is_user_defusing(%0) ( get_pdata_int(%0,232) & IsDefusing )
#define m_pActiveItem 373
// c4 offsets, linux diff is default 5
#define m_fC4State 96
const C4_START_DEFUSE = (1<<0)
const C4_PLANTED = (1<<8)
#define is_c4_planted(%0) ( get_pdata_int(%0, m_fC4State) & C4_PLANTED )
#define is_c4_being_defused(%0) get_pdata_int(%0, m_fC4State) & C4_START_DEFUSE
#define m_flDefuseCountDown 99
#define m_flC4Blow 100
// weapons(_c4) offsets
#define XO_WEAPON 4
#define m_pPlayer 41
#define m_fBombState 78
const C4_STARTED_ARMING = (1<<0)
#define is_c4_being_armed(%0) get_pdata_int(%0,m_fBombState,XO_WEAPON) & C4_STARTED_ARMING
#define m_flArmedTime 79
new g_iBarTime
new g_iWire, g_iC4, g_iDefuser, g_iPlanter
new g_iPlantMenuIndex, g_iDefuseMenuIndex
public plugin_init()
{
register_plugin(PLUGIN, VERSION, "ConnorMcLeod")
register_event("HLTV", "Event_HLTV_New_Round", "a", "1=0", "2=0")
register_event("BarTime", "Event_BarTime_Reset", "be", "1=0")
RegisterHam(Ham_Use, "grenade", "CGrenade_Use", 1)
RegisterHam(Ham_Weapon_PrimaryAttack, "weapon_c4", "CC4_PrimaryAttack", 1)
g_iMaxPlayers = get_maxplayers()
g_iBarTime = get_user_msgid("BarTime")
g_iDefuseMenuIndex = register_menuid("Cut a Wire" , 0)
register_menucmd(g_iDefuseMenuIndex, g_iKeys, "DefuseWireMenuCallBack")
g_iPlantMenuIndex = register_menuid("\wChoose a wire")
register_menucmd(g_iPlantMenuIndex, g_iKeys, "PlantWireMenuCallBack")
}
public Event_HLTV_New_Round()
{
g_iDefuser = 0
g_iC4 = 0
g_iPlanter = 0
}
public Event_BarTime_Reset( id )
{
if( id == g_iDefuser )
{
g_iDefuser = 0
new menuid, keys
get_user_menu(id, menuid, keys)
if( menuid == g_iDefuseMenuIndex )
{
show_menu(id, 0, " ", 1)
}
}
if( id == g_iPlanter )
{
new menuid, keys
get_user_menu(id, menuid, keys)
if( menuid == g_iPlantMenuIndex )
{
show_menu(id, 0, " ", 1)
}
}
}
public CGrenade_Use(c4, id)
{
if( !g_iDefuser && IsPlayer(id) && get_player_team(id) == TEAM_CT && is_c4_planted(c4) && is_c4_being_defused(c4) && is_user_defusing(id) )
{
g_iDefuser = id
g_iC4 = c4
show_menu
(
id,
g_iKeys,
"\wCut a Wire:^n\
Ignore this to defuse normally^n^n\
\
Get it right and the bomb is defused^n\
Get it wrong and the bomb normally explodes^n\
With no defuse kit you have 50%%\
chance of the bomb exploding^n\
even if you choose the right wire^n^n\
\
\y1. Blue^n\
2. Yellow^n\
3. Red^n\
4. Green^n^n\
\
5. Exit",
floatround( get_pdata_float(c4, m_flDefuseCountDown) - get_gametime() )
)
}
}
public DefuseWireMenuCallBack(id, key)
{
if( key == 4 )
{
return PLUGIN_HANDLED
}
message_begin(MSG_ONE, g_iBarTime, .player=id)
write_short(0)
message_end()
if( key != g_iWire || (!has_user_defuser(id) && random(100) < 50) )
{
set_pdata_float(g_iC4, m_flC4Blow, get_gametime())
dllfunc(DLLFunc_Think, g_iC4)
}
else
{
set_pdata_float(g_iC4, m_flDefuseCountDown, 0.0)
dllfunc(DLLFunc_Think, g_iC4)
}
new item = get_pdata_cbase(id, m_pActiveItem)
if( item > 0 )
{
ExecuteHamB(Ham_Item_Deploy, item)
}
return PLUGIN_HANDLED
}
public CC4_PrimaryAttack( c4 )
{
static id
id = get_pdata_cbase(c4, m_pPlayer, XO_WEAPON)
if( is_c4_being_armed( c4 ) )
{
if( id != g_iPlanter )
{
g_iPlanter = id
new Float:flTime = get_pdata_float(c4, m_flArmedTime, XO_WEAPON) - get_gametime()
show_menu
(
id,
g_iKeys,
"\wChoose a wire^n^n\
\
The CTs can try guess this for an instant defuse^n\
Exit, or ignore this for a random wire^n^n\
\
\y1. Blue^n\
2. Yellow^n\
3. Red^n\
4. Green^n^n\
\
5. Exit",
floatround(flTime)
)
set_task(flTime, "Task_ChooseForMe", id)
}
}
else if( id == g_iPlanter )
{
g_iPlanter = 0
}
}
public Task_ChooseForMe( id )
{
if( id == g_iPlanter )
{
g_iWire = random_num(0, 3)
}
}
public PlantWireMenuCallBack( id , key )
{
if( key != 4 )
{
g_iWire = key
}
else
{
g_iWire = random_num(0, 3)
}
remove_task(id)
return PLUGIN_HANDLED
}