1 // --------------------------------------------------------------------------
\r
2 // BEGIN REQUIRED CSQC FUNCTIONS
\r
6 void() menu_show_error =
\r
8 drawstring('0 200', "ERROR - MENU IS VISIBLE BUT NO MENU WAS DEFINED!", '8 8 0', '1 0 0', 1, 0);
\r
11 // CSQC_Init : Called every time the CSQC code is initialized (essentially at map load)
\r
12 // Useful for precaching things
\r
14 void() menu_sub_null =
\r
18 float last_pingrequest;
\r
24 void CSQC_Init(void)
\r
27 last_pingrequest = 0;
\r
32 pingList.sort_next = NULL;
\r
33 pingList.sort_prev = NULL;
\r
35 menu_visible = FALSE;
\r
36 menu_show = menu_show_error;
\r
37 menu_action = menu_sub_null;
\r
39 localcmd("alias order \"cmd order $*\"");
\r
40 //registercmd("ctf_menu");
\r
41 registercmd("ons_map");
\r
42 //registercmd("menu_action");
\r
44 registercvar("sbar_usecsqc", "1");
\r
50 pingbuf = buf_create();
\r
51 for(i = 0; i < maxclients; ++i)
\r
52 bufstr_add(pingbuf, "-", false);
\r
54 // CSQC_Shutdown : Called every time the CSQC code is shutdown (changing maps, quitting, etc)
\r
55 void CSQC_Shutdown(void)
\r
61 while(pingList.sort_next)
\r
63 next = pingList.sort_next;
\r
64 pingList.sort_next = next.sort_next;
\r
70 // CSQC_ConsoleCommand : Used to parse commands in the console that have been registered with the "registercmd" function
\r
71 // Return value should be 1 if CSQC handled the command, otherwise return 0 to have the engine handle it.
\r
72 float CSQC_ConsoleCommand(string strMessage)
\r
74 local float nReturn;
\r
78 tokenize(strMessage);
\r
81 local string strCmd;
\r
84 /*if(strCmd == "ctf_menu") {
\r
88 if(strCmd == "ons_map") {
\r
95 // CSQC_InputEvent : Used to perform actions based on any key pressed, key released and mouse on the client.
\r
96 // Return value should be 1 if CSQC handled the input, otherwise return 0 to have the input passed to the engine.
\r
97 // All keys are in ascii.
\r
98 // bInputType = 0 is key pressed, 1 is key released, 2 is mouse input.
\r
99 // In the case of keyboard input, nPrimary is the ascii code, and nSecondary is 0.
\r
100 // In the case of mouse input, nPrimary is xdelta, nSecondary is ydelta.
\r
101 float CSQC_InputEvent(float bInputType, float nPrimary, float nSecondary)
\r
103 local float bSkipKey;
\r
106 if(menu_action(bInputType, nPrimary, nSecondary))
\r
111 // END REQUIRED CSQC FUNCTIONS
\r
112 // --------------------------------------------------------------------------
\r
114 // --------------------------------------------------------------------------
\r
115 // BEGIN OPTIONAL CSQC FUNCTIONS
\r
117 // CSQC_Ent_Update : Called every frame that the server has indicated an update to the SSQC / CSQC entity has occured.
\r
118 // The only parameter reflects if the entity is "new" to the client, meaning it just came into the client's PVS.
\r
119 void(float bIsNewEntity) CSQC_Ent_Update =
\r
121 self.enttype = ReadByte();
\r
122 if(self.enttype == ENT_CLIENT_ENTCS)
\r
124 self.sv_entnum = ReadByte();
\r
125 self.origin_x = ReadCoord();
\r
126 self.origin_y = ReadCoord();
\r
127 self.angles_y = ReadCoord();
\r
128 self.origin_z = self.angles_x = self.angles_z = 0;
\r
132 //print(strcat("Adding entity: ", ftos(self.sv_entnum), "\n"));
\r
133 self.chain = gps_start;
\r
138 error("unknown entity type in CSQC_Ent_Update\n");
\r
141 // CSQC_Ent_Remove : Called when the server requests a SSQC / CSQC entity to be removed. Essentially call remove(self) as well.
\r
142 void CSQC_Ent_Remove()
\r
144 if(self.enttype == ENT_CLIENT_ENTCS)
\r
146 if(gps_start == self)
\r
147 gps_start = self.chain;
\r
153 while(ent.chain != self && ent.chain != world)
\r
155 if(ent.chain == self)
\r
156 ent.chain = self.chain;
\r
162 void Gamemode_Init()
\r
164 local string mapinfo, infoline;
\r
167 local vector mi_min, mi_max;
\r
169 draw_enginesbar = true;
\r
170 gametype = cvar("gametype");
\r
171 if(gametype == GAME_ONSLAUGHT) {
\r
172 if(!strcasecmp(substring(mapname, 0, 5), "maps/"))
\r
173 minimapname = substring(mapname, 5, 999);
\r
175 minimapname = mapname;
\r
176 len = strlen(minimapname);
\r
177 if(!strcasecmp(substring(minimapname, len-4, 4), ".bsp"))
\r
178 minimapname = substring(minimapname, 0, len-4);
\r
180 mapinfo = strcat("maps/", minimapname, ".info");
\r
181 minimapname = strzone(strcat("gfx/", minimapname, "_mini.tga"));
\r
183 mi_min = world.mins;
\r
184 mi_max = world.maxs;
\r
186 file = fopen(mapinfo, FILE_READ);
\r
188 while((infoline = fgets(file))) {
\r
189 if(!strncasecmp(infoline, "mins", 4)) {
\r
190 mi_min = stov(substring(infoline, 5, 999));
\r
191 } else if(!strncasecmp(infoline, "maxs", 4)) {
\r
192 mi_max = stov(substring(infoline, 5, 999));
\r
193 } else if(strncasecmp(infoline, "//", 2)) { // don't print comment-style lines
\r
194 print(strcat("mapinfo: ", infoline, "\n"));
\r
198 print(strcat("^1Error: ^7Mapinfo file '", mapinfo, "' missing! Minimap will be screwed.\n"));
\r
202 print(strcat("Mins: ", vtos(mi_min), " Maxs: ", vtos(mi_max), "\n"));
\r
204 mi_center = (mi_min + mi_max) * 0.5;
\r
205 mi_scale = mi_max - mi_min;
\r
208 print(strcat("Using ", minimapname, " as minimap.\n"));
\r
209 precache_pic(minimapname);
\r
210 precache_pic("gfx/ons-cp-neutral.tga");
\r
211 precache_pic("gfx/ons-cp-red.tga");
\r
212 precache_pic("gfx/ons-cp-blue.tga");
\r
213 precache_pic("gfx/ons-frame.tga");
\r
214 precache_pic("gfx/ons-frame-team.tga");
\r
215 } else if(gametype == GAME_KEYHUNT) {
\r
216 precache_pic("gfx/sb_key_carrying");
\r
217 precache_pic("gfx/sb_key_carrying_outline");
\r
218 draw_enginesbar = false;
\r
221 // CSQC_Parse_StuffCmd : Provides the stuffcmd string in the first parameter that the server provided. To execute standard behavior, simply execute localcmd with the string.
\r
222 void CSQC_Parse_StuffCmd(string strMessage)
\r
224 localcmd(strMessage);
\r
225 // watch for gametype changes!
\r
226 if(gametype != cvar("gametype"))
\r
237 last_pingrequest = time + 5;
\r
241 for(i = 0; i < maxclients; ++i)
\r
243 if(strlen(getplayerkey(i, "name")))
\r
247 while(pingList.sort_next)
\r
249 next = pingList.sort_next;
\r
250 pingList.sort_next = next.sort_next;
\r
253 pingList.sort_prev = NULL;
\r
255 localcmd("\nping\n");
\r
258 // CSQC_Parse_Print : Provides the print string in the first parameter that the server provided. To execute standard behavior, simply execute print with the string.
\r
259 void CSQC_Parse_Print(string strMessage)
\r
263 else if(strMessage != "Client ping times:\n")
\r
268 // pingList.sort_prev = last element
\r
270 ping = stof(strMessage);
\r
272 /*strMessage = substring(strMessage, 5, 999);
\r
273 print(strcat("Ping for # ", ftos(ping_line), " of ", ftos(parse_ping), " = ", ftos(ping), " player: "));
\r
275 print(" searching... ");*/
\r
276 for(i = 0; i < maxclients; ++i)
\r
278 if(strlen(getplayerkey(i, "name"))) {
\r
284 if(i >= maxclients)
\r
287 bufstr_set(pingbuf, i, ftos(ping));
\r
288 /*print(getplayerkey(i, "name"));
\r
292 tmp.sort_next = tmp.sort_prev = NULL;
\r
293 pingList.sort_prev.sort_next = tmp;
\r
294 pingList.sort_prev = tmp;*/
\r
297 if(ping_line >= parse_ping)
\r
298 parse_ping = false;
\r
301 // CSQC_Parse_CenterPrint : Provides the centerprint string in the first parameter that the server provided. To execute standard behavior, simply execute cprint with the string.
\r
302 void CSQC_Parse_CenterPrint(string strMessage)
\r
304 cprint(strMessage);
\r
306 // CSQC_Parse_TempEntity : Handles all temporary entity network data in the CSQC layer.
\r
307 // You must ALWAYS first acquire the temporary ID, which is sent as a byte.
\r
308 // Return value should be 1 if CSQC handled the temporary entity, otherwise return 0 to have the engine process the event.
\r
309 float CSQC_Parse_TempEntity()
\r
311 local float bHandled;
\r
315 nTEID = ReadByte();
\r
320 // Do something cool with TE_GUNSHOT!
\r
323 // No special logic for this temporary entity; return 0 so the engine can handle it
\r