Raised This Month: $51 Target: $400
 12% 

Solved Take Player +attack


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
XSlayer
Member
Join Date: Dec 2021
Old 07-16-2022 , 20:42   Take Player +attack
Reply With Quote #1

Hi, i wanted to know how to hook player primary attack,first of all, discard the ham forward, because it only runs when it fires itself, when you do something else it doesn't run, I just want to get if the player is pressing the primary attack, second, I read somewhere that CMD_Start is very bad for the CPU, so what options do I have to get it?( register_clcmd( "+attack", is blocked or something by the way )

Last edited by XSlayer; 07-26-2022 at 00:59.
XSlayer is offline
damage220
Member
Join Date: Jul 2022
Location: Ukraine
Old 07-16-2022 , 21:09   Re: Take Player +attack
Reply With Quote #2

Hi. There are IN_ATTACK and IN_ATTACK2 flags.
PHP Code:
public client_PreThink(cid)
{
    new 
btn;

    if(!
is_user_alive(cid))
        return;
    
btn get_user_button(cid);
    if(!(
btn IN_ATTACK))
        return;
    
/* do some things */

client_PreThink is also resource intensive, though.

Last edited by damage220; 07-16-2022 at 21:12.
damage220 is offline
XSlayer
Member
Join Date: Dec 2021
Old 07-16-2022 , 21:09   Re: Take Player +attack
Reply With Quote #3

Quote:
Originally Posted by damage220 View Post
Hi. There are IN_ATTACK and IN_ATTACK2 flags.
PHP Code:
public client_PreThink(cid)
{
    new 
btn;

    if(!
is_user_alive(cid))
        return;
    
btn get_user_button(cid);
    if(!(
btn IN_ATTACK))
        return;
    
/* do some things */


PreThink is more effective than cmd start? i mean for the cpu

PHP Code:
public @ClientCommand_InstantClientHandle )
{
      if(!
is_user_aliveClient ))
      {
           return 
1;
      }
      else
      {
         if(!
__int_Transformation[Client][5]) // Cant make an instant transformation
         

                 return 
1;
         }
         else
         {        
            if(
__int_Transformation[Client][0]) // Is in a transformation
            
{
                    return 
1;
            }
            else
            {            
               if(
get_user_weaponClient ) != 1// Not holding the correct weapon
               
{
                         return 
1;
               }   
               else
               { 
                      if(!
get_pdata_intClient198 )) // Not blocking
                      
{
                               return 
1;
                      }
                      else
                      {
                               static 
ControlControl get_uc(HandleUC_Buttons);

                               if((
Control == IN_ATTACK))
                               {
                                      
fxChargeInstantClient );
                               }
                      }
                       
               }
            }
         }
      }
      return 
0;

im doing this in CMD_Start

Last edited by XSlayer; 07-16-2022 at 21:12.
XSlayer is offline
damage220
Member
Join Date: Jul 2022
Location: Ukraine
Old 07-17-2022 , 10:44   Re: Take Player +attack
Reply With Quote #4

I have no idea which method is better, but you may try both. I would recommend to count how many times a method is called.
PHP Code:
public client_PreThink(cid)
{
    static 
count 0;

    
client_print(cidprint_chat"client_PreThink call #%d", ++count);
}

public 
ClientCommand_Instant(cidhandle)
{
    static 
count 0;

    
client_print(cidprint_chat"ClientCommand_Instant call #%d", ++count);

And choose the one that has less number.
PS: try to avoid nested "if" whenever possible.

Last edited by damage220; 07-17-2022 at 18:30.
damage220 is offline
Natsheh
Veteran Member
Join Date: Sep 2012
Old 07-18-2022 , 03:42   Re: Take Player +attack
Reply With Quote #5

Use cmd start its much better because its called when a player uses a key or hold a key.
__________________
@Jailbreak Main Mod v2.7.0 100%
@User Tag Prefix 100% done !
@Mystery Box 100% done !
@VIP System 100% done !

Natsheh is offline
Send a message via MSN to Natsheh Send a message via Skype™ to Natsheh
damage220
Member
Join Date: Jul 2022
Location: Ukraine
Old 07-18-2022 , 20:45   Re: Take Player +attack
Reply With Quote #6

Quote:
Originally Posted by Natsheh View Post
Use cmd start its much better because its called when a player uses a key or hold a key.
FM_CmdStart as well as client_PreThink or client_cmdStart is called on every frame, not a key press, and can be used to catch client state. You can make sure of it by changing fps_max value.
https://forums.alliedmods.net/showpo...03&postcount=5

Last edited by damage220; 07-18-2022 at 20:46.
damage220 is offline
Natsheh
Veteran Member
Join Date: Sep 2012
Old 07-19-2022 , 04:34   Re: Take Player +attack
Reply With Quote #7

Quote:
Originally Posted by damage220 View Post
FM_CmdStart as well as client_PreThink or client_cmdStart is called on every frame, not a key press, and can be used to catch client state. You can make sure of it by changing fps_max value.
https://forums.alliedmods.net/showpo...03&postcount=5
Cmdstart actually expect when a +action to be used then its called every frame otherwise when there is no action been used it will be stopped getting called.
__________________
@Jailbreak Main Mod v2.7.0 100%
@User Tag Prefix 100% done !
@Mystery Box 100% done !
@VIP System 100% done !


Last edited by Natsheh; 07-19-2022 at 04:35.
Natsheh is offline
Send a message via MSN to Natsheh Send a message via Skype™ to Natsheh
damage220
Member
Join Date: Jul 2022
Location: Ukraine
Old 07-19-2022 , 11:45   Re: Take Player +attack
Reply With Quote #8

Quote:
Originally Posted by Natsheh View Post
Cmdstart actually expect when a +action to be used then its called every frame otherwise when there is no action been used it will be stopped getting called.
Could you provide an example program? I did some tests and found out that any of the mentioned events are called on every frame no matter if there is +cmd or not.
damage220 is offline
wilian159
Member
Join Date: Dec 2013
Old 07-24-2022 , 22:16   Re: Take Player +attack
Reply With Quote #9

this ?:

PHP Code:
register_forward(FM_CmdStart"xCmdStart"false)

public 
xCmdStart(iduc_handlerandseed)
{
    if(!
is_user_alive(id))
        return 
FMRES_IGNORED
    
    
static xBtnxOldBtn
    xBtn 
get_uc(uc_handleUC_Buttons)
    
xOldBtn pev(idpev_oldbuttons)

    if((
xBtn IN_ATTACK) && !(xOldBtn IN_ATTACK))
    {
        const 
m_flNextAttack 83
        
const Float:nextTime 9999.0

        set_pdata_float
(idm_flNextAttacknextTime)

        
client_print(id3"-> attack block")
    }

    return 
FMRES_IGNORED

__________________
wilian159 is offline
damage220
Member
Join Date: Jul 2022
Location: Ukraine
Old 07-25-2022 , 03:51   Re: Take Player +attack
Reply With Quote #10

Quote:
Originally Posted by wilian159 View Post
this ?:

PHP Code:
register_forward(FM_CmdStart"xCmdStart"false)

public 
xCmdStart(iduc_handlerandseed)
{
    if(!
is_user_alive(id))
        return 
FMRES_IGNORED
    
    
static xBtnxOldBtn
    xBtn 
get_uc(uc_handleUC_Buttons)
    
xOldBtn pev(idpev_oldbuttons)

    if((
xBtn IN_ATTACK) && !(xOldBtn IN_ATTACK))
    {
        const 
m_flNextAttack 83
        
const Float:nextTime 9999.0

        set_pdata_float
(idm_flNextAttacknextTime)

        
client_print(id3"-> attack block")
    }

    return 
FMRES_IGNORED

No. It is called every frame even when player idle (i.e. do nothing). I was expecting that the handler will be called when I jump or shoot, or whatever but not when I am moving or idle.
damage220 is offline
Reply



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 01:17.


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