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 GC_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 GC_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 GC_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 GC_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 GC_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 GC_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 /* use this when creating a new command, making sure to place it in alphabetical order.
248 void GameCommand_(float request)
252 case GC_REQUEST_COMMAND:
259 case GC_REQUEST_USAGE:
261 print("\nUsage:^3 cl_cmd \n");
262 print(" No arguments required.\n");
270 // ==================================
271 // Macro system for client commands
272 // ==================================
274 // Do not hard code aliases for these, instead create them in commands.cfg... also: keep in alphabetical order, please ;)
275 #define CLIENT_COMMANDS(request,arguments) \
276 CLIENT_COMMAND("blurtest", GameCommand_blurtest(request), "Feature for testing blur postprocessing") \
277 CLIENT_COMMAND("hud", GameCommand_hud(request, arguments), "Commands regarding/controlling the HUD system") \
278 CLIENT_COMMAND("sendcvar", GameCommand_sendcvar(request, arguments), "Send a cvar to the server (like weaponpriority)") \
281 void GameCommand_macro_help()
283 #define CLIENT_COMMAND(name,function,description) \
284 { print(" ^2", name, "^7: ", description, "\n"); }
286 CLIENT_COMMANDS(0, 0)
287 #undef CLIENT_COMMAND
292 float GameCommand_macro_command(float argc)
294 #define CLIENT_COMMAND(name,function,description) \
295 { if(name == strtolower(argv(0))) { function; return TRUE; } }
297 CLIENT_COMMANDS(GC_REQUEST_COMMAND, argc)
298 #undef CLIENT_COMMAND
303 float GameCommand_macro_usage(float argc)
305 #define CLIENT_COMMAND(name,function,description) \
306 { if(name == strtolower(argv(1))) { function; return TRUE; } }
308 CLIENT_COMMANDS(GC_REQUEST_USAGE, argc)
309 #undef CLIENT_COMMAND
315 // =========================================
316 // Main Function Called By Engine (cl_cmd)
317 // =========================================
318 // If this function exists, client code handles gamecommand instead of the engine code.
320 void GameCommand(string command)
322 float argc = tokenize_console(command);
324 if(strtolower(argv(0)) == "help")
328 print("\nUsage:^3 cl_cmd COMMAND...^7, where possible commands are:\n");
329 GameCommand_macro_help();
330 GameCommand_Generic("help");
331 print("For help about specific commands, type cl_cmd help COMMAND\n");
334 else if(GameCommand_macro_usage(argc)) // Instead of trying to call a command, we're going to see detailed information about it
339 else if(GameCommand_Generic(command))
341 return; // handled by common/gamecommand.qc
343 else if(GameCommand_macro_command(argc)) // continue as usual and scan for normal commands
345 return; // handled by one of the above GameCommand_* functions
348 // nothing above caught the command, must be invalid
349 print("Unknown client command", ((command != "") ? strcat(" \"", command, "\"") : ""), ". For a list of supported commands, try cl_cmd help.\n");
355 // ===================================
356 // Macro system for console commands
357 // ===================================
359 // These functions are here specifically to add special + - commands to the game, and are not really normal commands.
360 // Please add client commands to the function above this, as this is only for special reasons.
361 #define CONSOLE_COMMANDS_NORMAL \
362 CONSOLE_COMMAND("+showscores", { scoreboard_showscores = TRUE; }) \
363 CONSOLE_COMMAND("-showscores", { scoreboard_showscores = FALSE; }) \
364 CONSOLE_COMMAND("+showaccuracy", { scoreboard_showaccuracy = TRUE; }) \
365 CONSOLE_COMMAND("-showaccuracy", { scoreboard_showaccuracy = FALSE; }) \
368 #define CONSOLE_COMMANDS_MOVEMENT \
369 CONSOLE_COMMAND("+forward", { ++camera_direction_x; }) \
370 CONSOLE_COMMAND("-forward", { --camera_direction_x; }) \
371 CONSOLE_COMMAND("+back", { --camera_direction_x; }) \
372 CONSOLE_COMMAND("-back", { ++camera_direction_x; }) \
373 CONSOLE_COMMAND("+moveup", { ++camera_direction_z; }) \
374 CONSOLE_COMMAND("-moveup", { --camera_direction_z; }) \
375 CONSOLE_COMMAND("+movedown", { --camera_direction_z; }) \
376 CONSOLE_COMMAND("-movedown", { ++camera_direction_z; }) \
377 CONSOLE_COMMAND("+moveright", { --camera_direction_y; }) \
378 CONSOLE_COMMAND("-moveright", { ++camera_direction_y; }) \
379 CONSOLE_COMMAND("+moveleft", { ++camera_direction_y; }) \
380 CONSOLE_COMMAND("-moveleft", { --camera_direction_y; }) \
381 CONSOLE_COMMAND("+roll_right", { ++camera_roll; }) \
382 CONSOLE_COMMAND("-roll_right", { --camera_roll; }) \
383 CONSOLE_COMMAND("+roll_left", { --camera_roll; }) \
384 CONSOLE_COMMAND("-roll_left", { ++camera_roll; }) \
387 void ConsoleCommand_macro_init()
389 // first init normal commands
390 #define CONSOLE_COMMAND(name,execution) \
391 { registercommand(name); }
393 CONSOLE_COMMANDS_NORMAL
394 #undef CONSOLE_COMMAND
396 // then init movement commands
401 #define CONSOLE_COMMAND(name,execution) \
402 { registercommand(name); }
404 CONSOLE_COMMANDS_MOVEMENT
405 #undef CONSOLE_COMMAND
413 float ConsoleCommand_macro_normal(float argc)
415 #define CONSOLE_COMMAND(name,execution) \
416 { if(name == strtolower(argv(0))) { { execution } return TRUE; } }
418 CONSOLE_COMMANDS_NORMAL
419 #undef CONSOLE_COMMAND
424 float ConsoleCommand_macro_movement(float argc)
428 #define CONSOLE_COMMAND(name,execution) \
429 { if(name == strtolower(argv(0))) { { execution } return TRUE; } }
431 CONSOLE_COMMANDS_MOVEMENT
432 #undef CONSOLE_COMMAND
439 // ======================================================
440 // Main Function Called By Engine (registered commands)
441 // ======================================================
442 // Used to parse commands in the console that have been registered with the "registercommand" function
444 float CSQC_ConsoleCommand(string command)
446 float argc = tokenize_console(command);
448 if(ConsoleCommand_macro_normal(argc))
452 else if(ConsoleCommand_macro_movement(argc))
457 // Return value should be 1 if CSQC handled the command, otherwise return 0 to have the engine handle it.