AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
|
01-06-2018
, 14:35
Re: [REQ] Detect no kill and punish ( Players which is not killing the enemies)
|
#30
|
Not sure if I understand correctly but here's how this version works.
Player 2 is in Player 1's viewcone; the viewcone check does not take into consideration any obstructions so tracelining will begin if the viewcone condition is met. Traceline is drawn between players to check for any obstructions. If a clear line can be drawn, the time at which a clear line was first drawn is stored. If at any time this line is broken (object in the way or either player looks away) the time is cleared. After cvar [nkp_sightthresholdseconds] seconds of uninterrupted eye contact (not direct, just have to be able to see each other), both are slayed. If multiple players can make eye contact with an enemy, only the first of many is slayed. First meaning highest amount of eye contact time OR if eye contact time is equal, lowest player index value.
The code is currently set in testing mode so you can see the logic in action. To do this, put yourself on terrorist team and put 1+ bots on the CT team. Approach a CT player so you can make eye contact, distance does not matter, and you will see messaging print on the screen. If you look away or make something block view, messaging will display. Remain in eye contact with a CT for 10 seconds and you will both be slayed. To remove the testing messages and make bots excluded from the CT player checking, comment out the [#define TESTING] line.
PHP Code:
#include <amxmodx> #include <cstrike> #include <engine> #include <fakemeta>
new const Version[] = "0.1";
#define TESTING
#define MAX_PLAYERS 32
new g_ThinkingEntity; new g_LastEyeContact[ MAX_PLAYERS + 1 ][ MAX_PLAYERS + 1 ]; new g_MaxPlayers; new g_pSightThreshold;
public plugin_init() { register_plugin( "No-Kill Punishment" , Version , "bugsy" ); register_event( "DeathMsg" , "EventDeathMsg" , "a" ); g_pSightThreshold = register_cvar( "nkp_sightthresholdseconds" , "10" ); g_MaxPlayers = get_maxplayers(); CreateEntity(); }
public client_disconnect( id ) { ResetPlayer( id ); }
public EventDeathMsg() { new iVictim = read_data( 2 ); ResetPlayer( iVictim ); }
public ViewEntity_Think( iEntity ) { new iT[ 32 ] , iCT[ 32 ] , iTNum , iCTNum , Float:fTOrigin[ 3 ] , Float:fCTOrigin[ 3 ] , iTPlayer , iCTPlayer , szTName[ 32 ] , szCTName[ 32 ]; new iThresholdSeconds , iSysTime; get_players( iT , iTNum , "ace" , "TERRORIST" ); #if defined TESTING get_players( iCT , iCTNum , "ae" , "CT" ); #else get_players( iCT , iCTNum , "ace" , "CT" ); #endif if ( iTNum && iCTNum ) { for ( new i = 0 ; i < iTNum ; i++ ) { iTPlayer = iT[ i ]; for ( new p = 0 ; p < iCTNum ; p++ ) { iCTPlayer = iCT[ p ]; entity_get_vector( iCTPlayer , EV_VEC_origin , fCTOrigin ); if ( is_in_viewcone( iTPlayer , fCTOrigin ) ) { entity_get_vector( iTPlayer , EV_VEC_origin , fTOrigin ); if ( IsInLineOfSight( fTOrigin , fCTOrigin ) ) { if ( !g_LastEyeContact[ iTPlayer ][ iCTPlayer ] ) { g_LastEyeContact[ iTPlayer ][ iCTPlayer ] = get_systime(); } #if defined TESTING else { get_user_name( iTPlayer , szTName , charsmax( szTName ) ); get_user_name( iCTPlayer , szCTName , charsmax( szCTName ) ); client_print( iTPlayer , print_chat , "%s AND %s CAN SEE EACH OTHER - %d SECONDS" , szTName , szCTName , ( get_systime() - g_LastEyeContact[ iTPlayer ][ iCTPlayer ] ) ); } #endif } #if defined TESTING else { if ( g_LastEyeContact[ iTPlayer ][ iCTPlayer ] ) { get_user_name( iTPlayer , szTName , charsmax( szTName ) ); get_user_name( iCTPlayer , szCTName , charsmax( szCTName ) ); client_print( iTPlayer , print_chat , "LINE OF SIGHT BROKEN FOR %s AND %s" , szTName , szCTName ); g_LastEyeContact[ iTPlayer ][ iCTPlayer ] = 0; } } #endif } else { #if defined TESTING if ( g_LastEyeContact[ iTPlayer ][ iCTPlayer ] ) { get_user_name( iTPlayer , szTName , charsmax( szTName ) ); get_user_name( iCTPlayer , szCTName , charsmax( szCTName ) ); client_print( iTPlayer , print_chat , "LINE OF SIGHT BROKEN FOR %s AND %s" , szTName , szCTName ); } #endif g_LastEyeContact[ iTPlayer ][ iCTPlayer ] = 0; } } } iSysTime = get_systime(); iThresholdSeconds = get_pcvar_num( g_pSightThreshold ); for ( new iT = 1 ; iT <= g_MaxPlayers ; iT++ ) { for ( new iCT = 1 ; iCT <= g_MaxPlayers ; iCT++ ) { if ( g_LastEyeContact[ iT ][ iCT ] && ( ( iSysTime - g_LastEyeContact[ iT ][ iCT ] ) >= iThresholdSeconds ) ) { get_user_name( iT , szTName , charsmax( szTName ) ); get_user_name( iCT , szCTName , charsmax( szCTName ) ); client_print( 0 , print_chat , "* Killing %s and %s for No-Killing!" , szTName , szCTName ); user_kill( iT ); user_kill( iCT ); g_LastEyeContact[ iT ][ iCT ] = 0; } } } } entity_set_float( g_ThinkingEntity , EV_FL_nextthink , get_gametime() + 0.1 ); }
bool:IsInLineOfSight( Float:fOrigin1[ 3 ] , Float:fOrigin2[ 3 ] ) { new iTrace , Float:fFraction; engfunc( EngFunc_TraceLine , fOrigin1 , fOrigin2 , IGNORE_MONSTERS , 0 , iTrace ); get_tr2( iTrace , TR_flFraction , fFraction ); return bool:( fFraction == 1.0 ); }
ResetPlayer( id ) { new CsTeams:csTeam = cs_get_user_team( id ); if ( csTeam == CS_TEAM_T ) { arrayset( g_LastEyeContact[ id ] , 0 , sizeof( g_LastEyeContact[] ) ); } else if ( csTeam == CS_TEAM_CT ) { for ( new iT = 1 ; iT <= g_MaxPlayers ; iT++ ) { g_LastEyeContact[ iT ][ id ] = 0; } } }
CreateEntity() { g_ThinkingEntity = create_entity( "info_target" ); entity_set_string( g_ThinkingEntity , EV_SZ_classname , "view_entity" ); register_think( "view_entity" , "ViewEntity_Think" ); entity_set_float( g_ThinkingEntity , EV_FL_nextthink , get_gametime() + 0.1 ); }
__________________
Last edited by Bugsy; 01-06-2018 at 15:39.
|
|