Hello, as stated in the title. I am trying to remove spread for all weapons on my cs:s server.
I have seen other cs:s servers do this. So I am wondering how I can also do this?
I looked around the forums, and found this code and tried it:
Code:
#pragma semicolon 1
#include <sourcemod>
#include <sdktools>
#pragma newdecls required
public Plugin myinfo =
{
name = "No Spread",
author = "godzcsgo",
description = "Removes spread from all weapons.",
version = "1.0.0",
url = ""
};
public Action OnPlayerRunCmd(int iClient, int &iButtons, int &iImpulse, float fVel[3], float fAngle[3], int &iWeapon, int &iSubType, int &iCmdnNum, int &iTickCount, int &iSeed)
{
if (IsPlayerAlive(iClient)) {
iSeed = 0;
return Plugin_Changed;
}
return Plugin_Continue;
}
But I am not sure it works? Can anyone confirm this is the right way to do it.
Thanks.
Edit:
Found something about modifying the m_fAccuracyPenalty, I did this but there still seems to be spread.
Updated code:
Code:
public void OnPluginStart() {
for (int client = 1; client <= MaxClients; client++) {
if (IsClientInGame(client)) {
if (IsPlayerAlive(client)) {
SDKHook(client, SDKHook_PreThink, NoSpread);
SDKHook(client, SDKHook_PreThinkPost, NoSpread);
SDKHook(client, SDKHook_PostThink, NoSpread);
SDKHook(client, SDKHook_PostThinkPost, NoSpread);
}
}
}
}
public Action NoSpread(int client) {
if (client <= 0 || client > MaxClients || !IsClientInGame(client) || GetClientTeam(client) < 2 || !IsPlayerAlive(client)) {
return Plugin_Continue;
}
int buttons = GetClientButtons(client);
float game_time = GetGameTime();
if (buttons & IN_ATTACK) {
int active_weapon = GetEntPropEnt(client, Prop_Send, "m_hActiveWeapon");
if (!IsValidEdict(active_weapon) || !IsValidEntity(active_weapon) || (active_weapon == -1)) return Plugin_Continue;
if (game_time < GetEntPropFloat(active_weapon, Prop_Send, "m_flNextPrimaryAttack")) return Plugin_Continue;
if (game_time < GetEntPropFloat(client, Prop_Send, "m_flNextAttack")) return Plugin_Continue;
int clip_ammo = GetEntProp(active_weapon, Prop_Send, "m_iClip1");
if (!clip_ammo) return Plugin_Continue;
float spread = 0.0;
SetEntPropFloat(active_weapon, Prop_Send, "m_fAccuracyPenalty", spread);
float new_spread = GetEntPropFloat(active_weapon, Prop_Send, "m_fAccuracyPenalty");
PrintToServer("Spread: %f", new_spread);
return Plugin_Changed;
}
return Plugin_Continue;
}