This repository has been archived by the owner on Jul 3, 2021. It is now read-only.
/
dynamic_theater.sp
244 lines (216 loc) · 6.47 KB
/
dynamic_theater.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
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
//----------------------------------------------------
// Dynamic theater for [INS]
// Put "exec theatertype.cfg" in bottom of server.cfg
// This plugin will create and edit the theatertype.cfg to run the right theater file
// Each time the server load or change map will run server.cfg but with theatertype.cfg execute
//----------------------------------------------------
#include <sourcemod>
#include <sdktools>
#include <sdkhooks>
//int nDynamicTheater;
bool bAllowVoteTheater = true;
bool bVoteStart = false;
int nVoteYes = 0;
int nVoteNo = 0;
new bool:g_bPlayerCanVote[MAXPLAYERS+1] = {true, ...};
public Plugin:myinfo = {
name = "[INS] Dynamic Theater File",
description = "Dynamically change theater file in game",
author = "Neko-",
version = "1.2.0",
}
public OnPluginStart()
{
RegConsoleCmd("votetheater", Vote_Theater, "Vote theater for next map");
RegConsoleCmd("yes", Vote_Yes, "Vote yes for next map theater change");
RegConsoleCmd("no", Vote_No, "Vote no for next map theater change");
//Admin command
//Admin can set theater right away
RegAdminCmd("settheater", SetDynamicTheater, ADMFLAG_KICK, "Set dynamic theater type");
}
public Action:SetDynamicTheater(client, args)
{
if (args < 1)
{
PrintToChat(client, "[DTheater] Usage: !dtheater <args>");
return Plugin_Handled;
}
decl String:Message[255];
GetCmdArgString(Message, 255);
decl String:NickName[64];
GetClientName(client, NickName, sizeof(NickName));
if(StrContains(Message, "sniper") != -1)
{
DynamicTheater(1);
PrintToChatAll("\x0759b0f9[INS]\x01 %s has set starting next map to use sniper theater", NickName);
}
else if(StrContains(Message, "nospy") != -1)
{
DynamicTheater(2);
PrintToChatAll("\x0759b0f9[INS]\x01 %s has set starting next map to use no spy theater with no indicator", NickName);
}
else if(StrContains(Message, "ins") != -1)
{
DynamicTheater(3);
PrintToChatAll("\x0759b0f9[INS]\x01 %s has set starting next map to use insurgent theater (Play as insurgent)", NickName);
}
else
{
DynamicTheater(0);
PrintToChatAll("\x0759b0f9[INS]\x01 %s has set starting next map to use normal theater", NickName);
}
return Plugin_Handled;
}
public OnMapEnd()
{
bAllowVoteTheater = true;
bVoteStart = false;
nVoteYes = 0;
nVoteNo = 0;
}
public OnClientPostAdminCheck(client)
{
g_bPlayerCanVote[client] = true;
}
public OnClientDisconnect(client)
{
g_bPlayerCanVote[client] = true;
}
public DynamicTheater(nTheaterType)
{
decl String:path[PLATFORM_MAX_PATH];
BuildPath(Path_SM,path,PLATFORM_MAX_PATH,"../../cfg/theatertype.cfg");
new Handle:fileHandle=OpenFile(path,"wb+");
if(nTheaterType == 1)
{
WriteFileLine(fileHandle, "mp_theater_override ins_custom_hardcore_sniper");
}
else if(nTheaterType == 2)
{
WriteFileLine(fileHandle, "mp_theater_override ins_custom_hardcore_nospy");
WriteFileLine(fileHandle, "sv_hud_targetindicator 0");
}
else if(nTheaterType == 3)
{
WriteFileLine(fileHandle, "mp_theater_override ins_switch_team_custom_hardcore");
}
else
{
WriteFileLine(fileHandle, "mp_theater_override ins_custom_hardcore");
}
CloseHandle(fileHandle);
}
public Action:Vote_Theater(client,args)
{
if (args < 1)
{
PrintToChat(client, "[DTheater] Usage: !votetheater <type>");
return Plugin_Handled;
}
if(!bAllowVoteTheater)
{
PrintToChat(client, "A vote already start");
return Plugin_Handled;
}
decl String:Message[255];
GetCmdArgString(Message, 255);
decl String:NickName[64];
GetClientName(client, NickName, sizeof(NickName));
if(StrContains(Message, "sniper") != -1)
{
bAllowVoteTheater = false;
bVoteStart = true;
PrintToChatAll("\x0759b0f9[INS]\x01 %s has started a vote to use sniper theater starting next map\nUse /yes and /no to vote", NickName);
CreateTimer(25.0, Timer_VoteTheater, 1, TIMER_FLAG_NO_MAPCHANGE);
}
else if(StrContains(Message, "nospy") != -1)
{
bAllowVoteTheater = false;
bVoteStart = true;
PrintToChatAll("\x0759b0f9[INS]\x01 %s has started a vote to use no spy theater and no indicator starting next map\nUse /yes and /no to vote", NickName);
CreateTimer(25.0, Timer_VoteTheater, 2, TIMER_FLAG_NO_MAPCHANGE);
}
else if(StrContains(Message, "ins") != -1)
{
bAllowVoteTheater = false;
bVoteStart = true;
PrintToChatAll("\x0759b0f9[INS]\x01 %s has started a vote to use insurgent theater (Play as insurgent) starting next map\nUse /yes and /no to vote", NickName);
CreateTimer(25.0, Timer_VoteTheater, 3, TIMER_FLAG_NO_MAPCHANGE);
}
else if(StrContains(Message, "normal") != -1)
{
bAllowVoteTheater = false;
bVoteStart = true;
PrintToChatAll("\x0759b0f9[INS]\x01 %s has started a vote to use normal theater starting next map\nUse /yes and /no to vote", NickName);
CreateTimer(25.0, Timer_VoteTheater, 0, TIMER_FLAG_NO_MAPCHANGE);
}
else
{
PrintToChat(client, "[DTheater] Invalid theater. Please use normal, ins, nospy, or sniper");
}
return Plugin_Handled;
}
public Action Timer_VoteTheater(Handle timer, nTheaterType)
{
if(nVoteYes > nVoteNo)
{
PrintToChatAll("\x0759b0f9[INS]\x01 Vote success! Theater will be change starting next map\nYes: %d\nNo: %d", nVoteYes, nVoteNo);
DynamicTheater(nTheaterType);
}
else
{
PrintToChatAll("\x0759b0f9[INS]\x01 Vote failed! Theater will not change\nYes: %d\nNo: %d", nVoteYes, nVoteNo);
}
//reset
bVoteStart = false;
bAllowVoteTheater = true;
nVoteYes = 0;
nVoteNo = 0;
for(new i = 1; i <= MaxClients; i++)
{
g_bPlayerCanVote[i] = true;
}
}
public Action:Vote_Yes(client,args)
{
if((bVoteStart) && (g_bPlayerCanVote[client]))
{
g_bPlayerCanVote[client] = false;
nVoteYes++;
PrintToChat(client, "You voted yes");
}
else if((bVoteStart) && (!g_bPlayerCanVote[client]))
{
PrintToChat(client, "You already voted");
}
else
{
return Plugin_Stop;
}
return Plugin_Handled;
}
public Action:Vote_No(client,args)
{
if((bVoteStart) && (g_bPlayerCanVote[client]))
{
g_bPlayerCanVote[client] = false;
nVoteNo++;
PrintToChat(client, "You voted no");
return Plugin_Handled;
}
else if((bVoteStart) && (!g_bPlayerCanVote[client]))
{
PrintToChat(client, "You already voted");
return Plugin_Handled;
}
else
{
return Plugin_Stop;
}
}
bool:IsValidClient(client)
{
if ( !( 1 <= client <= MaxClients ) || !IsClientInGame(client) )
return false;
return true;
}