-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathsm_autosilencer.sp
135 lines (111 loc) · 3.12 KB
/
sm_autosilencer.sp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
/* SM Autosilencer
*
* Copyright (C) 2017 Francisco 'Franc1sco' García
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the Free
* Software Foundation, either version 3 of the License, or (at your option)
* any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with
* this program. If not, see http://www.gnu.org/licenses/.
*/
#include <sourcemod>
#include <sdktools>
#include <sdkhooks>
#include <clientprefs>
new Handle:cookie = INVALID_HANDLE;
new bool:option_cookie[MAXPLAYERS + 1] = {true,...};
new bool:primera[2048] = false;
public Plugin:myinfo =
{
name = "SM Autosilencer",
author = "Franc1sco franug",
description = "oh yeah",
version = "1.1",
url = "http://steamcommunity.com/id/franug"
};
public OnPluginStart()
{
for(new i = 1; i < MaxClients; i++)
{
if(IsClientInGame(i))
{
OnClientPutInServer(i);
}
}
cookie = RegClientCookie("Autosilencer On/Off", "", CookieAccess_Private);
new info;
SetCookieMenuItem(CookieMenuHandler, any:info, "Autosilencer");
CreateConVar("sm_autosilencer_version", "1.1", "ok", FCVAR_PLUGIN|FCVAR_SPONLY|FCVAR_REPLICATED|FCVAR_NOTIFY|FCVAR_CHEAT|FCVAR_DONTRECORD);
}
public OnEntityCreated(entity, const String:classname[])
{
if(StrContains(classname, "weapon_") == 0)
{
primera[entity] = false;
}
}
public OnClientPutInServer(client)
{
SDKHook(client, SDKHook_WeaponEquip, Hook_OnWeaponEquip);
}
public Action:Hook_OnWeaponEquip(client, weapon)
{
if(primera[weapon]) return;
else primera[weapon] = true;
if(!option_cookie[client]) return;
decl String:item[20]; item[0] = '\0';
GetEdictClassname(weapon, item, sizeof(item));
if ((StrEqual(item, "weapon_m4a1") || StrEqual(item, "weapon_usp"))){
SetEntProp(weapon, Prop_Send, "m_bSilencerOn", 1);
SetEntProp(weapon, Prop_Send, "m_weaponMode", 1);
}
}
// Pref
public CookieMenuHandler(client, CookieMenuAction:action, any:info, String:buffer[], maxlen)
{
if (action == CookieMenuAction_DisplayOption)
{
decl String:status[10];
if (option_cookie[client])
{
Format(status, sizeof(status), "Enabled");
}
else
{
Format(status, sizeof(status), "Disabled");
}
Format(buffer, maxlen, "Autosilencer: %s", status);
}
// CookieMenuAction_SelectOption
else
{
option_cookie[client] = !option_cookie[client];
if (option_cookie[client])
{
SetClientCookie(client, cookie, "On");
PrintToChat(client, "\x04Autosilencer enabled");
}
else
{
SetClientCookie(client, cookie, "Off");
PrintToChat(client, "\x04Autosilencer disabled");
}
ShowCookieMenu(client);
}
}
public OnClientCookiesCached(client)
{
option_cookie[client] = GetCookie(client);
}
bool:GetCookie(client)
{
decl String:buffer[10];
GetClientCookie(client, cookie, buffer, sizeof(buffer));
return !StrEqual(buffer, "Off");
}