Hello. I have been thinking about changing speed of attacking and distance of hitting with a knife.
I have already done this in CS 1.6:
PHP Code:
//Code for doubleing speed
RegisterHam(Ham_Weapon_PrimaryAttack, "weapon_knife", "KnifeAttack_Post", 1);
RegisterHam(Ham_Weapon_SecondaryAttack, "weapon_knife", "KnifeAttack_Post", 1);
public KnifeAttack_Post(ent){
new id;
id=entity_get_edict(ent, EV_ENT_owner);
for(new i=46; i<=48; i++)
set_pdata_float(ent, i, (get_pdata_float(ent, i, 4)*2.0, 4)
return HAM_IGNORED;
}
//Code for doubleing distance
register_forward(FM_TraceLine, "TraceLine", 0);
public TraceLine(Float:vecStart[3], Float:vecEnd[3], conditions, id, ptr){
if(!IsPlayerAlive(id))
return FMRES_IGNORED;
if(get_user_weapon(id)!=CSW_KNIFE)
return FMRES_IGNORED;
static Float:flFraction, Float:vecAngles[3], Float:vecForward[3], attack_mod, Float:Distance;
pev(id, pev_v_angle, vecAngles);
engfunc(EngFunc_MakeVectors, vecAngles);
global_get(glb_v_forward, vecForward);
attack_mod=RoundFloat((vecStart[0]-vecEnd[0])/vecForward[0]*-1.0);
if(attack_mod!=48 && attack_mod!=32)
return FMRES_IGNORED;
Distance=2.0; //default 1.0
Distance*=attack_mod;
if(Distance<=0)
return FMRES_IGNORED;
get_tr2(ptr, TR_flFraction, flFraction);
xs_vec_mul_scalar(vecForward, Distance, vecForward);
xs_vec_add(vecStart, vecForward, vecEnd);
engfunc(EngFunc_TraceLine, vecStart, vecEnd, conditions, id, ptr);
return FMRES_SUPERCEDE;
}
I have experimented with SDKhooks on this matter:
PHP Code:
public void OnClientPutInServer(int client)
{
if (false == IsValidClient(client))
{
return;
}
SDKHook(client, SDKHook_FireBulletsPost, FireBulletsPost);
SDKHook(client, SDKHook_TraceAttack, TraceAttack);
}
public void FireBulletsPost(int client, int shots, const char[] weaponname)
{
sendDebugMessage("FireBulletsPost");
}
public Action TraceAttack(int victim, int& attacker, int& inflictor, float& damage, int& damagetype, int& ammotype, int hitbox, int hitgroup)
{
sendDebugMessage("TraceAttack");
}
But this only prints a message when i shoot somebody and deal damage, but not with a knife.
I have also gotten my hands on Prop Data Knife properties. I have:
PHP Code:
SetEntPropFloat(iWeaponTemp, Prop_Send, "m_flNextPrimaryAttack", GetGameTime() + 1.1);
SetEntPropFloat(iWeaponTemp, Prop_Send, "m_flNextSecondaryAttack", GetGameTime() + 1.1);
which should set the next attack to be avalible in 1.1 seconds. The problem is,
how do i catch when the players is attacking with a knife?
The second Prop Data that caught my attention were:
PHP Code:
- m_fMinRange1 (Offset 2440) (Save)(4 Bytes)
- m_fMinRange2 (Offset 2444) (Save)(4 Bytes)
- m_fMaxRange1 (Offset 2448) (Save)(4 Bytes)
- m_fMaxRange2 (Offset 2452) (Save)(4 Bytes)
But the question is, will this change the range of attacking? When do i change it? At player spawn? At weapon change? At weapon entity spawn?