new const Plugin_Name[ ] = "Safe Zone";
new const Plugin_Version[ ] = "0.1";
new const Plugin_Author[ ] = "Ruby";
#include <amxmodx>
#include <fakemeta>
#include <reapi>
#include <xs>
enum
{
STATUS_HIDE,
STATUS_SHOW,
STATUS_FLASH
};
new const Reference_Zone_Icon[ ] = "escape"; // rescue
new const Entity_Safe_Zone_Reference[ ] = "func_escapezone"; // func_hostage_rescue
new const Entity_Safe_Zone_ClassName[ ] = "ent_safe_zone";
new const Entity_Safe_Zone_Icon[ ] = "suit_full";
new const Entity_Safe_Zone_Color[ 3 ] = { 255, 255, 255 };
const bool: Entity_Safe_Zone_Icon_Flash = false;
new const Float: Hud_Safe_Zone_Pos[ 2 ] = { -1.0, 0.15 };
new const Hud_Safe_Zone_Color[ 3 ] = { 255, 255, 255 };
const Float: Hud_Safe_Zone_Duration = 1.5;
new Float: g_flFirstPoint[ 3 ], Float: g_flSecondPoint[ 3 ];
new bool: g_bInSafeZone[ MAX_PLAYERS + 1 ],
g_HudSyncObj_SafeZone;
public plugin_init( )
{
register_plugin( Plugin_Name, Plugin_Version, Plugin_Author );
register_message( get_user_msgid( "StatusIcon" ), "Message__StatusIcon" );
register_event( "StatusIcon", "Event__StatusIcon_Show", "be", "1=1", fmt( "2=%s", Reference_Zone_Icon ) );
register_event( "StatusIcon", "Event__StatusIcon_Hide", "be", "1=0", fmt( "2=%s", Reference_Zone_Icon ) );
RegisterHookChain( RG_CSGameRules_FPlayerCanTakeDamage, "RG_CSGameRules__FPlayerCanTakeDamage_Pre", false );
g_HudSyncObj_SafeZone = CreateHudSyncObj( );
register_clcmd( "radio1", "Command__Radio1" );
register_clcmd( "radio2", "Command__Radio2" );
register_clcmd( "radio3", "Command__CreateSafeZone" );
}
public plugin_natives( )
{
register_native( "in_safe_zone", "Native__InSafeZone" );
}
public client_putinserver( pPlayer )
{
g_bInSafeZone[ pPlayer ] = false;
}
public Command__Radio1( const pPlayer )
{
new vecOrigin[ 3 ]; get_user_origin( pPlayer, vecOrigin, 3 );
IVecFVec( vecOrigin, g_flFirstPoint );
}
public Command__Radio2( const pPlayer )
{
new vecOrigin[ 3 ]; get_user_origin( pPlayer, vecOrigin, 3 );
IVecFVec( vecOrigin, g_flSecondPoint );
}
public Command__CreateSafeZone( const pPlayer )
Create__SafeZone( g_flFirstPoint, g_flSecondPoint );
public Message__StatusIcon( const iMsgId, const iMsgDest, const iMsgEntity )
{
enum { arg_status = 1, arg_sprite_name, arg_color_r };
new szSpriteName[ 8 ]; get_msg_arg_string( arg_sprite_name, szSpriteName, charsmax( szSpriteName ) );
if ( !equal( szSpriteName, Reference_Zone_Icon ) )
return;
if ( Entity_Safe_Zone_Icon_Flash && get_msg_arg_int( arg_status ) == STATUS_SHOW )
set_msg_arg_int( arg_status, ARG_BYTE, STATUS_FLASH );
set_msg_arg_string( arg_sprite_name, Entity_Safe_Zone_Icon );
if ( get_msg_arg_int( arg_status ) == STATUS_HIDE )
return;
for ( new i; i < 3; i++ )
set_msg_arg_int( arg_color_r + i, ARG_BYTE, Entity_Safe_Zone_Color[ i ] );
}
public Event__StatusIcon_Show( const pPlayer )
{
if ( !is_user_alive( pPlayer ) ) // ???
return;
g_bInSafeZone[ pPlayer ] = true;
set_entvar( pPlayer, var_takedamage, DAMAGE_NO ); // Боты не трогают неуязвимых ( yb_check_enemy_invincibility )
set_hudmessage( Hud_Safe_Zone_Color[ 0 ], Hud_Safe_Zone_Color[ 1 ], Hud_Safe_Zone_Color[ 2 ], Hud_Safe_Zone_Pos[ 0 ], Hud_Safe_Zone_Pos[ 1 ], .holdtime = Hud_Safe_Zone_Duration );
ShowSyncHudMsg( pPlayer, g_HudSyncObj_SafeZone, "Вы зашли в безопасную зону!" );
}
public Event__StatusIcon_Hide( const pPlayer )
{
if ( !is_user_alive( pPlayer ) ) // ???
return;
g_bInSafeZone[ pPlayer ] = false;
set_entvar( pPlayer, var_takedamage, DAMAGE_YES );
set_hudmessage( Hud_Safe_Zone_Color[ 0 ], Hud_Safe_Zone_Color[ 1 ], Hud_Safe_Zone_Color[ 2 ], Hud_Safe_Zone_Pos[ 0 ], Hud_Safe_Zone_Pos[ 1 ], .holdtime = Hud_Safe_Zone_Duration );
ShowSyncHudMsg( pPlayer, g_HudSyncObj_SafeZone, "Вы вышли из безопасной зоны!" );
}
public RG_CSGameRules__FPlayerCanTakeDamage_Pre( const pVictim, const pAttacker )
{
if ( !is_user_alive( pVictim ) )
return HC_CONTINUE;
if ( g_bInSafeZone[ pVictim ] || g_bInSafeZone[ pAttacker ] )
{
SetHookChainReturn( ATYPE_INTEGER, false );
return HC_SUPERCEDE;
}
return HC_CONTINUE;
}
public bool: Native__InSafeZone( const iPluginId, const iParams )
{
enum { arg_player = 1 };
static pPlayer; pPlayer = get_param( arg_player );
if ( !is_user_alive( pPlayer ) )
return false;
return g_bInSafeZone[ pPlayer ];
}
stock bool: Create__SafeZone( const Float: vecFirstPoint[ 3 ], const Float: vecSecondPoint[ 3 ] )
{
new pEntity = rg_create_entity( Entity_Safe_Zone_Reference );
if ( is_nullent( pEntity ) )
return false;
new Float: vecCenter[ 3 ], Float: flMins[ 3 ], Float: flMaxs[ 3 ];
for ( new i, Float: flSize[ 3 ]; i < 3; i++ )
{
vecCenter[ i ] = ( vecFirstPoint[ i ] + vecSecondPoint[ i ] ) / 2.0;
flSize[ i ] = floatabs( vecFirstPoint[ i ] - vecSecondPoint[ i ] );
flMins[ i ] = flSize[ i ] / -2.0;
flMaxs[ i ] = flSize[ i ] / 2.0;
}
set_entvar( pEntity, var_classname, Entity_Safe_Zone_ClassName );
set_entvar( pEntity, var_solid, SOLID_BBOX );
dllfunc( DLLFunc_Spawn, pEntity );
engfunc( EngFunc_SetOrigin, pEntity, vecCenter );
engfunc( EngFunc_SetSize, pEntity, flMins, flMaxs );
return true;
}