1 // ==============================================
2 // CSQC client commands code, written by Samual
3 // Last updated: November 26th, 2011
4 // ==============================================
7 if(cmd == "mv_download") {
8 Cmd_MapVote_MapDownload(argc);
10 else if(cmd == "scoreboard_columns_set") {
11 Cmd_HUD_SetFields(argc);
13 else if(cmd == "scoreboard_columns_help") {
16 else if(cmd == "spawn") {
21 setorigin(e, view_origin);
22 e.angles = view_angles;
23 e.draw = DrawDebugModel;
24 e.classname = "debugmodel";
26 else if(cmd == "vyes")
30 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)
32 localcmd("setreport cl_allow_uid2name 1\n");
38 localcmd("cmd vote yes\n");
47 localcmd("setreport cl_allow_uid2name 0\n");
53 localcmd("cmd vote no\n");
58 // ============================
59 // Misc. Supporting Functions
60 // ============================
62 float cvar_clientsettemp(string tmp_cvar, string value)
66 for(e = world; (e = find(e, classname, "saved_cvar_value")); )
67 if(e.netname == tmp_cvar)
70 // creating a new entity to keep track of this cvar
72 e.classname = "saved_cvar_value";
73 e.netname = strzone(tmp_cvar);
74 e.message = strzone(cvar_string(tmp_cvar));
77 // an entity for this cvar already exists, update the value
79 cvar_set(tmp_cvar, value);
83 float cvar_clientsettemp_restore()
88 for(e = world; (e = find(e, classname, "saved_cvar_value")); )
89 { cvar_set(e.netname, e.message); ++i; }
96 if(time - floor(time) > 0.5)
103 self.renderflags = 0;
104 self.drawmask = MASK_NORMAL;
109 // =======================
110 // Command Sub-Functions
111 // =======================
113 void GameCommand_blurtest(float request)
115 // Simple command to work with postprocessing temporarily... possibly completely pointless, the glsl shader is used for a real feature now...
116 // Anyway, to enable it, just compile the client with -DBLURTEST and then you can use the command.
121 case CMD_REQUEST_COMMAND:
123 blurtest_time0 = time;
124 blurtest_time1 = time + stof(argv(1));
125 blurtest_radius = stof(argv(2));
126 blurtest_power = stof(argv(3));
127 print("Enabled blurtest\n");
132 case CMD_REQUEST_USAGE:
134 print("\nUsage:^3 cl_cmd blurtest\n");
135 print(" No arguments required.\n");
142 print("Blurtest is not enabled on this client.\n");
148 void GameCommand_hud(float request, float argc) // TODO: Add aliases in commands.cfg
152 case CMD_REQUEST_COMMAND:
158 cvar_set("_hud_configure", ftos(!autocvar__hud_configure));
166 HUD_Panel_ExportCfg(argv(2));
171 break; // go to usage, we're missing the paramater needed here.
178 hud_panel_radar_maximized = (stof(argv(2)) != 0);
180 hud_panel_radar_maximized = !hud_panel_radar_maximized;
185 case "scoreboard_columns_set":
187 Cmd_HUD_SetFields(argc); // todo update this function
192 case "scoreboard_columns_help":
194 Cmd_HUD_Help(argc); // todo update this function
203 print("Incorrect parameters for ^2hud^7\n");
204 case CMD_REQUEST_USAGE:
206 print("\nUsage:^3 cl_cmd hud action [configname | radartoggle]\n");
207 print(" Where 'action' is the command to complete,\n");
208 print(" 'configname' is the name to save to for \"save\" action,\n");
209 print(" and 'radartoggle' is to control hud_panel_radar_maximized for \"radar\" action.\n");
210 print(" Full list of commands here: \"configure, save, radar.\"\n");
216 void GameCommand_sendcvar(float request, float argc)
220 case CMD_REQUEST_COMMAND:
222 // W_FixWeaponOrder will trash argv, so save what we need.
223 string thiscvar = strzone(argv(1));
224 string s = cvar_string(thiscvar);
226 if(thiscvar == "cl_weaponpriority")
227 s = W_FixWeaponOrder(W_NumberWeaponOrder(s), 1);
228 else if(substring(thiscvar, 0, 17) == "cl_weaponpriority" && strlen(thiscvar) == 18)
229 s = W_FixWeaponOrder(W_NumberWeaponOrder(s), 0);
231 localcmd("cmd sentcvar ", thiscvar, " \"", s, "\"\n");
238 case CMD_REQUEST_USAGE:
240 print("\nUsage:^3 cl_cmd sendcvar <cvar>\n");
241 print(" Where 'cvar' is the cvar plus arguments to send to the server.\n");
247 void GameCommand_settemp(float request, float argc)
251 case GC_REQUEST_COMMAND:
253 if((argv(1) == "restore") && (argc == 3))
255 float i = cvar_clientsettemp_restore();
258 dprint("Restored ", ftos(i), " temporary cvar settings to their original values.\n");
260 dprint("Nothing to restore.\n");
264 if(cvar_clientsettemp(argv(1), argv(2)))
265 dprint("Creating new settemp tracker for ", argv(1), " and setting it to \"", argv(2), "\" temporarily.\n");
267 dprint("Already had a tracker for ", argv(1), ", updating it to \"", argv(2), "\".\n");
274 case GC_REQUEST_USAGE:
276 print("\nUsage:^3 cl_cmd settemp <cvar> | [restore]\n");
277 print(" Where 'cvar' is the cvar plus arguments to send to the server,\n");
278 print(" or 'restore' allows you to restore all of the original temporary cvar values.\n");
284 /* use this when creating a new command, making sure to place it in alphabetical order.
285 void GameCommand_(float request)
289 case CMD_REQUEST_COMMAND:
296 case CMD_REQUEST_USAGE:
298 print("\nUsage:^3 cl_cmd \n");
299 print(" No arguments required.\n");
307 // ==================================
308 // Macro system for client commands
309 // ==================================
311 // Do not hard code aliases for these, instead create them in commands.cfg... also: keep in alphabetical order, please ;)
312 #define CLIENT_COMMANDS(request,arguments) \
313 CLIENT_COMMAND("blurtest", GameCommand_blurtest(request), "Feature for testing blur postprocessing") \
314 CLIENT_COMMAND("hud", GameCommand_hud(request, arguments), "Commands regarding/controlling the HUD system") \
315 CLIENT_COMMAND("sendcvar", GameCommand_sendcvar(request, arguments), "Send a cvar to the server (like weaponpriority)") \
316 CLIENT_COMMAND("settemp", GameCommand_settemp(request, arguments), "Temporarily set a value to a cvar which is restored by command or end of each match") \
319 void GameCommand_macro_help()
321 #define CLIENT_COMMAND(name,function,description) \
322 { print(" ^2", name, "^7: ", description, "\n"); }
324 CLIENT_COMMANDS(0, 0)
325 #undef CLIENT_COMMAND
330 float GameCommand_macro_command(float argc)
332 #define CLIENT_COMMAND(name,function,description) \
333 { if(name == strtolower(argv(0))) { function; return TRUE; } }
335 CLIENT_COMMANDS(CMD_REQUEST_COMMAND, argc)
336 #undef CLIENT_COMMAND
341 float GameCommand_macro_usage(float argc)
343 #define CLIENT_COMMAND(name,function,description) \
344 { if(name == strtolower(argv(1))) { function; return TRUE; } }
346 CLIENT_COMMANDS(CMD_REQUEST_USAGE, argc)
347 #undef CLIENT_COMMAND
353 // =========================================
354 // Main Function Called By Engine (cl_cmd)
355 // =========================================
356 // If this function exists, client code handles gamecommand instead of the engine code.
358 void GameCommand(string command)
360 float argc = tokenize_console(command);
362 if(strtolower(argv(0)) == "help")
366 print("\nUsage:^3 cl_cmd COMMAND...^7, where possible commands are:\n");
367 GameCommand_macro_help();
368 GameCommand_Generic("help");
369 print("For help about specific commands, type cl_cmd help COMMAND\n");
372 else if(GameCommand_macro_usage(argc)) // Instead of trying to call a command, we're going to see detailed information about it
377 else if(GameCommand_Generic(command))
379 return; // handled by common/gamecommand.qc
381 else if(GameCommand_macro_command(argc)) // continue as usual and scan for normal commands
383 return; // handled by one of the above GameCommand_* functions
386 // nothing above caught the command, must be invalid
387 print("Unknown client command", ((command != "") ? strcat(" \"", command, "\"") : ""), ". For a list of supported commands, try cl_cmd help.\n");
393 // ===================================
394 // Macro system for console commands
395 // ===================================
397 // These functions are here specifically to add special + - commands to the game, and are not really normal commands.
398 // Please add client commands to the function above this, as this is only for special reasons.
399 #define CONSOLE_COMMANDS_NORMAL \
400 CONSOLE_COMMAND("+showscores", { scoreboard_showscores = TRUE; }) \
401 CONSOLE_COMMAND("-showscores", { scoreboard_showscores = FALSE; }) \
402 CONSOLE_COMMAND("+showaccuracy", { scoreboard_showaccuracy = TRUE; }) \
403 CONSOLE_COMMAND("-showaccuracy", { scoreboard_showaccuracy = FALSE; }) \
406 #define CONSOLE_COMMANDS_MOVEMENT \
407 CONSOLE_COMMAND("+forward", { ++camera_direction_x; }) \
408 CONSOLE_COMMAND("-forward", { --camera_direction_x; }) \
409 CONSOLE_COMMAND("+back", { --camera_direction_x; }) \
410 CONSOLE_COMMAND("-back", { ++camera_direction_x; }) \
411 CONSOLE_COMMAND("+moveup", { ++camera_direction_z; }) \
412 CONSOLE_COMMAND("-moveup", { --camera_direction_z; }) \
413 CONSOLE_COMMAND("+movedown", { --camera_direction_z; }) \
414 CONSOLE_COMMAND("-movedown", { ++camera_direction_z; }) \
415 CONSOLE_COMMAND("+moveright", { --camera_direction_y; }) \
416 CONSOLE_COMMAND("-moveright", { ++camera_direction_y; }) \
417 CONSOLE_COMMAND("+moveleft", { ++camera_direction_y; }) \
418 CONSOLE_COMMAND("-moveleft", { --camera_direction_y; }) \
419 CONSOLE_COMMAND("+roll_right", { ++camera_roll; }) \
420 CONSOLE_COMMAND("-roll_right", { --camera_roll; }) \
421 CONSOLE_COMMAND("+roll_left", { --camera_roll; }) \
422 CONSOLE_COMMAND("-roll_left", { ++camera_roll; }) \
425 void ConsoleCommand_macro_init()
427 // first init normal commands
428 #define CONSOLE_COMMAND(name,execution) \
429 { registercommand(name); }
431 CONSOLE_COMMANDS_NORMAL
432 #undef CONSOLE_COMMAND
434 // then init movement commands
439 #define CONSOLE_COMMAND(name,execution) \
440 { registercommand(name); }
442 CONSOLE_COMMANDS_MOVEMENT
443 #undef CONSOLE_COMMAND
451 float ConsoleCommand_macro_normal(float argc)
453 #define CONSOLE_COMMAND(name,execution) \
454 { if(name == strtolower(argv(0))) { { execution } return TRUE; } }
456 CONSOLE_COMMANDS_NORMAL
457 #undef CONSOLE_COMMAND
462 float ConsoleCommand_macro_movement(float argc)
466 #define CONSOLE_COMMAND(name,execution) \
467 { if(name == strtolower(argv(0))) { { execution } return TRUE; } }
469 CONSOLE_COMMANDS_MOVEMENT
470 #undef CONSOLE_COMMAND
477 // ======================================================
478 // Main Function Called By Engine (registered commands)
479 // ======================================================
480 // Used to parse commands in the console that have been registered with the "registercommand" function
482 float CSQC_ConsoleCommand(string command)
484 float argc = tokenize_console(command);
486 if(ConsoleCommand_macro_normal(argc))
490 else if(ConsoleCommand_macro_movement(argc))
495 // Return value should be 1 if CSQC handled the command, otherwise return 0 to have the engine handle it.