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

Block secondary knife attack for a certain time


Post New Thread Reply   
 
Thread Tools Display Modes
DeMNiX
Veteran Member
Join Date: Nov 2011
Location: Russia
Old 07-21-2018 , 00:41   Re: Block secondary knife attack for a certain time
Reply With Quote #11

lol
Spoiler


can do better like this? If you set a value greater than zero, the attack event simply does not happen until the time expires
PHP Code:
#include <amxmodx>
#include <fakemeta> 
#include <hamsandwich> 

#define m_flNextSecondaryAttack 47 
#define OFFSET_WEAPON 4 
#define OFFSET_PLAYER 5 
#define  m_pActiveItem 373

#define PDATA_SAFE 2

#define DELAY 10.0

#define BYCOMMAND

public plugin_init()
{
    
#if defined BYCOMMAND
        
register_clcmd("say /block""clcmd_block");
    
#endif

    
RegisterHam(Ham_Weapon_SecondaryAttack"weapon_knife""fw_Knife_SecondaryAttack_Post"true);
}

#if defined BYCOMMAND
    
public clcmd_block(id)
    {
        new 
pActiveItempActiveItem get_pdata_cbase(idm_pActiveItemOFFSET_PLAYER);

        if (
pev_valid(pActiveItem) != PDATA_SAFE) {

            return;
        }

        
set_pdata_float(pActiveItemm_flNextSecondaryAttackDELAYOFFSET_WEAPON);
    }
#endif

public fw_Knife_SecondaryAttack_Post(iEnt)
{
    
set_pdata_float(iEntm_flNextSecondaryAttackDELAYOFFSET_WEAPON);

__________________
My channel with test codes
https://www.youtube.com/user/demnix03

Zombie Riot [Scenario & bots-zombie 11.11.2023]
https://youtu.be/8ZZan-aq2sc
DeMNiX is offline
wicho
Veteran Member
Join Date: Feb 2012
Location: GuateAmala
Old 07-21-2018 , 14:30   Re: Block secondary knife attack for a certain time
Reply With Quote #12

I did it like that, it blocks the primary attack always but I have a problem with the secondary attack. The problem is that I can attack twice and when I attack for the second time the bar that indicates that you have to wait for 10 seconds comes out. How can I make it so that I attack only once and the bar comes out after the attack?

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

#define PLUGIN "New Plug-In"
#define VERSION "1.0"
#define AUTHOR "author"

const OFFSET_OWNER 41
const OFFSET_LINUX 4

const m_flNextPrimaryAttack 46
const m_flNextSecondaryAttack 47
const m_pActiveItem 373

new Float:g_flTime[33]

public 
plugin_init() 
{
    
register_plugin(PLUGINVERSIONAUTHOR)
    
    
RegisterHam(Ham_Weapon_SecondaryAttack"weapon_knife""ham_weapon_secundaryattack")
    
RegisterHam(Ham_Weapon_SecondaryAttack "weapon_knife""BlockPrimaryKnife"1)
}

public 
ham_weapon_secundaryattack(ent)
{    
    if (!
pev_valid(ent))
    return 
HAM_IGNORED;
    
    static 
idFloat:flCurrentTimeiWpnID
    id 
get_pdata_cbase(entOFFSET_OWNEROFFSET_LINUX)
    
flCurrentTime get_gametime()
    
iWpnID get_pdata_cbase(idm_pActiveItem5)
    
    if(
g_flTime[id] > flCurrentTime)
    {
        
Make_BarTime(id10)
        
set_pdata_float(iWpnIDm_flNextSecondaryAttack, (g_flTime[id] - flCurrentTime), OFFSET_LINUX)
        return 
HAM_SUPERCEDE;
    }
    
    
g_flTime[id] = flCurrentTime 10.0
    
    
return HAM_IGNORED;


public 
BlockPrimaryKnife(ent)
{    
    
set_pdata_float(entm_flNextPrimaryAttack9999.0OFFSET_LINUX)


Make_BarTime(idiSeconds

    
message_begin(MSG_ONE_UNRELIABLEg_iBarTime, .player=id)
    
write_short(iSeconds)
    
message_end()

wicho is offline
Celena Luna
Veteran Member
Join Date: Aug 2013
Location: Nagazora
Old 07-21-2018 , 23:38   Re: Block secondary knife attack for a certain time
Reply With Quote #13

I am lazy so just do it like this

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

#define PLUGIN "New Plug-In" 
#define VERSION "1.0" 
#define AUTHOR "author" 

public plugin_init()  

    
register_plugin(PLUGINVERSIONAUTHOR
     
    
RegisterHam(Ham_Weapon_SecondaryAttack"weapon_knife""ham_weapon_secundaryattack"
    
RegisterHam(Ham_Weapon_SecondaryAttack "weapon_knife""BlockPrimaryKnife"1


public 
ham_weapon_secundaryattack(ent
{     
    
Make_BarTime(id10
    
Set_Player_NextAttack(id10.0)
    
Set_Weapon_Idle(idCSW_KNIFE 10.0
}  

public 
BlockPrimaryKnife(ent
{     
    return 
HAM_SUPERCEDE //Just block it already
}  

Make_BarTime(idiSeconds)  
{  
    
message_begin(MSG_ONE_UNRELIABLEg_iBarTime, .player=id
    
write_short(iSeconds
    
message_end() 
}  

stock Set_Weapon_Idle(idWeaponId ,Float:TimeIdle)
{
    static 
entwpnentwpn fm_get_user_weapon_entity(idWeaponId)
    if(!
pev_valid(entwpn))
        return

    
set_pdata_float(entwpn46TimeIdle4)
    
set_pdata_float(entwpn47TimeIdle4)
    
set_pdata_float(entwpn48TimeIdle 0.54)
}

stock Set_Player_NextAttack(idFloat:NextTimeset_pdata_float(id83NextTime5
__________________
My plugin:
Celena Luna is offline
CrazY.
Veteran Member
Join Date: May 2015
Location: SP, Brazil
Old 07-22-2018 , 09:26   Re: Block secondary knife attack for a certain time
Reply With Quote #14

Quote:
Code:
RegisterHam(Ham_Weapon_SecondaryAttack , "weapon_knife", "BlockPrimaryKnife", 1) ;
Code:
public BlockPrimaryKnife(ent)  {          return HAM_SUPERCEDE //Just block it already }
To block, should register as an pre, not post.

Quote:
Originally Posted by CrazY.
Return values it's ignored in post callbacks
__________________









Last edited by CrazY.; 07-22-2018 at 09:26.
CrazY. is offline
Celena Luna
Veteran Member
Join Date: Aug 2013
Location: Nagazora
Old 07-22-2018 , 10:42   Re: Block secondary knife attack for a certain time
Reply With Quote #15

Quote:
Originally Posted by CrazY. View Post
To block, should register as an pre, not post.
Wait, he Hook Post Secondary and wrote block PrimaryAttack at public ∑(゚Д゚)
I didn't notice

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

#define PLUGIN "New Plug-In" 
#define VERSION "1.0" 
#define AUTHOR "author" 

public plugin_init()  

    
register_plugin(PLUGINVERSIONAUTHOR
     
    
RegisterHam(Ham_Weapon_PrimaryAttack "weapon_knife""ham_weapon_primaryattack"
    
RegisterHam(Ham_Weapon_SecondaryAttack"weapon_knife""ham_weapon_secondaryattack_post"1


public 
ham_weapon_primaryattack(ent
{     
    return 
HAM_SUPERCEDE //Just block it already
}  

public 
ham_weapon_secondaryattack_post(ent
{     
    
Make_BarTime(id10
    
Set_Player_NextAttack(id10.0)
    
Set_Weapon_Idle(idCSW_KNIFE 10.0
}  

Make_BarTime(idiSeconds)  
{  
    
message_begin(MSG_ONE_UNRELIABLEg_iBarTime, .player=id
    
write_short(iSeconds
    
message_end() 
}  

stock Set_Weapon_Idle(idWeaponId ,Float:TimeIdle)
{
    static 
entwpnentwpn fm_get_user_weapon_entity(idWeaponId)
    if(!
pev_valid(entwpn))
        return

    
set_pdata_float(entwpn46TimeIdle4)
    
set_pdata_float(entwpn47TimeIdle4)
    
set_pdata_float(entwpn48TimeIdle 0.54)
}

stock Set_Player_NextAttack(idFloat:NextTimeset_pdata_float(id83NextTime5
This should work
__________________
My plugin:

Last edited by Celena Luna; 07-22-2018 at 12:41.
Celena Luna is offline
DeMNiX
Veteran Member
Join Date: Nov 2011
Location: Russia
Old 07-23-2018 , 03:24   Re: Block secondary knife attack for a certain time
Reply With Quote #16

@celena, stop write bullshit

why are u guys use post + pre? explain me for what? just use secondary hook in pre state and set in pre flSecondaryattack offset for weapon = it will block secondary button on this weapon on setted time
__________________
My channel with test codes
https://www.youtube.com/user/demnix03

Zombie Riot [Scenario & bots-zombie 11.11.2023]
https://youtu.be/8ZZan-aq2sc
DeMNiX is offline
Celena Luna
Veteran Member
Join Date: Aug 2013
Location: Nagazora
Old 07-23-2018 , 03:33   Re: Block secondary knife attack for a certain time
Reply With Quote #17

Quote:
Originally Posted by DeMNiX View Post
@celena, stop write bullshit

why are u guys use post + pre? explain me for what? just use secondary hook in pre state and set in pre flSecondaryattack offset for weapon = it will block secondary button on this weapon on setted time
He also want to block PrimaryAttack too.
And he want to use SecondaryAttack first then delay + show the bar.
My writing could be shitty but I haven't found a better way yet.
__________________
My plugin:

Last edited by Celena Luna; 07-23-2018 at 03:49.
Celena Luna is offline
DeMNiX
Veteran Member
Join Date: Nov 2011
Location: Russia
Old 07-23-2018 , 03:39   Re: Block secondary knife attack for a certain time
Reply With Quote #18

so what a problem to block primary via flNext_PrimaryAttack too?
if u set SecondaryAttack offset in pre state next attack will be delayed by offset's value
__________________
My channel with test codes
https://www.youtube.com/user/demnix03

Zombie Riot [Scenario & bots-zombie 11.11.2023]
https://youtu.be/8ZZan-aq2sc
DeMNiX is offline
Ghosted
Veteran Member
Join Date: Apr 2015
Location: Georgia
Old 07-23-2018 , 03:40   Re: Block secondary knife attack for a certain time
Reply With Quote #19

Code:
#include <amxmodx>
#include <amxmisc>
#include <hamsandwich>
#include <fakemeta>
#include <engine>

#define KNIFE_NEXTATTACK EV_FL_fuser4
#define m_flNextSecondaryAttack	47

const Float:KnifeNextAttackDelay = 10.0;

public plugin_init()
{
	register_plugin("Knife Delay", "1.0", "Ghost");
	RegisterHam(Ham_Item_Deploy, "weapon_knife", "Ham_Knife_Deploy", 1);
	RegisterHam(Ham_Weapon_SecondaryAttack, "weapon_knife", "Ham_Knife_SecondaryAttack_Post", 1);
}

public Ham_Knife_Deploy(Entity)
{
	new Float:DeployTime = get_pdata_float(Entity, m_flNextSecondaryAttack);
	new Float:MinimumDeployTime = entity_get_float(Entity, KNIFE_NEXTATTACK);
	new Float:GameTime = get_gametime();
	
	if (DeployTime + GameTime < MinimumDeployTime)
		set_pdata_float(Entity, m_flNextSecondaryAttack, MinimumDeployTime - GameTime);
}

public Ham_Knife_SecondaryAttack_Post(Entity)
{
	set_pdata_float(Entity, m_flNextSecondaryAttack, KnifeNextAttackDelay);
	entity_set_float(Entity, KNIFE_NEXTATTACK, get_gametime() + KnifeNextAttackDelay);
}
__________________

[MOD] CS Weapon Mod V1.7.1
[MM] MetaMod-C V1.0
[MOD] CS NPC Mod (5%)


Probably Left AM

Last edited by Ghosted; 07-23-2018 at 03:41.
Ghosted is offline
Celena Luna
Veteran Member
Join Date: Aug 2013
Location: Nagazora
Old 07-23-2018 , 03:59   Re: Block secondary knife attack for a certain time
Reply With Quote #20

Quote:
Originally Posted by DeMNiX View Post
so what a problem to block primary via flNext_PrimaryAttack too?
if u set SecondaryAttack offset in pre state next attack will be delayed by offset's value
I forgot about that...
My bad then...
This correct?

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

#define DELAY 10.0 

public plugin_init() 

    
RegisterHam(Ham_Weapon_PrimaryAttack"weapon_knife""fw_Knife_PrimaryAttack"); 
    
RegisterHam(Ham_Weapon_SecondaryAttack"weapon_knife""fw_Knife_SecondaryAttack_Post"true); 
}

public 
fw_Knife_PrimaryAttack(Ent

    
set_pdata_float(Ent46DELAY4); 


public 
fw_Knife_SecondaryAttack_Post(Ent

    static 
ownerowner pev(Entpev_owner)
    
set_pdata_float(Ent47DELAY4);
    
Make_BarTime(Ownerfloatround(Delay)) 

}

Make_BarTime(idiSeconds)  
{  
    
message_begin(MSG_ONE_UNRELIABLEget_user_msgid("BarTime"), .player=id
    
write_short(iSeconds
    
message_end() 

__________________
My plugin:

Last edited by Celena Luna; 07-23-2018 at 04:01.
Celena Luna 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 04:15.


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