Raised This Month: $ Target: $400
 0% 

[L4D2] Remove shove penalty when equip pistols?


  
 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
ddd123
Senior Member
Join Date: May 2021
Old 04-16-2022 , 11:30   Re: [L4D2] Remove shove penalty when equip pistols?
Reply With Quote #3

Quote:
Originally Posted by Marttt View Post
Probably you will have to listen to something like OnPlayerRunCmd and reset the client prop for these weapons

Check my plugin [L4D2] Gnome and Cola Shove Damage,
it has a cvar that makes the cola/gnome with an unlimited shove.

PHP Code:
SetEntProp(clientProp_Send"m_iShovePenalty"g_iShoveMinPenalty); 
Thank you
Okay, i combine and edit with Martt's script and Timocop's script and i think it work okay, i guess?

I feel like i get more crash and game close without error even more when i go to next chapter after i have this plugin or maybe the other plugins causing this trouble (or maybe coincidence, i really dont know)

Can someone check the script if everything is okay or you can improve more and better without crashes?

Code:
#include <sourcemod>
#include <sdktools>

#pragma semicolon 1

new Handle:hConVar_NoShoveEnabled = INVALID_HANDLE;
new Handle:hConVar_NoShoveWeapons = INVALID_HANDLE;

new bool:bEnabled = true;
new String:sAllowedWeapons[64][32];
new iAllowedWeaponsCount = 64;
new iPerf_AllowedWeapon[MAXPLAYERS+1] = 0; //For very good Performance in a loop! [0 = Nothing | 1 = True | 2 = False]
new iPerf_ActiveWeapon[MAXPLAYERS+1] = -1; // For "iPerf_AllowedWeapon"
static int    g_iShoveMinPenalty;

public Plugin:myinfo = 
{
	name = "No shove Pistols",
	author = "ddd123, original code:Timocop and Marttt",
	description = "No shove Pistol (or any weapons)",
	version = "1.0",
	url = "https://forums.alliedmods.net/showthread.php?t=337368"
}

public OnPluginStart()
{

	hConVar_NoShoveEnabled = CreateConVar("l4d_noshovepistols_enabled", "1", "1 - enable / 0 - disable", FCVAR_REPLICATED | FCVAR_NOTIFY );
	hConVar_NoShoveWeapons = CreateConVar("l4d_noshovepistols_weapons", "weapon_pistol;weapon_magnum;weapon_pistol_magnum;magnum", "allow weapons, Use ';' to add more",  FCVAR_REPLICATED | FCVAR_NOTIFY);
	HookConVarChange(hConVar_NoShoveEnabled, ConVarChanged);
	HookConVarChange(hConVar_NoShoveWeapons, ConVarChanged);
	
	AutoExecConfig(true, "l4d_noshove_pistols");
	
	WeaponStringCalculation();
}

public ConVarChanged(Handle:convar, const String:oldValue[], const String:newValue[])
{
	if(convar == hConVar_NoShoveEnabled)
	{
		bEnabled = GetConVarBool(hConVar_NoShoveEnabled);
	}
	else if(convar == hConVar_NoShoveWeapons)
	{
		WeaponStringCalculation();
	}
}

WeaponStringCalculation()
{
	decl String:sConVarAllowedWeapons[256];
	GetConVarString(hConVar_NoShoveWeapons, sConVarAllowedWeapons, sizeof(sConVarAllowedWeapons));
	
	new iWeaponNumbers = ReplaceString(sConVarAllowedWeapons, sizeof(sConVarAllowedWeapons), ";", ";", false);
	iAllowedWeaponsCount = iWeaponNumbers;

	ExplodeString(sConVarAllowedWeapons, ";", sAllowedWeapons, iWeaponNumbers + 1, 32);
}

public Action:OnPlayerRunCmd(client, &buttons, &impulse, Float:vel[3], Float:angles[3], &weapon)
{ 
	if(!bEnabled)
	return Plugin_Continue;

	if (buttons & IN_ATTACK2)
	{
		if(!IsClientInGame(client)
			|| !IsPlayerAlive(client)
			|| GetClientTeam(client) != 2)
		return Plugin_Continue;

		new iActiveWeapon = GetEntPropEnt(client, Prop_Send, "m_hActiveWeapon");
		new bWeaponChanged = ((iActiveWeapon != iPerf_ActiveWeapon[client]) || (iPerf_ActiveWeapon[client] == -1));
		iPerf_ActiveWeapon[client] = iActiveWeapon;
		
		if(bWeaponChanged)
		{
			iPerf_AllowedWeapon[client] = 0;
		}
		
		if(!IsAllowedWeapon(client))
		return Plugin_Continue;

		int shovePenalty = GetEntProp(client, Prop_Send, "m_iShovePenalty");
		if (shovePenalty > g_iShoveMinPenalty)
		{
			SetEntProp(client, Prop_Send, "m_iShovePenalty", g_iShoveMinPenalty);
		}
	}
	/* else
	{
		if(iPerf_AllowedWeapon[client])
		iPerf_AllowedWeapon[client] = 0;
	} */
	return Plugin_Continue;
}

stock bool:IsAllowedWeapon(client)
{
	if(iPerf_AllowedWeapon[client] == 1)
	return true;
	else if(iPerf_AllowedWeapon[client] == 2)
	return false;
	
	decl String:sCurrentWeaponName[32];
	GetClientWeapon(client, sCurrentWeaponName, sizeof(sCurrentWeaponName));
	
	for(new i = 0; i <= iAllowedWeaponsCount; i++)
	{
		if(StrEqual(sAllowedWeapons[i], sCurrentWeaponName, false))
		{
			iPerf_AllowedWeapon[client] = 1;
			return true;
		}
		
	}
	
	iPerf_AllowedWeapon[client] = 2;
	return false;
}
I accidentally name the script "no shove pistols" instead "no shove cooldown/penalty on pistols" but ehhh still only remove the cooldown/penalty

______________________
EDIT: NVM, i think it was other plugins cause the issue
Attached Files
File Type: sp Get Plugin or Get Source (No shove Pistols.sp - 58 views - 3.5 KB)

Last edited by ddd123; 04-17-2022 at 13:55. Reason: smx not required
ddd123 is offline
 



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 05:22.


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