1 // ==============================================
2 // CSQC client commands code, written by Samual
3 // Last updated: December 16th, 2011
4 // ==============================================
11 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)
13 localcmd("setreport cl_allow_uid2name 1\n");
19 localcmd("cmd vote yes\n");
28 localcmd("setreport cl_allow_uid2name 0\n");
34 localcmd("cmd vote no\n");
39 // ============================
40 // Misc. Supporting Functions
41 // ============================
43 float cvar_clientsettemp(string tmp_cvar, string value)
47 for(e = world; (e = find(e, classname, "saved_cvar_value")); )
48 if(e.netname == tmp_cvar)
51 // creating a new entity to keep track of this cvar
53 e.classname = "saved_cvar_value";
54 e.netname = strzone(tmp_cvar);
55 e.message = strzone(cvar_string(tmp_cvar));
58 // an entity for this cvar already exists, update the value
60 cvar_set(tmp_cvar, value);
64 float cvar_clientsettemp_restore()
69 for(e = world; (e = find(e, classname, "saved_cvar_value")); )
70 { cvar_set(e.netname, e.message); ++i; }
77 if(time - floor(time) > 0.5)
85 self.drawmask = MASK_NORMAL;
90 // =======================
91 // Command Sub-Functions
92 // =======================
94 void GameCommand_blurtest(float request)
96 // Simple command to work with postprocessing temporarily... possibly completely pointless, the glsl shader is used for a real feature now...
97 // Anyway, to enable it, just compile the client with -DBLURTEST and then you can use the command.
102 case CMD_REQUEST_COMMAND:
104 blurtest_time0 = time;
105 blurtest_time1 = time + stof(argv(1));
106 blurtest_radius = stof(argv(2));
107 blurtest_power = stof(argv(3));
108 print("Enabled blurtest\n");
113 case CMD_REQUEST_USAGE:
115 print("\nUsage:^3 cl_cmd blurtest\n");
116 print(" No arguments required.\n");
123 print("Blurtest is not enabled on this client.\n");
129 void GameCommand_debugmodel(float request, float argc)
133 case CMD_REQUEST_COMMAND:
135 string modelname = argv(1);
136 entity debugmodel_entity;
138 debugmodel_entity = spawn();
139 precache_model(modelname);
140 setmodel(debugmodel_entity, modelname);
141 setorigin(debugmodel_entity, view_origin);
142 debugmodel_entity.angles = view_angles;
143 debugmodel_entity.draw = DrawDebugModel;
144 debugmodel_entity.classname = "debugmodel";
150 case CMD_REQUEST_USAGE:
152 print("\nUsage:^3 cl_cmd debugmodel model\n");
153 print(" Where 'model' is a string of the model name to use for the debug model.\n");
159 void GameCommand_hud(float request, float argc) // TODO: Add aliases in commands.cfg
163 case CMD_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 CMD_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_mv_download(float request, float argc)
231 case CMD_REQUEST_COMMAND:
233 Cmd_MapVote_MapDownload(argc);
239 case CMD_REQUEST_USAGE:
241 print("\nUsage:^3 cl_cmd mapvote_download mapid\n");
242 print(" Where 'mapid' is the id number of the map to request an image of on the map vote selection menu.\n");
248 void GameCommand_sendcvar(float request, float argc)
252 case CMD_REQUEST_COMMAND:
254 // W_FixWeaponOrder will trash argv, so save what we need.
255 string thiscvar = strzone(argv(1));
256 string s = cvar_string(thiscvar);
258 if(thiscvar == "cl_weaponpriority")
259 s = W_FixWeaponOrder(W_NumberWeaponOrder(s), 1);
260 else if(substring(thiscvar, 0, 17) == "cl_weaponpriority" && strlen(thiscvar) == 18)
261 s = W_FixWeaponOrder(W_NumberWeaponOrder(s), 0);
263 localcmd("cmd sentcvar ", thiscvar, " \"", s, "\"\n");
270 case CMD_REQUEST_USAGE:
272 print("\nUsage:^3 cl_cmd sendcvar <cvar>\n");
273 print(" Where 'cvar' is the cvar plus arguments to send to the server.\n");
279 void GameCommand_settemp(float request, float argc)
283 case CMD_REQUEST_COMMAND:
285 if((argv(1) == "restore") && (argc == 3))
287 float i = cvar_clientsettemp_restore();
290 dprint("Restored ", ftos(i), " temporary cvar settings to their original values.\n");
292 dprint("Nothing to restore.\n");
296 if(cvar_clientsettemp(argv(1), argv(2)))
297 dprint("Creating new settemp tracker for ", argv(1), " and setting it to \"", argv(2), "\" temporarily.\n");
299 dprint("Already had a tracker for ", argv(1), ", updating it to \"", argv(2), "\".\n");
306 case CMD_REQUEST_USAGE:
308 print("\nUsage:^3 cl_cmd settemp <cvar> | [restore]\n");
309 print(" Where 'cvar' is the cvar plus arguments to send to the server,\n");
310 print(" or 'restore' allows you to restore all of the original temporary cvar values.\n");
316 /* use this when creating a new command, making sure to place it in alphabetical order.
317 void GameCommand_(float request)
321 case CMD_REQUEST_COMMAND:
328 case CMD_REQUEST_USAGE:
330 print("\nUsage:^3 cl_cmd \n");
331 print(" No arguments required.\n");
339 // ==================================
340 // Macro system for client commands
341 // ==================================
343 // Do not hard code aliases for these, instead create them in commands.cfg... also: keep in alphabetical order, please ;)
344 #define CLIENT_COMMANDS(request,arguments) \
345 CLIENT_COMMAND("blurtest", GameCommand_blurtest(request), "Feature for testing blur postprocessing") \
346 CLIENT_COMMAND("debugmodel", GameCommand_debugmodel(request, arguments), "Spawn a debug model manually") \
347 CLIENT_COMMAND("hud", GameCommand_hud(request, arguments), "Commands regarding/controlling the HUD system") \
348 CLIENT_COMMAND("mv_download", GameCommand_mv_download(request, arguments), "Retrieve mapshot picture from the server") \
349 CLIENT_COMMAND("sendcvar", GameCommand_sendcvar(request, arguments), "Send a cvar to the server (like weaponpriority)") \
350 CLIENT_COMMAND("settemp", GameCommand_settemp(request, arguments), "Temporarily set a value to a cvar which is restored by command or end of each match") \
353 void GameCommand_macro_help()
355 #define CLIENT_COMMAND(name,function,description) \
356 { print(" ^2", name, "^7: ", description, "\n"); }
358 CLIENT_COMMANDS(0, 0)
359 #undef CLIENT_COMMAND
364 float GameCommand_macro_command(float argc)
366 #define CLIENT_COMMAND(name,function,description) \
367 { if(name == strtolower(argv(0))) { function; return TRUE; } }
369 CLIENT_COMMANDS(CMD_REQUEST_COMMAND, argc)
370 #undef CLIENT_COMMAND
375 float GameCommand_macro_usage(float argc)
377 #define CLIENT_COMMAND(name,function,description) \
378 { if(name == strtolower(argv(1))) { function; return TRUE; } }
380 CLIENT_COMMANDS(CMD_REQUEST_USAGE, argc)
381 #undef CLIENT_COMMAND
387 // =========================================
388 // Main Function Called By Engine (cl_cmd)
389 // =========================================
390 // If this function exists, client code handles gamecommand instead of the engine code.
392 void GameCommand(string command)
394 float argc = tokenize_console(command);
396 if(strtolower(argv(0)) == "help")
400 print("\nUsage:^3 cl_cmd COMMAND...^7, where possible commands are:\n");
401 GameCommand_macro_help();
402 GameCommand_Generic("help");
403 print("For help about specific commands, type cl_cmd help COMMAND\n");
406 else if(GameCommand_macro_usage(argc)) // Instead of trying to call a command, we're going to see detailed information about it
411 else if(GameCommand_Generic(command))
413 return; // handled by common/gamecommand.qc
415 else if(GameCommand_macro_command(argc)) // continue as usual and scan for normal commands
417 return; // handled by one of the above GameCommand_* functions
420 // nothing above caught the command, must be invalid
421 print("Unknown client command", ((command != "") ? strcat(" \"", command, "\"") : ""), ". For a list of supported commands, try cl_cmd help.\n");
427 // ===================================
428 // Macro system for console commands
429 // ===================================
431 // These functions are here specifically to add special + - commands to the game, and are not really normal commands.
432 // Please add client commands to the function above this, as this is only for special reasons.
433 #define CONSOLE_COMMANDS_NORMAL \
434 CONSOLE_COMMAND("+showscores", { scoreboard_showscores = TRUE; }) \
435 CONSOLE_COMMAND("-showscores", { scoreboard_showscores = FALSE; }) \
436 CONSOLE_COMMAND("+showaccuracy", { scoreboard_showaccuracy = TRUE; }) \
437 CONSOLE_COMMAND("-showaccuracy", { scoreboard_showaccuracy = FALSE; }) \
440 #define CONSOLE_COMMANDS_MOVEMENT \
441 CONSOLE_COMMAND("+forward", { ++camera_direction_x; }) \
442 CONSOLE_COMMAND("-forward", { --camera_direction_x; }) \
443 CONSOLE_COMMAND("+back", { --camera_direction_x; }) \
444 CONSOLE_COMMAND("-back", { ++camera_direction_x; }) \
445 CONSOLE_COMMAND("+moveup", { ++camera_direction_z; }) \
446 CONSOLE_COMMAND("-moveup", { --camera_direction_z; }) \
447 CONSOLE_COMMAND("+movedown", { --camera_direction_z; }) \
448 CONSOLE_COMMAND("-movedown", { ++camera_direction_z; }) \
449 CONSOLE_COMMAND("+moveright", { --camera_direction_y; }) \
450 CONSOLE_COMMAND("-moveright", { ++camera_direction_y; }) \
451 CONSOLE_COMMAND("+moveleft", { ++camera_direction_y; }) \
452 CONSOLE_COMMAND("-moveleft", { --camera_direction_y; }) \
453 CONSOLE_COMMAND("+roll_right", { ++camera_roll; }) \
454 CONSOLE_COMMAND("-roll_right", { --camera_roll; }) \
455 CONSOLE_COMMAND("+roll_left", { --camera_roll; }) \
456 CONSOLE_COMMAND("-roll_left", { ++camera_roll; }) \
459 void ConsoleCommand_macro_init()
461 // first init normal commands
462 #define CONSOLE_COMMAND(name,execution) \
463 { registercommand(name); }
465 CONSOLE_COMMANDS_NORMAL
466 #undef CONSOLE_COMMAND
468 // then init movement commands
473 #define CONSOLE_COMMAND(name,execution) \
474 { registercommand(name); }
476 CONSOLE_COMMANDS_MOVEMENT
477 #undef CONSOLE_COMMAND
485 float ConsoleCommand_macro_normal(float argc)
487 #define CONSOLE_COMMAND(name,execution) \
488 { if(name == strtolower(argv(0))) { { execution } return TRUE; } }
490 CONSOLE_COMMANDS_NORMAL
491 #undef CONSOLE_COMMAND
496 float ConsoleCommand_macro_movement(float argc)
500 #define CONSOLE_COMMAND(name,execution) \
501 { if(name == strtolower(argv(0))) { { execution } return TRUE; } }
503 CONSOLE_COMMANDS_MOVEMENT
504 #undef CONSOLE_COMMAND
511 // ======================================================
512 // Main Function Called By Engine (registered commands)
513 // ======================================================
514 // Used to parse commands in the console that have been registered with the "registercommand" function
516 float CSQC_ConsoleCommand(string command)
518 float argc = tokenize_console(command);
520 if(ConsoleCommand_macro_normal(argc))
524 else if(ConsoleCommand_macro_movement(argc))
529 // Return value should be 1 if CSQC handled the command, otherwise return 0 to have the engine handle it.