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 == "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");
59 #define GC_REQUEST_COMMAND 1
60 #define GC_REQUEST_USAGE 2
62 void Cmd_HUD_SetFields(float);
63 void Cmd_HUD_Help(float);
69 // ============================
70 // Misc. Supporting Functions
71 // ============================
73 float cvar_clientsettemp(string tmp_cvar, string value)
77 for(e = world; (e = find(e, classname, "saved_cvar_value")); )
78 if(e.netname == tmp_cvar)
81 // creating a new entity to keep track of this cvar
83 e.classname = "saved_cvar_value";
84 e.netname = strzone(tmp_cvar);
85 e.message = strzone(cvar_string(tmp_cvar));
88 // an entity for this cvar already exists, update the value
90 cvar_set(tmp_cvar, value);
94 float cvar_clientsettemp_restore()
99 for(e = world; (e = find(e, classname, "saved_cvar_value")); )
100 { cvar_set(e.netname, e.message); ++i; }
105 void DrawDebugModel()
107 if(time - floor(time) > 0.5)
114 self.renderflags = 0;
115 self.drawmask = MASK_NORMAL;
120 // =======================
121 // Command Sub-Functions
122 // =======================
124 void GameCommand_blurtest(float request)
126 // Simple command to work with postprocessing temporarily... possibly completely pointless, the glsl shader is used for a real feature now...
127 // Anyway, to enable it, just compile the client with -DBLURTEST and then you can use the command.
132 case GC_REQUEST_COMMAND:
134 blurtest_time0 = time;
135 blurtest_time1 = time + stof(argv(1));
136 blurtest_radius = stof(argv(2));
137 blurtest_power = stof(argv(3));
138 print("Enabled blurtest\n");
143 case GC_REQUEST_USAGE:
145 print("\nUsage:^3 cl_cmd blurtest\n");
146 print(" No arguments required.\n");
153 print("Blurtest is not enabled on this client.\n");
159 void GameCommand_hud(float request, float argc) // TODO: Add aliases in commands.cfg
163 case GC_REQUEST_COMMAND:
169 cvar_set("_hud_configure", ftos(!autocvar__hud_configure));
177 HUD_Panel_ExportCfg(argv(2));
182 break; // go to usage, we're missing the paramater needed here.
189 hud_panel_radar_maximized = (stof(argv(2)) != 0);
191 hud_panel_radar_maximized = !hud_panel_radar_maximized;
196 case "scoreboard_columns_set":
198 Cmd_HUD_SetFields(argc); // todo update this function
203 case "scoreboard_columns_help":
205 Cmd_HUD_Help(argc); // todo update this function
214 print("Incorrect parameters for ^2hud^7\n");
215 case GC_REQUEST_USAGE:
217 print("\nUsage:^3 cl_cmd hud action [configname | radartoggle]\n");
218 print(" Where 'action' is the command to complete,\n");
219 print(" 'configname' is the name to save to for \"save\" action,\n");
220 print(" and 'radartoggle' is to control hud_panel_radar_maximized for \"radar\" action.\n");
221 print(" Full list of commands here: \"configure, save, radar.\"\n");
227 void GameCommand_sendcvar(float request, float argc)
231 case GC_REQUEST_COMMAND:
233 // W_FixWeaponOrder will trash argv, so save what we need.
234 string thiscvar = strzone(argv(1));
235 string s = cvar_string(thiscvar);
237 if(thiscvar == "cl_weaponpriority")
238 s = W_FixWeaponOrder(W_NumberWeaponOrder(s), 1);
239 else if(substring(thiscvar, 0, 17) == "cl_weaponpriority" && strlen(thiscvar) == 18)
240 s = W_FixWeaponOrder(W_NumberWeaponOrder(s), 0);
242 localcmd("cmd sentcvar ", thiscvar, " \"", s, "\"\n");
249 case GC_REQUEST_USAGE:
251 print("\nUsage:^3 cl_cmd sendcvar <cvar>\n");
252 print(" Where 'cvar' is the cvar plus arguments to send to the server.\n");
258 void GameCommand_settemp(float request, float argc)
262 case GC_REQUEST_COMMAND:
264 if((argv(1) == "restore") && (argc == 3))
266 float i = cvar_clientsettemp_restore();
269 print("Restored ", ftos(i), " temporary cvar settings to their original values.\n");
271 print("Nothing to restore.\n");
275 if(cvar_clientsettemp(argv(1), argv(2)))
276 print("Creating new settemp tracker for ", argv(1), " and setting it to \"", argv(2), "\" temporarily.\n");
278 print("Already had a tracker for ", argv(1), ", updating it to \"", argv(2), "\".\n");
285 case GC_REQUEST_USAGE:
287 print("\nUsage:^3 cl_cmd settemp <cvar> | [restore]\n");
288 print(" Where 'cvar' is the cvar plus arguments to send to the server,\n");
289 print(" or 'restore' allows you to restore all of the original temporary cvar values.\n");
295 /* use this when creating a new command, making sure to place it in alphabetical order.
296 void GameCommand_(float request)
300 case GC_REQUEST_COMMAND:
307 case GC_REQUEST_USAGE:
309 print("\nUsage:^3 cl_cmd \n");
310 print(" No arguments required.\n");
318 // ==================================
319 // Macro system for client commands
320 // ==================================
322 // Do not hard code aliases for these, instead create them in commands.cfg... also: keep in alphabetical order, please ;)
323 #define CLIENT_COMMANDS(request,arguments) \
324 CLIENT_COMMAND("blurtest", GameCommand_blurtest(request), "Feature for testing blur postprocessing") \
325 CLIENT_COMMAND("hud", GameCommand_hud(request, arguments), "Commands regarding/controlling the HUD system") \
326 CLIENT_COMMAND("sendcvar", GameCommand_sendcvar(request, arguments), "Send a cvar to the server (like weaponpriority)") \
327 CLIENT_COMMAND("settemp", GameCommand_settemp(request, arguments), "Temporarily set a value to a cvar which is restored by command or end of each match") \
330 void GameCommand_macro_help()
332 #define CLIENT_COMMAND(name,function,description) \
333 { print(" ^2", name, "^7: ", description, "\n"); }
335 CLIENT_COMMANDS(0, 0)
336 #undef CLIENT_COMMAND
341 float GameCommand_macro_command(float argc)
343 #define CLIENT_COMMAND(name,function,description) \
344 { if(name == strtolower(argv(0))) { function; return TRUE; } }
346 CLIENT_COMMANDS(GC_REQUEST_COMMAND, argc)
347 #undef CLIENT_COMMAND
352 float GameCommand_macro_usage(float argc)
354 #define CLIENT_COMMAND(name,function,description) \
355 { if(name == strtolower(argv(1))) { function; return TRUE; } }
357 CLIENT_COMMANDS(GC_REQUEST_USAGE, argc)
358 #undef CLIENT_COMMAND
364 // =========================================
365 // Main Function Called By Engine (cl_cmd)
366 // =========================================
367 // If this function exists, client code handles gamecommand instead of the engine code.
369 void GameCommand(string command)
371 float argc = tokenize_console(command);
373 if(strtolower(argv(0)) == "help")
377 print("\nUsage:^3 cl_cmd COMMAND...^7, where possible commands are:\n");
378 GameCommand_macro_help();
379 GameCommand_Generic("help");
380 print("For help about specific commands, type cl_cmd help COMMAND\n");
383 else if(GameCommand_macro_usage(argc)) // Instead of trying to call a command, we're going to see detailed information about it
388 else if(GameCommand_Generic(command))
390 return; // handled by common/gamecommand.qc
392 else if(GameCommand_macro_command(argc)) // continue as usual and scan for normal commands
394 return; // handled by one of the above GameCommand_* functions
397 // nothing above caught the command, must be invalid
398 print("Unknown client command", ((command != "") ? strcat(" \"", command, "\"") : ""), ". For a list of supported commands, try cl_cmd help.\n");
404 // ===================================
405 // Macro system for console commands
406 // ===================================
408 // These functions are here specifically to add special + - commands to the game, and are not really normal commands.
409 // Please add client commands to the function above this, as this is only for special reasons.
410 #define CONSOLE_COMMANDS_NORMAL \
411 CONSOLE_COMMAND("+showscores", { scoreboard_showscores = TRUE; }) \
412 CONSOLE_COMMAND("-showscores", { scoreboard_showscores = FALSE; }) \
413 CONSOLE_COMMAND("+showaccuracy", { scoreboard_showaccuracy = TRUE; }) \
414 CONSOLE_COMMAND("-showaccuracy", { scoreboard_showaccuracy = FALSE; }) \
417 #define CONSOLE_COMMANDS_MOVEMENT \
418 CONSOLE_COMMAND("+forward", { ++camera_direction_x; }) \
419 CONSOLE_COMMAND("-forward", { --camera_direction_x; }) \
420 CONSOLE_COMMAND("+back", { --camera_direction_x; }) \
421 CONSOLE_COMMAND("-back", { ++camera_direction_x; }) \
422 CONSOLE_COMMAND("+moveup", { ++camera_direction_z; }) \
423 CONSOLE_COMMAND("-moveup", { --camera_direction_z; }) \
424 CONSOLE_COMMAND("+movedown", { --camera_direction_z; }) \
425 CONSOLE_COMMAND("-movedown", { ++camera_direction_z; }) \
426 CONSOLE_COMMAND("+moveright", { --camera_direction_y; }) \
427 CONSOLE_COMMAND("-moveright", { ++camera_direction_y; }) \
428 CONSOLE_COMMAND("+moveleft", { ++camera_direction_y; }) \
429 CONSOLE_COMMAND("-moveleft", { --camera_direction_y; }) \
430 CONSOLE_COMMAND("+roll_right", { ++camera_roll; }) \
431 CONSOLE_COMMAND("-roll_right", { --camera_roll; }) \
432 CONSOLE_COMMAND("+roll_left", { --camera_roll; }) \
433 CONSOLE_COMMAND("-roll_left", { ++camera_roll; }) \
436 void ConsoleCommand_macro_init()
438 // first init normal commands
439 #define CONSOLE_COMMAND(name,execution) \
440 { registercmd(name); }
442 CONSOLE_COMMANDS_NORMAL
443 #undef CONSOLE_COMMAND
445 // then init movement commands
450 #define CONSOLE_COMMAND(name,execution) \
451 { registercmd(name); }
453 CONSOLE_COMMANDS_MOVEMENT
454 #undef CONSOLE_COMMAND
462 float ConsoleCommand_macro_normal(float argc)
464 #define CONSOLE_COMMAND(name,execution) \
465 { if(name == strtolower(argv(0))) { { execution } return TRUE; } }
467 CONSOLE_COMMANDS_NORMAL
468 #undef CONSOLE_COMMAND
473 float ConsoleCommand_macro_movement(float argc)
477 #define CONSOLE_COMMAND(name,execution) \
478 { if(name == strtolower(argv(0))) { { execution } return TRUE; } }
480 CONSOLE_COMMANDS_MOVEMENT
481 #undef CONSOLE_COMMAND
488 // ======================================================
489 // Main Function Called By Engine (registered commands)
490 // ======================================================
491 // Used to parse commands in the console that have been registered with the "registercmd" function
493 float CSQC_ConsoleCommand(string command)
495 float argc = tokenize_console(command);
497 if(ConsoleCommand_macro_normal(argc))
501 else if(ConsoleCommand_macro_movement(argc))
506 // Return value should be 1 if CSQC handled the command, otherwise return 0 to have the engine handle it.