-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsoundtriggers.sp
155 lines (124 loc) · 3.35 KB
/
soundtriggers.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
#pragma semicolon 1
#pragma dynamic 65536
#include <sourcemod>
#include <sdktools>
#include <colors>
#include <clientprefs>
#include <cstrike>
new Float:g_lastplay[MAXPLAYERS + 1];
new Handle:g_listkv = INVALID_HANDLE;
public Plugin:myinfo =
{
name = "soundtriggers",
author = "KaeMing",
description = "chaofansea soundtrig",
version = "1.00",
url = "kaemingtan.com"
};
public OnPluginStart()
{
AddCommandListener(Command_Say, "say");
}
public OnPluginEnd()
{
Handles_Close();
}
public OnMapStart()
{
for (new index = 1; index <= MAXPLAYERS; index++)
g_lastplay[index] = 0.0;
Handles_Close();
decl String:cfgfile[PLATFORM_MAX_PATH + 1];
decl String:filelocation[PLATFORM_MAX_PATH + 1];
decl String:filelocationFake[PLATFORM_MAX_PATH + 1];
BuildPath(Path_SM, cfgfile, sizeof(cfgfile), "configs/saysounds.cfg");
if(FileExists(cfgfile))
{
g_listkv = CreateKeyValues("Sound Combinations");
FileToKeyValues(g_listkv, cfgfile);
KvRewind(g_listkv);
if (KvGotoFirstSubKey(g_listkv))
{
do {
filelocation[0] = '\0';
KvGetString(g_listkv, "file", filelocation, sizeof(filelocation), "");
if (filelocation[0] != '\0')
{
Format(filelocationFake, sizeof(filelocationFake), "*%s", filelocation);
Format(filelocation, sizeof(filelocation), "sound/%s", filelocation);
AddFileToDownloadsTable(filelocation);
AddToStringTable(FindStringTable("soundprecache"), filelocationFake);
}
} while (KvGotoNextKey(g_listkv));
}
}
}
public OnMapEnd()
{
Handles_Close();
}
public OnClientAuthorized(client, const String:auth[])
{
if(client != 0)
g_lastplay[client] = 0.0;
}
public Action:Command_Say(client, const String:command[], argc)
{
decl String:speech[64];
new startidx = 0;
if (GetCmdArgString(speech, sizeof(speech)) < 1)
return Plugin_Continue;
if (speech[strlen(speech) - 1] == '"')
{
speech[strlen(speech) - 1] = '\0';
startidx = 1;
}
Sound_Play(client, speech[startidx], SNDCHAN_STATIC);
return Plugin_Continue;
}
static Sound_Play(client, const String:speech[], channel)
{
decl String:filelocation[PLATFORM_MAX_PATH + 1];
decl String:filelocationFake[PLATFORM_MAX_PATH + 1];
new Float:thetime = GetGameTime();
if(g_listkv != INVALID_HANDLE)
{
KvRewind(g_listkv);
if (KvJumpToKey(g_listkv, speech))
{
KvGetString(g_listkv, "file", filelocation, sizeof(filelocation));
if (filelocation[0] != '\0')
{
if (g_lastplay[client] < thetime)
{
if (speech[0] && IsValidClient(client))
g_lastplay[client] = thetime + 1.5;
{
if (CheckCommandAccess(client, "saysoundslle", ADMFLAG_CUSTOM1) || CheckCommandAccess(client, "saysoundslle", ADMFLAG_CUSTOM2))
{
Format(filelocationFake, sizeof(filelocationFake), "*%s", filelocation);
EmitSoundToAll(filelocationFake, SOUND_FROM_PLAYER, channel);
PrintToChatAll(" \x04[ChaoFan SoundTrig]\x01 %N played \x04%s\x01", client, speech);
}
}
}
else
PrintToChat(client, " \x04[ChaoFan SoundTrig]\x01 You may only use the same sound after \x041.5 \x01seconds !");
}
}
}
}
static bool:IsValidClient(client)
{
if (client == 0 || !IsClientConnected(client) || IsFakeClient(client) || !IsClientInGame(client))
return false;
return true;
}
static Handles_Close()
{
if (g_listkv != INVALID_HANDLE)
{
CloseHandle(g_listkv);
g_listkv = INVALID_HANDLE;
}
}