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");
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 /* use this when creating a new command, making sure to place it in alphabetical order.
259 void GameCommand_(float request)
263 case GC_REQUEST_COMMAND:
270 case GC_REQUEST_USAGE:
272 print("\nUsage:^3 cl_cmd \n");
273 print(" No arguments required.\n");
281 // ==================================
282 // Macro system for client commands
283 // ==================================
285 // Do not hard code aliases for these, instead create them in commands.cfg... also: keep in alphabetical order, please ;)
286 #define CLIENT_COMMANDS(request,arguments) \
287 CLIENT_COMMAND("blurtest", GameCommand_blurtest(request), "Feature for testing blur postprocessing") \
288 CLIENT_COMMAND("hud", GameCommand_hud(request, arguments), "Commands regarding/controlling the HUD system") \
289 CLIENT_COMMAND("sendcvar", GameCommand_sendcvar(request, arguments), "Send a cvar to the server (like weaponpriority)") \
292 void GameCommand_macro_help()
294 #define CLIENT_COMMAND(name,function,description) \
295 { print(" ^2", name, "^7: ", description, "\n"); }
297 CLIENT_COMMANDS(0, 0)
298 #undef CLIENT_COMMAND
303 float GameCommand_macro_command(float argc)
305 #define CLIENT_COMMAND(name,function,description) \
306 { if(name == strtolower(argv(0))) { function; return TRUE; } }
308 CLIENT_COMMANDS(GC_REQUEST_COMMAND, argc)
309 #undef CLIENT_COMMAND
314 float GameCommand_macro_usage(float argc)
316 #define CLIENT_COMMAND(name,function,description) \
317 { if(name == strtolower(argv(1))) { function; return TRUE; } }
319 CLIENT_COMMANDS(GC_REQUEST_USAGE, argc)
320 #undef CLIENT_COMMAND
326 // =========================================
327 // Main Function Called By Engine (cl_cmd)
328 // =========================================
329 // If this function exists, client code handles gamecommand instead of the engine code.
331 void GameCommand(string command)
333 float argc = tokenize_console(command);
335 if(strtolower(argv(0)) == "help")
339 print("\nUsage:^3 cl_cmd COMMAND...^7, where possible commands are:\n");
340 GameCommand_macro_help();
341 GameCommand_Generic("help");
342 print("For help about specific commands, type cl_cmd help COMMAND\n");
345 else if(GameCommand_macro_usage(argc)) // Instead of trying to call a command, we're going to see detailed information about it
350 else if(GameCommand_Generic(command))
352 return; // handled by common/gamecommand.qc
354 else if(GameCommand_macro_command(argc)) // continue as usual and scan for normal commands
356 return; // handled by one of the above GameCommand_* functions
359 // nothing above caught the command, must be invalid
360 print("Unknown client command", ((command != "") ? strcat(" \"", command, "\"") : ""), ". For a list of supported commands, try cl_cmd help.\n");
366 // ===================================
367 // Macro system for console commands
368 // ===================================
370 // These functions are here specifically to add special + - commands to the game, and are not really normal commands.
371 // Please add client commands to the function above this, as this is only for special reasons.
372 #define CONSOLE_COMMANDS_NORMAL \
373 CONSOLE_COMMAND("+showscores", { scoreboard_showscores = TRUE; }) \
374 CONSOLE_COMMAND("-showscores", { scoreboard_showscores = FALSE; }) \
375 CONSOLE_COMMAND("+showaccuracy", { scoreboard_showaccuracy = TRUE; }) \
376 CONSOLE_COMMAND("-showaccuracy", { scoreboard_showaccuracy = FALSE; }) \
379 #define CONSOLE_COMMANDS_MOVEMENT \
380 CONSOLE_COMMAND("+forward", { ++camera_direction_x; }) \
381 CONSOLE_COMMAND("-forward", { --camera_direction_x; }) \
382 CONSOLE_COMMAND("+back", { --camera_direction_x; }) \
383 CONSOLE_COMMAND("-back", { ++camera_direction_x; }) \
384 CONSOLE_COMMAND("+moveup", { ++camera_direction_z; }) \
385 CONSOLE_COMMAND("-moveup", { --camera_direction_z; }) \
386 CONSOLE_COMMAND("+movedown", { --camera_direction_z; }) \
387 CONSOLE_COMMAND("-movedown", { ++camera_direction_z; }) \
388 CONSOLE_COMMAND("+moveright", { --camera_direction_y; }) \
389 CONSOLE_COMMAND("-moveright", { ++camera_direction_y; }) \
390 CONSOLE_COMMAND("+moveleft", { ++camera_direction_y; }) \
391 CONSOLE_COMMAND("-moveleft", { --camera_direction_y; }) \
392 CONSOLE_COMMAND("+roll_right", { ++camera_roll; }) \
393 CONSOLE_COMMAND("-roll_right", { --camera_roll; }) \
394 CONSOLE_COMMAND("+roll_left", { --camera_roll; }) \
395 CONSOLE_COMMAND("-roll_left", { ++camera_roll; }) \
398 void ConsoleCommand_macro_init()
400 // first init normal commands
401 #define CONSOLE_COMMAND(name,execution) \
402 { registercommand(name); }
404 CONSOLE_COMMANDS_NORMAL
405 #undef CONSOLE_COMMAND
407 // then init movement commands
412 #define CONSOLE_COMMAND(name,execution) \
413 { registercommand(name); }
415 CONSOLE_COMMANDS_MOVEMENT
416 #undef CONSOLE_COMMAND
424 float ConsoleCommand_macro_normal(float argc)
426 #define CONSOLE_COMMAND(name,execution) \
427 { if(name == strtolower(argv(0))) { { execution } return TRUE; } }
429 CONSOLE_COMMANDS_NORMAL
430 #undef CONSOLE_COMMAND
435 float ConsoleCommand_macro_movement(float argc)
439 #define CONSOLE_COMMAND(name,execution) \
440 { if(name == strtolower(argv(0))) { { execution } return TRUE; } }
442 CONSOLE_COMMANDS_MOVEMENT
443 #undef CONSOLE_COMMAND
450 // ======================================================
451 // Main Function Called By Engine (registered commands)
452 // ======================================================
453 // Used to parse commands in the console that have been registered with the "registercommand" function
455 float CSQC_ConsoleCommand(string command)
457 float argc = tokenize_console(command);
459 if(ConsoleCommand_macro_normal(argc))
463 else if(ConsoleCommand_macro_movement(argc))
468 // Return value should be 1 if CSQC handled the command, otherwise return 0 to have the engine handle it.