AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Delay Knife Attack (https://forums.alliedmods.net/showthread.php?t=226145)

Randomize 09-14-2013 07:16

Delay Knife Attack
 
How to make the damage delay? It only delay the animation.
PHP Code:

#include <amxmodx>
#include <amxmisc>
#include <fakemeta>
#include <engine>
#include <hamsandwich>
#include <xs>

#define PLUGIN     "Knife Delay"
#define VERSION "1.0"
#define AUTHOR     "DavidJr"

#define    m_flNextPrimaryAttack    46
#define    m_flNextSecondaryAttack    47
#define    m_flTimeWeaponIdle        48

new primary_delaysecondary_delayprimary_distancesecondary_distance

// Player vars
new g_attacking[33// get attacking

// Cached stuff for players
#define MAX_DISTANCE 40

new bool:g_amok_kukri[33]
new 
bool:g_bRemoveBlood[33]

public 
plugin_init() 
{
    
register_plugin(PLUGINVERSIONAUTHOR)
    
    
//Register Event
    
register_event("CurWeapon""Event_CurWeapon""be""1=1")
    
    
//Register Console Command
    
register_concmd("amok","cmdBuy")
    
    
//Register Forward
    
register_forward(FM_TraceLine"fw_TraceLine")
    
register_forward(FM_TraceHull"fw_TraceHull")
    
    
//Register Ham
    
RegisterHam(Ham_Weapon_PrimaryAttack"weapon_knife""fw_PrimaryAttack")
    
RegisterHam(Ham_Weapon_SecondaryAttack"weapon_knife""fw_SecondaryAttack")
    
RegisterHam(Ham_Weapon_PrimaryAttack"weapon_knife""fw_PrimaryAttack_Post"1)
    
RegisterHam(Ham_Weapon_SecondaryAttack"weapon_knife""fw_SecondaryAttack_Post"1)
    
RegisterHam(Ham_Weapon_PrimaryAttack"weapon_knife""Knife_PrimaryAttack"1)
    
RegisterHam(Ham_Weapon_SecondaryAttack"weapon_knife""Knife_SecondaryAttack"1)
    
RegisterHam(Ham_Weapon_PrimaryAttack"weapon_knife""Ham_KnifeAttack_Post"1)
    
RegisterHam(Ham_Weapon_SecondaryAttack"weapon_knife""Ham_KnifeAttack_Post"1)
    
RegisterHam(Ham_TakeDamage"player""Ham_TakeDamage_Pre"0)
    
RegisterHam(Ham_BloodColor"player""Ham_BloodColor_Pre"0)
    
    
// Register Cvar
    
primary_delay register_cvar("knife_attack1""1.1"//Delay Primary Attack
    
secondary_delay register_cvar("knife_attack2""1.25"//Delay Secondary
    
primary_distance register_cvar("knife_distance1""48.0"//Distance Primary Attack
    
secondary_distance register_cvar("knife_distance2""48.0"//Distance Secondary Attack
}
public 
plugin_precache()
{
    
precache_model("models/nst_wpn/p_primary_1.mdl")
    
precache_model("models/nst_wpn/v_amok_kukri.mdl")
}

public 
client_connect(id)
{
    
g_amok_kukri[id] = false
}
public 
cmdBuy(id)
{
    
g_amok_kukri[id] = true
}
public 
Event_CurWeapon(id)
{
    new 
weapon get_user_weapon(id)
    if(
weapon == CSW_KNIFE)
    {
        if(
g_amok_kukri[id])
        {
            
entity_set_string(idEV_SZ_viewmodel"models/nst_wpn/v_amok_kukri.mdl")
            
entity_set_string(idEV_SZ_weaponmodel"models/nst_wpn/p_primary_1.mdl")
        }
    }
}
/*================================================================================
 [Main Forwards]
=================================================================================*/
public fw_PrimaryAttack(weapon_ent)
{
    static 
owner
    owner 
pev(weapon_entpev_owner)
    
    
g_attacking[owner] = 1
}
public 
fw_SecondaryAttack(weapon_ent)
{
    
// Get owner
    
static owner
    owner 
pev(weapon_entpev_owner)
    
    
g_attacking[owner] = 2
}
public 
fw_PrimaryAttack_Post(weapon_ent)
{
    
// Get owner
    
static owner
    owner 
pev(weapon_entpev_owner)
    
    
g_attacking[owner] = 0
}
public 
fw_SecondaryAttack_Post(weapon_ent)
{
    
// Get owner
    
static owner
    owner 
pev(weapon_entpev_owner)
    
    
g_attacking[owner] = 0
}
public 
fw_TraceLine(Float:vector_start[3], Float:vector_end[3], ignored_monsteridhandle)
{
    
// Not alive
    
if (!is_user_alive(id))
        return 
FMRES_IGNORED;
    
    
// Not using knife
    
if (get_user_weapon(id) != CSW_KNIFE)
        return 
FMRES_IGNORED;
    
    
// Not attacking
    
if (!g_attacking[id])
        return 
FMRES_IGNORED;
    
    
pev(idpev_v_anglevector_end)
    
angle_vector(vector_endANGLEVECTOR_FORWARDvector_end)
    
    if (
g_attacking[id] == 1)
    {
        
xs_vec_mul_scalar(vector_endget_pcvar_float(primary_distance), vector_end)
    }
    else
    {
        
xs_vec_mul_scalar(vector_endget_pcvar_float(secondary_distance), vector_end)
    }
    
xs_vec_add(vector_startvector_endvector_end)
    
engfunc(EngFunc_TraceLinevector_startvector_endignored_monsteridhandle)
    
    return 
FMRES_SUPERCEDE
}
public 
fw_TraceHull(Float:vector_start[3], Float:vector_end[3], ignored_monsterhullidhandle)
{
    
// Not alive
    
if (!is_user_alive(id))
        return 
FMRES_IGNORED;
    
    
// Not using knife
    
if (get_user_weapon(id) != CSW_KNIFE)
        return 
FMRES_IGNORED;
    
    
// Not attacking
    
if (!g_attacking[id])
        return 
FMRES_IGNORED;
    
    
pev(idpev_v_anglevector_end)
    
angle_vector(vector_endANGLEVECTOR_FORWARDvector_end)
    
    if (
g_attacking[id] == 1)
    {
        
xs_vec_mul_scalar(vector_endget_pcvar_float(primary_distance), vector_end)
    }
    else
    {
        
xs_vec_mul_scalar(vector_endget_pcvar_float(secondary_distance), vector_end)
    }
    
    
xs_vec_add(vector_startvector_endvector_end)
    
engfunc(EngFunc_TraceHullvector_startvector_endignored_monsterhullidhandle)
    
    return 
FMRES_SUPERCEDE
}
public 
Ham_BloodColor_Pre(id)
{
    if(
g_bRemoveBlood[id])
    {
        
SetHamReturnInteger(-1)
        return 
HAM_SUPERCEDE
    
}
    
    return 
HAM_IGNORED
}
public 
Ham_KnifeAttack_Post(iEntity)
{
    new 
id pev(iEntitypev_owner)
    
    new 
iParams[4]
    
iParams[0] = id
    iParams
[1] = 35
    iParams
[2] = DMG_NEVERGIB DMG_SLASH
    iParams
[3] = iEntity
    
    set_task
(2.0"Task_CheckDamage"_iParamssizeof iParams)
    
    return 
HAM_IGNORED
}
public 
Ham_TakeDamage_Pre(iVictimiInflictoriAttackerFloat:flDamageiBits)
{
    if(!
is_user_alive(iAttacker) || !is_user_alive(iVictim))
        return 
HAM_IGNORED;
    
    if(
get_user_weapon(iAttacker) == CSW_KNIFE)
    {
        
g_bRemoveBlood[iAttacker] = true
        
return HAM_SUPERCEDE
    
}
    
    else 
g_bRemoveBlood[iAttacker] = false
    
    
return HAM_IGNORED;
}
public 
Task_CheckDamage(szParams[])
{
    new 
iAttacker szParams[0]
    new 
iDamage szParams[1]
    new 
iBits szParams[2]
    new 
iInflictor szParams[3]
    
    if(!
is_user_alive(iAttacker))
    return
    
    new 
iTargetiBody
    
    get_user_aiming
(iAttackeriTargetiBodyMAX_DISTANCE)

    if(!
is_user_alive(iTarget))
        return;
        
    
ExecuteHam(Ham_TakeDamageiTargetiInflictoriAttackerfloat(iDamage), iBits)
    
    return;
}  
public 
Knife_PrimaryAttack(ent)
{
    static 
Float:delay delay get_pcvar_float(primary_delay)
    
    
set_pdata_float(entm_flNextPrimaryAttackdelay4)
    
set_pdata_float(entm_flTimeWeaponIdledelay4)
}
public 
Knife_SecondaryAttack(ent)
{
    static 
Float:delay delay get_pcvar_float(secondary_delay)
    
    
set_pdata_float(entm_flNextSecondaryAttackdelay4)
    
set_pdata_float(entm_flTimeWeaponIdledelay4)



dark_style 09-14-2013 07:25

Re: Delay Knife Attack
 
https://forums.alliedmods.net/showthread.php?t=166175

Randomize 09-14-2013 07:42

Re: Delay Knife Attack
 
It didn't work, I've tried it.

~Ice*shOt 09-14-2013 10:24

Re: Delay Knife Attack
 
PHP Code:

    RegisterHam(Ham_Weapon_PrimaryAttack"weapon_knife""Fwd_AttackSpeed"1)
    
RegisterHam(Ham_Item_Deploy "weapon_knife""Fwd_AttackSpeed"1)

public 
Fwd_AttackSpeed(const Entity)
{
    if (!
pev_valid(Entity))
        return 
HAM_IGNORED

    set_pdata_float
(Entity461.14)
    
set_pdata_float(Entity471.254)

    return 
HAM_IGNORED



Randomize 10-05-2013 01:17

Re: Delay Knife Attack
 
Thanks Ice Shot, it works, but the problem is the default damage still appears and then the delayed ones. How to block default knife damage?

~Ice*shOt 10-05-2013 07:46

Re: Delay Knife Attack
 
return HAM_IGNORED in takedamage forward on weapon knife.

Randomize 10-05-2013 09:30

Re: Delay Knife Attack
 
Already did, still same. This just delay the animation, no the inflictor damage.
PHP Code:

    if (g_has_amok_kukri[id])
    {
        
set_pdata_float(entm_flNextPrimaryAttackdelay4)
        
set_pdata_float(entm_flNextSecondaryAttackdelay4)
        
set_pdata_float(entm_flTimeWeaponIdledelay4)
    }
    return 
HAM_IGNORED 


Black Rose 10-05-2013 10:57

Re: Delay Knife Attack
 
I believe it should be SUPERCEDE.
HAM_IGNORED has the same function as PLUGIN_CONTINUE for example. No change is made, the function will continue as expected.

I don't know if you're using the code in the first post still but make sure the damage manipulation is done on a pre-hook. On post it is too late.

Randomize 10-07-2013 10:21

Re: Delay Knife Attack
 
Black_Rose, It didn't work either. Also I have retyped the new code, still same. The inflictor damage can't be delayed. I don't want to use Ham_TakeDamage at all.

PHP Code:

#include <amxmodx>
#include <amxmisc>
#include <fakemeta>
#include <hamsandwich>

#define    m_pPlayer    41
#define    m_flNextPrimaryAttack    46
#define    m_flNextSecondaryAttack    47
#define    m_flTimeWeaponIdle        48

new knife_models[2][] = {"models/nst_wpn/p_knife.mdl""models/nst_wpn/v_knife.mdl"}

new 
primary_delaysecondary_delayprimary_damagesecondary_damageprimary_distancesecondary_distance

new bool:g_has_knife[33]

public 
plugin_init() 
{
    
register_plugin(PLUGINVERSIONAUTHOR)
    
    
//Register Event
    
register_event("CurWeapon""Event_CurWeapon""be""1=1")
    
    
//Register Console Command
    
register_concmd("amok","cmd_buy")

    
//Register Ham
    
RegisterHam(Ham_Item_Deploy "weapon_knife""Primary_Attack_Pre"1)
    
RegisterHam(Ham_Item_Deploy "weapon_knife""Secondary_Attack_Pre"1)
    
RegisterHam(Ham_TakeDamage"player""Ham_TakeDamage_Pre"0)
    
    
// Register Cvar
    
primary_delay register_cvar("knife_attack1""1.4"//Delay Primary Attack
    
secondary_delay register_cvar("knife_attack2""1.8"//Delay Secondary
    
primary_damage register_cvar("knife_damage1""0.7"//Delay Primary Attack
    
secondary_damage register_cvar("knife_damage2""0.8"//Delay Secondary
    
primary_distance register_cvar("knife_distance1""70"//Distance Primary Attack
    
secondary_distance register_cvar("knife_distance2""90"//Distance Secondary Attack
}
public 
plugin_precache()
{
    
precache_model(knife_models[0])
    
precache_model(knife_models[1])
}

public 
client_connect(id)
{
    
g_has_knife[id] = false
}
public 
cmd_buy(id)
{
    
g_has_knife[id] = true
}
public 
Event_CurWeapon(id)
{
    if(
get_user_weapon(id) == CSW_KNIFE && g_has_knife[id])
    {
        
set_pev(idpev_weaponmodel2knife_models[0])
        
set_pev(idpev_viewmodel2knife_models[1])
    }
}
public 
Primary_Attack_Pre(ent)
{
    new 
id get_pdata_cbase(entm_pPlayer4)
    static 
Float:delay delay get_pcvar_float(primary_delay)
    
    if (
g_has_knife[id])
    {
        
set_pdata_float(entm_flNextPrimaryAttackdelay4)
        
set_pdata_float(entm_flNextSecondaryAttackdelay4)
        
set_pdata_float(entm_flTimeWeaponIdledelay4)
    }
    return 
HAM_SUPERCEDE
}
public 
Secondary_Attack_Pre(ent)
{
    new 
id get_pdata_cbase(entm_pPlayer4)
    static 
Float:delay delay get_pcvar_float(secondary_delay)
    
    if (
g_has_knife[id])
    {
        
set_pdata_float(entm_flNextPrimaryAttackdelay4)
        
set_pdata_float(entm_flNextSecondaryAttackdelay4)
        
set_pdata_float(entm_flTimeWeaponIdledelay4)
    }
    return 
HAM_SUPERCEDE



Black Rose 10-07-2013 16:06

Delay Knife Attack
 
If you want to block the original damage you have to use TakeDamage.
I'll test the code tomorrow unless someone beats me to it.


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

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