-
Notifications
You must be signed in to change notification settings - Fork 3
/
gfldm.sp
182 lines (158 loc) · 5.76 KB
/
gfldm.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
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
// 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 <sdkhooks>
#include <gfldm>
#include <gfldm-chat>
public Plugin myinfo = {
name = "GFLDM Core",
author = "Dreae",
description = "Basic DM QoL improvements",
version = GFLDM_VERSION,
url = "https://github.com/GFLClan/gfl-dm-pack"
}
ConVar cvar_remove_physics_ents;
ConVar cvar_clean_up_weapons;
ConVar cvar_autorestart_map;
ConVar cvar_mapchange_delay;
bool clean_up_weapons = false;
int map_reload_time = 0;
int map_reload_interval = 0;
int map_change_delay = 0;
public void OnPluginStart() {
cvar_remove_physics_ents = CreateConVar("gfldm_remove_physics_ents", "1", "Remove CPhysicsPropMultiplayer");
cvar_clean_up_weapons = CreateConVar("gfldm_clean_up_weapons", "1", "Remove dropped weapons");
cvar_clean_up_weapons.AddChangeHook(CvarChanged);
cvar_autorestart_map = CreateConVar("gfldm_restart_map_interval", "0", "Restart the map every x seconds");
cvar_autorestart_map.AddChangeHook(CvarChanged);
cvar_mapchange_delay = CreateConVar("gfldm_restart_map_delay", "5", "Wait x seconds before reloading the map");
cvar_mapchange_delay.AddChangeHook(CvarChanged);
GFLDM_DefineVersion("gfldm_version");
HookEvent("round_start", Event_RoundStart);
for (int c = 1; c <= MaxClients; c++) {
if (IsClientInGame(c)) {
OnClientPutInServer(c);
}
}
AutoExecConfig();
LoadTranslations("gfldm.phrases.txt");
CreateTimer(1.0, Timer_CheckMapReload, 0, TIMER_REPEAT);
}
public void OnConfigsExecuted() {
clean_up_weapons = cvar_clean_up_weapons.BoolValue;
if (clean_up_weapons) {
for (int c = MaxClients + 1; c < GetMaxEntities(); c++) {
RemoveIfWeapon(c);
}
}
int new_map_reload_interval = cvar_autorestart_map.IntValue;
if (new_map_reload_interval != map_reload_interval){
if (new_map_reload_interval != 0) {
map_reload_time = GetTime() + new_map_reload_interval;
map_reload_interval = new_map_reload_interval;
} else if (new_map_reload_interval == 0) {
map_reload_time = 0;
}
}
map_change_delay = cvar_mapchange_delay.IntValue;
}
public void CvarChanged(ConVar cvar, const char[] oldValue, const char[] newValue) {
OnConfigsExecuted();
}
public Action Timer_CheckMapReload(Handle timer) {
if (map_reload_time != 0) {
int time = GetTime();
if(time >= map_reload_time) {
map_reload_time = time + map_change_delay + map_reload_interval;
GFLDM_PrintToChatAll("%t", "Map Restarting in...", map_change_delay);
CreateTimer(1.0, Timer_ReloadMap, time + map_change_delay, TIMER_REPEAT | TIMER_FLAG_NO_MAPCHANGE);
}
}
}
public Action Timer_ReloadMap(Handle timer, any data) {
int change_time = data;
int time = GetTime();
if (time < change_time) {
GFLDM_PrintToChatAll("%t", "Map Restarting in...", change_time - time);
} else {
char current_map[PLATFORM_MAX_PATH];
change_time = time + map_reload_interval;
GetCurrentMap(current_map, sizeof(current_map));
ForceChangeLevel(current_map, "GFLDM Map Restart");
return Plugin_Stop;
}
return Plugin_Continue;
}
public void OnMapStart() {
ConVar bot_quota = FindConVar("bot_quota");
bot_quota.Flags = bot_quota.Flags & (~FCVAR_NOTIFY);
RemovePhysicsProps();
}
public void Event_RoundStart(Event event, const char[] name, bool dontBroadcast) {
RemovePhysicsProps();
}
public void OnClientPutInServer(int client) {
if (IsValidEdict(client)) {
SDKHook(client, SDKHook_WeaponDropPost, SDKHook_OnWeaponDropPost);
}
}
public void OnEntityCreated(int entity) {
if (IsValidEdict(entity) && clean_up_weapons) {
char clsname[64];
if (GetEdictClassname(entity, clsname, sizeof(clsname))) {
if (StrContains(clsname, "weapon_") != -1) {
CreateTimer(0.25, Timer_CheckWeapon, entity, TIMER_FLAG_NO_MAPCHANGE);
}
}
}
}
public Action Timer_CheckWeapon(Handle timer, any entity) {
RemoveIfWeapon(entity);
}
void RemoveIfWeapon(int entity) {
if (IsValidEdict(entity)) {
char clsname[64];
if (GetEdictClassname(entity, clsname, sizeof(clsname))) {
if (StrContains(clsname, "weapon_") != -1) {
if (GetEntPropEnt(entity, Prop_Send, "m_hOwnerEntity", 0) == -1) {
RemoveEntity(entity);
}
}
}
}
}
void RemovePhysicsProps() {
if (cvar_remove_physics_ents.BoolValue) {
char clsname[128];
int max_ents = GetMaxEntities();
for (int c = 0; c < max_ents; c++) {
if (IsValidEdict(c)) {
if (GetEdictClassname(c, clsname, sizeof(clsname))) {
if (StrEqual(clsname, "prop_physics_multiplayer")) {
RemoveEdict(c);
}
}
}
}
}
}
public void SDKHook_OnWeaponDropPost(int client, int weapon) {
if (IsValidEntity(weapon) && clean_up_weapons) {
RemoveEntity(weapon);
}
}