You're right, I've tested with this following plugin, type "tank" to spawn an entity in front of you, by default the yaw range is 110°, and if you type "range" it will update the range to 360° and it's well updated right away without needed to spawn again.
Code: Select all
#include <amxmodx>
#include <fakemeta>
#include <hamsandwich>
#include <engine>
#include <xs>
const MAX_CLIENTS = 32;
const MAX_ENTITIES = ( 900 + ( MAX_CLIENTS * 15 ) ) / 32;
new isTank[ MAX_ENTITIES ];
#define SetIsTank(%1) ( isTank[ %1 >> 5 ] |= ( 1 << ( %1 & 31 ) ) )
#define ClearIsTank(%1) ( isTank[ %1 >> 5 ] &= ~( 1 << ( %1 & 31 ) ) )
#define IsTank(%1) ( isTank[ %1 >> 5 ] & ( 1 << ( %1 & 31 ) ) )
public plugin_precache()
{
register_forward( FM_Spawn, "Entities_Spawn" );
precache_model( "models/turret.mdl" );
precache_model( "sprites/muzzleflash2.spr" );
precache_sound( "ambience/turretrot1.wav" );
}
public Entities_Spawn ( const entity )
{
new classname[ 32 ];
pev( entity, pev_classname, classname, charsmax( classname ) );
if ( pev_valid( entity ) )
{
equal( classname, "func_tank" ) ? SetIsTank( entity ) : ClearIsTank( entity );
}
}
public plugin_init()
{
register_plugin( "", "", "" );
register_forward( FM_FindClientInPVS, "FindClientInPVS" );
register_clcmd( "tank" , "ClientCommand_CreateTank" );
register_clcmd( "range", "ClientCommand_ChangeRange" );
}
public ClientCommand_CreateTank ( const client )
{
new Float:origin[ 3 ]
GetAimOriginDistance( client, origin, 200.0 );
new tank = create_entity( "func_tank" );
engfunc( EngFunc_SetModel, tank, "models/v_m4a1.mdl" );
engfunc( EngFunc_SetOrigin, tank, origin );
DispatchKeyValue( tank, "rotatesound" , "ambience/turretrot1.wav" );
DispatchKeyValue( tank, "spriteflash" , "sprites/muzzleflash2.spr" );
DispatchKeyValue( tank, "spritescale" , "1" );
DispatchKeyValue( tank, "bullet" , "1" );
DispatchKeyValue( tank, "firespread" , "1" );
DispatchKeyValue( tank, "persistence" , "1" );
DispatchKeyValue( tank, "bullet_damage", "1" );
DispatchKeyValue( tank, "firerate" , "15" );
DispatchKeyValue( tank, "yawrate" , "500" );
DispatchKeyValue( tank, "yawrange" , "55" );
DispatchKeyValue( tank, "yawtolerance" , "5" );
DispatchKeyValue( tank, "pitchrate" , "500" );
DispatchKeyValue( tank, "pitchrange" , "55" );
DispatchKeyValue( tank, "pitchtolerance", "5" );
DispatchKeyValue( tank, "barrelz" , "4" );
DispatchKeyValue( tank, "barrely" , "0" );
DispatchKeyValue( tank, "barrel" , "30" );
set_pev( tank, pev_spawnflags, SF_TANK_ACTIVE );
DispatchSpawn( tank );
}
public ClientCommand_ChangeRange ( const client )
{
new tank = FM_NULLENT;
while ( ( tank = find_ent_by_class( tank, "func_tank" ) ) )
{
DispatchKeyValue( tank, "yawrange", "180" );
}
return PLUGIN_HANDLED;
}
public FindClientInPVS ( const entity )
{
if ( IsTank( entity ) )
{
forward_return( FMV_CELL, find_ent_by_class( 0, "player" ) );
return FMRES_SUPERCEDE;
}
return FMRES_IGNORED;
}
GetAimOriginDistance( index, Float:origin[ 3 ], Float:distance )
{
new Float:start[ 3 ];
new Float:view_ofs[ 3 ];
pev( index, pev_origin, start );
pev( index, pev_view_ofs, view_ofs );
xs_vec_add( start, view_ofs, start );
new Float:dest[ 3 ];
pev( index, pev_v_angle, dest );
engfunc( EngFunc_MakeVectors, dest );
global_get( glb_v_forward, dest );
xs_vec_mul_scalar( dest, distance, dest );
xs_vec_add( start, dest, dest );
engfunc( EngFunc_TraceLine, start, dest, IGNORE_MONSTERS, index, 0 );
get_tr2( 0, TR_vecEndPos, origin );
}
Nice plugin Arkshine!
Is it possible to make it be "unfriendly" to specific players?
This plugin was just a test, it should not be used like that, but for what you ask, you have to do like in #2, looping through all players and adding your filters instead of using directly find_ent_by_class().
It only target 1 player.
when the player dead, tank still target that player
See the second post. You have to filter. It was just an example.