View Single Post
Arkshine
AMX Mod X Plugin Approver
Join Date: Oct 2005
Old 05-07-2010 , 14:53   Re: Automatic func_tanks in Counter Strike
Reply With Quote #21

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.

PHP Code:

    
#include <amxmodx>
    #include <fakemeta>
    #include <hamsandwich>
    #include <engine>
    #include <xs>
    
    
const MAX_CLIENTS  32;
    const 
MAX_ENTITIES = ( 900 + ( MAX_CLIENTS 15 ) ) / 32;

    new 
isTankMAX_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_forwardFM_Spawn"Entities_Spawn" );
        
        
precache_model"models/turret.mdl" );
        
precache_model"sprites/muzzleflash2.spr" );
        
precache_sound"ambience/turretrot1.wav" );
    }

    public 
Entities_Spawn ( const entity )
    {
        new 
classname32 ];
        
peventitypev_classnameclassnamecharsmaxclassname ) );

        if ( 
pev_validentity ) )
        {
            
equalclassname"func_tank" ) ? SetIsTankentity ) : ClearIsTankentity );
        }
    }

    public 
plugin_init()
    {
        
register_plugin"""""" );
        
        
register_forwardFM_FindClientInPVS"FindClientInPVS" );
        
        
register_clcmd"tank" "ClientCommand_CreateTank" );
        
register_clcmd"range""ClientCommand_ChangeRange" );
    }

    public 
ClientCommand_CreateTank ( const client )
    {
        new 
Float:origin]
        
GetAimOriginDistanceclientorigin200.0 );
    
        new 
tank create_entity"func_tank" );
        
        
engfuncEngFunc_SetModeltank"models/v_m4a1.mdl" );
        
engfuncEngFunc_SetOrigintankorigin );

        
DispatchKeyValuetank"rotatesound"  "ambience/turretrot1.wav"  );
        
DispatchKeyValuetank"spriteflash"  "sprites/muzzleflash2.spr" );
        
DispatchKeyValuetank"spritescale"  "1" );
        
DispatchKeyValuetank"bullet"       "1" );
        
DispatchKeyValuetank"firespread"   "1" );
        
DispatchKeyValuetank"persistence"  "1" );
        
DispatchKeyValuetank"bullet_damage""1" );
        
DispatchKeyValuetank"firerate"     "15"  );
        
DispatchKeyValuetank"yawrate"      "500" );
        
DispatchKeyValuetank"yawrange"     "55"  );
        
DispatchKeyValuetank"yawtolerance" "5"   );
        
DispatchKeyValuetank"pitchrate"    "500" );
        
DispatchKeyValuetank"pitchrange"   "55"  );
        
DispatchKeyValuetank"pitchtolerance""5"  );
        
DispatchKeyValuetank"barrelz"      "4"   );
        
DispatchKeyValuetank"barrely"      "0"   );
        
DispatchKeyValuetank"barrel"       "30"  );
        
        
set_pevtankpev_spawnflagsSF_TANK_ACTIVE );
        
DispatchSpawntank );
    }
    
    public 
ClientCommand_ChangeRange ( const client )
    {
        new 
tank FM_NULLENT;
        
        while ( ( 
tank find_ent_by_classtank"func_tank" ) ) )
        {
            
DispatchKeyValuetank"yawrange""180" );
        }
        
        return 
PLUGIN_HANDLED;
    }   

    public 
FindClientInPVS ( const entity )
    {
        if ( 
IsTankentity ) )
        {
            
forward_returnFMV_CELLfind_ent_by_class0"player" ) );
            return 
FMRES_SUPERCEDE;
        }
        
        return 
FMRES_IGNORED;
    }
    
    
GetAimOriginDistanceindexFloat:origin], Float:distance 
    {
        new 
Float:start];
        new 
Float:view_ofs];
        
        
pevindexpev_originstart );
        
pevindexpev_view_ofsview_ofs );
        
        
xs_vec_addstartview_ofsstart );

        new 
Float:dest];
        
pevindexpev_v_angledest );
        
        
engfuncEngFunc_MakeVectorsdest );
        
global_getglb_v_forwarddest );
        
        
xs_vec_mul_scalardestdistancedest );
        
xs_vec_addstartdestdest );

        
engfuncEngFunc_TraceLinestartdestIGNORE_MONSTERSindex);
        
get_tr20TR_vecEndPosorigin );
    } 
__________________
Arkshine is offline