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

Block secondary knife attack for a certain time


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
wicho
Veteran Member
Join Date: Feb 2012
Location: GuateAmala
Old 06-30-2018 , 14:59   Block secondary knife attack for a certain time
Reply With Quote #1

Hi all, well as the title says, how can I block the knife for a certain time and without animation bugs? For example, when a player uses the secondary attack of the knife I want to block it for 10 seconds and after that time passes, the player can use it again and so on. Can someone give me an example please? Thanks in advance
wicho is offline
HamletEagle
AMX Mod X Plugin Approver
Join Date: Sep 2013
Location: Romania
Old 06-30-2018 , 15:07   Re: Block secondary knife attack for a certain time
Reply With Quote #2

m_flNextSecondaryAttack
__________________
HamletEagle is offline
wicho
Veteran Member
Join Date: Feb 2012
Location: GuateAmala
Old 06-30-2018 , 16:50   Re: Block secondary knife attack for a certain time
Reply With Quote #3

It's okay like this?

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

const m_flNextSecondaryAttack 47
const OFFSET_OWNER 41
const OFFSET_LINUX 4

new Float:g_flTime[33]

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

public 
ham_weapon_secundaryattack(ent)
{    
         if (!
pev_valid(ent))
               return 
HAM_IGNORED    
    
         
static idFloat:flCurrentTime
         id 
get_pdata_cbase(entOFFSET_OWNEROFFSET_LINUX)
         
flCurrentTime get_gametime()
    
         if(
g_flTime[id] > flCurrentTime)
         {
         
set_pdata_float(ent m_flNextSecondaryAttack 9999.0OFFSET_LINUX)
              return 
HAM_SUPERCEDE
         
}
    
         
g_flTime[id] = flCurrentTime 10.0
    
         
return HAM_IGNORED


Last edited by wicho; 06-30-2018 at 16:53.
wicho is offline
E1_531G
Senior Member
Join Date: Dec 2017
Old 06-30-2018 , 17:19   Re: Block secondary knife attack for a certain time
Reply With Quote #4

The hook must be PRE not POST.
__________________
My English is A0
E1_531G is offline
wicho
Veteran Member
Join Date: Feb 2012
Location: GuateAmala
Old 07-01-2018 , 11:55   Re: Block secondary knife attack for a certain time
Reply With Quote #5

I change it thanks, but when I attack once then I can not use the secondary attack again, I mean, when ten seconds pass I can not use it again, it always block.

Last edited by wicho; 07-01-2018 at 11:59.
wicho is offline
Celena Luna
Veteran Member
Join Date: Aug 2013
Location: Nagazora
Old 07-01-2018 , 13:22   Re: Block secondary knife attack for a certain time
Reply With Quote #6

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

const m_flNextSecondaryAttack 47
const OFFSET_LINUX 4

public plugin_init() 
{
        
RegisterHam(Ham_Weapon_SecondaryAttack "weapon_knife" "ham_weapon_secundaryattack" 0)
        
RegisterHam(Ham_Weapon_SecondaryAttack "weapon_knife" "ham_weapon_secundaryattack_post" 1)
}

public 
ham_weapon_secundaryattack(ent)
{    
         if (!
pev_valid(ent))
               return 
HAM_IGNORED    
    
         
static Float:flCurrentTime
         flCurrentTime 
get_pdata_float(entm_flNextSecondaryAttackOFFSET_LINUX//Get Secondary Attack Delay 

         
if(flCurrentTime 0.0//If it still > 0 then Stop it
             
return HAM_SUPERCEDE

    
         
return HAM_IGNORED
}  

public 
ham_weapon_secundaryattack_post(ent)
{    
         if (!
pev_valid(ent))
               return 
HAM_IGNORED

         
//Executed above. Time to set delay
         
set_pdata_float(ent m_flNextSecondaryAttack 10.0OFFSET_LINUX)    

         return 
HAM_IGNORED
 

__________________
My plugin:
Celena Luna is offline
CrazY.
Veteran Member
Join Date: May 2015
Location: SP, Brazil
Old 07-01-2018 , 14:02   Re: Block secondary knife attack for a certain time
Reply With Quote #7

@Celena Luna, you don't need to check if weapon is an valid entity. If it's not, hook will not be called. Return values it's ignored in post callbacks, so you don't need to return anything.
__________________









Last edited by CrazY.; 07-01-2018 at 14:04.
CrazY. is offline
Celena Luna
Veteran Member
Join Date: Aug 2013
Location: Nagazora
Old 07-01-2018 , 14:48   Re: Block secondary knife attack for a certain time
Reply With Quote #8

Quote:
Originally Posted by CrazY. View Post
@Celena Luna, you don't need to check if weapon is an valid entity. If it's not, hook will not be called. Return values it's ignored in post callbacks, so you don't need to return anything.
oh yeah, I forgot
__________________
My plugin:
Celena Luna is offline
HamletEagle
AMX Mod X Plugin Approver
Join Date: Sep 2013
Location: Romania
Old 07-02-2018 , 04:35   Re: Block secondary knife attack for a certain time
Reply With Quote #9

Quote:
Originally Posted by wicho View Post
I change it thanks, but when I attack once then I can not use the secondary attack again, I mean, when ten seconds pass I can not use it again, it always block.
Why are you surprised? You set the next attack after 9999.0 seconds. It should simply be 10.
__________________

Last edited by HamletEagle; 07-02-2018 at 04:36.
HamletEagle is offline
wicho
Veteran Member
Join Date: Feb 2012
Location: GuateAmala
Old 07-20-2018 , 23:41   Re: Block secondary knife attack for a certain time
Reply With Quote #10

Sorry to revive but I forget this, Celena Luna I tested your code but blocks the secundary attack all the time..
wicho 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 13:34.


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