PDA

View Full Version : [CSGO] Block left click knife


sim242
10-06-2014, 13:55
Hey guys, I'm currently finishing off a project I've been working on for a while, I'm keeping it under wraps for now until it's finished and I put it on a server and then I'll share the IP if interested.

Basically I want to detect when a player attacks using a knife and if they do attack using a knife I want to block left click knife attacks so you can only knife someone by right clicking. I've seen it done on some other servers and I've searched thoroughly but unfortunately I've found no answer to my question.

Any help is appreciated :)

Bara
10-06-2014, 14:01
Try this.

sim242
10-06-2014, 14:45
Just tried it out, seems to work thank you very much! One problem though, it shows the beginning of the knife animation which looks really glitchy. Is there a way of stopping left click knifing without it showing an animation? I read somewhere you can do it with PreThink or something but I have no idea how.

xf117
10-07-2014, 12:07
Just tried it out, seems to work thank you very much! One problem though, it shows the beginning of the knife animation which looks really glitchy. Is there a way of stopping left click knifing without it showing an animation? I read somewhere you can do it with PreThink or something but I have no idea how.

Probably not. It's a client side prediction. Game expects the knife to attack even if you blocked it on server.

sim242
10-07-2014, 12:15
Probably not. It's a client side prediction. Game expects the knife to attack even if you blocked it on server.

Fair enough, thanks anyway :)

Franc1sco
10-07-2014, 12:58
I use this code for make ultra fast attack

FastAttack(client)
{
new ActiveWeapon = GetEntPropEnt(client, Prop_Send, "m_hActiveWeapon");
if(IsValidEntity(ActiveWeapon))
{

SetEntPropFloat(ActiveWeapon, Prop_Send, "m_flNextPrimaryAttack", 0.50);
SetEntPropFloat(client, Prop_Send, "m_flNextAttack", GetGameTime());
SetEntProp(client, Prop_Send, "m_iShotsFired", 0);

new Float:NoRecoil[3] = {0.0, 0.0, 0.0};
SetEntPropVector(client, Prop_Send, "m_vecPunchAngle", NoRecoil);
}
}



You can edit the values for make the next primary attack semi infinite, like

// code

NextAttack(client, 99999.0); // next attack in 99999 seconds = no left click

// code

NextAttack(client, Float:value)
{
new ActiveWeapon = GetEntPropEnt(client, Prop_Send, "m_hActiveWeapon");
if(IsValidEntity(ActiveWeapon))
{

SetEntPropFloat(ActiveWeapon, Prop_Send, "m_flNextPrimaryAttack", value);
}
}

sim242
10-07-2014, 13:27
:D Thanks Franc1sco! Where about would I use these functions though? I'm not aware of any function that is called before an attack in which this could be used to prevent a left click knife.

Mitchell
10-07-2014, 16:03
-1 would return false in IsValidEntity
so basically you're checking if the entity isn't -1 twice. (IsValidEntity already checks this afaik, if it doesnt then it would error out if -1 is passed through before you can even check -1)

EDIT: i've made my own version, doesn't check every frame if a player has used his knife. not tested.

sim242
10-07-2014, 16:43
Unfortunately no your version doesn't work :/ Thanks for trying to help though :)

Uncle Jessie
03-22-2017, 23:01
Try this.
THANK YOU!