Raised This Month: $ Target: $400
 0% 

How to tell if a player is holding the fire button


  
 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
Author Message
SamuraiBarbi
Senior Member
Join Date: Aug 2006
Location: United States
Old 11-03-2009 , 15:47   How to tell if a player is holding the fire button
Reply With Quote #1

Hello,
I found code someone posted here for Team Fortress Classic which turned the demoman's green pipes into sticky pipes that stick to players and walls. While the feature is neat, I would like to alter it a bit so that the pipes function as they would normally unless a player presses and holds down the fire button. The idea I have is that the pipes should only stick to things if the player is still holding down the fire button when they pipe makes contact with another player or a map surface. Otherwise if the player just presses the fire button the pipe just does it's usual thing.

I'm not sure how exactly to go about this though. Here's the code I found. Any help, pointers, and suggestions are much appreciated.

Code:
    #include <amxmodx>
    #include <engine>
    #include <fakemeta>
    #include <hamsandwich>
    
    const MAX_CLIENTS = 32;
    new bool:gHasPipeLauncher[ MAX_CLIENTS + 1 char ];
    
    enum _:Coord_e { Float:x, Float:y, Float:z };
    
    #define VectorMS(%1,%2,%3,%4)     ( %4[ x ] = %1[ x ] - %2 * %3[ x ], %4[ y ] = %1[ y ] - %2 * %3[ y ], %4[ z ] = %1[ z ] - %2 * %3[ z ] )
    #define VectorLength(%1)          ( floatsqroot ( %1[ x ] * %1[ x ] + %1[ y ] * %1[ y ] + %1[ z ] * %1[ z ] ) )
    
    #define message_begin_f(%1,%2,%3) ( engfunc ( EngFunc_MessageBegin, %1, %2, %3 ) )
    #define write_coord_f(%1)         ( engfunc ( EngFunc_WriteCoord, %1 ) )
    
    #define PlayerHasTech(%1)         ( is_user_alive( %1 ) && gHasPipeLauncher{ %1 } )
    
    public plugin_init ()
    {
        register_plugin( "Sticky PipeBombs", "1.0.0", "Arkshine" );
    
        register_touch( "tf_gl_pipebomb", "worldspawn", "CTech_TouchWorld" );
        register_touch( "tf_gl_pipebomb", "func_wall",  "CTech_TouchWorld" );
        register_touch( "tf_gl_pipebomb", "player"   ,  "CTech_TouchPlayer" );
        
        RegisterHam( Ham_Item_Deploy , "tf_weapon_pl", "CTech_DeployWeapon", 1 );
        RegisterHam( Ham_Item_Holster, "tf_weapon_pl", "CTech_HolsterWeapon", 1 );
    }

    public client_disconnect( Player )
    {
        gHasPipeLauncher{ Player } = false;
    }    

    public CTech_TouchWorld ( const PipeBomb, const Other )
    {
        if ( pev_valid( PipeBomb ) && pev( PipeBomb, pev_movetype ) != MOVETYPE_NONE && PlayerHasTech( pev( PipeBomb, pev_owner ) ) )
        {
            static Float:Velocity[ Coord_e ];
            static Float:Origin  [ Coord_e ];
            
            pev( PipeBomb, pev_origin, Origin );
            pev( PipeBomb, pev_velocity, Velocity );
            
            VectorNormalize( Velocity );
            VectorMS( Origin, 4.0, Velocity, Origin );
        
            set_pev( PipeBomb, pev_movetype, MOVETYPE_NONE );
            set_pev( PipeBomb, pev_origin, Origin );
            set_pev( PipeBomb, pev_velocity , Float:{ 0.0, 0.0, 0.0 } );
            set_pev( PipeBomb, pev_avelocity, Float:{ 0.0, 0.0, 0.0 } );
            
            FX_Sparks( Origin ); 
        }
    }
    
    public CTech_TouchPlayer ( const PipeBomb, const Other )
    {
        if ( pev_valid( PipeBomb ) && is_user_alive( Other ) )
        {
            static Float:Origin[ Coord_e ];
            pev( PipeBomb, pev_origin, Origin );
            
            set_pev( PipeBomb, pev_movetype, MOVETYPE_FOLLOW );
            set_pev( PipeBomb, pev_aiment, Other );
            set_pev( PipeBomb, pev_origin, Origin );
            set_pev( PipeBomb, pev_velocity , Float:{ 0.0, 0.0, 0.0 } );
            set_pev( PipeBomb, pev_avelocity, Float:{ 0.0, 0.0, 0.0 } );
            
            FX_Sparks( Origin ); 
        }
    }
    
    public CTech_DeployWeapon ( const PipeLauncher )
    {
        gHasPipeLauncher{ pev( PipeLauncher, pev_owner ) } = true;
    }
    
    public CTech_HolsterWeapon ( const PipeLauncher )
    {
        gHasPipeLauncher{ pev( PipeLauncher, pev_owner ) } = false;
    }
    
    FX_Sparks ( const Float:Origin[ Coord_e ] )
    {
        message_begin_f( MSG_PVS, SVC_TEMPENTITY, Origin, 0 );
        write_byte( TE_SPARKS );
        write_coord_f( Origin[ x ] );
        write_coord_f( Origin[ y ] );
        write_coord_f( Origin[ z ] );
        message_end ();
    }
    
    VectorNormalize ( Float:Source[ Coord_e ] )
    {
        new Float:Invlen = 1.0 / VectorLength( Source );

        Source[ x ] *= Invlen
        Source[ y ] *= Invlen;
        Source[ z ] *= Invlen;
    }
SamuraiBarbi is offline
Send a message via AIM to SamuraiBarbi Send a message via MSN to SamuraiBarbi Send a message via Yahoo to SamuraiBarbi
 



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 17:33.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode