Parent Directory | Revision Log
Revision 17 - (view) (download)
1 : | ian | 1 | /* AMX Mod X |
2 : | * NextMap Plugin | ||
3 : | * | ||
4 : | * by the AMX Mod X Development Team | ||
5 : | * originally developed by OLO | ||
6 : | * | ||
7 : | * This file is part of AMX Mod X. | ||
8 : | * | ||
9 : | * | ||
10 : | * This program is free software; you can redistribute it and/or modify it | ||
11 : | * under the terms of the GNU General Public License as published by the | ||
12 : | * Free Software Foundation; either version 2 of the License, or (at | ||
13 : | * your option) any later version. | ||
14 : | * | ||
15 : | * This program is distributed in the hope that it will be useful, but | ||
16 : | * WITHOUT ANY WARRANTY; without even the implied warranty of | ||
17 : | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
18 : | * General Public License for more details. | ||
19 : | * | ||
20 : | * You should have received a copy of the GNU General Public License | ||
21 : | * along with this program; if not, write to the Free Software Foundation, | ||
22 : | * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
23 : | * | ||
24 : | * In addition, as a special exception, the author gives permission to | ||
25 : | * link the code of this program with the Half-Life Game Engine ("HL | ||
26 : | * Engine") and Modified Game Libraries ("MODs") developed by Valve, | ||
27 : | * L.L.C ("Valve"). You must obey the GNU General Public License in all | ||
28 : | * respects for all of the code used other than the HL Engine and MODs | ||
29 : | * from Valve. If you modify this file, you may extend this exception | ||
30 : | * to your version of the file, but you are not obligated to do so. If | ||
31 : | * you do not wish to do so, delete this exception statement from your | ||
32 : | * version. | ||
33 : | */ | ||
34 : | |||
35 : | #include <amxmodx> | ||
36 : | |||
37 : | // WARNING: If you comment this line make sure | ||
38 : | // that in your mapcycle file maps don't repeat. | ||
39 : | // However the same map in a row is still valid. | ||
40 : | #define OBEY_MAPCYCLE | ||
41 : | |||
42 : | new g_nextMap[32] | ||
43 : | new g_mapCycle[32] | ||
44 : | new g_pos | ||
45 : | |||
46 : | public plugin_init() | ||
47 : | { | ||
48 : | register_plugin("NextMap", AMXX_VERSION_STR, "AMXX Dev Team") | ||
49 : | register_dictionary("nextmap.txt") | ||
50 : | register_event("30", "changeMap", "a") | ||
51 : | register_clcmd("say nextmap", "sayNextMap", 0, "- displays nextmap") | ||
52 : | register_clcmd("say currentmap", "sayCurrentMap", 0, "- display current map") | ||
53 : | register_clcmd("say ff", "sayFFStatus", 0, "- display friendly fire status") | ||
54 : | register_cvar("amx_nextmap", "", FCVAR_SERVER|FCVAR_EXTDLL|FCVAR_SPONLY) | ||
55 : | |||
56 : | new szString[32], szString2[32], szString3[8] | ||
57 : | |||
58 : | get_localinfo("lastmapcycle", szString, 31) | ||
59 : | parse(szString, szString2, 31, szString3, 7) | ||
60 : | g_pos = str_to_num(szString3) | ||
61 : | get_cvar_string("mapcyclefile", g_mapCycle, 31) | ||
62 : | |||
63 : | if (!equal(g_mapCycle, szString2)) | ||
64 : | g_pos = 0 // mapcyclefile has been changed - go from first | ||
65 : | |||
66 : | readMapCycle(g_mapCycle, g_nextMap, 31) | ||
67 : | set_cvar_string("amx_nextmap", g_nextMap) | ||
68 : | format(szString3, 31, "%s %d", g_mapCycle, g_pos) // save lastmapcycle settings | ||
69 : | set_localinfo("lastmapcycle", szString3) | ||
70 : | } | ||
71 : | |||
72 : | getNextMapName(szArg[], iMax) | ||
73 : | { | ||
74 : | new len = get_cvar_string("amx_nextmap", szArg, iMax) | ||
75 : | |||
76 : | ian | 17 | if (ValidMap(szArg)) return len |
77 : | ian | 1 | len = copy(szArg, iMax, g_nextMap) |
78 : | set_cvar_string("amx_nextmap", g_nextMap) | ||
79 : | |||
80 : | return len | ||
81 : | } | ||
82 : | |||
83 : | public sayNextMap() | ||
84 : | { | ||
85 : | new name[32] | ||
86 : | |||
87 : | getNextMapName(name, 31) | ||
88 : | client_print(0, print_chat, "%L %s", LANG_PLAYER, "NEXT_MAP", name) | ||
89 : | } | ||
90 : | |||
91 : | public sayCurrentMap() | ||
92 : | { | ||
93 : | new mapname[32] | ||
94 : | |||
95 : | get_mapname(mapname, 31) | ||
96 : | client_print(0, print_chat, "%L: %s", LANG_PLAYER, "PLAYED_MAP", mapname) | ||
97 : | } | ||
98 : | |||
99 : | public sayFFStatus() | ||
100 : | { | ||
101 : | client_print(0, print_chat, "%L: %L", LANG_PLAYER, "FRIEND_FIRE", LANG_PLAYER, get_cvar_num("mp_friendlyfire") ? "ON" : "OFF") | ||
102 : | } | ||
103 : | |||
104 : | public delayedChange(param[]) | ||
105 : | { | ||
106 : | set_cvar_float("mp_chattime", get_cvar_float("mp_chattime") - 2.0) | ||
107 : | server_cmd("changelevel %s", param) | ||
108 : | } | ||
109 : | |||
110 : | public changeMap() | ||
111 : | { | ||
112 : | new string[32] | ||
113 : | new Float:chattime = get_cvar_float("mp_chattime") | ||
114 : | |||
115 : | set_cvar_float("mp_chattime", chattime + 2.0) // make sure mp_chattime is long | ||
116 : | new len = getNextMapName(string, 31) + 1 | ||
117 : | set_task(chattime, "delayedChange", 0, string, len) // change with 1.5 sec. delay | ||
118 : | } | ||
119 : | |||
120 : | new g_warning[] = "WARNING: Couldn't find a valid map or the file doesn't exist (file ^"%s^")" | ||
121 : | |||
122 : | ian | 17 | stock bool:ValidMap(mapname[]) |
123 : | { | ||
124 : | if ( is_map_valid(mapname) ) | ||
125 : | { | ||
126 : | return true; | ||
127 : | } | ||
128 : | // If the is_map_valid check failed, check the end of the string | ||
129 : | new len = strlen(mapname) - 4; | ||
130 : | |||
131 : | // The mapname was too short to possibly house the .bsp extension | ||
132 : | if (len < 0) | ||
133 : | { | ||
134 : | return false; | ||
135 : | } | ||
136 : | if ( equali(mapname[len], ".bsp") ) | ||
137 : | { | ||
138 : | // If the ending was .bsp, then cut it off. | ||
139 : | // the string is byref'ed, so this copies back to the loaded text. | ||
140 : | mapname[len] = '^0'; | ||
141 : | |||
142 : | // recheck | ||
143 : | if ( is_map_valid(mapname) ) | ||
144 : | { | ||
145 : | return true; | ||
146 : | } | ||
147 : | } | ||
148 : | |||
149 : | return false; | ||
150 : | } | ||
151 : | |||
152 : | ian | 1 | #if defined OBEY_MAPCYCLE |
153 : | readMapCycle(szFileName[], szNext[], iNext) | ||
154 : | { | ||
155 : | new b, i = 0, iMaps = 0 | ||
156 : | new szBuffer[32], szFirst[32] | ||
157 : | |||
158 : | if (file_exists(szFileName)) | ||
159 : | { | ||
160 : | while (read_file(szFileName, i++, szBuffer, 31, b)) | ||
161 : | { | ||
162 : | ian | 17 | if (!isalnum(szBuffer[0]) || !ValidMap(szBuffer)) continue |
163 : | |||
164 : | ian | 1 | if (!iMaps) |
165 : | copy(szFirst, 31, szBuffer) | ||
166 : | |||
167 : | if (++iMaps > g_pos) | ||
168 : | { | ||
169 : | copy(szNext, iNext, szBuffer) | ||
170 : | g_pos = iMaps | ||
171 : | return | ||
172 : | } | ||
173 : | } | ||
174 : | } | ||
175 : | |||
176 : | if (!iMaps) | ||
177 : | { | ||
178 : | log_amx(g_warning, szFileName) | ||
179 : | get_mapname(szFirst, 31) | ||
180 : | } | ||
181 : | |||
182 : | copy(szNext, iNext, szFirst) | ||
183 : | g_pos = 1 | ||
184 : | } | ||
185 : | |||
186 : | #else | ||
187 : | |||
188 : | readMapCycle(szFileName[], szNext[], iNext) | ||
189 : | { | ||
190 : | new b, i = 0, iMaps = 0 | ||
191 : | new szBuffer[32], szFirst[32], szCurrent[32] | ||
192 : | |||
193 : | get_mapname(szCurrent, 31) | ||
194 : | |||
195 : | new a = g_pos | ||
196 : | |||
197 : | if (file_exists(szFileName)) | ||
198 : | { | ||
199 : | while (read_file(szFileName, i++, szBuffer, 31, b)) | ||
200 : | { | ||
201 : | ian | 17 | if (!isalnum(szBuffer[0]) || !ValidMap(szBuffer)) continue |
202 : | ian | 1 | |
203 : | if (!iMaps) | ||
204 : | { | ||
205 : | iMaps = 1 | ||
206 : | copy(szFirst, 31, szBuffer) | ||
207 : | } | ||
208 : | |||
209 : | if (iMaps == 1) | ||
210 : | { | ||
211 : | if (equali(szCurrent, szBuffer)) | ||
212 : | { | ||
213 : | if (a-- == 0) | ||
214 : | iMaps = 2 | ||
215 : | } | ||
216 : | } else { | ||
217 : | if (equali(szCurrent, szBuffer)) | ||
218 : | ++g_pos | ||
219 : | else | ||
220 : | g_pos = 0 | ||
221 : | |||
222 : | copy(szNext, iNext, szBuffer) | ||
223 : | return | ||
224 : | } | ||
225 : | } | ||
226 : | } | ||
227 : | |||
228 : | if (!iMaps) | ||
229 : | { | ||
230 : | log_amx(g_warning, szFileName) | ||
231 : | copy(szNext, iNext, szCurrent) | ||
232 : | } | ||
233 : | else | ||
234 : | copy(szNext, iNext, szFirst) | ||
235 : | |||
236 : | g_pos = 0 | ||
237 : | } | ||
238 : | #endif |
Contact | ViewVC Help |
Powered by ViewVC 1.0.4 |