Raised This Month: $359 Target: $400
 89%   Almost there!

[CS:GO] Modifying knife properties


Post New Thread Reply   
 
Thread Tools Display Modes
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
Cruze
Veteran Member
Join Date: May 2017
Old 07-10-2022 , 18:59   Re: [CS:GO] Modifying knife properties
Reply With Quote #2

Use OnPlayerRunCmd -> Check whether active weapon is knife || bayonet -> Check if buttons & IN_ATTACK || buttons & IN_ATTACK2 -> You can try the following (not sure if it works):
PHP Code:
SetEntPropFloat(weaponEntProp_Send"m_flPlaybackRate"Amount); 
Revert back to normal playbackrate after a second or two according to your preference.
__________________
Taking paid private requests! Add me on steam/discord!
AlliedModders Releases | Github | Private Plugins | Steam | Discord
Cruze is offline
Franc1sco
Veteran Member
Join Date: Oct 2010
Location: Spain (Madrid)
Old 07-11-2022 , 03:15   Re: [CS:GO] Modifying knife properties
Reply With Quote #3

For detect when attack with knife you can use too:

PHP Code:
#include <sourcemod>

public void OnPluginStart()
{
    
HookEvent("weapon_fire"EventWeaponFire); 
}

public 
Action EventWeaponFire(Handle eventchar[] namebool dontBroadcast)
{
    
char szWeapon[32];
    
GetEventString(event"weapon"szWeaponsizeof(szWeapon));
    if(!
StrEqual(szWeapon"weapon_knife") && !StrEqual(szWeapon"weapon_bayonet"))
        return;
        
    
int client GetClientOfUserId(GetEventInt(event"userid")); // player index
    
    // attacking with knife
    
int ActiveWeapon GetEntPropEnt(clientProp_Send"m_hActiveWeapon"); 
    
SetEntPropFloat(ActiveWeaponProp_Send"m_flNextPrimaryAttack"GetGameTime() + 1.1);
    
SetEntPropFloat(ActiveWeaponProp_Send"m_flNextSecondaryAttack"GetGameTime() + 1.1);

__________________
Veteran SourceMod Coder -> Activity channel
Taking paid and free jobs.
Contact: Steam, Telegram or discord ( Franc1sco#7876 ).

You like my work? +Rep in my steam profile comments or donate.


Last edited by Franc1sco; 07-11-2022 at 03:17.
Franc1sco is offline
Send a message via MSN to Franc1sco
Vasto_Lorde
Junior Member
Join Date: Oct 2016
Old 07-11-2022 , 05:57   Re: [CS:GO] Modifying knife properties
Reply With Quote #4

Quote:
Originally Posted by Cruze View Post
Use OnPlayerRunCmd -> Check whether active weapon is knife || bayonet -> Check if buttons & IN_ATTACK || buttons & IN_ATTACK2 -> You can try the following (not sure if it works):
PHP Code:
SetEntPropFloat(weaponEntProp_Send"m_flPlaybackRate"Amount); 
Revert back to normal playbackrate after a second or two according to your preference.
I think OnPlayerRunCmd repeats itself too much so i want to avoid using. But thank you for your suggestion



Quote:
Originally Posted by Franc1sco View Post
For detect when attack with knife you can use too:

PHP Code:
#include <sourcemod>

public void OnPluginStart()
{
    
HookEvent("weapon_fire"EventWeaponFire); 
}

public 
Action EventWeaponFire(Handle eventchar[] namebool dontBroadcast)
{
    
char szWeapon[32];
    
GetEventString(event"weapon"szWeaponsizeof(szWeapon));
    if(!
StrEqual(szWeapon"weapon_knife") && !StrEqual(szWeapon"weapon_bayonet"))
        return;
        
    
int client GetClientOfUserId(GetEventInt(event"userid")); // player index
    
    // attacking with knife
    
int ActiveWeapon GetEntPropEnt(clientProp_Send"m_hActiveWeapon"); 
    
SetEntPropFloat(ActiveWeaponProp_Send"m_flNextPrimaryAttack"GetGameTime() + 1.1);
    
SetEntPropFloat(ActiveWeaponProp_Send"m_flNextSecondaryAttack"GetGameTime() + 1.1);

That works very well, thank you. I have tested it and the secondary knife attack is not being hooked. So this does not suit my needs



I have searched again for a while and stumbled upon this: https://forums.alliedmods.net/showth...=307436&page=2
Soundhooking does work well. This is working code:
PHP Code:
#include <sdktools_sound>

AddNormalSoundHook(SoundHook);

public 
Action SoundHook(int clients[MAXPLAYERS], intnumClientschar sample[PLATFORM_MAX_PATH],
                 
intentityintchannelfloatvolumeintlevelintpitchintflags,
                 
char soundEntry[PLATFORM_MAX_PATH], intseed)
{
    if (
StrContains(sample"knife/knife_"false) == -1)
    {
        return 
Plugin_Continue;
    }

    if (
StrContains(sample"deploy"false) > -1)
    {
        return 
Plugin_Continue;
    }

    
int   client              GetEntPropEnt(entityProp_Data"m_hOwnerEntity");
    
int   activeWeapon        GetEntPropEnt(clientProp_Send"m_hActiveWeapon");
    
float gameTime            GetGameTime();
    
float nextPrimaryAttack   GetEntPropFloat(activeWeaponProp_Send"m_flNextPrimaryAttack");
    
float nextSecondaryAttack GetEntPropFloat(activeWeaponProp_Send"m_flNextSecondaryAttack");
    
float modifier            0.5//modify here

    
nextPrimaryAttack   = ((nextPrimaryAttack gameTime) * modifier) + gameTime;
    
nextSecondaryAttack = ((nextSecondaryAttack gameTime) * modifier) + gameTime;

    
SetEntPropFloat(activeWeaponProp_Send"m_flNextPrimaryAttack"nextPrimaryAttack);
    
SetEntPropFloat(activeWeaponProp_Send"m_flNextSecondaryAttack"nextSecondaryAttack);

    
sendDebugMessage("SoundHook buffing attack speed by %f"modifier);

    return 
Plugin_Continue;

I am satisfied with this solution. But the knife hit distance is still remaining. I will try to figure it out but if anyone has some ideas on how to get that, i would very much appreciate some brainstorming

Last edited by Vasto_Lorde; 07-11-2022 at 05:58.
Vasto_Lorde is offline
Vasto_Lorde
Junior Member
Join Date: Oct 2016
Old 07-11-2022 , 15:53   Re: [CS:GO] Modifying knife properties
Reply With Quote #5

I have managed to write this code:
PHP Code:
    char PropsToCheck[][] = {
        
"m_fMaxRange1",
        
"m_fMinRange1",
        
"m_fMaxRange2",
        
"m_fMinRange2",
    };
    
float distance 100;

    for (
int i 0sizeof(PropsToCheck); i++)
    {
        if (
HasEntProp(entProp_DataPropsToCheck[i]))
        {
            
sendDebugMessage("%s value is %f, setting to %f"PropsToCheck[i], GetEntPropFloat(entProp_DataPropsToCheck[i]), GetEntPropFloat(entProp_DataPropsToCheck[i]) * distance);
            
SetEntPropFloat(entProp_DataPropsToCheck[i], GetEntPropFloat(entProp_DataPropsToCheck[i]) * distance);
        }
        else {
            
sendDebugMessage("No %s prop"PropsToCheck[i]);
        }
    } 
It actually changes the values, but nothing happens in game. Also the HasEntProp says that those properties does not exist when i try to do this with Prop_Send.

I have also checked other props that had some keywords like "range" in them, but it did not detect those props on Knife Entity. Any other ideas?
Vasto_Lorde is offline
poggu
Junior Member
Join Date: Dec 2021
Old 07-11-2022 , 17:06   Re: [CS:GO] Modifying knife properties
Reply With Quote #6

The slash/stab distance is hard coded and there's no netprop for it. I made a simple memroy patch that can change the stab distance
https://github.com/perilouswithadoll...knife.cpp#L326
Attached Files
File Type: sp Get Plugin or Get Source (knife-range.sp - 15 views - 912 Bytes)
File Type: txt stab-range.txt (403 Bytes, 9 views)

Last edited by poggu; 07-11-2022 at 17:08.
poggu is offline
eyal282
Veteran Member
Join Date: Aug 2011
Old 07-12-2022 , 06:00   Re: [CS:GO] Modifying knife properties
Reply With Quote #7

Quote:
Originally Posted by poggu View Post
The slash/stab distance is hard coded and there's no netprop for it. I made a simple memroy patch that can change the stab distance
https://github.com/perilouswithadoll...knife.cpp#L326
Now for the following question, can you make it filter per player by altering the variable whenever the knife would be swung.

I definitely have ideas for making the baseball bat Gun XP Mod Unlock Shop allow it
__________________
I am available to make plugins for pay.

Discord: Eyal282#1334
eyal282 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 21:29.


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