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 float cvar_clientsettemp(string tmp_cvar, string value)
80 for(e = world; (e = find(e, classname, "saved_cvar_value")); )
81 if(e.netname == tmp_cvar)
84 // creating a new entity to keep track of this cvar
86 e.classname = "saved_cvar_value";
87 e.netname = strzone(tmp_cvar);
88 e.message = strzone(cvar_string(tmp_cvar));
91 // an entity for this cvar already exists, update the value
93 cvar_set(tmp_cvar, value);
97 float cvar_clientsettemp_restore()
102 for(e = world; (e = find(e, classname, "saved_cvar_value")); )
103 { cvar_set(e.netname, e.message); ++i; }
107 void DrawDebugModel()
109 if(time - floor(time) > 0.5)
116 self.renderflags = 0;
117 self.drawmask = MASK_NORMAL;
122 // =======================
123 // Command Sub-Functions
124 // =======================
126 void GameCommand_blurtest(float request)
128 // Simple command to work with postprocessing temporarily... possibly completely pointless, the glsl shader is used for a real feature now...
129 // Anyway, to enable it, just compile the client with -DBLURTEST and then you can use the command.
134 case GC_REQUEST_COMMAND:
136 blurtest_time0 = time;
137 blurtest_time1 = time + stof(argv(1));
138 blurtest_radius = stof(argv(2));
139 blurtest_power = stof(argv(3));
140 print("Enabled blurtest\n");
145 case GC_REQUEST_USAGE:
147 print("\nUsage:^3 cl_cmd blurtest\n");
148 print(" No arguments required.\n");
155 print("Blurtest is not enabled on this client.\n");
161 void GameCommand_hud(float request, float argc) // TODO: Add aliases in commands.cfg
165 case GC_REQUEST_COMMAND:
171 cvar_set("_hud_configure", ftos(!autocvar__hud_configure));
179 HUD_Panel_ExportCfg(argv(2));
184 break; // go to usage, we're missing the paramater needed here.
191 hud_panel_radar_maximized = (stof(argv(2)) != 0);
193 hud_panel_radar_maximized = !hud_panel_radar_maximized;
202 print("Incorrect parameters for ^2hud^7\n");
203 case GC_REQUEST_USAGE:
205 print("\nUsage:^3 cl_cmd hud action [configname | radartoggle]\n");
206 print(" Where 'action' is the command to complete,\n");
207 print(" 'configname' is the name to save to for \"save\" action,\n");
208 print(" and 'radartoggle' is to control hud_panel_radar_maximized for \"radar\" action.\n");
209 print(" Full list of commands here: \"configure, save, radar.\"\n");
215 void GameCommand_sendcvar(float request, float argc)
219 case GC_REQUEST_COMMAND:
221 // W_FixWeaponOrder will trash argv, so save what we need.
222 string thiscvar = strzone(argv(1));
223 string s = cvar_string(thiscvar);
225 if(thiscvar == "cl_weaponpriority")
226 s = W_FixWeaponOrder(W_NumberWeaponOrder(s), 1);
227 else if(substring(thiscvar, 0, 17) == "cl_weaponpriority" && strlen(thiscvar) == 18)
228 s = W_FixWeaponOrder(W_NumberWeaponOrder(s), 0);
230 localcmd("cmd sentcvar ", thiscvar, " \"", s, "\"\n");
237 case GC_REQUEST_USAGE:
239 print("\nUsage:^3 cl_cmd sendcvar <cvar>\n");
240 print(" Where 'cvar' is the cvar plus arguments to send to the server.\n");
246 void GameCommand_settemp(float request, float argc)
250 case GC_REQUEST_COMMAND:
257 case GC_REQUEST_USAGE:
259 print("\nUsage:^3 cl_cmd \n");
260 print(" No arguments required.\n");
266 /* use this when creating a new command, making sure to place it in alphabetical order.
267 void GameCommand_(float request)
271 case GC_REQUEST_COMMAND:
278 case GC_REQUEST_USAGE:
280 print("\nUsage:^3 cl_cmd \n");
281 print(" No arguments required.\n");
289 // ==================================
290 // Macro system for client commands
291 // ==================================
293 // Do not hard code aliases for these, instead create them in commands.cfg... also: keep in alphabetical order, please ;)
294 #define CLIENT_COMMANDS(request,arguments) \
295 CLIENT_COMMAND("blurtest", GameCommand_blurtest(request), "Feature for testing blur postprocessing") \
296 CLIENT_COMMAND("hud", GameCommand_hud(request, arguments), "Commands regarding/controlling the HUD system") \
297 CLIENT_COMMAND("sendcvar", GameCommand_sendcvar(request, arguments), "Send a cvar to the server (like weaponpriority)") \
298 CLIENT_COMMAND("settemp", GameCommand_settemp(request, arguments), "Temporarily set a value to a cvar which will be cleared next match") \
301 void GameCommand_macro_help()
303 #define CLIENT_COMMAND(name,function,description) \
304 { print(" ^2", name, "^7: ", description, "\n"); }
306 CLIENT_COMMANDS(0, 0)
307 #undef CLIENT_COMMAND
312 float GameCommand_macro_command(float argc)
314 #define CLIENT_COMMAND(name,function,description) \
315 { if(name == strtolower(argv(0))) { function; return TRUE; } }
317 CLIENT_COMMANDS(GC_REQUEST_COMMAND, argc)
318 #undef CLIENT_COMMAND
323 float GameCommand_macro_usage(float argc)
325 #define CLIENT_COMMAND(name,function,description) \
326 { if(name == strtolower(argv(1))) { function; return TRUE; } }
328 CLIENT_COMMANDS(GC_REQUEST_USAGE, argc)
329 #undef CLIENT_COMMAND
335 // =========================================
336 // Main Function Called By Engine (cl_cmd)
337 // =========================================
338 // If this function exists, client code handles gamecommand instead of the engine code.
340 void GameCommand(string command)
342 float argc = tokenize_console(command);
344 if(strtolower(argv(0)) == "help")
348 print("\nUsage:^3 cl_cmd COMMAND...^7, where possible commands are:\n");
349 GameCommand_macro_help();
350 GameCommand_Generic("help");
351 print("For help about specific commands, type cl_cmd help COMMAND\n");
354 else if(GameCommand_macro_usage(argc)) // Instead of trying to call a command, we're going to see detailed information about it
359 else if(GameCommand_Generic(command))
361 return; // handled by common/gamecommand.qc
363 else if(GameCommand_macro_command(argc)) // continue as usual and scan for normal commands
365 return; // handled by one of the above GameCommand_* functions
368 // nothing above caught the command, must be invalid
369 print("Unknown client command", ((command != "") ? strcat(" \"", command, "\"") : ""), ". For a list of supported commands, try cl_cmd help.\n");
375 // ===================================
376 // Macro system for console commands
377 // ===================================
379 // These functions are here specifically to add special + - commands to the game, and are not really normal commands.
380 // Please add client commands to the function above this, as this is only for special reasons.
381 #define CONSOLE_COMMANDS_NORMAL \
382 CONSOLE_COMMAND("+showscores", { scoreboard_showscores = TRUE; }) \
383 CONSOLE_COMMAND("-showscores", { scoreboard_showscores = FALSE; }) \
384 CONSOLE_COMMAND("+showaccuracy", { scoreboard_showaccuracy = TRUE; }) \
385 CONSOLE_COMMAND("-showaccuracy", { scoreboard_showaccuracy = FALSE; }) \
388 #define CONSOLE_COMMANDS_MOVEMENT \
389 CONSOLE_COMMAND("+forward", { ++camera_direction_x; }) \
390 CONSOLE_COMMAND("-forward", { --camera_direction_x; }) \
391 CONSOLE_COMMAND("+back", { --camera_direction_x; }) \
392 CONSOLE_COMMAND("-back", { ++camera_direction_x; }) \
393 CONSOLE_COMMAND("+moveup", { ++camera_direction_z; }) \
394 CONSOLE_COMMAND("-moveup", { --camera_direction_z; }) \
395 CONSOLE_COMMAND("+movedown", { --camera_direction_z; }) \
396 CONSOLE_COMMAND("-movedown", { ++camera_direction_z; }) \
397 CONSOLE_COMMAND("+moveright", { --camera_direction_y; }) \
398 CONSOLE_COMMAND("-moveright", { ++camera_direction_y; }) \
399 CONSOLE_COMMAND("+moveleft", { ++camera_direction_y; }) \
400 CONSOLE_COMMAND("-moveleft", { --camera_direction_y; }) \
401 CONSOLE_COMMAND("+roll_right", { ++camera_roll; }) \
402 CONSOLE_COMMAND("-roll_right", { --camera_roll; }) \
403 CONSOLE_COMMAND("+roll_left", { --camera_roll; }) \
404 CONSOLE_COMMAND("-roll_left", { ++camera_roll; }) \
407 void ConsoleCommand_macro_init()
409 // first init normal commands
410 #define CONSOLE_COMMAND(name,execution) \
411 { registercmd(name); }
413 CONSOLE_COMMANDS_NORMAL
414 #undef CONSOLE_COMMAND
416 // then init movement commands
421 #define CONSOLE_COMMAND(name,execution) \
422 { registercmd(name); }
424 CONSOLE_COMMANDS_MOVEMENT
425 #undef CONSOLE_COMMAND
433 float ConsoleCommand_macro_normal(float argc)
435 #define CONSOLE_COMMAND(name,execution) \
436 { if(name == strtolower(argv(0))) { { execution } return TRUE; } }
438 CONSOLE_COMMANDS_NORMAL
439 #undef CONSOLE_COMMAND
444 float ConsoleCommand_macro_movement(float argc)
448 #define CONSOLE_COMMAND(name,execution) \
449 { if(name == strtolower(argv(0))) { { execution } return TRUE; } }
451 CONSOLE_COMMANDS_MOVEMENT
452 #undef CONSOLE_COMMAND
459 // ======================================================
460 // Main Function Called By Engine (registered commands)
461 // ======================================================
462 // Used to parse commands in the console that have been registered with the "registercmd" function
464 float CSQC_ConsoleCommand(string command)
466 float argc = tokenize_console(command);
468 if(ConsoleCommand_macro_normal(argc))
472 else if(ConsoleCommand_macro_movement(argc))
477 // Return value should be 1 if CSQC handled the command, otherwise return 0 to have the engine handle it.