View Single Post
Author Message
Vasto_Lorde
Junior Member
Join Date: Oct 2016
Old 07-10-2022 , 17:07   [CS:GO] Modifying knife properties
Reply With Quote #1

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(entEV_ENT_owner);
    
    for(new 
i=46i<=48i++)
        
set_pdata_float(enti, (get_pdata_float(enti4)*2.04)

    return 
HAM_IGNORED;
}

//Code for doubleing distance
register_forward(FM_TraceLine"TraceLine"0);


public 
TraceLine(Float:vecStart[3], Float:vecEnd[3], conditionsidptr){
    if(!
IsPlayerAlive(id))
        return 
FMRES_IGNORED;
    if(
get_user_weapon(id)!=CSW_KNIFE)
        return 
FMRES_IGNORED;

    static 
Float:flFractionFloat:vecAngles[3], Float:vecForward[3], attack_modFloat:Distance;
    
pev(idpev_v_anglevecAngles);
    
engfunc(EngFunc_MakeVectorsvecAngles);

    
global_get(glb_v_forwardvecForward);

    
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(ptrTR_flFractionflFraction);

    
xs_vec_mul_scalar(vecForwardDistancevecForward);
    
xs_vec_add(vecStartvecForwardvecEnd);

    
engfunc(EngFunc_TraceLinevecStartvecEndconditionsidptr);

    return 
FMRES_SUPERCEDE;

I have experimented with SDKhooks on this matter:
PHP Code:
public void OnClientPutInServer(int client)
{
    if (
false == IsValidClient(client))
    {
        return;
    }

    
SDKHook(clientSDKHook_FireBulletsPostFireBulletsPost);
    
SDKHook(clientSDKHook_TraceAttackTraceAttack);
}


public 
void FireBulletsPost(int clientint shots, const char[] weaponname)
{
    
sendDebugMessage("FireBulletsPost");
}

public 
Action TraceAttack(int victimintattackerintinflictorfloatdamageintdamagetypeintammotypeint hitboxint 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(iWeaponTempProp_Send"m_flNextPrimaryAttack"GetGameTime() + 1.1);
    
SetEntPropFloat(iWeaponTempProp_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?

Last edited by Vasto_Lorde; 07-11-2022 at 05:59.
Vasto_Lorde is offline