#include < amxmodx >
#include < amxmisc >
#include < hamsandwich >
#include < cstrike >
#include < engine >
#include < fakemeta_util >
#include < zombienightmare >
// from fakemeta util by VEN
#define fm_find_ent_by_class(%1,%2) engfunc(EngFunc_FindEntityByString, %1, "classname", %2)
#define fm_remove_entity(%1) engfunc(EngFunc_RemoveEntity, %1)
new const Float: BARICADE_MINSIZE[] = { -30.0, -30.0, -30.0 };
new const Float: BARICADE_MAXSIZE[] = { 30.0, 30.0, 30.0 };
new const Float: HealthBr[] = { 1500.0 };
new szModels[][] =
{
"models/ls_sandbags.mdl"
}
new const Class_Name[] = "Barricade"
new const Class_Name_Fake[] = "Barricade_fake"
new CanBePlaced[ 33 ], szBarricade[ 33 ], PlayerOwner[ 33 ], sz_Br[ 33 ], sz_LastHud[ 33 ], szItem, g_iMaxPlayers;
new Float:szOrigin[ 3 ];
public plugin_precache() {
for( new i;i < sizeof szModels;i++ )
engfunc( EngFunc_PrecacheModel, szModels[i] );
}
public plugin_init() {
register_plugin(
"[ZN] Addon: Barricade",
"0.1 (Beta)",
"Kulogram"
);
register_event("HLTV","event_newround", "a","1=0", "2=0");
register_think( Class_Name_Fake, "ThinkBarricade" );
register_forward( FM_OnFreeEntPrivateData, "OnFreeEntPrivateData" );
RegisterHam( Ham_Spawn, "player", "fw_PlayerSpawn_Post", 1 );
RegisterHam( Ham_TakeDamage,"func_wall","fw_TakeDamage" );
RegisterHam( Ham_Killed, "func_wall", "fw_PlayerKilled", 1 );
//BarTime = get_user_msgid( "BarTime" );
szItem = zp_register_extra_item( "Barricade", 10, ZP_TEAM_HUMAN );
}
public fw_TakeDamage( victim, inflictor, attacker, Float:damage, damage_type, pPlayer ) {
new sz_classname[ 32 ]
if( !equali( sz_classname, Class_Name ) )
return HAM_IGNORED;
if( zp_get_user_zombie( attacker ) )
return HAM_IGNORED;
new Float:szHealth;
pev( victim, pev_health, szHealth );
szHealth -= damage;
if ( szHealth <= 0.0 ) {
client_printcolor( pPlayer, "!y[!gZN!y] Твой объект уничтожен" );
}
else if( szHealth < 400.0 ) {
fm_set_rendering( victim, kRenderFxGlowShell, 255, 10, 10, kRenderNormal, 16) // Если меньше 400 хп у баррикады, она будет выделена Красным.
client_printcolor( pPlayer, "!y[!gZN!y] Твоей баррикаде осталось менее 400 хп" );
}
else if( szHealth < 950.0 ) {
fm_set_rendering( victim, kRenderFxGlowShell, 255, 200, 100, kRenderNormal, 16) // Если меньше 950 хп у баррикады, она будет выделена Желтым.
client_printcolor( pPlayer, "!y[!gZN!y] Твоей баррикаде осталось менее 950 хп" );
}
else if( szHealth < 1450.0 ) {
fm_set_rendering( victim, kRenderFxGlowShell, 10, 255, 10, kRenderNormal, 16) // Если меньше 1450 хп у баррикады, она будет выделена Зеленым.
client_printcolor( pPlayer, "!y[!gZN!y] Твоей баррикаде осталось менее 1450 хп" );
}
return HAM_SUPERCEDE;
}
public fw_PlayerKilled( victim, attacker, shouldgib, pPlayer ) {
new sz_classname[ 32 ], Float:health;
entity_get_string( victim , EV_SZ_classname , sz_classname, charsmax( sz_classname ) )
health = entity_get_float( victim, EV_FL_health )
if( equal( sz_classname, Class_Name ) && is_valid_ent( victim ) && zp_get_user_zombie( attacker ) && health <= 0.0 ) {
client_printcolor( 0 ,"!t[!gZN!t] !yТы получил !g5 !yAmmoPacks, уничтожив мешки с песком" )
return HAM_IGNORED;
}
if( sz_Br[ pPlayer ] && is_valid_ent( sz_Br[ pPlayer ] ) )
remove_entity( sz_Br[ pPlayer ] );
return HAM_IGNORED;
}
public fw_PlayerSpawn_Post( pPlayer ) {
if(!is_user_connected( pPlayer ) || zp_get_user_zombie( pPlayer ) )
return;
sz_LastHud[ pPlayer ] = get_systime();
}
public event_newround() {
for ( new pPlayer; pPlayer <= get_maxplayers(); pPlayer++ ) {
remove_allpalletswbags();
szBarricade[ pPlayer ] = 0
PlayerOwner[ pPlayer ] = 0
if( sz_Br[ pPlayer ] && is_valid_ent( sz_Br[ pPlayer ] ) )
remove_entity( sz_Br[ pPlayer ] );
}
}
public zp_user_infected_post( pPlayer ){
if ( sz_Br[ pPlayer ] && is_valid_ent( sz_Br[ pPlayer ] ) )
remove_entity( sz_Br[ pPlayer ] );
szBarricade[ pPlayer ] = 0
PlayerOwner[ pPlayer ] = 0
}
public client_disconnected( pPlayer ) {
if ( sz_Br[ pPlayer ] && is_valid_ent( sz_Br[ pPlayer ] ) )
remove_entity( sz_Br[ pPlayer ] );
szBarricade[ pPlayer ] = 0
PlayerOwner[ pPlayer ] = 0
}
public zp_fw_core_infect(pPlayer) {
if ( sz_Br[ pPlayer ] && is_valid_ent( sz_Br[ pPlayer ] ) )
remove_entity( sz_Br[ pPlayer ] );
szBarricade[ pPlayer ] = 0
PlayerOwner[ pPlayer ] = 0
}
public OnFreeEntPrivateData(pPlayer)
{
if (!FClassnameIs(pPlayer, Class_Name_Fake) )
return FMRES_IGNORED;
new pOwner = pev(pPlayer, pev_owner);
if ((1 <= pOwner <= g_iMaxPlayers))
sz_Br[pOwner] = 0;
return FMRES_IGNORED;
}
public client_PreThink( pPlayer ) {
new buttons = pev( pPlayer, pev_button )
new oldbuttons = pev( pPlayer, pev_oldbuttons )
if( !is_user_alive( pPlayer ) || zp_get_user_zombie( pPlayer ) || szBarricade[ pPlayer ] < 0 )
return PLUGIN_HANDLED;
if ( buttons & IN_USE && ~oldbuttons & IN_USE) {
set_barricade( pPlayer );
}
return PLUGIN_HANDLED;
}
public set_barricade( pPlayer ) {
if( !is_valid_ent( sz_Br[ pPlayer ] ) )
return PLUGIN_HANDLED;
new Int = sz_Br[ pPlayer ];
new Float:vecAngles[3]
GetOriginAimEndEyes( pPlayer, 128, szOrigin, vecAngles );
//engfunc( EngFunc_SetOrigin, Int, szOrigin );
if(CanBePlaced[ pPlayer ] == 2) {
client_printcolor( pPlayer, "!y[!gZN!y] Нее друг, тормози, можно только на земле" )
HologramCreate( pPlayer );
return PLUGIN_CONTINUE;
}
new Float:a_Maxs[ 3 ], Float:a_Mins[ 3 ];
a_Mins = BARICADE_MINSIZE;
a_Maxs = BARICADE_MAXSIZE;
engfunc( EngFunc_SetModel, Int,szModels[ random( sizeof szModels ) ] );
set_pev( Int, pev_classname, Class_Name );
engfunc( EngFunc_SetSize, Int, a_Mins, a_Maxs );
set_pev( Int, pev_body, 3 );
set_pev( Int, pev_nextthink, get_gametime() );
set_pev( Int, pev_solid, SOLID_BBOX );
set_pev( Int, pev_movetype , MOVETYPE_FLY );
set_pev( Int, pev_health, HealthBr );
set_pev( Int, pev_takedamage, DAMAGE_YES );
sz_Br[ pPlayer ] = 0;
szBarricade[ pPlayer ]-= 1
fm_set_user_rendering( Int );
return PLUGIN_CONTINUE;
}
public HologramCreate( pPlayer ) {
new Int = sz_Br[ pPlayer ];
if ( Int > 0 && is_valid_ent( Int ) ) {
// engfunc( EngFunc_SetOrigin, Int, szOrigin );
// по идее ниче не делаем, в синке объекта перемещаемся
} else {
Int = create_entity( "info_target" );
if( !Int )
return PLUGIN_HANDLED;
static Float:vecAngles[3]
GetOriginAimEndEyes( pPlayer, 128, szOrigin, vecAngles )
engfunc( EngFunc_SetModel, Int,szModels[ random( sizeof szModels ) ] );
engfunc( EngFunc_SetOrigin, Int, szOrigin );
set_pev( Int, pev_classname, Class_Name_Fake );
set_pev( Int, pev_owner, pPlayer );
set_pev( Int, pev_rendermode, kRenderTransAdd );
set_pev( Int, pev_renderamt, 200.0 );
set_pev( Int, pev_body, 1 );
set_pev( Int, pev_nextthink, get_gametime() );
set_pev( Int, pev_solid, SOLID_NOT );
set_pev( Int, pev_movetype, MOVETYPE_FLY ); // Movestep <- for Preview
sz_Br[ pPlayer ] = Int;
}
return PLUGIN_HANDLED;
}
public ThinkBarricade( Barricade ) {
if (pev_valid( Barricade ) != 2)
return PLUGIN_CONTINUE;
static pOwner;
pOwner = pev( Barricade, pev_owner );
if ( !is_user_alive( pOwner ) )
return PLUGIN_HANDLED;
static iBody, Float:vecColor[3], Float:vecAngles[3];
GetOriginAimEndEyes( pOwner, 128, szOrigin, vecAngles );
iBody = 2
xs_vec_set( vecColor, 0.0, 255.0, 0.0 );
engfunc( EngFunc_SetOrigin, Barricade, szOrigin );
fm_set_rendering( Barricade , kRenderFxDistort , 0 , 0 , 0 , kRenderTransAdd , 127 )
if ( !IsHullVacant( szOrigin, HULL_HEAD, Barricade ) ) {
if( Check_CreateBr() || Check_HologramBr() ) {
iBody = 1
xs_vec_set( vecColor, 255.0, 0.0, 0.0 );
}
}
CanBePlaced[ pOwner ] = iBody;
set_pev( Barricade, pev_angles, vecAngles );
set_pev( Barricade, pev_body, iBody );
set_pev( Barricade, pev_nextthink, get_gametime() + 0.01 );
return PLUGIN_HANDLED;
}
public Check_CreateBr() {
static victim
victim = -1
while ( ( victim = find_ent_in_sphere( victim, szOrigin, 200.0 ) ) != 0 ) {
new sz_classname[ 32 ];
entity_get_string( victim , EV_SZ_classname , sz_classname, 31 );
if( !equali( sz_classname, Class_Name ) ) {
if( is_user_connected( victim ) && is_user_alive( victim ) && PlayerOwner[ victim ] == 0 )
return false;
}
}
return true
}
public Check_HologramBr() {
static victim
victim = -1
while ( ( victim = find_ent_in_sphere( victim, szOrigin, 200.0 ) ) != 0 ) {
new sz_classname[32];
entity_get_string( victim , EV_SZ_classname , sz_classname, 31 );
if( !equali( sz_classname, Class_Name_Fake ) ) {
if( is_user_connected( victim ) && is_user_alive( victim ) && PlayerOwner[ victim ] == 0 )
return PLUGIN_HANDLED;
}
}
return true
}
public zp_extra_item_selected( pPlayer, itemid ) {
if ( itemid == szItem ) {
if( szBarricade[ pPlayer ] > 0 ) {
client_printcolor( pPlayer, "!y[!gZP!y] Макcимальное кол-во барикад достигнуто." )
zp_set_user_ammo_packs( pPlayer, zp_get_user_ammo_packs( pPlayer ) + 5 );
return PLUGIN_HANDLED;
}
szBarricade[ pPlayer ]+= 1
HologramCreate( pPlayer );
Hud_Selected( pPlayer );
}
return PLUGIN_HANDLED;
}
public Hud_Selected( pPlayer ) {
if( sz_LastHud[ pPlayer ] > get_systime() )
return PLUGIN_HANDLED;
set_dhudmessage( 200, 200, 200, -1.0, 0.73, 0, 6.0, 2.0, 1.0, 1.0 );
show_dhudmessage( pPlayer, "Что бы установить баррикаду^nНажми на [Е]" );
sz_LastHud[ pPlayer ] = get_systime() + 10
return PLUGIN_HANDLED;
}
bool:IsHullVacant( const Float:vecSrc[ 3 ], iHull, pEntToSkip = 0 ) {
engfunc( EngFunc_TraceHull, vecSrc, vecSrc, DONT_IGNORE_MONSTERS, iHull, pEntToSkip, 0 );
return bool:( !get_tr2( 0, TR_AllSolid ) && !get_tr2( 0, TR_StartSolid ) && get_tr2( 0, TR_InOpen ) );
}
GetOriginAimEndEyes( ent, iDistance, Float:vecOut[3], Float:vecAngles[3] ) {
static Float:vecSrc[ 3 ], Float:vecEnd[ 3 ], Float:vecViewOfs[ 3 ], Float:vecVelocity[ 3 ];
static Float:flFraction;
pev( ent, pev_origin, vecSrc );
pev( ent, pev_view_ofs, vecViewOfs );
xs_vec_add( vecSrc, vecViewOfs, vecSrc );
velocity_by_aim( ent, iDistance, vecVelocity );
xs_vec_add( vecSrc, vecVelocity, vecEnd );
engfunc( EngFunc_TraceLine, vecSrc, vecEnd, DONT_IGNORE_MONSTERS, ent, 0 );
get_tr2( 0, TR_flFraction, flFraction );
if ( flFraction < 1.0 )
{
static Float:vecPlaneNormal[ 3 ];
get_tr2( 0, TR_PlaneNormal, vecPlaneNormal );
get_tr2( 0, TR_vecEndPos, vecOut );
xs_vec_mul_scalar( vecPlaneNormal, 1.0, vecPlaneNormal );
xs_vec_add( vecOut, vecPlaneNormal, vecOut );
}
else
{
xs_vec_copy( vecEnd, vecOut );
}
vecVelocity[ 2 ] = 0.0;
vector_to_angle( vecVelocity, vecAngles );
}
FClassnameIs( Ent, const szClassName[] ) {
if ( pev_valid( Ent ) != 2 )
return 0;
new szpClassName[ 32 ];
pev( Ent, pev_classname, szpClassName, charsmax( szpClassName ) );
return equal( szClassName, szpClassName );
}
stock remove_allpalletswbags() {
new pallets = -1;
while( ( pallets = fm_find_ent_by_class( pallets, Class_Name ) ) )
fm_remove_entity( pallets );
}
stock client_printcolor( pPlayer, iInput[], any:... ) {
new iCount = 1, Players[ 32 ]
static iMsg[ 191 ]
vformat( iMsg, 190, iInput, 3 )
replace_all( iMsg, 190, "!g", "^4" )
replace_all( iMsg, 190, "!y", "^1" )
replace_all( iMsg, 190, "!t", "^3" )
if( pPlayer ) Players[ 0 ] = pPlayer; else get_players( Players, iCount, "ch" )
{
for( new i = 0; i < iCount; i++ ) {
if( is_user_connected( Players[ i ] ) ) {
message_begin( MSG_ONE_UNRELIABLE, get_user_msgid( "SayText" ), _, Players[ i ] )
write_byte( Players[ i ] )
write_string( iMsg )
message_end( )
}
}
}
}