AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Block secondary knife attack for a certain time (https://forums.alliedmods.net/showthread.php?t=308711)

wicho 06-30-2018 14:59

Block secondary knife attack for a certain time
 
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

HamletEagle 06-30-2018 15:07

Re: Block secondary knife attack for a certain time
 
m_flNextSecondaryAttack

wicho 06-30-2018 16:50

Re: Block secondary knife attack for a certain time
 
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



E1_531G 06-30-2018 17:19

Re: Block secondary knife attack for a certain time
 
The hook must be PRE not POST.

wicho 07-01-2018 11:55

Re: Block secondary knife attack for a certain time
 
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.

Celena Luna 07-01-2018 13:22

Re: Block secondary knife attack for a certain time
 
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
 



CrazY. 07-01-2018 14:02

Re: Block secondary knife attack for a certain time
 
@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.

Celena Luna 07-01-2018 14:48

Re: Block secondary knife attack for a certain time
 
Quote:

Originally Posted by CrazY. (Post 2600356)
@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 :P

HamletEagle 07-02-2018 04:35

Re: Block secondary knife attack for a certain time
 
Quote:

Originally Posted by wicho (Post 2600336)
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.

wicho 07-20-2018 23:41

Re: Block secondary knife attack for a certain time
 
Sorry to revive but I forget this, Celena Luna I tested your code but blocks the secundary attack all the time..


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

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