|
ds@1952
|
1 |
/** |
|
ds@1952
|
2 |
* vim: set ts=4 : |
|
ds@1952
|
3 |
* ============================================================================= |
|
ds@1952
|
4 |
* SourceMod Nextmap Plugin |
|
ds@1952
|
5 |
* Adds sm_nextmap cvar for changing map and nextmap chat trigger. |
|
ds@1952
|
6 |
* |
|
ds@1952
|
7 |
* SourceMod (C)2004-2008 AlliedModders LLC. All rights reserved. |
|
ds@1952
|
8 |
* ============================================================================= |
|
ds@1952
|
9 |
* |
|
ds@1952
|
10 |
* This program is free software; you can redistribute it and/or modify it under |
|
ds@1952
|
11 |
* the terms of the GNU General Public License, version 3.0, as published by the |
|
ds@1952
|
12 |
* Free Software Foundation. |
|
ds@1952
|
13 |
* |
|
ds@1952
|
14 |
* This program is distributed in the hope that it will be useful, but WITHOUT |
|
ds@1952
|
15 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
|
ds@1952
|
16 |
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more |
|
ds@1952
|
17 |
* details. |
|
ds@1952
|
18 |
* |
|
ds@1952
|
19 |
* You should have received a copy of the GNU General Public License along with |
|
ds@1952
|
20 |
* this program. If not, see <http://www.gnu.org/licenses/>. |
|
ds@1952
|
21 |
* |
|
ds@1952
|
22 |
* As a special exception, AlliedModders LLC gives you permission to link the |
|
ds@1952
|
23 |
* code of this program (as well as its derivative works) to "Half-Life 2," the |
|
ds@1952
|
24 |
* "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software |
|
ds@1952
|
25 |
* by the Valve Corporation. You must obey the GNU General Public License in |
|
ds@1952
|
26 |
* all respects for all other code used. Additionally, AlliedModders LLC grants |
|
ds@1952
|
27 |
* this exception to all derivative works. AlliedModders LLC defines further |
|
ds@1952
|
28 |
* exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007), |
|
ds@1952
|
29 |
* or <http://www.sourcemod.net/license.php>. |
|
ds@1952
|
30 |
* |
|
ds@1952
|
31 |
* Version: $Id$ |
|
ds@1952
|
32 |
*/ |
|
ds@1952
|
33 |
|
|
ds@1952
|
34 |
#pragma semicolon 1 |
|
ds@1952
|
35 |
|
|
ds@1952
|
36 |
#include <sourcemod> |
|
pred@2077
|
37 |
#include "include/nextmap.inc" |
|
pred@2077
|
38 |
|
|
ds@1952
|
39 |
|
|
ds@1952
|
40 |
public Plugin:myinfo = |
|
ds@1952
|
41 |
{ |
|
ds@1952
|
42 |
name = "Nextmap", |
|
ds@1952
|
43 |
author = "AlliedModders LLC", |
|
ds@1952
|
44 |
description = "Provides nextmap and sm_nextmap", |
|
ds@1952
|
45 |
version = SOURCEMOD_VERSION, |
|
ds@1952
|
46 |
url = "http://www.sourcemod.net/" |
|
ds@1952
|
47 |
}; |
|
ds@1952
|
48 |
|
|
ds@1952
|
49 |
|
|
ds@1952
|
50 |
new g_MapPos = -1; |
|
ds@1952
|
51 |
new Handle:g_MapList = INVALID_HANDLE; |
|
ds@1952
|
52 |
new g_MapListSerial = -1; |
|
ds@1952
|
53 |
|
|
ds@1952
|
54 |
public OnPluginStart() |
|
ds@1952
|
55 |
{ |
|
ds@1952
|
56 |
LoadTranslations("common.phrases"); |
|
ds@1952
|
57 |
LoadTranslations("nextmap.phrases"); |
|
ds@1952
|
58 |
|
|
ds@1952
|
59 |
g_MapList = CreateArray(32); |
|
ds@1952
|
60 |
|
|
ds@1952
|
61 |
RegConsoleCmd("say", Command_Say); |
|
ds@1952
|
62 |
RegConsoleCmd("say_team", Command_Say); |
|
ds@1952
|
63 |
|
|
pred@2083
|
64 |
RegConsoleCmd("nextmap", Command_Nextmap); |
|
ds@1952
|
65 |
|
|
ds@1952
|
66 |
RegAdminCmd("sm_setnextmap", Command_SetNextmap, ADMFLAG_CHANGEMAP, "sm_setnextmap <map>"); |
|
ds@1952
|
67 |
RegConsoleCmd("listmaps", Command_List); |
|
ds@1952
|
68 |
|
|
ds@1952
|
69 |
// Set to the current map so OnMapStart() will know what to do |
|
ds@1952
|
70 |
decl String:currentMap[64]; |
|
ds@1952
|
71 |
GetCurrentMap(currentMap, 64); |
|
pred@2077
|
72 |
SetNextMap(currentMap); |
|
ds@1952
|
73 |
} |
|
ds@1952
|
74 |
|
|
ds@1952
|
75 |
public OnConfigsExecuted() |
|
ds@1952
|
76 |
{ |
|
ds@1952
|
77 |
decl String:lastMap[64], String:currentMap[64]; |
|
pred@2077
|
78 |
GetNextMap(lastMap, sizeof(lastMap)); |
|
ds@1952
|
79 |
GetCurrentMap(currentMap, 64); |
|
ds@1952
|
80 |
|
|
ds@1952
|
81 |
// Why am I doing this? If we switched to a new map, but it wasn't what we expected (Due to sm_map, sm_votemap, or |
|
ds@1952
|
82 |
// some other plugin/command), we don't want to scramble the map cycle. Or for example, admin switches to a custom map |
|
ds@1952
|
83 |
// not in mapcyclefile. So we keep it set to the last expected nextmap. - ferret |
|
ds@1952
|
84 |
if (strcmp(lastMap, currentMap) == 0) |
|
ds@1952
|
85 |
{ |
|
ds@1952
|
86 |
FindAndSetNextMap(); |
|
ds@1952
|
87 |
} |
|
ds@1952
|
88 |
} |
|
ds@1952
|
89 |
|
|
ds@1952
|
90 |
public Action:Command_Say(client, args) |
|
ds@1952
|
91 |
{ |
|
ds@1952
|
92 |
decl String:text[192]; |
|
ds@1952
|
93 |
if (GetCmdArgString(text, sizeof(text)) < 1) |
|
ds@1952
|
94 |
{ |
|
ds@1952
|
95 |
return Plugin_Continue; |
|
ds@1952
|
96 |
} |
|
ds@1952
|
97 |
|
|
ds@1952
|
98 |
new startidx; |
|
ds@1952
|
99 |
if (text[strlen(text)-1] == '"') |
|
ds@1952
|
100 |
{ |
|
ds@1952
|
101 |
text[strlen(text)-1] = '\0'; |
|
ds@1952
|
102 |
startidx = 1; |
|
ds@1952
|
103 |
} |
|
ds@1952
|
104 |
|
|
ds@1952
|
105 |
decl String:message[8]; |
|
ds@1952
|
106 |
BreakString(text[startidx], message, sizeof(message)); |
|
ds@1952
|
107 |
|
|
ds@1952
|
108 |
if (strcmp(message, "nextmap", false) == 0) |
|
ds@1952
|
109 |
{ |
|
ds@1952
|
110 |
decl String:map[32]; |
|
pred@2077
|
111 |
GetNextMap(map, sizeof(map)); |
|
ds@1952
|
112 |
|
|
pred@2083
|
113 |
PrintToChat(client, "[SM] %t", "Next Map", map); |
|
ds@1952
|
114 |
} |
|
ds@1952
|
115 |
|
|
ds@1952
|
116 |
return Plugin_Continue; |
|
ds@1952
|
117 |
} |
|
ds@1952
|
118 |
|
|
ds@1952
|
119 |
public Action:Command_SetNextmap(client, args) |
|
ds@1952
|
120 |
{ |
|
ds@1952
|
121 |
if (args < 1) |
|
ds@1952
|
122 |
{ |
|
ds@1952
|
123 |
ReplyToCommand(client, "[SM] Usage: sm_setnextmap <map>"); |
|
ds@1952
|
124 |
return Plugin_Handled; |
|
ds@1952
|
125 |
} |
|
ds@1952
|
126 |
|
|
ds@1952
|
127 |
decl String:map[64]; |
|
ds@1952
|
128 |
GetCmdArg(1, map, sizeof(map)); |
|
ds@1952
|
129 |
|
|
ds@1952
|
130 |
if (!IsMapValid(map)) |
|
ds@1952
|
131 |
{ |
|
ds@1952
|
132 |
ReplyToCommand(client, "[SM] %t", "Map was not found", map); |
|
ds@1952
|
133 |
return Plugin_Handled; |
|
ds@1952
|
134 |
} |
|
ds@1952
|
135 |
|
|
pred@2077
|
136 |
ShowActivity(client, "%t", "Changed Next Map", map); |
|
pred@2077
|
137 |
LogMessage("\"%L\" changed nextmap to \"%s\"", client, map); |
|
ds@1952
|
138 |
|
|
pred@2077
|
139 |
SetNextMap(map); |
|
ds@1952
|
140 |
|
|
ds@1952
|
141 |
return Plugin_Handled; |
|
ds@1952
|
142 |
} |
|
ds@1952
|
143 |
|
|
ds@1952
|
144 |
public Action:Command_List(client, args) |
|
ds@1952
|
145 |
{ |
|
ds@1952
|
146 |
PrintToConsole(client, "Map Cycle:"); |
|
ds@1952
|
147 |
|
|
ds@1952
|
148 |
new mapCount = GetArraySize(g_MapList); |
|
ds@1952
|
149 |
decl String:mapName[32]; |
|
ds@1952
|
150 |
for (new i = 0; i < mapCount; i++) |
|
ds@1952
|
151 |
{ |
|
ds@1952
|
152 |
GetArrayString(g_MapList, i, mapName, sizeof(mapName)); |
|
ds@1952
|
153 |
PrintToConsole(client, "%s", mapName); |
|
ds@1952
|
154 |
} |
|
ds@1952
|
155 |
|
|
ds@1952
|
156 |
return Plugin_Handled; |
|
ds@1952
|
157 |
} |
|
ds@1952
|
158 |
|
|
pred@2083
|
159 |
public Action:Command_Nextmap(client, args) |
|
ds@1952
|
160 |
{ |
|
ds@1952
|
161 |
decl String:map[64]; |
|
ds@1952
|
162 |
|
|
pred@2077
|
163 |
GetNextMap(map, sizeof(map)); |
|
ds@1952
|
164 |
|
|
pred@2083
|
165 |
ReplyToCommand(client, "[SM] %t", "Next Map", map); |
|
ds@1952
|
166 |
|
|
ds@1952
|
167 |
return Plugin_Handled; |
|
ds@1952
|
168 |
} |
|
ds@1952
|
169 |
|
|
ds@1952
|
170 |
FindAndSetNextMap() |
|
ds@1952
|
171 |
{ |
|
ds@1952
|
172 |
if (ReadMapList(g_MapList, |
|
ds@1952
|
173 |
g_MapListSerial, |
|
ds@1952
|
174 |
"mapcyclefile", |
|
ds@1952
|
175 |
MAPLIST_FLAG_CLEARARRAY|MAPLIST_FLAG_NO_DEFAULT) |
|
ds@1952
|
176 |
== INVALID_HANDLE) |
|
ds@1952
|
177 |
{ |
|
ds@1952
|
178 |
if (g_MapListSerial == -1) |
|
ds@1952
|
179 |
{ |
|
ds@1952
|
180 |
LogError("FATAL: Cannot load map cycle. Nextmap not loaded."); |
|
ds@1952
|
181 |
SetFailState("Mapcycle Not Found"); |
|
ds@1952
|
182 |
} |
|
ds@1952
|
183 |
} |
|
ds@1952
|
184 |
|
|
ds@1952
|
185 |
new mapCount = GetArraySize(g_MapList); |
|
ds@1952
|
186 |
decl String:mapName[32]; |
|
ds@1952
|
187 |
|
|
ds@1952
|
188 |
if (g_MapPos == -1) |
|
ds@1952
|
189 |
{ |
|
ds@1952
|
190 |
decl String:current[64]; |
|
ds@1952
|
191 |
GetCurrentMap(current, 64); |
|
ds@1952
|
192 |
|
|
ds@1952
|
193 |
for (new i = 0; i < mapCount; i++) |
|
ds@1952
|
194 |
{ |
|
ds@1952
|
195 |
GetArrayString(g_MapList, i, mapName, sizeof(mapName)); |
|
ds@1952
|
196 |
if (strcmp(current, mapName, false) == 0) |
|
ds@1952
|
197 |
{ |
|
ds@1952
|
198 |
g_MapPos = i; |
|
ds@1952
|
199 |
break; |
|
ds@1952
|
200 |
} |
|
ds@1952
|
201 |
} |
|
ds@1952
|
202 |
|
|
ds@1952
|
203 |
if (g_MapPos == -1) |
|
ds@1952
|
204 |
g_MapPos = 0; |
|
ds@1952
|
205 |
} |
|
ds@1952
|
206 |
|
|
ds@1952
|
207 |
g_MapPos++; |
|
ds@1952
|
208 |
if (g_MapPos >= mapCount) |
|
ds@1952
|
209 |
g_MapPos = 0; |
|
ds@1952
|
210 |
|
|
ds@1952
|
211 |
GetArrayString(g_MapList, g_MapPos, mapName, sizeof(mapName)); |
|
pred@2077
|
212 |
SetNextMap(mapName); |
|
ds@1952
|
213 |
} |