AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   How to tell if a player is holding the fire button (https://forums.alliedmods.net/showthread.php?t=108287)

SamuraiBarbi 11-03-2009 15:47

How to tell if a player is holding the fire button
 
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;
    }


grimvh2 11-03-2009 16:05

Re: How to tell if a player is holding the fire button
 
Forward
PHP Code:

/* Forward */
register_forward(FM_CmdStart"fwd_FM_CmdStart_pre"0); 

Get Buttons

PHP Code:

static button;
button get_uc(uc_handleUC_Buttons); 

Check for IN_ATTACK
PHP Code:

if(button IN_ATTACK)
{
    
//ur code



SamuraiBarbi 11-03-2009 16:22

Re: How to tell if a player is holding the fire button
 
Thank you so much! There's still only one problem I can think of in order to prevent it from being 'buggy' How can I be sure that the player never released the fire button?

For example, a buggy thing that I could forsee being a possible problem is, if a player presses the fire button to shoot a pipe, releases the fire button and goes to press the fire button again as the previous pipe touches another player or a surface. It seems I need a method like what you've provided but I also need to be able to check if the player ever released the fire button.

Doc-Holiday 11-04-2009 00:33

Re: How to tell if a player is holding the fire button
 
Quote:

Originally Posted by SamuraiBarbi (Post 980046)
Thank you so much! There's still only one problem I can think of in order to prevent it from being 'buggy' How can I be sure that the player never released the fire button?

For example, a buggy thing that I could forsee being a possible problem is, if a player presses the fire button to shoot a pipe, releases the fire button and goes to press the fire button again as the previous pipe touches another player or a surface. It seems I need a method like what you've provided but I also need to be able to check if the player ever released the fire button.

IN_ATTACK means button is pressed will fire each time it is pressed... how ever if you do it like ongameframe(in css) it will check constantly so if you release it it stops.

grimvh2 11-04-2009 07:48

Re: How to tell if a player is holding the fire button
 
PHP Code:

new holding_fire[33];

if(
button IN_ATTACK)
{
    
holding_fire[id]++;
}
else
{
   
holding_fire[id]=0;


PHP Code:

public YourFunction(?)
{
   if(
holding_fire[player])
   {
        
// ...
   
}




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

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