Raised This Month: $12 Target: $400
 3% 

[CSGO] Blocking Left knife


Post New Thread Reply   
 
Thread Tools Display Modes
The Killer NL
AlliedModders Donor
Join Date: Aug 2018
Location: The Netherlands
Old 10-15-2018 , 01:23   Re: [CSGO] Blocking Left knife
Reply With Quote #11

Quote:
Originally Posted by shanapu View Post
It is. In the worst case, your plugin will do fifteen StrEqual checks before it blocks the attack.
Baras example just needs a maximum of two checks. Where IIRC StrContains is less expensive than StrEqual. And when valve adds a new knife the probability is high they will call it somethig like knife (or bayonet), so there will be no need to edit your plugin for a valve update.

But the main reason why I decided to post here is:
With your method to block the attack players can easily lag the server and make it unplayable.

Instead of block the attack on OnPlayerRunCmd I recommend this method:

PHP Code:
void EnableWeaponFire(int clientbool status true)
{
    if (
status// true = allow shooting
    
{
        
SDKUnhook(clientSDKHook_PreThinkPreThinkWeapon);
    }
    else 
// false = suppress shooting
    
{
        
SDKHook(clientSDKHook_PreThinkPreThinkWeapon);
    
    }
}
 public 
Action PreThinkWeapon(int client)
{
     
int weapon GetEntPropEnt(clientProp_Send"m_hActiveWeapon");
     if (
weapon || !IsValidEdict(weapon) || !IsValidEntity(weapon))
        return 
Plugin_Continue;
     
SetEntPropFloat(weaponProp_Send"m_flNextPrimaryAttack"GetGameTime() + 0.25);  // Primary
     
SetEntPropFloat(weaponProp_Send"m_flNextSecondaryAttack"GetGameTime() + 0.25);  // Secondary
     
return Plugin_Continue;

I see, i kinda been using it for a long time on a server of mine never kinda felt lag but i get ur point i'll try looking into it when i have time
__________________


Last edited by The Killer NL; 10-15-2018 at 01:24.
The Killer NL is offline
eyal282
Veteran Member
Join Date: Aug 2011
Old 10-15-2018 , 02:50   Re: [CSGO] Blocking Left knife
Reply With Quote #12

IIRC, GetEdictClassname always returns weapo_knife for a knife. Only in events the weapon name requires this.
__________________
I am available to make plugins for pay.

Discord: Eyal282#1334
eyal282 is offline
SM9
Veteran Member
Join Date: Sep 2013
Location: United Kingdom
Old 10-15-2018 , 14:06   Re: [CSGO] Blocking Left knife
Reply With Quote #13

This version works perfectly without any client side prediction issues, It also has no need for comparing classnames or definition indexes therefore is future proof and will work with any knife valve ever adds to the game.

PHP Code:
#include <sdktools>
#include <cstrike>

public Plugin myinfo 
{
    
name "Block Left Knife"
    
author "Bara, [Updated by The Killer [NL], SM9();]",
    
description "Block Left Knife"
    
version "2.4"
    
url "www.bara.in, www.upvotegaming.com"
}

public 
Action OnPlayerRunCmd(int iClientint iButtonsint iImpulsefloat vVelocity[3], float vAngles[3], int iWeapon)
{
    if (!
IsClientInGame(iClient) || !IsPlayerAlive(iClient)) {
        return 
Plugin_Continue;
    }
    
    
int iKnife GetPlayerWeaponSlot(iClientCS_SLOT_KNIFE);
    
    if(
iKnife == -|| !IsValidEntity(iKnife)) {
        return 
Plugin_Continue;
    }
    
    
SetEntPropFloat(iKnifeProp_Send"m_flNextPrimaryAttack"GetGameTime() + 1.0);
    
    if(
iKnife != iWeapon) {
        return 
Plugin_Continue;
    }
    
    
iButtons &= ~IN_ATTACK;
    
    return 
Plugin_Changed;

Attached Files
File Type: sp Get Plugin or Get Source (blockleftknifeupkiller.sp - 258 views - 837 Bytes)
SM9 is offline
shanapu
Veteran Member
Join Date: Apr 2015
Location: .de
Old 10-15-2018 , 14:33   Re: [CSGO] Blocking Left knife
Reply With Quote #14

Quote:
Originally Posted by SM9 View Post
This version works perfectly without any client side prediction issues, It also has no need for comparing classnames or definition indexes therefore is future proof and will work with any knife valve ever adds to the game.
[code]


PHP Code:
int iKnife GetPlayerWeaponSlot(iClientCS_SLOT_KNIFE); 
b,b,.. but wouldn't this also block taser which is also in CS_SLOT_KNIFE?
__________________
coding & free software
shanapu is offline
Mitchell
~lick~
Join Date: Mar 2010
Old 10-15-2018 , 15:41   Re: [CSGO] Blocking Left knife
Reply With Quote #15

Quote:
Originally Posted by shanapu View Post


PHP Code:
int iKnife GetPlayerWeaponSlot(iClientCS_SLOT_KNIFE); 
b,b,.. but wouldn't this also block taser which is also in CS_SLOT_KNIFE?
you can check to see if it's a taser though, i doubt csgo will be adding any custom tasers or any other weapons in the melee slot. If you really want to do less checks in the prethink you could probably just use the weapon switch hook.

Last edited by Mitchell; 10-15-2018 at 15:42.
Mitchell is offline
SM9
Veteran Member
Join Date: Sep 2013
Location: United Kingdom
Old 10-15-2018 , 16:06   Re: [CSGO] Blocking Left knife
Reply With Quote #16

New version which should be less expensive (Tested and does not break tasers)

PHP Code:
#include <sdktools>
#include <sdkhooks>
#include <cstrike>

public Plugin myinfo 
{
    
name "Block Left Knife"
    
author "Bara, [Updated by The Killer [NL], SM9();]"
    
description "Block Left Knife"
    
version "2.5"
    
url "www.bara.in, www.upvotegaming.com"
}

ArrayList g_alActiveKnives null;

public 
void OnPluginStart()
{
    
g_alActiveKnives = new ArrayList();
    
    for (
int i 1<= MaxClientsi++) {
        if (!
IsClientInGame(i)) {
            continue;
        }
        
        
OnClientPutInServer(i);
        
FindAndAddKnifeInitial(i);
    }
    
    
TriggerTimer(CreateTimer(0.5Timer_UpdateKnives_TIMER_REPEAT));
}

public 
void OnClientPutInServer(int iClient) {
    
SDKHookEx(iClientSDKHook_WeaponEquipPostOnWeaponEquipPost);
}

public 
void OnWeaponEquipPost(int iClientint iWeapon)
{
    if (
iWeapon != GetPlayerWeaponSlot(iClientCS_SLOT_KNIFE)) {
        return;
    }
    
    if(
CS_ItemDefIndexToID(GetEntProp(iWeaponProp_Send"m_iItemDefinitionIndex")) == CSWeapon_TASER) {
        return;
    }
    
    
int iEntRef EntIndexToEntRef(iWeapon);
    
    if (
g_alActiveKnives.FindValue(iEntRef) != -1) {
        return;
    }
    
    
g_alActiveKnives.Push(iEntRef);
}

public 
Action Timer_UpdateKnives(Handle hTimer)
{
    
int iKnife = -1;
    
int iEntRef INVALID_ENT_REFERENCE;
    
    for (
int i 0g_alActiveKnives.Lengthi++) {
        
iEntRef g_alActiveKnives.Get(i);
        
        if(
iEntRef == INVALID_ENT_REFERENCE) {
            
g_alActiveKnives.Erase(i);
            continue;
        }
        
        
iKnife EntRefToEntIndex(iEntRef);
        
        if (
iKnife <= MaxClients || !IsValidEntity(iKnife)) {
            
g_alActiveKnives.Erase(i);
            continue;
        }
        
        
SetEntPropFloat(iKnifeProp_Send"m_flNextPrimaryAttack"GetGameTime() + 999.0);
    }
}

public 
void OnEntityDestroyed(int iEntity)
{
    
int iEntRef INVALID_ENT_REFERENCE;
    
    if(
iEntity 0) {
        
iEntRef iEntity;
    } else {
        
iEntRef EntIndexToEntRef(iEntity);
    }
    
    
int iKnifeIndex g_alActiveKnives.FindValue(iEntRef);
    
    if (
iKnifeIndex == -1) {
        return;
    }
    
    
g_alActiveKnives.Erase(iKnifeIndex);
}

void FindAndAddKnifeInitial(int iClient)
{
    
int iWeapon = -1;
    
int iEntRef INVALID_ENT_REFERENCE;
    
    for (
int i 0GetEntPropArraySize(iClientProp_Send"m_hMyWeapons"); i++) {
        
iWeapon GetEntPropEnt(iClientProp_Send"m_hMyWeapons"i);
        
        if (
iWeapon <= MaxClients || !IsValidEntity(iWeapon)) {
            continue;
        }
        
        if (
iWeapon != GetPlayerWeaponSlot(iClientCS_SLOT_KNIFE)) {
            continue;
        }
        
        if(
CS_ItemDefIndexToID(GetEntProp(iWeaponProp_Send"m_iItemDefinitionIndex")) == CSWeapon_TASER) {
            return;
        }
        
        
iEntRef EntIndexToEntRef(iWeapon);
        
        if (
g_alActiveKnives.FindValue(iEntRef) != -1) {
            continue;
        }
        
        
g_alActiveKnives.Push(iEntRef);
    }

Attached Files
File Type: sp Get Plugin or Get Source (blockleftknifeupkiller.sp - 249 views - 2.7 KB)

Last edited by SM9; 10-16-2018 at 05:15. Reason: Switched GetEntityClassname to CS_ItemDefIndexToID
SM9 is offline
The Killer NL
AlliedModders Donor
Join Date: Aug 2018
Location: The Netherlands
Old 10-16-2018 , 04:21   Re: [CSGO] Blocking Left knife
Reply With Quote #17

Quote:
Originally Posted by SM9 View Post
New version which should be less expensive (Tested and does not break tasers)

PHP Code:
#include <sdktools>
#include <sdkhooks>
#include <cstrike>

public Plugin myinfo 
{
    
name "Block Left Knife"
    
author "Bara, [Updated by The Killer [NL], SM9();]"
    
description "Block Left Knife"
    
version "2.5"
    
url "www.bara.in, www.upvotegaming.com"
}

ArrayList g_alActiveKnives null;

public 
void OnPluginStart()
{
    
g_alActiveKnives = new ArrayList();
    
    for (
int i 1<= MaxClientsi++) {
        if (!
IsClientInGame(i)) {
            continue;
        }
        
        
OnClientPutInServer(i);
        
FindAndAddKnifeInitial(i);
    }
    
    
TriggerTimer(CreateTimer(0.5Timer_UpdateKnives_TIMER_REPEAT));
}

public 
void OnClientPutInServer(int iClient) {
    
SDKHookEx(iClientSDKHook_WeaponEquipPostOnWeaponEquipPost);
}

public 
void OnEntityDestroyed(int iEntity)
{
    
int iEntRef INVALID_ENT_REFERENCE;
    
    if(
iEntity 0) {
        
iEntRef iEntity;
    } else {
        
iEntRef EntIndexToEntRef(iEntity);
    }
    
    
int iKnifeIndex g_alActiveKnives.FindValue(iEntRef);
    
    if (
iKnifeIndex == -1) {
        return;
    }
    
    
g_alActiveKnives.Erase(iKnifeIndex);
}

public 
void OnWeaponEquipPost(int iClientint iWeapon)
{
    if (
iWeapon != GetPlayerWeaponSlot(iClientCS_SLOT_KNIFE)) {
        return;
    }
    
    
char szClassName[48]; 
    
    if(!
GetEntityClassname(iWeaponszClassNamesizeof(szClassName))) {
        return;
    }
    
    if(
StrContains(szClassName"taser"false) != -1) {
        return;
    }
    
    
int iEntRef EntIndexToEntRef(iWeapon);
    
    if (
g_alActiveKnives.FindValue(iEntRef) != -1) {
        return;
    }
    
    
g_alActiveKnives.Push(iEntRef);
}

public 
Action Timer_UpdateKnives(Handle hTimer)
{
    
int iKnife = -1;
    
int iEntRef INVALID_ENT_REFERENCE;
    
    for (
int i 0g_alActiveKnives.Lengthi++) {
        
iEntRef g_alActiveKnives.Get(i);
        
        if(
iEntRef == INVALID_ENT_REFERENCE) {
            
g_alActiveKnives.Erase(i);
            continue;
        }
        
        
iKnife EntRefToEntIndex(iEntRef);
        
        if (
iKnife <= MaxClients || !IsValidEntity(iKnife)) {
            
g_alActiveKnives.Erase(i);
            continue;
        }
        
        
SetEntPropFloat(iKnifeProp_Send"m_flNextPrimaryAttack"GetGameTime() + 999.0);
    }
}

void FindAndAddKnifeInitial(int iClient)
{
    
int iWeapon = -1;
    
int iEntRef INVALID_ENT_REFERENCE;
    
    
char szClassName[48]; 
    
    for (
int i 0GetEntPropArraySize(iClientProp_Send"m_hMyWeapons"); i++) {
        
iWeapon GetEntPropEnt(iClientProp_Send"m_hMyWeapons"i);
        
        if (
iWeapon <= MaxClients || !IsValidEntity(iWeapon)) {
            continue;
        }
        
        if (
iWeapon != GetPlayerWeaponSlot(iClientCS_SLOT_KNIFE)) {
            continue;
        }
        
        if(!
GetEntityClassname(iWeaponszClassNamesizeof(szClassName))) {
            continue;
        }
        
        if(
StrContains(szClassName"taser"false) != -1) {
            continue;
        }
        
        
iEntRef EntIndexToEntRef(iWeapon);
        
        if (
g_alActiveKnives.FindValue(iEntRef) != -1) {
            continue;
        }
        
        
g_alActiveKnives.Push(iEntRef);
    }

Do you mind me changing the main one to this and add u into the credits list? since it works good.
__________________

The Killer NL is offline
SM9
Veteran Member
Join Date: Sep 2013
Location: United Kingdom
Old 10-16-2018 , 05:18   Re: [CSGO] Blocking Left knife
Reply With Quote #18

Quote:
Originally Posted by The Killer NL View Post
Do you mind me changing the main one to this and add u into the credits list? since it works good.
Sure! I also changed GetEntityClassname to CS_ItemDefIndexToID as suggested by Dr1fter / GAMMACASE
SM9 is offline
The Killer NL
AlliedModders Donor
Join Date: Aug 2018
Location: The Netherlands
Old 10-16-2018 , 05:51   Re: [CSGO] Blocking Left knife
Reply With Quote #19

Quote:
Originally Posted by SM9 View Post
Sure! I also changed GetEntityClassname to CS_ItemDefIndexToID as suggested by Dr1fter / GAMMACASE
I am not home right now so can't look into it just tried to compile so i could change it i changed to ur old version for now but if im home ill look into it or if ur able to change it than that would be appreciated to.

undefined symbol "CS_ItemDefIndexToID" Line 42
undefined symbol "CS_ItemDefIndexToID" Line 114
__________________

The Killer NL is offline
eyal282
Veteran Member
Join Date: Aug 2011
Old 10-16-2018 , 07:08   Re: [CSGO] Blocking Left knife
Reply With Quote #20

Quote:
Originally Posted by SM9 View Post
New version which should be less expensive (Tested and does not break tasers)

PHP Code:
#include <sdktools>
#include <sdkhooks>
#include <cstrike>

public Plugin myinfo 
{
    
name "Block Left Knife"
    
author "Bara, [Updated by The Killer [NL], SM9();]"
    
description "Block Left Knife"
    
version "2.5"
    
url "www.bara.in, www.upvotegaming.com"
}

ArrayList g_alActiveKnives null;

public 
void OnPluginStart()
{
    
g_alActiveKnives = new ArrayList();
    
    for (
int i 1<= MaxClientsi++) {
        if (!
IsClientInGame(i)) {
            continue;
        }
        
        
OnClientPutInServer(i);
        
FindAndAddKnifeInitial(i);
    }
    
    
TriggerTimer(CreateTimer(0.5Timer_UpdateKnives_TIMER_REPEAT));
}

public 
void OnClientPutInServer(int iClient) {
    
SDKHookEx(iClientSDKHook_WeaponEquipPostOnWeaponEquipPost);
}

public 
void OnWeaponEquipPost(int iClientint iWeapon)
{
    if (
iWeapon != GetPlayerWeaponSlot(iClientCS_SLOT_KNIFE)) {
        return;
    }
    
    if(
CS_ItemDefIndexToID(GetEntProp(iWeaponProp_Send"m_iItemDefinitionIndex")) == CSWeapon_TASER) {
        return;
    }
    
    
int iEntRef EntIndexToEntRef(iWeapon);
    
    if (
g_alActiveKnives.FindValue(iEntRef) != -1) {
        return;
    }
    
    
g_alActiveKnives.Push(iEntRef);
}

public 
Action Timer_UpdateKnives(Handle hTimer)
{
    
int iKnife = -1;
    
int iEntRef INVALID_ENT_REFERENCE;
    
    for (
int i 0g_alActiveKnives.Lengthi++) {
        
iEntRef g_alActiveKnives.Get(i);
        
        if(
iEntRef == INVALID_ENT_REFERENCE) {
            
g_alActiveKnives.Erase(i);
            continue;
        }
        
        
iKnife EntRefToEntIndex(iEntRef);
        
        if (
iKnife <= MaxClients || !IsValidEntity(iKnife)) {
            
g_alActiveKnives.Erase(i);
            continue;
        }
        
        
SetEntPropFloat(iKnifeProp_Send"m_flNextPrimaryAttack"GetGameTime() + 999.0);
    }
}

public 
void OnEntityDestroyed(int iEntity)
{
    
int iEntRef INVALID_ENT_REFERENCE;
    
    if(
iEntity 0) {
        
iEntRef iEntity;
    } else {
        
iEntRef EntIndexToEntRef(iEntity);
    }
    
    
int iKnifeIndex g_alActiveKnives.FindValue(iEntRef);
    
    if (
iKnifeIndex == -1) {
        return;
    }
    
    
g_alActiveKnives.Erase(iKnifeIndex);
}

void FindAndAddKnifeInitial(int iClient)
{
    
int iWeapon = -1;
    
int iEntRef INVALID_ENT_REFERENCE;
    
    for (
int i 0GetEntPropArraySize(iClientProp_Send"m_hMyWeapons"); i++) {
        
iWeapon GetEntPropEnt(iClientProp_Send"m_hMyWeapons"i);
        
        if (
iWeapon <= MaxClients || !IsValidEntity(iWeapon)) {
            continue;
        }
        
        if (
iWeapon != GetPlayerWeaponSlot(iClientCS_SLOT_KNIFE)) {
            continue;
        }
        
        if(
CS_ItemDefIndexToID(GetEntProp(iWeaponProp_Send"m_iItemDefinitionIndex")) == CSWeapon_TASER) {
            return;
        }
        
        
iEntRef EntIndexToEntRef(iWeapon);
        
        if (
g_alActiveKnives.FindValue(iEntRef) != -1) {
            continue;
        }
        
        
g_alActiveKnives.Push(iEntRef);
    }

Does it work changing the next prim attack to a value like 21747483647.0 on weapon equip, blocking the need for any timers or functions that fire more than 10 a second? Should a right click negate it you can try hooking right attack somehow.
__________________
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 10:26.


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