-
Notifications
You must be signed in to change notification settings - Fork 3
/
gfldm-noscopes.sp
166 lines (133 loc) · 5.22 KB
/
gfldm-noscopes.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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
// Copyright (C) 2020 dreae
//
// This file is part of gfl-dm-pack.
//
// gfl-dm-pack 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.
//
// gfl-dm-pack 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 gfl-dm-pack. If not, see <http://www.gnu.org/licenses/>.
#pragma semicolon 1
#include <sourcemod>
#include <gfldm>
#include <gfldm-chat>
#include <gfldm-clientprefs>
int noscopes[MAXPLAYERS + 1];
int headshots[MAXPLAYERS + 1];
int annouce_kill_count = 4;
public Plugin myinfo = {
name = "GFLDM NoScopes",
author = "Dreae",
description = "Announces noscopes",
version = GFLDM_VERSION,
url = "https://github.com/GFLClan/gfl-dm-pack"
};
GlobalForward fwd_OnNoscope = null;
bool noscopes_enabled[MAXPLAYERS + 1] = {true, ...};
Cookie noscopes_cookie;
public void OnPluginStart() {
GFLDM_DefineVersion("gfldm_noscopes_version");
if(GetEngineVersion() != Engine_CSGO && GetEngineVersion() != Engine_CSS) {
SetFailState("Plugin supports CSS and CS:GO only.");
}
noscopes_cookie = new Cookie("GFLDM_Noscopes", "", CookieAccess_Protected);
FIRE_CLIENT_COOKIES()
RegConsoleCmd("sm_noscopes", Cmd_Noscopes, "Toggle noscope notifications");
HookEvent("player_death", OnPlayerDeath);
LoadTranslations("gfldm_noscopes.phrases");
}
public APLRes AskPluginLoad2(Handle myself, bool late, char[] error, int err_max) {
fwd_OnNoscope = new GlobalForward("GFLDM_OnNoscope", ET_Ignore, Param_Cell, Param_Cell, Param_Cell, Param_Float);
CreateNative("GFLDM_GetNoscopes", native_GetNoscopes);
CreateNative("GFLDM_GetNoscopeHeadshots", native_GetNoscopeHeadshots);
RegPluginLibrary("gfldm-noscopes");
}
public void OnClientConnected(int client) {
noscopes[client] = 0;
headshots[client] = 0;
}
LOAD_COOKIE_BOOL(noscopes_cookie, noscopes_enabled, "on", true)
public Action Cmd_Noscopes(int client, int args) {
if (!GFLDM_IsValidClient(client)) {
return Plugin_Handled;
}
noscopes_enabled[client] = !noscopes_enabled[client];
if (noscopes_enabled[client]) {
noscopes_cookie.Set(client, "on");
GFLDM_PrintToChat(client, "%t", "Noscopes enabled");
} else {
noscopes_cookie.Set(client, "off");
GFLDM_PrintToChat(client, "%t", "Noscopes disabled");
}
return Plugin_Handled;
}
public void OnPlayerDeath(Event event, const char[] name, bool dontBroadcast) {
int victim = GetClientOfUserId(event.GetInt("userid"));
int attacker = GetClientOfUserId(event.GetInt("attacker"));
if (!GFLDM_IsValidClient(victim, true) || !GFLDM_IsValidClient(attacker)) {
return;
}
char weapon[64];
event.GetString("weapon", weapon, sizeof(weapon));
if ((StrContains(weapon, "awp") != -1 || StrContains(weapon, "ssg08") != -1 || StrContains(weapon, "scout") != -1) && !IsScoped(attacker)) {
float distance = GetDistance(attacker, victim);
bool headshot = event.GetBool("headshot");
if (fwd_OnNoscope != INVALID_HANDLE) {
Call_StartForward(fwd_OnNoscope);
Call_PushCell(attacker);
Call_PushCell(victim);
Call_PushCell(headshot);
Call_PushFloat(distance);
Call_Finish();
}
noscopes[attacker]++;
if (headshot) {
headshots[attacker]++;
GFLDM_PrintToChatFilter(ChatFilter_NoscopesEnabled, "%t", "Headshot noscoped", attacker, victim, distance);
} else {
GFLDM_PrintToChatFilter(ChatFilter_NoscopesEnabled, "%t", "Noscoped", attacker, victim, distance);
}
if (noscopes[attacker] % annouce_kill_count == 0) {
GFLDM_PrintToChatFilter(ChatFilter_NoscopesEnabled, "%t", "Total noscopes", attacker, noscopes[attacker], headshots[attacker]);
}
}
}
public bool ChatFilter_NoscopesEnabled(int client) {
return GFLDM_IsValidClient(client) && noscopes_enabled[client];
}
public int native_GetNoscopes(Handle plugin, int numParams) {
int client = GetNativeCell(1);
if (GFLDM_IsValidClient(client)) {
return noscopes[client];
}
return 0;
}
public int native_GetNoscopeHeadshots(Handle plugin, int numParams) {
int client = GetNativeCell(1);
if (GFLDM_IsValidClient(client)) {
return headshots[client];
}
return 0;
}
float GetDistance(int a, int b) {
float a_origin[3];
GetClientAbsOrigin(a, a_origin);
float b_origin[3];
GetClientAbsOrigin(b, b_origin);
// Magic number from https://developer.valvesoftware.com/wiki/Dimensions
return GetVectorDistance(a_origin, b_origin) / 52.49;
}
bool IsScoped(int client) {
if (GetEngineVersion() != Engine_CSS) {
return GetEntProp(client, Prop_Send, "m_bIsScoped") > 0;
} else {
return (0 < GetEntProp(client, Prop_Data, "m_iFOV") < GetEntProp(client, Prop_Data, "m_iDefaultFOV"));
}
}