1 // ==============================================
2 // CSQC client commands code, written by Samual
3 // Last updated: November 8th, 2011
4 // ==============================================
7 if(cmd == "mv_download") {
8 Cmd_MapVote_MapDownload(argc);
10 else if(cmd == "settemp") {
11 cvar_clientsettemp(argv(1), argv(2));
13 else if(cmd == "scoreboard_columns_set") {
14 Cmd_HUD_SetFields(argc);
16 else if(cmd == "scoreboard_columns_help") {
19 else if(cmd == "spawn") {
24 setorigin(e, view_origin);
25 e.angles = view_angles;
26 e.draw = DrawDebugModel;
27 e.classname = "debugmodel";
29 else if(cmd == "vyes")
33 vote_active = 0; // force the panel to disappear right as we have selected the value (to prevent it from fading out in the normal vote panel pos)
35 localcmd("setreport cl_allow_uid2name 1\n");
41 localcmd("cmd vote yes\n");
50 localcmd("setreport cl_allow_uid2name 0\n");
56 localcmd("cmd vote no\n");
62 #define GC_REQUEST_COMMAND 1
63 #define GC_REQUEST_USAGE 2
65 void Cmd_HUD_SetFields(float);
66 void Cmd_HUD_Help(float);
72 // ============================
73 // Misc. Supporting Functions
74 // ============================
76 void cvar_clientsettemp(string cv, string val)
79 for(e = world; (e = find(e, classname, "saved_cvar_value")); )
83 e.classname = "saved_cvar_value";
84 e.netname = strzone(cv);
85 e.message = strzone(cvar_string(cv));
90 void cvar_clientsettemp_restore()
93 for(e = world; (e = find(e, classname, "saved_cvar_value")); )
94 cvar_set(e.netname, e.message);
98 if(time - floor(time) > 0.5)
105 self.renderflags = 0;
106 self.drawmask = MASK_NORMAL;
111 // =======================
112 // Command Sub-Functions
113 // =======================
115 void GameCommand_blurtest(float request)
117 // Simple command to work with postprocessing temporarily... possibly completely pointless, the glsl shader is used for a real feature now...
118 // Anyway, to enable it, just compile the client with -DBLURTEST and then you can use the command.
123 case GC_REQUEST_COMMAND:
125 blurtest_time0 = time;
126 blurtest_time1 = time + stof(argv(1));
127 blurtest_radius = stof(argv(2));
128 blurtest_power = stof(argv(3));
129 print("Enabled blurtest\n");
134 case GC_REQUEST_USAGE:
136 print("\nUsage:^3 cl_cmd blurtest\n");
137 print(" No arguments required.\n");
144 print("Blurtest is not enabled on this client.\n");
150 void GameCommand_hud(float request, float argc) // TODO: Add aliases in commands.cfg
154 case GC_REQUEST_COMMAND:
160 cvar_set("_hud_configure", ftos(!autocvar__hud_configure));
168 HUD_Panel_ExportCfg(argv(2));
173 break; // go to usage, we're missing the paramater needed here.
180 hud_panel_radar_maximized = (stof(argv(2)) != 0);
182 hud_panel_radar_maximized = !hud_panel_radar_maximized;
191 print("Incorrect parameters for ^2hud^7\n");
192 case GC_REQUEST_USAGE:
194 print("\nUsage:^3 cl_cmd hud action [configname | radartoggle]\n");
195 print(" Where 'action' is the command to complete,\n");
196 print(" 'configname' is the name to save to for \"save\" action,\n");
197 print(" and 'radartoggle' is what to set hud_panel_radar_maximized to.\n");
198 print(" Full list of commands here: \"configure, save, radar.\"\n");
204 void GameCommand_sendcvar(float request, float argc) // wtf? why?
208 case GC_REQUEST_COMMAND:
210 // W_FixWeaponOrder will trash argv, so save what we need.
211 string thiscvar = strzone(argv(1));
212 string s = cvar_string(thiscvar);
214 if(thiscvar == "cl_weaponpriority")
215 s = W_FixWeaponOrder(W_NumberWeaponOrder(s), 1);
216 else if(substring(thiscvar, 0, 17) == "cl_weaponpriority" && strlen(thiscvar) == 18)
217 s = W_FixWeaponOrder(W_NumberWeaponOrder(s), 0);
219 localcmd("cmd sentcvar ", thiscvar, " \"", s, "\"\n");
226 case GC_REQUEST_USAGE:
228 print("\nUsage:^3 cl_cmd sendcvar <cvar>\n");
229 print(" Where 'cvar' is the cvar plus arguments to send to the server.\n");
235 /* use this when creating a new command, making sure to place it in alphabetical order.
236 void GameCommand_(float request)
240 case GC_REQUEST_COMMAND:
247 case GC_REQUEST_USAGE:
249 print("\nUsage:^3 cl_cmd \n");
250 print(" No arguments required.\n");
258 // ==================================
259 // Macro system for client commands
260 // ==================================
262 // Do not hard code aliases for these, instead create them in commands.cfg... also: keep in alphabetical order, please ;)
263 #define CLIENT_COMMANDS(request,arguments) \
264 CLIENT_COMMAND("blurtest", GameCommand_blurtest(request), "Feature for testing blur postprocessing") \
265 CLIENT_COMMAND("hud", GameCommand_hud(request, arguments), "Commands regarding/controlling the HUD system") \
266 CLIENT_COMMAND("sendcvar", GameCommand_sendcvar(request, arguments), "Send a cvar to the server (like weaponpriority)") \
269 void GameCommand_macro_help()
271 #define CLIENT_COMMAND(name,function,description) \
272 { print(" ^2", name, "^7: ", description, "\n"); }
274 CLIENT_COMMANDS(0, 0)
275 #undef CLIENT_COMMAND
280 float GameCommand_macro_command(float argc)
282 #define CLIENT_COMMAND(name,function,description) \
283 { if(name == strtolower(argv(0))) { function; return TRUE; } }
285 CLIENT_COMMANDS(GC_REQUEST_COMMAND, argc)
286 #undef CLIENT_COMMAND
291 float GameCommand_macro_usage(float argc)
293 #define CLIENT_COMMAND(name,function,description) \
294 { if(name == strtolower(argv(1))) { function; return TRUE; } }
296 CLIENT_COMMANDS(GC_REQUEST_USAGE, argc)
297 #undef CLIENT_COMMAND
303 // =========================================
304 // Main Function Called By Engine (cl_cmd)
305 // =========================================
306 // If this function exists, client code handles gamecommand instead of the engine code.
308 void GameCommand(string command)
310 float argc = tokenize_console(command);
312 if(strtolower(argv(0)) == "help")
316 print("\nUsage:^3 cl_cmd COMMAND...^7, where possible commands are:\n");
317 GameCommand_macro_help();
318 GameCommand_Generic("help");
319 print("For help about specific commands, type cl_cmd help COMMAND\n");
322 else if(GameCommand_macro_usage(argc)) // Instead of trying to call a command, we're going to see detailed information about it
327 else if(GameCommand_Generic(command))
329 return; // handled by common/gamecommand.qc
331 else if(GameCommand_macro_command(argc)) // continue as usual and scan for normal commands
333 return; // handled by one of the above GameCommand_* functions
336 // nothing above caught the command, must be invalid
337 print("Invalid command. For a list of supported commands, try cl_cmd help.\n");
343 // ===================================
344 // Macro system for console commands
345 // ===================================
347 // These functions are here specifically to add special + - commands to the game, and are not really normal commands.
348 // Please add client commands to the function above this, as this is only for special reasons.
349 #define CONSOLE_COMMANDS_NORMAL \
350 CONSOLE_COMMAND("+showscores", { scoreboard_showscores = TRUE; }) \
351 CONSOLE_COMMAND("-showscores", { scoreboard_showscores = FALSE; }) \
352 CONSOLE_COMMAND("+showaccuracy", { scoreboard_showaccuracy = TRUE; }) \
353 CONSOLE_COMMAND("-showaccuracy", { scoreboard_showaccuracy = FALSE; }) \
356 #define CONSOLE_COMMANDS_MOVEMENT \
357 CONSOLE_COMMAND("+forward", { ++camera_direction_x; }) \
358 CONSOLE_COMMAND("-forward", { --camera_direction_x; }) \
359 CONSOLE_COMMAND("+back", { --camera_direction_x; }) \
360 CONSOLE_COMMAND("-back", { ++camera_direction_x; }) \
361 CONSOLE_COMMAND("+moveup", { ++camera_direction_z; }) \
362 CONSOLE_COMMAND("-moveup", { --camera_direction_z; }) \
363 CONSOLE_COMMAND("+movedown", { --camera_direction_z; }) \
364 CONSOLE_COMMAND("-movedown", { ++camera_direction_z; }) \
365 CONSOLE_COMMAND("+moveright", { --camera_direction_y; }) \
366 CONSOLE_COMMAND("-moveright", { ++camera_direction_y; }) \
367 CONSOLE_COMMAND("+moveleft", { ++camera_direction_y; }) \
368 CONSOLE_COMMAND("-moveleft", { --camera_direction_y; }) \
369 CONSOLE_COMMAND("+roll_right", { ++camera_roll; }) \
370 CONSOLE_COMMAND("-roll_right", { --camera_roll; }) \
371 CONSOLE_COMMAND("+roll_left", { --camera_roll; }) \
372 CONSOLE_COMMAND("-roll_left", { ++camera_roll; }) \
375 void ConsoleCommand_macro_init()
377 // first init normal commands
378 #define CONSOLE_COMMAND(name,execution) \
379 { registercmd(name); }
381 CONSOLE_COMMANDS_NORMAL
382 #undef CONSOLE_COMMAND
384 // then init movement commands
389 #define CONSOLE_COMMAND(name,execution) \
390 { registercmd(name); }
392 CONSOLE_COMMANDS_MOVEMENT
393 #undef CONSOLE_COMMAND
401 float ConsoleCommand_macro_normal(float argc)
403 #define CONSOLE_COMMAND(name,execution) \
404 { if(name == strtolower(argv(0))) { { execution } return TRUE; } }
406 CONSOLE_COMMANDS_NORMAL
407 #undef CONSOLE_COMMAND
412 float ConsoleCommand_macro_movement(float argc)
416 #define CONSOLE_COMMAND(name,execution) \
417 { if(name == strtolower(argv(0))) { { execution } return TRUE; } }
419 CONSOLE_COMMANDS_MOVEMENT
420 #undef CONSOLE_COMMAND
427 // ======================================================
428 // Main Function Called By Engine (registered commands)
429 // ======================================================
430 // Used to parse commands in the console that have been registered with the "registercmd" function
432 float CSQC_ConsoleCommand(string command)
434 float argc = tokenize_console(command);
436 if(ConsoleCommand_macro_normal(argc))
440 else if(ConsoleCommand_macro_movement(argc))
445 // Return value should be 1 if CSQC handled the command, otherwise return 0 to have the engine handle it.