Raised This Month: $ Target: $400
 0% 

How to catch holding fire button


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Apokalipsisa
Member
Join Date: May 2012
Old 09-06-2012 , 11:55   How to catch holding fire button
Reply With Quote #1

Pls give me a example how to properly catch if holding fire button on the mouse and if its released.
Apokalipsisa is offline
Torge
Veteran Member
Join Date: Oct 2011
Old 09-06-2012 , 13:27   Re: How to catch holding fire button
Reply With Quote #2

PHP Code:
#include <amxmodx>
#include <engine>
#include <fakemeta>

public client_PreThink(id)
{
    new 
button;
    
button pev(idpev_button);
    
    if (
button IN_ATTACK)
    {
        
// Your code
    
}

Not sure if it works too for holding, but you can try it.
Torge is offline
Apokalipsisa
Member
Join Date: May 2012
Old 09-06-2012 , 13:36   Re: How to catch holding fire button
Reply With Quote #3

Quote:
Originally Posted by Torge View Post
PHP Code:
#include <amxmodx>
#include <engine>
#include <fakemeta>

public client_PreThink(id)
{
    new 
button;
    
button pev(idpev_button);
    
    if (
button IN_ATTACK)
    {
        
// Your code
    
}

Not sure if it works too for holding, but you can try it.
Ok thanks,but i want to detect if players stop holding attack buton too.
Apokalipsisa is offline
Torge
Veteran Member
Join Date: Oct 2011
Old 09-06-2012 , 13:37   Re: How to catch holding fire button
Reply With Quote #4

Take it:

PHP Code:
#include <amxmodx>
#include <engine>
#include <fakemeta>

public client_PreThink(id)
{
    new 
button;
    
button pev(idpev_button);
    
    if (
button IN_ATTACK)
    {
        
// Your code
    
}
    else
    {
       
// Your code
    
}

Torge is offline
matsi
Thinkosaur
Join Date: Sep 2006
Old 09-06-2012 , 14:30   Re: How to catch holding fire button
Reply With Quote #5

Quote:
Originally Posted by Torge View Post
PHP Code:
#include <amxmodx>
#include <engine>
#include <fakemeta>

public client_PreThink(id)
{
    new 
button;
    
button pev(idpev_button);
    
    if (
button IN_ATTACK)
    {
        
// Your code
    
}

Not sure if it works too for holding, but you can try it.
Thats exactly how it will work and if you want to check if player just pressed attack once you must check old_buttons as well... FYI Prethink is not the correct way to check buttons.
__________________

Accepting all kinds of requests via private message.
matsi is offline
ConnorMcLeod
Veteran Member
Join Date: Jul 2006
Location: France (95)
Old 09-06-2012 , 15:09   Re: How to catch holding fire button
Reply With Quote #6

Ripped from CBasePlayer:reThink, should work.

PHP Code:
#include <amxmodx>
#include <fakemeta>

#define m_afButtonLast 245

public plugin_init()
{
    
register_forward(FM_CmdStart"OnCmdStart"false)
}

public 
OnCmdStart(idcmd)
{
    static 
buttonsbuttonsChangedbuttonPressedbuttonReleased
    buttons 
get_uc(cmdUC_Buttons)

    
buttonsChanged get_pdata_int(idm_afButtonLast) ^ buttons

    buttonPressed 
buttonsChanged buttons
    buttonReleased 
buttonsChanged & ~buttons

    
if( buttonPressed IN_ATTACK )
    {
        
// just pressed +attack
    
}
    else if( 
buttonReleased IN_ATTACK )
    {
        
// just released +attack
    
}

__________________
- tired and retired -

- my plugins -
ConnorMcLeod is offline
11922911
Senior Member
Join Date: Dec 2011
Location: Yuen Long Country
Old 09-07-2012 , 03:53   Re: How to catch holding fire button
Reply With Quote #7

Quote:
Originally Posted by ConnorMcLeod View Post
Ripped from CBasePlayer:reThink, should work.

PHP Code:
#include <amxmodx>
#include <fakemeta>

#define m_afButtonLast 245

public plugin_init()
{
    
register_forward(FM_CmdStart"OnCmdStart"false)
}

public 
OnCmdStart(idcmd)
{
    static 
buttonsbuttonsChangedbuttonPressedbuttonReleased
    buttons 
get_uc(cmdUC_Buttons)

    
buttonsChanged get_pdata_int(idm_afButtonLast) ^ buttons

    buttonPressed 
buttonsChanged buttons
    buttonReleased 
buttonsChanged & ~buttons

    
if( buttonPressed IN_ATTACK )
    {
        
// just pressed +attack
    
}
    else if( 
buttonReleased IN_ATTACK )
    {
        
// just released +attack
    
}

Nice ConnorMcLeod, i love your coding

Last edited by 11922911; 09-07-2012 at 03:54.
11922911 is offline
Apokalipsisa
Member
Join Date: May 2012
Old 09-07-2012 , 07:57   Re: How to catch holding fire button
Reply With Quote #8

Thank you all for the answers.I dont wan't to post a new topic(becouse i will make to much spam) and i will ask my another question here.Can someone tell me why my noob code doesn't work ?

PHP Code:
#include <amxmodx>
#include <engine>
#include <cstrike>
#include <fakemeta>
#include <csx>
#include <colorchat>


public plugin_init()
{
    
register_plugin("C4 Anti-Camper","1.0","Apokalipsisa")
    
    
register_logevent("start",2,"1=Round_Start")
    
register_forward(FM_CmdStart,"fwd_FM_CmdStart_pre",0)
    
    if(
engfunc(EngFunc_FindEntityByString, -1"classname","func_bomb_target") || engfunc(EngFunc_FindEntityByString, -1"classname","info_bomb_target"))
    {        
        
register_event("StatusIcon""event_bomb_pickup""be""1=1""1=2""2=c4")
        
register_event("TextMsg""event_bomb_pickup""bc""2&#Got_bomb")
        
register_event("TextMsg""event_bomb_dropped""bc""2&#Game_bomb_d")
    }
    else
    {
        
pause("ad")
        
        return
    } 
}

public 
event_bomb_pickup(id)
{
    if(!
is_user_alive(id)) return
        
    if(
cs_get_user_team(id) == CS_TEAM_T)
    {
        
remove_task(id 222)
        
set_task(1.0,"CheckMoving",id 111 __"b")
    }


public 
event_bomb_dropped()
{
    new 
players[32],numi,id
    get_players
(players,num)
    
    for(
i=0;i<num;i++)
    {
        
id players[i]
    
        if(!
is_user_alive(id)) return
    
        
remove_task(id 111)
        
set_task(2.0,"BombPlant",id 222 __"b")
    }
}

public 
bomb_planted(id)
{
    if(!
is_user_alive(id)) return
        
    
remove_task(111)
        
    if(
cs_get_user_team(id) == CS_TEAM_CT)
    {
        
set_task(1.0,"CheckMoving",id 111 __"b")
    }
}

public 
CheckMoving(id)
{
    static 
iStillCounter[33]
    static 
FloatfVelocity[3]
        
    if(!
is_user_alive(id)) return
        
    
pev(id,pev_velocity,fVelocity)
    
    if(
fVelocity[0] || fVelocity[1] || fVelocity[2])
    {
        
iStillCounter[id] = 0
    
}
    else
    {
        if (++
iStillCounter[id] >= 5)
        {
            if(
cs_get_user_team(id) == CS_TEAM_T)
            {
                
ColorChat(id,GREEN,"PLANT C4!")
                
user_slap(id,0)
            }
                    
            if(
cs_get_user_team(id) == CS_TEAM_CT)
            {
                
ColorChat(id,GREEN,"DEFUSE C4!")
                
user_slap(id,0)
            }
        }
    }
}

public 
bomb_defusing(id)
{
    new 
buttons pev(idpev_button)
    new 
oldbuttons pev(idpev_oldbuttons)
    
    if(
buttons IN_USE)
    {
        
remove_task(id 111)
    }
    
    if(
oldbuttons IN_USE && !(buttons IN_USE))
    {
        
set_task(1.0,"CheckMoving",id 111 __"b")
    }
    
    if(
buttons IN_USE && !(oldbuttons IN_USE))
    {
        
ColorChat(id,GREEN,"test test test")
    }
    
    return 
FMRES_IGNORED
}

public 
start(id)
{
    
remove_task(id 111)
}

public 
bomb_defused(id)
{
    
remove_task(id 111)
}

public 
bomb_explode(id)
{
    
remove_task(id 111)
}

public 
BombPlant(id)
{
    if(!
is_user_alive(id)) return
    
    
ColorChat(id,GREEN,"TAKE C4 AND PLANT!")
    
user_slap(id,0)
}

public 
bomb_planting(id)
{
    new 
button;
    
button pev(idpev_button);
    
    if (
button IN_ATTACK)
    {
        
remove_task(id 111)
    }
    else
    {
        
set_task(1.0,"CheckMoving",id 111 __"b")
    }

Apokalipsisa is offline
Torge
Veteran Member
Join Date: Oct 2011
Old 09-07-2012 , 08:04   Re: How to catch holding fire button
Reply With Quote #9

Quote:
Originally Posted by Apokalipsisa View Post
Thank you all for the answers.I dont wan't to post a new topic(becouse i will make to much spam) and i will ask my another question here.Can someone tell me why my noob code doesn't work ?

PHP Code:
#include <amxmodx>
#include <engine>
#include <cstrike>
#include <fakemeta>
#include <csx>
#include <colorchat>


public plugin_init()
{
    
register_plugin("C4 Anti-Camper","1.0","Apokalipsisa")
    
    
register_logevent("start",2,"1=Round_Start")
    
register_forward(FM_CmdStart,"fwd_FM_CmdStart_pre",0)
    
    if(
engfunc(EngFunc_FindEntityByString, -1"classname","func_bomb_target") || engfunc(EngFunc_FindEntityByString, -1"classname","info_bomb_target"))
    {        
        
register_event("StatusIcon""event_bomb_pickup""be""1=1""1=2""2=c4")
        
register_event("TextMsg""event_bomb_pickup""bc""2&#Got_bomb")
        
register_event("TextMsg""event_bomb_dropped""bc""2&#Game_bomb_d")
    }
    else
    {
        
pause("ad")
        
        return
    } 
}

public 
event_bomb_pickup(id)
{
    if(!
is_user_alive(id)) return
        
    if(
cs_get_user_team(id) == CS_TEAM_T)
    {
        
remove_task(id 222)
        
set_task(1.0,"CheckMoving",id 111 __"b")
    }


public 
event_bomb_dropped()
{
    new 
players[32],numi,id
    get_players
(players,num)
    
    for(
i=0;i<num;i++)
    {
        
id players[i]
    
        if(!
is_user_alive(id)) return
    
        
remove_task(id 111)
        
set_task(2.0,"BombPlant",id 222 __"b")
    }
}

public 
bomb_planted(id)
{
    if(!
is_user_alive(id)) return
        
    
remove_task(111)
        
    if(
cs_get_user_team(id) == CS_TEAM_CT)
    {
        
set_task(1.0,"CheckMoving",id 111 __"b")
    }
}

public 
CheckMoving(id)
{
    static 
iStillCounter[33]
    static 
FloatfVelocity[3]
        
    if(!
is_user_alive(id)) return
        
    
pev(id,pev_velocity,fVelocity)
    
    if(
fVelocity[0] || fVelocity[1] || fVelocity[2])
    {
        
iStillCounter[id] = 0
    
}
    else
    {
        if (++
iStillCounter[id] >= 5)
        {
            if(
cs_get_user_team(id) == CS_TEAM_T)
            {
                
ColorChat(id,GREEN,"PLANT C4!")
                
user_slap(id,0)
            }
                    
            if(
cs_get_user_team(id) == CS_TEAM_CT)
            {
                
ColorChat(id,GREEN,"DEFUSE C4!")
                
user_slap(id,0)
            }
        }
    }
}

public 
bomb_defusing(id)
{
    new 
buttons pev(idpev_button)
    new 
oldbuttons pev(idpev_oldbuttons)
    
    if(
buttons IN_USE)
    {
        
remove_task(id 111)
    }
    
    if(
oldbuttons IN_USE && !(buttons IN_USE))
    {
        
set_task(1.0,"CheckMoving",id 111 __"b")
    }
    
    if(
buttons IN_USE && !(oldbuttons IN_USE))
    {
        
ColorChat(id,GREEN,"test test test")
    }
    
    return 
FMRES_IGNORED
}

public 
start(id)
{
    
remove_task(id 111)
}

public 
bomb_defused(id)
{
    
remove_task(id 111)
}

public 
bomb_explode(id)
{
    
remove_task(id 111)
}

public 
BombPlant(id)
{
    if(!
is_user_alive(id)) return
    
    
ColorChat(id,GREEN,"TAKE C4 AND PLANT!")
    
user_slap(id,0)
}

public 
bomb_planting(id)
{
    new 
button;
    
button pev(idpev_button);
    
    if (
button IN_ATTACK)
    {
        
remove_task(id 111)
    }
    else
    {
        
set_task(1.0,"CheckMoving",id 111 __"b")
    }

Shows your code errors ?
Torge is offline
Apokalipsisa
Member
Join Date: May 2012
Old 09-07-2012 , 09:47   Re: How to catch holding fire button
Reply With Quote #10

Quote:
Originally Posted by Torge View Post
Shows your code errors ?
No compile errors or runtime errors in game,but still i dont know why nothing works?

Last edited by Apokalipsisa; 09-07-2012 at 09:48.
Apokalipsisa is offline
Old 09-07-2012, 09:49
Torge
This message has been deleted by Torge. Reason: My fault..
Reply


Thread Tools
Display Modes

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 08:20.


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