Raised This Month: $32 Target: $400
 8% 

Delay Knife Attack


Post New Thread Reply   
 
Thread Tools Display Modes
Black Rose
Veteran Member
Join Date: Feb 2011
Location: Stockholm, Sweden
Old 10-13-2013 , 08:34   Re: Delay Knife Attack
Reply With Quote #21

Did you write "amok"?
It only works with knife.
__________________
Black Rose is offline
Randomize
BANNED
Join Date: May 2012
Location: in your heart
Old 10-13-2013 , 09:16   Re: Delay Knife Attack
Reply With Quote #22

Black, yes I wrote it in console, and amok is custom knife I made.

Last edited by Randomize; 10-13-2013 at 09:22.
Randomize is offline
Black Rose
Veteran Member
Join Date: Feb 2011
Location: Stockholm, Sweden
Old 10-13-2013 , 09:19   Re: Delay Knife Attack
Reply With Quote #23

I also hope you realized i commented out the custom models because I didn't have them.
You obviously need to uncomment them and remove the default models i used instead.

If that's not the problem. What exactly is not working? Are there any errors?
It was working fine when I tried it.
__________________
Black Rose is offline
Randomize
BANNED
Join Date: May 2012
Location: in your heart
Old 10-13-2013 , 09:29   Re: Delay Knife Attack
Reply With Quote #24

The damage still didn't delayed also I have tried with the default knife. Take a look with my code:

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

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

#define    m_pPlayer    41
#define    m_flNextPrimaryAttack    46
#define    m_flNextSecondaryAttack    47
#define    m_flTimeWeaponIdle        48
#define m_flNextAttack                83
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], 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","cmd_buy")

    
//Register Ham
    
RegisterHam(Ham_Weapon_PrimaryAttack"weapon_knife""Primary_Attack"1)
    
RegisterHam(Ham_Weapon_SecondaryAttack"weapon_knife""Secondary_Attack"1)
    
RegisterHam(Ham_Weapon_PrimaryAttack"weapon_knife""Primary_Attack_Pre"1)
    
RegisterHam(Ham_Weapon_SecondaryAttack"weapon_knife""Secondary_Attack_Pre"1)
    
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)
    
RegisterHam(Ham_BloodColor"player""Ham_BloodColor_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 
Ham_BloodColor_Pre(id)
{
    if(
g_bRemoveBlood[id])
    {
        
SetHamReturnInteger(-1)
        return 
HAM_SUPERCEDE
    
}
    return 
HAM_IGNORED
}
public 
Primary_Attack(iEntity)
{
    new 
id pev(iEntitypev_owner)
    
    new 
iParams[4]
    
iParams[0] = id
    iParams
[1] = 56
    iParams
[2] = DMG_NEVERGIB DMG_SLASH
    iParams
[3] = iEntity
    
    
static Float:damage damage get_pcvar_float(primary_damage)
    
    
set_task(damage"Primary_Attack_Post"_iParamssizeof iParams)
       
    return 
HAM_IGNORED
}
public 
Secondary_Attack(ent)
{
    new 
id pev(entpev_owner)
    
    new 
iParams[4]
    
iParams[0] = id
    iParams
[1] = 107
    iParams
[2] = DMG_NEVERGIB DMG_SLASH
    iParams
[3] = ent
    
    
static Float:damage damage get_pcvar_float(secondary_damage)
    
    
set_task(damage"Secondary_Attack_Post"_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_has_knife[iAttacker])
    {
        
g_bRemoveBlood[iAttacker] = true
        
return HAM_SUPERCEDE
    
}
    else 
g_bRemoveBlood[iAttacker] = false
    
    
return HAM_IGNORED
}
public 
Primary_Attack_Post(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
    
    
new distance get_pcvar_num(primary_distance)
    
    
get_user_aiming(iAttackeriTargetiBodydistance)

    if(!
is_user_alive(iTarget))
        return;
        
    
ExecuteHam(Ham_TakeDamageiTargetiInflictoriAttackerfloat(iDamage), iBits)
    
    return;
}  
public 
Secondary_Attack_Post(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
    
    
new distance get_pcvar_num(secondary_distance)
    
    
get_user_aiming(iAttackeriTargetiBodydistance)

    if(!
is_user_alive(iTarget))
        return;
        
    
ExecuteHam(Ham_TakeDamageiTargetiInflictoriAttackerfloat(iDamage), iBits)
    
    return;
}  
public 
Primary_Attack_Pre(ent)
{
    new 
id get_pdata_cbase(entm_pPlayer4)
    static 
Float:delay delay get_pcvar_float(primary_delay)
    
    
set_pdata_float(entm_flNextPrimaryAttackdelay4)
    
set_pdata_float(entm_flNextSecondaryAttackdelay4)
    
set_pdata_float(entm_flTimeWeaponIdledelay4)
    return 
HAM_IGNORED
}
public 
Secondary_Attack_Pre(ent)
{
    
//new id = get_pdata_cbase(ent, m_pPlayer, 4)
    
new id pev(entpev_owner)
    static 
Float:delay delay get_pcvar_float(secondary_delay)
    static 
Float:damage damage get_pcvar_float(secondary_damage)
    
    
set_pdata_float(entm_flNextPrimaryAttackdelay4)
    
set_pdata_float(entm_flNextSecondaryAttackdelay4)
    
set_pdata_float(entm_flTimeWeaponIdledelay4)
    
set_pdata_float(idm_flNextAttackdamage5)
    
    return 
HAM_SUPERCEDE

Forget about the custom model, I have removed it. If you try it with default model, you'll see the knife will attack twice in single attack. What I want is second the damage after the default damage. The second damage that I try is delayed by cvar knife_delay1. Do you get it sir?

Last edited by Randomize; 10-13-2013 at 09:29.
Randomize is offline
Black Rose
Veteran Member
Join Date: Feb 2011
Location: Stockholm, Sweden
Old 10-13-2013 , 12:16   Delay Knife Attack
Reply With Quote #25

I still have no idea what you want. Explain it step by step if you have to.
__________________
Black Rose is offline
Randomize
BANNED
Join Date: May 2012
Location: in your heart
Old 10-14-2013 , 05:26   Re: Delay Knife Attack
Reply With Quote #26

Hmm.. I just try to delay the stab. If you stab with default knife, the damage occurs before the stab animation starts, does it? I want the damage directly occurs when the stab animation is performed. I'll upload the model.

Here is the model, if we attack with this knife, the damage should be performed when the animation is slashing (hit the body) but the default damage is performed when the animation starts to slashing.
Attached Files
File Type: zip v_amok_kukri.zip (296.8 KB, 93 views)

Last edited by Randomize; 10-14-2013 at 05:37.
Randomize is offline
Black Rose
Veteran Member
Join Date: Feb 2011
Location: Stockholm, Sweden
Old 10-20-2013 , 02:19   Re: Delay Knife Attack
Reply With Quote #27

Have fun.
Please let me know about any problems or errors. Especially the pdata offsets on linux.
Code:
#include <amxmodx> #include <fakemeta> #include <hamsandwich> #include <xs> #define m_pPlayer      41 // CBasePlayerItem, Linux +4 #define m_flNextAttack  83 // CBasePlayer, Linux +5 #define P_MODEL "models/p_knife.mdl" #define V_MODEL "models/v_amok_kukri.mdl" new bool:gKnife[33],     gKnifeEntity,     gMaxPlayers,     gPModel,     gVModel,         pCvar_PriDelay,     pCvar_PriDamage,     pCvar_PriFreq,     pCvar_PriRange,     pCvar_SecDelay,     pCvar_SecDamage,     pCvar_SecFreq,     pCvar_SecRange; new const Float:PrimaryDamage[] = {     15.0,   /* Generic */     60.0,   /* Head */     15.0,   /* Chest */     18.75/* Stomach */     15.0,   /* Left Arm */     15.0,   /* Right Arm */     11.25/* Left Leg */     11.25   /* Right Leg */ }; new const Float:SecondaryDamage[] = {     65.0,   /* Generic */     260.0/* Head */     65.0,   /* Chest */     81.25/* Stomach */     65.0,   /* Left Arm */     65.0,   /* Right Arm */     48.75/* Left Leg */     48.75   /* Right Leg */ }; new const gSoundBHitFlesh[][] = {     "player/bhit_flesh-1.wav",     "player/bhit_flesh-2.wav",     "player/bhit_flesh-3.wav" }; new const gSoundKnifeHit[][] = {     "weapons/knife_hit1.wav",     "weapons/knife_hit2.wav",     "weapons/knife_hit3.wav",     "weapons/knife_hit4.wav" }; new const gSoundKnifeSlash[][] = {     "weapons/knife_slash1.wav",     "weapons/knife_slash2.wav" }; #define ATTACK_PRIMARY 1 #define ATTACK_SECONDARY 2 public plugin_init() {         register_plugin("Delay Knife Attack", "1.0", "[ --{-@ ]");         register_concmd("amok","cmd_buy");         RegisterHam(Ham_Killed, "player", "fwd_Killed");     RegisterHam(Ham_Weapon_PrimaryAttack, "weapon_knife", "fwd_Weapon_PrimaryAttack_Pre");     RegisterHam(Ham_Weapon_SecondaryAttack, "weapon_knife", "fwd_Weapon_SecondaryAttack_Pre");     RegisterHam(Ham_TraceAttack, "player", "fwd_TraceAttack_Pre");     RegisterHam(Ham_Item_Deploy, "weapon_knife", "fwd_ItemDeploy_Post", 1);         register_forward(FM_EmitSound, "fwd_EmitSound");         if ( ( gKnifeEntity = engfunc(EngFunc_CreateNamedEntity, engfunc(EngFunc_AllocString, "weapon_knife")) ) )         set_pdata_int(gKnifeEntity, m_pPlayer, 0, 4); // Just so Ham won't deny us.         pCvar_PriDelay = register_cvar("knife_delay_pri", "0.5");     pCvar_PriDamage = register_cvar("knife_damage_pri", "1.2");     pCvar_PriFreq = register_cvar("knife_frequency_pri", "1.0");     pCvar_PriRange = register_cvar("knife_range_pri", "48");         pCvar_SecDelay = register_cvar("knife_delay_sec", "0.8");     pCvar_SecDamage = register_cvar("knife_damage_sec", "1.2");     pCvar_SecFreq = register_cvar("knife_frequency_sec", "1.2");     pCvar_SecRange = register_cvar("knife_range_sec", "32");     gMaxPlayers = get_maxplayers(); } public fwd_EmitSound(id, channel, const sound[], Float:vol, Float:attn, flags, pitch) {         if ( is_user_connected(id) && gKnife[id] && ( channel == CHAN_WEAPON || channel == CHAN_ITEM ) && equal(sound, "weapons/knife_", 14) && ! equal(sound[14], "deploy", 6) )         return FMRES_SUPERCEDE;         return FMRES_IGNORED; } public plugin_precache() {         precache_model(P_MODEL);     precache_model(V_MODEL);         gPModel = engfunc(EngFunc_AllocString, P_MODEL);     gVModel = engfunc(EngFunc_AllocString, V_MODEL);         for ( new i = 0 ; i < sizeof gSoundBHitFlesh ; i++ )         precache_sound(gSoundBHitFlesh[i]);         for ( new i = 0 ; i < sizeof gSoundKnifeHit ; i++ )         precache_sound(gSoundKnifeHit[i]);         for ( new i = 0 ; i < sizeof gSoundKnifeSlash ; i++ )         precache_sound(gSoundKnifeSlash[i]); } public client_disconnect(id) {     gKnife[id] = false;     remove_task(id); } public cmd_buy(id)     gKnife[id] = true; public fwd_ItemDeploy_Post(ent) {         new id = get_pdata_cbase(ent, m_pPlayer, 4);         if ( is_user_alive(id) && gKnife[id] ) {         set_pev_string(id, pev_weaponmodel2, gPModel);         set_pev_string(id, pev_viewmodel2, gVModel);     } } public fwd_TraceAttack_Pre(victim, attacker, Float:damage, Float:direction[3], tracehandle, damagebits) {         if ( 1 <= attacker <= gMaxPlayers && gKnife[attacker] )         return HAM_SUPERCEDE;         return HAM_IGNORED; } public fwd_Weapon_PrimaryAttack_Pre(ent)     ProcessAttack(ent, ATTACK_PRIMARY); public fwd_Weapon_SecondaryAttack_Pre(ent)     ProcessAttack(ent, ATTACK_SECONDARY); ProcessAttack(ent, AttackType) {         new id = get_pdata_cbase(ent, m_pPlayer, 4);         if ( ! gKnife[id] )         return;         new TaskData[2];     TaskData[0] = id;     TaskData[1] = AttackType;         set_pdata_float(id, m_flNextAttack, AttackType == ATTACK_PRIMARY ? get_pcvar_float(pCvar_PriFreq) : get_pcvar_float(pCvar_SecFreq), 5);     set_task(AttackType == ATTACK_PRIMARY ? get_pcvar_float(pCvar_PriDelay) : get_pcvar_float(pCvar_SecDelay), "task_DelayAttack", id, TaskData, 2); } public task_DelayAttack(TaskData[]) {         new id = TaskData[0];     new AttackType = TaskData[1];         new Float:viewofs[3];     new Float:start[3];     new Float:end[3];     new Float:AimVec[3];         pev(id, pev_origin, start);     pev(id, pev_view_ofs, viewofs);     xs_vec_add(start, viewofs, start);         velocity_by_aim(id, 1, AimVec);     xs_vec_mul_scalar(AimVec, AttackType == ATTACK_PRIMARY ? get_pcvar_float(pCvar_PriRange) : get_pcvar_float(pCvar_SecRange), end);     xs_vec_add(start, end, end);         new hTrace, Float:trFraction, bool:trHull;         engfunc(EngFunc_TraceLine, start, end, DONT_IGNORE_MONSTERS, id, hTrace);     get_tr2(hTrace, TR_flFraction, trFraction);         if ( trFraction >= 1.00 ) {         engfunc(EngFunc_TraceHull, start, end, DONT_IGNORE_MONSTERS, HULL_HEAD, id, hTrace);         get_tr2(hTrace, TR_flFraction, trFraction);         trHull = true;     }         if ( trFraction >= 1.00 )         emit_sound(id, CHAN_WEAPON, gSoundKnifeSlash[random(sizeof gSoundKnifeSlash)], VOL_NORM, ATTN_NORM, 0, 94);     else {         new trPlayer = get_tr2(hTrace, TR_pHit);                 if ( 1 <= trPlayer <= gMaxPlayers ) {                         emit_sound(trPlayer, CHAN_VOICE, gSoundBHitFlesh[random(sizeof gSoundBHitFlesh)], VOL_NORM, ATTN_NORM, 0, PITCH_NORM);                         new hTraceAttack = create_tr2();             if ( trHull )                 engfunc(EngFunc_TraceHull, start, end, DONT_IGNORE_MONSTERS, HULL_HEAD, id, hTraceAttack);             else                 engfunc(EngFunc_TraceLine, start, end, DONT_IGNORE_MONSTERS, id, hTraceAttack);             ExecuteHam(Ham_TraceAttack, trPlayer, id, AttackType == ATTACK_PRIMARY ? PrimaryDamage[0] : SecondaryDamage[0], AimVec, hTraceAttack, DMG_BULLET|DMG_NEVERGIB);             free_tr2(hTraceAttack);                                     if ( AttackType == ATTACK_PRIMARY ) {                 emit_sound(id, CHAN_WEAPON, gSoundKnifeHit[random(sizeof gSoundKnifeHit)], VOL_NORM, ATTN_NORM, 0, PITCH_NORM);                 ExecuteHam(Ham_TakeDamage, trPlayer, gKnifeEntity, id, PrimaryDamage[get_tr2(hTrace, TR_iHitgroup)] * get_pcvar_float(pCvar_PriDamage), DMG_BULLET|DMG_NEVERGIB);             }             else {                 emit_sound(id, CHAN_WEAPON, "weapons/knife_stab.wav", VOL_NORM, ATTN_NORM, 0, PITCH_NORM);                 ExecuteHam(Ham_TakeDamage, trPlayer, gKnifeEntity, id, ( SecondaryDamage[get_tr2(hTrace, TR_iHitgroup)] * get_pcvar_float(pCvar_SecDamage) * ( ( IsBackstab(id, trPlayer) ) ? 3.0 : 1.0 ) ), DMG_BULLET|DMG_NEVERGIB);             }         }         else             emit_sound(id, CHAN_ITEM, "weapons/knife_hitwall1.wav", VOL_NORM, ATTN_NORM, 0, random_num(98, 101));     }         free_tr2(hTrace); } bool:IsBackstab(const attacker, const victim) {         new Float: vec1[3];     new Float: vec2[3];         velocity_by_aim(attacker, 1, vec1);         new Float:invlen = xs_rsqrt(vec1[0] * vec1[0] + vec1[1] * vec1[1]);     vec1[0] *= invlen;     vec1[1] *= invlen;         pev(victim, pev_angles, vec2);     angle_vector(vec2, ANGLEVECTOR_FORWARD, vec2);         return vec1[0] * vec2[0] + vec1[1] * vec2[1] > 0.8 ? true : false; } public fwd_Killed(victim, attacker, shouldgib)     remove_task(victim);
__________________

Last edited by Black Rose; 10-23-2013 at 14:59.
Black Rose is offline
yokomo
Surprise Ascot!
Join Date: May 2010
Location: Malaysia
Old 10-20-2013 , 03:27   Re: Delay Knife Attack
Reply With Quote #28

Since you are using Ham module, you can replace:
Code:
register_event("CurWeapon", "Event_CurWeapon", "be", "1=1")
with ham forward:
Code:
RegisterHam(Ham_Item_Deploy, "weapon_knife", "OnKnifeDeployPost", 1)
PHP Code:
public OnKnifeDeployPost(ent)
{
    static 
idid get_pdata_cbase(ent414)
    if(
is_user_connected(id) && bHasCustomKnife[id]) ReplaceModel(id);

yokomo is offline
ConnorMcLeod
Veteran Member
Join Date: Jul 2006
Location: France (95)
Old 10-20-2013 , 03:49   Re: Delay Knife Attack
Reply With Quote #29

m_flNextAttack is a CBasePlayer offset, linux diff is 5.
__________________
- tired and retired -

- my plugins -
ConnorMcLeod is offline
Randomize
BANNED
Join Date: May 2012
Location: in your heart
Old 10-21-2013 , 04:10   Re: Delay Knife Attack
Reply With Quote #30

Black Rose, amazing! This is perfect! but there's a damage occured before the delayed, take a look: I have recorded with your code http://youtu.be/PTT312Zgcbs could you remove it? I try with SetHamParamFloat(4, 0.0) but didn't work
Randomize is offline
Reply


Thread Tools
Display Modes

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 20:48.


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