AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   How to catch holding fire button (https://forums.alliedmods.net/showthread.php?t=195339)

Apokalipsisa 09-06-2012 11:55

How to catch holding fire button
 
Pls give me a example how to properly catch if holding fire button on the mouse and if its released.

Torge 09-06-2012 13:27

Re: How to catch holding fire button
 
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.

Apokalipsisa 09-06-2012 13:36

Re: How to catch holding fire button
 
Quote:

Originally Posted by Torge (Post 1792823)
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.

Torge 09-06-2012 13:37

Re: How to catch holding fire button
 
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
    
}



matsi 09-06-2012 14:30

Re: How to catch holding fire button
 
Quote:

Originally Posted by Torge (Post 1792823)
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.

ConnorMcLeod 09-06-2012 15:09

Re: How to catch holding fire button
 
Ripped from CBasePlayer::PreThink, 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
    
}



11922911 09-07-2012 03:53

Re: How to catch holding fire button
 
Quote:

Originally Posted by ConnorMcLeod (Post 1792872)
Ripped from CBasePlayer::PreThink, 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 :)

Apokalipsisa 09-07-2012 07:57

Re: How to catch holding fire button
 
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 :D ?

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")
    }



Torge 09-07-2012 08:04

Re: How to catch holding fire button
 
Quote:

Originally Posted by Apokalipsisa (Post 1793375)
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 :D ?

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 ?

Apokalipsisa 09-07-2012 09:47

Re: How to catch holding fire button
 
Quote:

Originally Posted by Torge (Post 1793377)
Shows your code errors ?

No compile errors or runtime errors in game,but still i dont know why nothing works?


All times are GMT -4. The time now is 08:20.

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