/* Plugin generated by AMXX-Studio */
#include <amxmodx>
#include <amxmisc>
#include <engine>
#include <fakemeta>
#include <hamsandwich>
#define PLUGIN "Multiplayer Bhops [LAN Style]"
#define VERSION "0.1b"
#define AUTHOR "kraster"
#define MAXENTS 1365
new Array:entvars [MAXENTS];
new g_isAlive[33];
#define MaskEnt(%0) ( 1<<(%0 & 31) )
new g_iSpectatedId[33];
enum _:BlocksClasses
{
FUNC_DOOR
}
enum _:TOGGLE_STATE
{
TS_AT_TOP,
TS_AT_BOTTOM,
TS_GOING_UP,
TS_GOING_DOWN
}
new const GetNeededThinksFromToggleState[][] = {
{0, 2, 3, 1},
{2, 0, 1, 3},
{1, 3, 0, 2},
{3, 1, 2, 0}
}
public plugin_init ()
{
register_plugin( PLUGIN, VERSION, AUTHOR );
register_forward( FM_AddToFullPack, "fwdAddToFullPack_Post", 1 );
register_forward( FM_PlayerPreThink, "fwdPlayerPreThink_Pre", 0 );
RegisterHam( Ham_Spawn, "player", "fw_PlayerSpawn", 1 );
RegisterHam( Ham_Killed, "player", "fw_PlayerKilled", 1 );
RegisterHam( Ham_Spawn, "weaponbox", "FwdSpawnWeaponbox", 1 );
static HamHook:iHhBlockTouch[BlocksClasses];
static const szClassesAndHandlers[BlocksClasses][][] = {
{ "func_door", "Touch_Block" }
};
for ( new i; i < sizeof(iHhBlockTouch); i++ )
{
if ( iHhBlockTouch[i] )
{
EnableHamForward( iHhBlockTouch[i] );
}else {
iHhBlockTouch[i] = RegisterHam( Ham_Touch, szClassesAndHandlers[i][0], szClassesAndHandlers[i][1] );
}
}
for(new count = 0, entity = -1 ; (( entity = engfunc( EngFunc_FindEntityByString, entity, "classname", "func_door" )) > 0 ) ; count++ )
{
set_pev(entity, pev_groupinfo, -2)
}
}
public client_authorized(id)
{
set_pev(id, pev_groupinfo, MaskEnt(id)|MaskEnt(0));
}
public fw_PlayerSpawn( id )
{
g_isAlive[id] = is_user_alive( id );
//client_authorized(id)
}
public pfn_keyvalue( ent )
{
new class [1], key [32], value [32], keyvalue [64];
copy_keyvalue( class, 0, key, 32, value, 32 );
if ( !entvars [ent] )
entvars [ent] = ArrayCreate( 64, 1 );
format( keyvalue, 64, "%s*%s", key, value );
ArrayPushString( entvars [ent], keyvalue );
return(PLUGIN_CONTINUE);
}
public FwdSpawnWeaponbox( iEntity )
{
new owner = pev( iEntity, pev_owner);
set_pev( iEntity, pev_groupinfo, MaskEnt(owner))
}
public Touch_Block( iBlock, id )
{
new classname[32]
pev(id, pev_classname, classname, 31)
if(equal(classname, "weaponbox"))
{
return(HAM_IGNORED);
}
new iuser4 = pev(iBlock, pev_iuser4);
new icont2 = pev(iBlock, pev_controller_2);
new groupinfo = pev(iBlock, pev_groupinfo);
if(icont2 == id)
{
remove_task(iBlock+8910)
dllfunc(DLLFunc_Use,iBlock,id)
set_task(0.1, "DoorThink", iBlock+8910 ,.flags = "b");
return(HAM_IGNORED);
}
if(iuser4 & MaskEnt(id))
{
if(groupinfo & MaskEnt(id))
{
goto createent
return(HAM_SUPERCEDE);
}
else
{
dllfunc(DLLFunc_Use,iBlock,id)
return(HAM_IGNORED);
}
return(HAM_SUPERCEDE);
}
else
{
goto createent
return(HAM_SUPERCEDE);
}
createent:
{
groupinfo &= ~MaskEnt(id)
set_pev(iBlock, pev_groupinfo, groupinfo);
set_pev( id, pev_groupinfo, MaskEnt(id)|MaskEnt(0))
new ent = copyent( id, iBlock );
set_pev(ent, pev_groupinfo, MaskEnt(id));
iuser4 |= MaskEnt(id);
set_task(0.1, "DoorThink", ent+8910 ,.flags = "b");
set_pev(ent, pev_controller_2, id);
set_pev(ent, pev_enemy, iBlock);
set_pev(iBlock, pev_iuser4, iuser4);
dllfunc(DLLFunc_Use,ent,id)
return(HAM_SUPERCEDE);
}
}
public DoorThink(ent)
{
ent -= 8910;
static iNeedThinks[MAXENTS]
iNeedThinks[ent] = GetNeededThinksFromToggleState[ ExecuteHam(Ham_GetToggleState, ent) ][ TS_AT_TOP ]
static bool:ThinkPass[MAXENTS]
if(iNeedThinks[ent] == 0)
ThinkPass[ent] = true;
if(iNeedThinks[ent] == 2 && ThinkPass[ent])
{
ThinkPass[ent] = false;
remove_task(ent+8910);
new origblock = pev(ent, pev_enemy);
new id = pev(ent, pev_controller_2);
new groupinfo = pev(origblock, pev_groupinfo)
groupinfo |= MaskEnt(id)
new iuser4 = pev(origblock, pev_iuser4);
iuser4 &= ~MaskEnt(id);
set_pev(origblock, pev_iuser4, iuser4);
set_pev(origblock, pev_groupinfo, groupinfo);
set_pev( ent, pev_flags, FL_KILLME )
dllfunc( DLLFunc_Think, ent )
}
}
public fwdPlayerPreThink_Pre( plr )
{
if( !g_isAlive[plr] )
{
g_iSpectatedId[plr] = pev( plr, pev_iuser2 );
set_pev(plr, pev_groupinfo, MaskEnt(g_iSpectatedId[plr]))
}
else
{
if(get_user_team(plr) == 3)
{
g_isAlive[plr] = false;
}
}
}
public fwdAddToFullPack_Post( es, e, ent, host, hostflags, player, pset )
{
if(pev_valid(ent))
{
new class[32];
pev( ent, pev_classname, class, 31 );
if(equal(class, "func_door"))
{
new groupinfo = pev(ent, pev_groupinfo);
new cont2 = pev(ent, pev_controller_2)
new iuser4 = pev(ent, pev_iuser4)
if(groupinfo & MaskEnt(host))
{
if(iuser4 & MaskEnt(host))
{
set_es(es, ES_RenderMode, kRenderTransAlpha);
set_es(es, ES_RenderAmt, 0);
}
else
if(!g_isAlive[host])
{
if(iuser4 & MaskEnt(g_iSpectatedId[host]))
{
set_es(es, ES_RenderMode, kRenderTransAlpha);
set_es(es, ES_RenderAmt, 0);
}
}
return(FMRES_IGNORED);
}
if( cont2 == host)
{
return(FMRES_IGNORED);
}
if( iuser4 & MaskEnt(host))
{
set_es(es, ES_RenderMode, kRenderTransAlpha);
set_es(es, ES_RenderAmt, 0);
return(FMRES_IGNORED);
}
}
}
return(FMRES_IGNORED);
}
public copyent( id, ent )
{
new newent, keyvalue [64], key [32], value [32];
entity_get_string( ent, EV_SZ_classname, value, 32 );
newent = create_entity( value );
if ( !newent )
return(PLUGIN_HANDLED);
for ( new i = 0; i < ArraySize( entvars [ent] ); i++ )
{
ArrayGetString( entvars[ent], i, keyvalue, 64 );
strtok( keyvalue, key, 32, value, 32, '*' );
setKeyValue( newent, key, value );
}
new Float:origin [3], Float:mins[3], Float:maxs[3], Float:absmin[3], Float:absmax[3], Float:size[3];
entity_get_vector( ent, EV_VEC_mins, mins );
entity_get_vector( ent, EV_VEC_maxs, maxs );
entity_get_vector( ent, EV_VEC_absmin, absmin );
entity_get_vector( ent, EV_VEC_absmax, absmax );
entity_get_vector( ent, EV_VEC_origin, origin );
entity_get_vector( ent, EV_VEC_size, size );
entity_set_vector( newent, EV_VEC_mins, mins );
entity_set_vector( newent, EV_VEC_maxs, maxs );
entity_set_vector( newent, EV_VEC_absmin, absmin );
entity_set_vector( newent, EV_VEC_absmax, absmax );
entity_set_origin( newent, origin );
entity_set_vector( newent, EV_VEC_size, size );
DispatchSpawn( newent );
return(newent);
}
public setKeyValue( ent, key[], value[] )
{
new item, keyvalue [64];
DispatchKeyValue( ent, key, value );
if ( !entvars [ent] )
entvars [ent] = ArrayCreate( 64, 1 );
format( keyvalue, 64, "%s*%s", key, value );
if ( (item = arrayfindkey( ent, key ) ) == -1 )
ArrayPushString( entvars [ent], keyvalue );
else
ArraySetString( entvars [ent], item, keyvalue );
}
public arrayfindkey( ent, tofind[] )
{
if ( !entvars[ent] )
return(-1);
new keyvalue [64], key [32], value [32];
for ( new i = 0; i < ArraySize( entvars [ent] ); i++ )
{
ArrayGetString( entvars[ent], i, keyvalue, 64 );
strtok( keyvalue, key, 32, value, 32, '*' );
if ( equal( key, tofind ) )
return(i);
}
return(-1);
}
public client_disconnected( id )
{
g_isAlive[id] = false;
}
public fw_PlayerKilled( id )
{
g_isAlive[id] = false;
}