1 // ==============================================
2 // CSQC client commands code, written by Samual
3 // Last updated: December 16th, 2011
4 // ==============================================
6 float cvar_clientsettemp(string tmp_cvar, string value)
8 float created_saved_value;
11 if not(tmp_cvar || value)
13 dprint("Error: Invalid usage of cvar_clientsettemp(string, string); !\n");
17 for(e = world; (e = find(e, classname, "saved_cvar_value")); )
18 if(e.netname == tmp_cvar)
19 goto saved; // skip creation
21 // creating a new entity to keep track of this cvar
23 e.classname = "saved_cvar_value";
24 e.netname = strzone(tmp_cvar);
25 e.message = strzone(cvar_string(tmp_cvar));
26 created_saved_value = TRUE;
28 // an entity for this cvar already exists
31 // update the cvar to the value given
32 cvar_set(tmp_cvar, value);
34 return created_saved_value;
37 float cvar_clientsettemp_restore()
42 for(e = world; (e = find(e, classname, "saved_cvar_value")); )
43 { cvar_set(e.netname, e.message); ++i; }
50 if(time - floor(time) > 0.5)
58 self.drawmask = MASK_NORMAL;
63 // =======================
64 // Command Sub-Functions
65 // =======================
67 void LocalCommand_blurtest(float request)
69 // Simple command to work with postprocessing temporarily... possibly completely pointless, the glsl shader is used for a real feature now...
70 // Anyway, to enable it, just compile the client with -DBLURTEST and then you can use the command.
75 case CMD_REQUEST_COMMAND:
77 blurtest_time0 = time;
78 blurtest_time1 = time + stof(argv(1));
79 blurtest_radius = stof(argv(2));
80 blurtest_power = stof(argv(3));
81 print("Enabled blurtest\n");
86 case CMD_REQUEST_USAGE:
88 print("\nUsage:^3 cl_cmd blurtest\n");
89 print(" No arguments required.\n");
96 print("Blurtest is not enabled on this client.\n");
102 void LocalCommand_debugmodel(float request, float argc)
106 case CMD_REQUEST_COMMAND:
108 string modelname = argv(1);
109 entity debugmodel_entity;
111 debugmodel_entity = spawn();
112 precache_model(modelname);
113 setmodel(debugmodel_entity, modelname);
114 setorigin(debugmodel_entity, view_origin);
115 debugmodel_entity.angles = view_angles;
116 debugmodel_entity.draw = DrawDebugModel;
117 debugmodel_entity.classname = "debugmodel";
123 case CMD_REQUEST_USAGE:
125 print("\nUsage:^3 cl_cmd debugmodel model\n");
126 print(" Where 'model' is a string of the model name to use for the debug model.\n");
132 void LocalCommand_handlevote(float request, float argc)
136 case CMD_REQUEST_COMMAND:
138 float vote_selection;
141 if(InterpretBoolean(argv(1)))
154 if(uid2name_dialog) // handled by "uid2name" option
159 localcmd(strcat("setreport cl_allow_uid2name ", ftos(vote_selection - 1), "\n"));
162 else { localcmd(strcat("cmd vote ", vote_string, "\n")); }
169 print("Incorrect parameters for ^2handlevote^7\n");
170 case CMD_REQUEST_USAGE:
172 print("\nUsage:^3 cl_cmd handlevote vote\n");
173 print(" Where 'vote' is the selection for either the current poll or uid2name.\n");
179 void LocalCommand_hud(float request, float argc)
183 case CMD_REQUEST_COMMAND:
189 cvar_set("_hud_configure", ftos(!autocvar__hud_configure));
197 HUD_Panel_ExportCfg(argv(2));
202 break; // go to usage, we're missing the paramater needed here.
206 case "scoreboard_columns_set":
208 Cmd_HUD_SetFields(argc);
212 case "scoreboard_columns_help":
220 hud_panel_radar_maximized = (argv(2) ? InterpretBoolean(argv(2)) : !hud_panel_radar_maximized);
227 print("Incorrect parameters for ^2hud^7\n");
228 case CMD_REQUEST_USAGE:
230 print("\nUsage:^3 cl_cmd hud action [configname | radartoggle | layout]\n");
231 print(" Where 'action' is the command to complete,\n");
232 print(" 'configname' is the name to save to for \"save\" action,\n");
233 print(" 'radartoggle' is to control hud_panel_radar_maximized for \"radar\" action,\n");
234 print(" and 'layout' is how to organize the scoreboard columns for the set action.\n");
235 print(" Full list of commands here: \"configure, save, scoreboard_columns_help, scoreboard_columns_set, radar.\"\n");
241 void LocalCommand_localprint(float request, float argc)
245 case CMD_REQUEST_COMMAND:
249 centerprint_hud(argv(1));
255 print("Incorrect parameters for ^2localprint^7\n");
256 case CMD_REQUEST_USAGE:
258 print("\nUsage:^3 cl_cmd localprint \"message\"\n");
259 print(" 'message' is the centerprint message to send to yourself.\n");
265 void LocalCommand_mv_download(float request, float argc)
269 case CMD_REQUEST_COMMAND:
271 Cmd_MapVote_MapDownload(argc);
276 case CMD_REQUEST_USAGE:
278 print("\nUsage:^3 cl_cmd mv_download mapid\n");
279 print(" Where 'mapid' is the id number of the map to request an image of on the map vote selection menu.\n");
285 void LocalCommand_sendcvar(float request, float argc)
289 case CMD_REQUEST_COMMAND:
291 // W_FixWeaponOrder will trash argv, so save what we need.
292 string thiscvar = strzone(argv(1));
293 string s = cvar_string(thiscvar);
295 if(thiscvar == "cl_weaponpriority")
296 s = W_FixWeaponOrder(W_NumberWeaponOrder(s), 1);
297 else if(substring(thiscvar, 0, 17) == "cl_weaponpriority" && strlen(thiscvar) == 18)
298 s = W_FixWeaponOrder(W_NumberWeaponOrder(s), 0);
300 localcmd("cmd sentcvar ", thiscvar, " \"", s, "\"\n");
306 case CMD_REQUEST_USAGE:
308 print("\nUsage:^3 cl_cmd sendcvar <cvar>\n");
309 print(" Where 'cvar' is the cvar plus arguments to send to the server.\n");
315 void LocalCommand_settemp(float request, float argc)
319 case CMD_REQUEST_COMMAND:
321 if((argv(1) == "restore") && argv(2))
323 float i = cvar_clientsettemp_restore();
326 dprint("Restored ", ftos(i), " temporary cvar settings to their original values.\n");
328 dprint("Nothing to restore.\n");
334 if(cvar_clientsettemp(argv(1), argv(2)))
335 dprint("Creating new settemp tracker for ", argv(1), " and setting it to \"", argv(2), "\" temporarily.\n");
337 dprint("Already had a tracker for ", argv(1), ", updating it to \"", argv(2), "\".\n");
344 print("Incorrect parameters for ^2settemp^7\n");
345 case CMD_REQUEST_USAGE:
347 print("\nUsage:^3 cl_cmd settemp \"cvar\" | [restore]\n");
348 print(" Where 'cvar' is the cvar plus arguments to send to the server,\n");
349 print(" or 'restore' allows you to restore all of the original temporary cvar values.\n");
355 /* use this when creating a new command, making sure to place it in alphabetical order.
356 void LocalCommand_(float request)
360 case CMD_REQUEST_COMMAND:
367 case CMD_REQUEST_USAGE:
369 print("\nUsage:^3 cl_cmd \n");
370 print(" No arguments required.\n");
378 // ==================================
379 // Macro system for client commands
380 // ==================================
382 // Do not hard code aliases for these, instead create them in commands.cfg... also: keep in alphabetical order, please ;)
383 #define CLIENT_COMMANDS(request,arguments) \
384 CLIENT_COMMAND("blurtest", LocalCommand_blurtest(request), "Feature for testing blur postprocessing") \
385 CLIENT_COMMAND("debugmodel", LocalCommand_debugmodel(request, arguments), "Spawn a debug model manually") \
386 CLIENT_COMMAND("handlevote", LocalCommand_handlevote(request, arguments), "System to handle selecting a vote or option") \
387 CLIENT_COMMAND("hud", LocalCommand_hud(request, arguments), "Commands regarding/controlling the HUD system") \
388 CLIENT_COMMAND("localprint", LocalCommand_localprint(request, arguments), "Create your own centerprint sent to yourself") \
389 CLIENT_COMMAND("mv_download", LocalCommand_mv_download(request, arguments), "Retrieve mapshot picture from the server") \
390 CLIENT_COMMAND("sendcvar", LocalCommand_sendcvar(request, arguments), "Send a cvar to the server (like weaponpriority)") \
391 CLIENT_COMMAND("settemp", LocalCommand_settemp(request, arguments), "Temporarily set a value to a cvar which is restored by command or end of each match") \
394 void LocalCommand_macro_help()
396 #define CLIENT_COMMAND(name,function,description) \
397 { print(" ^2", name, "^7: ", description, "\n"); }
399 CLIENT_COMMANDS(0, 0)
400 #undef CLIENT_COMMAND
405 float LocalCommand_macro_command(float argc)
407 #define CLIENT_COMMAND(name,function,description) \
408 { if(name == strtolower(argv(0))) { function; return TRUE; } }
410 CLIENT_COMMANDS(CMD_REQUEST_COMMAND, argc)
411 #undef CLIENT_COMMAND
416 float LocalCommand_macro_usage(float argc)
418 #define CLIENT_COMMAND(name,function,description) \
419 { if(name == strtolower(argv(1))) { function; return TRUE; } }
421 CLIENT_COMMANDS(CMD_REQUEST_USAGE, argc)
422 #undef CLIENT_COMMAND
428 // =========================================
429 // Main Function Called By Engine (cl_cmd)
430 // =========================================
431 // If this function exists, client code handles gamecommand instead of the engine code.
433 void GameCommand(string command)
435 float argc = tokenize_console(command);
437 if(strtolower(argv(0)) == "help")
441 print("\nUsage:^3 cl_cmd COMMAND...^7, where possible commands are:\n");
442 LocalCommand_macro_help();
443 GameCommand_Generic("help");
444 print("For help about specific commands, type cl_cmd help COMMAND\n");
447 else if(LocalCommand_macro_usage(argc)) // Instead of trying to call a command, we're going to see detailed information about it
452 else if(GameCommand_Generic(command))
454 return; // handled by common/command/generic.qc
456 else if(LocalCommand_macro_command(argc)) // continue as usual and scan for normal commands
458 return; // handled by one of the above LocalCommand_* functions
461 // nothing above caught the command, must be invalid
462 print(((command != "") ? strcat("Unknown client command \"", command, "\"") : "No command provided"), ". For a list of supported commands, try cl_cmd help.\n");
468 // ===================================
469 // Macro system for console commands
470 // ===================================
472 // These functions are here specifically to add special + - commands to the game, and are not really normal commands.
473 // Please add client commands to the function above this, as this is only for special reasons.
474 #define CONSOLE_COMMANDS_NORMAL \
475 CONSOLE_COMMAND("+showscores", { scoreboard_showscores = TRUE; }) \
476 CONSOLE_COMMAND("-showscores", { scoreboard_showscores = FALSE; }) \
477 CONSOLE_COMMAND("+showaccuracy", { scoreboard_showaccuracy = TRUE; }) \
478 CONSOLE_COMMAND("-showaccuracy", { scoreboard_showaccuracy = FALSE; }) \
481 #define CONSOLE_COMMANDS_MOVEMENT \
482 CONSOLE_COMMAND("+forward", { ++camera_direction_x; }) \
483 CONSOLE_COMMAND("-forward", { --camera_direction_x; }) \
484 CONSOLE_COMMAND("+back", { --camera_direction_x; }) \
485 CONSOLE_COMMAND("-back", { ++camera_direction_x; }) \
486 CONSOLE_COMMAND("+moveup", { ++camera_direction_z; }) \
487 CONSOLE_COMMAND("-moveup", { --camera_direction_z; }) \
488 CONSOLE_COMMAND("+movedown", { --camera_direction_z; }) \
489 CONSOLE_COMMAND("-movedown", { ++camera_direction_z; }) \
490 CONSOLE_COMMAND("+moveright", { --camera_direction_y; }) \
491 CONSOLE_COMMAND("-moveright", { ++camera_direction_y; }) \
492 CONSOLE_COMMAND("+moveleft", { ++camera_direction_y; }) \
493 CONSOLE_COMMAND("-moveleft", { --camera_direction_y; }) \
494 CONSOLE_COMMAND("+roll_right", { ++camera_roll; }) \
495 CONSOLE_COMMAND("-roll_right", { --camera_roll; }) \
496 CONSOLE_COMMAND("+roll_left", { --camera_roll; }) \
497 CONSOLE_COMMAND("-roll_left", { ++camera_roll; }) \
500 void ConsoleCommand_macro_init()
502 // first init normal commands
503 #define CONSOLE_COMMAND(name,execution) \
504 { registercommand(name); }
506 CONSOLE_COMMANDS_NORMAL
507 #undef CONSOLE_COMMAND
509 // then init movement commands
514 #define CONSOLE_COMMAND(name,execution) \
515 { registercommand(name); }
517 CONSOLE_COMMANDS_MOVEMENT
518 #undef CONSOLE_COMMAND
526 float ConsoleCommand_macro_normal(float argc)
528 #define CONSOLE_COMMAND(name,execution) \
529 { if(name == strtolower(argv(0))) { { execution } return TRUE; } }
531 CONSOLE_COMMANDS_NORMAL
532 #undef CONSOLE_COMMAND
537 float ConsoleCommand_macro_movement(float argc)
541 #define CONSOLE_COMMAND(name,execution) \
542 { if(name == strtolower(argv(0))) { { execution } return TRUE; } }
544 CONSOLE_COMMANDS_MOVEMENT
545 #undef CONSOLE_COMMAND
552 // ======================================================
553 // Main Function Called By Engine (registered commands)
554 // ======================================================
555 // Used to parse commands in the console that have been registered with the "registercommand" function
557 float CSQC_ConsoleCommand(string command)
559 float argc = tokenize_console(command);
561 if(ConsoleCommand_macro_normal(argc))
565 else if(ConsoleCommand_macro_movement(argc))
570 // Return value should be 1 if CSQC handled the command, otherwise return 0 to have the engine handle it.