AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Plugins (https://forums.alliedmods.net/forumdisplay.php?f=108)
-   -   [CSGO] Blocking Left knife (https://forums.alliedmods.net/showthread.php?t=311353)

The Killer NL 10-15-2018 01:23

Re: [CSGO] Blocking Left knife
 
Quote:

Originally Posted by shanapu (Post 2619710)
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

eyal282 10-15-2018 02:50

Re: [CSGO] Blocking Left knife
 
IIRC, GetEdictClassname always returns weapo_knife for a knife. Only in events the weapon name requires this.

SM9 10-15-2018 14:06

Re: [CSGO] Blocking Left knife
 
1 Attachment(s)
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;



shanapu 10-15-2018 14:33

Re: [CSGO] Blocking Left knife
 
Quote:

Originally Posted by SM9 (Post 2619841)
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]

:bacon!:

PHP Code:

int iKnife GetPlayerWeaponSlot(iClientCS_SLOT_KNIFE); 

b,b,.. but wouldn't this also block taser which is also in CS_SLOT_KNIFE?

Mitchell 10-15-2018 15:41

Re: [CSGO] Blocking Left knife
 
Quote:

Originally Posted by shanapu (Post 2619844)
:bacon!:

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.

SM9 10-15-2018 16:06

Re: [CSGO] Blocking Left knife
 
1 Attachment(s)
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);
    }



The Killer NL 10-16-2018 04:21

Re: [CSGO] Blocking Left knife
 
Quote:

Originally Posted by SM9 (Post 2619850)
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.

SM9 10-16-2018 05:18

Re: [CSGO] Blocking Left knife
 
Quote:

Originally Posted by The Killer NL (Post 2619907)
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 :up:

The Killer NL 10-16-2018 05:51

Re: [CSGO] Blocking Left knife
 
Quote:

Originally Posted by SM9 (Post 2619918)
Sure! I also changed GetEntityClassname to CS_ItemDefIndexToID as suggested by Dr1fter / GAMMACASE :up:

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

eyal282 10-16-2018 07:08

Re: [CSGO] Blocking Left knife
 
Quote:

Originally Posted by SM9 (Post 2619850)
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.


All times are GMT -4. The time now is 06:01.

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