/* 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.1"
#define PLUGIN "Auto Plant Bomb At Round Start"
// "player" offsets
#define m_iUserState 193 // don't name this offset OFFSET_DEFUSE_PLANT since (1<<0) is wheter player wants or not to hear radios
const hasC4 = (1<<8)
#define m_fClientMapZone 235 // m_fMapZone ??
#define m_rgpPlayerItems_Slot5 372
#define m_pActiveItem 373
// "weapon_***" offsets
#define XO_WEAPON 4
// "weapon_c4" specific offsets
#define m_fBombState 78
const C4_STARTED_ARMING = 1<<0
new Array:g_aBombSites, g_iSitesCount
new bool:g_bPlanted
public plugin_init()
{
register_plugin(PLUGIN, VERSION, "ConnorMcLeod")
static const CLASSNAME[] = "classname"
new ent = FM_NULLENT, Float:origin[3]
while( ( ent = engfunc(EngFunc_FindEntityByString, ent, CLASSNAME, "func_bomb_target") ) )
{
if( !g_aBombSites )
{
g_aBombSites = ArrayCreate(3, 2)
}
fm_get_brush_entity_origin(ent, origin)
ArrayPushArray(g_aBombSites, origin)
}
ent = FM_NULLENT
while( ( ent = engfunc(EngFunc_FindEntityByString, ent, CLASSNAME, "info_bomb_target") ) )
{
if( !g_aBombSites )
{
g_aBombSites = ArrayCreate(3, 2)
}
fm_get_brush_entity_origin(ent, origin)
ArrayPushArray(g_aBombSites, origin)
}
if( g_aBombSites )
{
register_event("HLTV", "Event_HLTV_New_Round", "a", "1=0", "2=0")
register_logevent("LogEvent_Spawned_With_The_Bomb", 3, "2=Spawned_With_The_Bomb")
register_logevent("LogEvent_Planted_The_Bomb", 3, "2=Planted_The_Bomb")
g_iSitesCount = ArraySize( g_aBombSites )
}
}
public LogEvent_Planted_The_Bomb()
{
g_bPlanted = true
}
public Event_HLTV_New_Round()
{
g_bPlanted = false
}
public LogEvent_Spawned_With_The_Bomb()
{
new szLogUser[80], szName[32]
read_logargv(0, szLogUser, charsmax(szLogUser))
parse_loguser(szLogUser, szName, charsmax(szName))
new id = get_user_index(szName)
if( is_user_alive(id) )
{
new c4 = get_pdata_cbase(id, m_rgpPlayerItems_Slot5)
if( c4 > 0 )
{
if( !g_bPlanted )
{
new flags = pev(id, pev_flags)
set_pev(id, pev_flags, flags | FL_ONGROUND)
set_pdata_int(id, m_fClientMapZone, get_pdata_int(id, m_fClientMapZone) | (1<<1))
set_pdata_int(c4, m_fBombState, get_pdata_int(c4, m_fBombState, XO_WEAPON) | C4_STARTED_ARMING, XO_WEAPON)
new Float:origin[3], Float:siteOrigin[3]
pev(id, pev_origin, origin)
ArrayGetArray(g_aBombSites, random(g_iSitesCount), siteOrigin)
set_pev(id, pev_origin, siteOrigin)
ExecuteHam(Ham_Weapon_PrimaryAttack, c4)
set_pev(id, pev_origin, origin)
set_pev(id, pev_flags, flags)
}
else
{
if( get_pdata_cbase(id, m_pActiveItem) == c4 )
{
ExecuteHam(Ham_Weapon_RetireWeapon, c4)
}
if( ExecuteHam(Ham_RemovePlayerItem, id, c4) )
{
user_has_weapon(id, CSW_C4, 0)
ExecuteHam(Ham_Item_Kill, c4)
set_pev(id, pev_body, 0)
set_pdata_int(id, m_iUserState, get_pdata_int(id, m_iUserState) & ~hasC4)
}
}
}
}
}
fm_get_brush_entity_origin(index, Float:origin[3]) {
new Float:mins[3], Float:maxs[3];
pev(index, pev_origin, origin); // this needed ???
pev(index, pev_mins, mins);
pev(index, pev_maxs, maxs);
origin[0] += (mins[0] + maxs[0]) * 0.5;
origin[1] += (mins[1] + maxs[1]) * 0.5;
origin[2] += (mins[2] + maxs[2]) * 0.5;
return 1;
}