-
Notifications
You must be signed in to change notification settings - Fork 3
/
gfldm-sounds.sp
112 lines (95 loc) · 3.72 KB
/
gfldm-sounds.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
// 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 <sdktools_sound>
#include <gfldm>
public Plugin myinfo = {
name = "GFLDM Sounds",
author = "Dreae",
description = "DM sound improvements",
version = GFLDM_VERSION,
url = "https://github.com/GFLClan/gfl-dm-pack"
}
ConVar cvar_block_sounds;
ConVar cvar_spawn_sounds;
ConVar cvar_kill_sounds;
bool block_sounds = false;
bool spawn_sounds = false;
bool kill_sounds = false;
public void OnPluginStart() {
GFLDM_DefineVersion("gfldm_sounds_version");
cvar_block_sounds = CreateConVar("gfldm_block_sounds", "1", "Blocks itempickup sounds");
cvar_spawn_sounds = CreateConVar("gfldm_spawn_sounds", "1", "Emit sound from players after spawn");
cvar_kill_sounds = CreateConVar("gfldm_kill_sounds", "1", "Emit sound to player on kills");
cvar_block_sounds.AddChangeHook(Cvar_ConfigChanged);
cvar_spawn_sounds.AddChangeHook(Cvar_ConfigChanged);
cvar_kill_sounds.AddChangeHook(Cvar_ConfigChanged);
AddNormalSoundHook(Hook_NormalSound);
HookEvent("player_spawn", Hook_PlayerSpawn);
HookEvent("player_death", Hook_PlayerDeath);
AutoExecConfig();
}
public void OnMapStart() {
PrecacheSound("buttons/button19.wav", true);
PrecacheSound("buttons/bell1.wav", true);
}
public void OnConfigsExecuted() {
block_sounds = cvar_block_sounds.BoolValue;
spawn_sounds = cvar_spawn_sounds.BoolValue;
kill_sounds = cvar_kill_sounds.BoolValue;
}
public void Cvar_ConfigChanged(ConVar cvar, const char[] oldValue, const char[] newValue) {
OnConfigsExecuted();
}
public void Hook_PlayerSpawn(Event event, const char[] name, bool dontBroadcast) {
if (spawn_sounds) {
int client = GetClientOfUserId(event.GetInt("userid"));
if (GFLDM_IsValidClient(client, true)) {
CreateTimer(0.1, Timer_EmitSpawnSound, client, TIMER_FLAG_NO_MAPCHANGE);
}
}
}
public void Hook_PlayerDeath(Event event, const char[] name, bool dontBroadcast) {
if (kill_sounds) {
int victim = GetClientOfUserId(event.GetInt("userid"));
int attacker = GetClientOfUserId(event.GetInt("attacker"));
if (attacker != victim && GFLDM_IsValidClient(attacker)) {
EmitSoundToClient(attacker, "buttons/bell1.wav", attacker, SNDCHAN_AUTO, SNDLEVEL_NORMAL, SND_NOFLAGS, 0.5);
}
}
}
public Action Timer_EmitSpawnSound(Handle timer, any client) {
if (GFLDM_IsValidClient(client, true)) {
float origin[3];
GetClientAbsOrigin(client, origin);
EmitAmbientSound("buttons/button19.wav", origin, client, SNDLEVEL_TRAFFIC);
}
return Plugin_Stop;
}
public Action Hook_NormalSound(
int clients[MAXPLAYERS], int &numClients, char sample[PLATFORM_MAX_PATH],
int &entity, int &channel, float &volume, int &level, int &pitch, int &flags,
char soundEntry[PLATFORM_MAX_PATH], int &seed
) {
if (block_sounds) {
if (StrEqual(sample, "items/itempickup.wav") || StrEqual(sample, "items/ammopickup.wav")) {
return Plugin_Stop;
}
}
return Plugin_Continue;
}