1 // ==============================================
2 // CSQC client commands code, written by Samual
3 // Last updated: December 27th, 2011
4 // ==============================================
7 float cvar_clientsettemp(string tmp_cvar, string value)
9 float created_saved_value;
12 if not(tmp_cvar || value)
14 dprint("Error: Invalid usage of cvar_clientsettemp(string, string); !\n");
18 for(e = world; (e = find(e, classname, "saved_cvar_value")); )
19 if(e.netname == tmp_cvar)
20 goto saved; // skip creation
22 // creating a new entity to keep track of this cvar
24 e.classname = "saved_cvar_value";
25 e.netname = strzone(tmp_cvar);
26 e.message = strzone(cvar_string(tmp_cvar));
27 created_saved_value = TRUE;
29 // an entity for this cvar already exists
32 // update the cvar to the value given
33 cvar_set(tmp_cvar, value);
35 return created_saved_value;
38 float cvar_clientsettemp_restore()
43 for(e = world; (e = find(e, classname, "saved_cvar_value")); )
44 { cvar_set(e.netname, e.message); ++i; }
51 if(time - floor(time) > 0.5)
59 self.drawmask = MASK_NORMAL;
64 // =======================
65 // Command Sub-Functions
66 // =======================
68 void LocalCommand_blurtest(float request)
70 // Simple command to work with postprocessing temporarily... possibly completely pointless, the glsl shader is used for a real feature now...
71 // Anyway, to enable it, just compile the client with -DBLURTEST and then you can use the command.
76 case CMD_REQUEST_COMMAND:
78 blurtest_time0 = time;
79 blurtest_time1 = time + stof(argv(1));
80 blurtest_radius = stof(argv(2));
81 blurtest_power = stof(argv(3));
82 print("Enabled blurtest\n");
87 case CMD_REQUEST_USAGE:
89 print("\nUsage:^3 cl_cmd blurtest\n");
90 print(" No arguments required.\n");
97 print("Blurtest is not enabled on this client.\n");
103 void LocalCommand_debugmodel(float request, float argc)
107 case CMD_REQUEST_COMMAND:
109 string modelname = argv(1);
110 entity debugmodel_entity;
112 debugmodel_entity = spawn();
113 precache_model(modelname);
114 setmodel(debugmodel_entity, modelname);
115 setorigin(debugmodel_entity, view_origin);
116 debugmodel_entity.angles = view_angles;
117 debugmodel_entity.draw = DrawDebugModel;
118 debugmodel_entity.classname = "debugmodel";
124 case CMD_REQUEST_USAGE:
126 print("\nUsage:^3 cl_cmd debugmodel model\n");
127 print(" Where 'model' is a string of the model name to use for the debug model.\n");
133 void LocalCommand_handlevote(float request, float argc)
137 case CMD_REQUEST_COMMAND:
139 float vote_selection;
142 if(InterpretBoolean(argv(1)))
155 if(uid2name_dialog) // handled by "uid2name" option
160 localcmd(strcat("setreport cl_allow_uid2name ", ftos(vote_selection - 1), "\n"));
163 else { localcmd(strcat("cmd vote ", vote_string, "\n")); }
170 print("Incorrect parameters for ^2handlevote^7\n");
171 case CMD_REQUEST_USAGE:
173 print("\nUsage:^3 cl_cmd handlevote vote\n");
174 print(" Where 'vote' is the selection for either the current poll or uid2name.\n");
180 void LocalCommand_hud(float request, float argc)
184 case CMD_REQUEST_COMMAND:
190 cvar_set("_hud_configure", ftos(!autocvar__hud_configure));
198 HUD_Panel_ExportCfg(argv(2));
203 break; // go to usage, we're missing the paramater needed here.
207 case "scoreboard_columns_set":
209 Cmd_HUD_SetFields(argc);
213 case "scoreboard_columns_help":
221 hud_panel_radar_maximized = (argv(2) ? InterpretBoolean(argv(2)) : !hud_panel_radar_maximized);
228 print("Incorrect parameters for ^2hud^7\n");
229 case CMD_REQUEST_USAGE:
231 print("\nUsage:^3 cl_cmd hud action [configname | radartoggle | layout]\n");
232 print(" Where 'action' is the command to complete,\n");
233 print(" 'configname' is the name to save to for \"save\" action,\n");
234 print(" 'radartoggle' is to control hud_panel_radar_maximized for \"radar\" action,\n");
235 print(" and 'layout' is how to organize the scoreboard columns for the set action.\n");
236 print(" Full list of commands here: \"configure, save, scoreboard_columns_help, scoreboard_columns_set, radar.\"\n");
242 void LocalCommand_localprint(float request, float argc)
246 case CMD_REQUEST_COMMAND:
250 centerprint_hud(argv(1));
256 print("Incorrect parameters for ^2localprint^7\n");
257 case CMD_REQUEST_USAGE:
259 print("\nUsage:^3 cl_cmd localprint \"message\"\n");
260 print(" 'message' is the centerprint message to send to yourself.\n");
266 void LocalCommand_mv_download(float request, float argc)
270 case CMD_REQUEST_COMMAND:
272 Cmd_MapVote_MapDownload(argc);
277 case CMD_REQUEST_USAGE:
279 print("\nUsage:^3 cl_cmd mv_download mapid\n");
280 print(" Where 'mapid' is the id number of the map to request an image of on the map vote selection menu.\n");
286 void LocalCommand_sendcvar(float request, float argc)
290 case CMD_REQUEST_COMMAND:
292 // W_FixWeaponOrder will trash argv, so save what we need.
293 string thiscvar = strzone(argv(1));
294 string s = cvar_string(thiscvar);
296 if(thiscvar == "cl_weaponpriority")
297 s = W_FixWeaponOrder(W_NumberWeaponOrder(s), 1);
298 else if(substring(thiscvar, 0, 17) == "cl_weaponpriority" && strlen(thiscvar) == 18)
299 s = W_FixWeaponOrder(W_NumberWeaponOrder(s), 0);
301 localcmd("cmd sentcvar ", thiscvar, " \"", s, "\"\n");
307 case CMD_REQUEST_USAGE:
309 print("\nUsage:^3 cl_cmd sendcvar <cvar>\n");
310 print(" Where 'cvar' is the cvar plus arguments to send to the server.\n");
316 void LocalCommand_settemp(float request, float argc)
320 case CMD_REQUEST_COMMAND:
324 if(cvar_settemp(argv(1), argv(2)))
325 dprint("Creating new settemp tracker for ", argv(1), " and setting it to \"", argv(2), "\" temporarily.\n");
327 dprint("Already had a tracker for ", argv(1), ", updating it to \"", argv(2), "\".\n");
334 print("Incorrect parameters for ^2settemp^7\n");
335 case CMD_REQUEST_USAGE:
337 print("\nUsage:^3 cl_cmd settemp \"cvar\" \"arguments\"\n");
338 print(" Where 'cvar' is the cvar you want to temporarily set with 'arguments'.\n");
344 void LocalCommand_settemp_restore(float request, float argc)
348 case CMD_REQUEST_COMMAND:
350 float i = cvar_settemp_restore();
353 dprint("Restored ", ftos(i), " temporary cvar settings to their original values.\n");
355 dprint("Nothing to restore.\n");
361 case CMD_REQUEST_USAGE:
363 print("\nUsage:^3 cl_cmd settemp_restore\n");
364 print(" No arguments required.\n");
370 /* use this when creating a new command, making sure to place it in alphabetical order... also,
371 ** ADD ALL NEW COMMANDS TO commands.cfg WITH PROPER ALIASES IN THE SAME FASHION!
372 void LocalCommand_(float request)
376 case CMD_REQUEST_COMMAND:
383 case CMD_REQUEST_USAGE:
385 print("\nUsage:^3 cl_cmd \n");
386 print(" No arguments required.\n");
394 // ==================================
395 // Macro system for client commands
396 // ==================================
398 // Do not hard code aliases for these, instead create them in commands.cfg... also: keep in alphabetical order, please ;)
399 #define CLIENT_COMMANDS(request,arguments) \
400 CLIENT_COMMAND("blurtest", LocalCommand_blurtest(request), "Feature for testing blur postprocessing") \
401 CLIENT_COMMAND("debugmodel", LocalCommand_debugmodel(request, arguments), "Spawn a debug model manually") \
402 CLIENT_COMMAND("handlevote", LocalCommand_handlevote(request, arguments), "System to handle selecting a vote or option") \
403 CLIENT_COMMAND("hud", LocalCommand_hud(request, arguments), "Commands regarding/controlling the HUD system") \
404 CLIENT_COMMAND("localprint", LocalCommand_localprint(request, arguments), "Create your own centerprint sent to yourself") \
405 CLIENT_COMMAND("mv_download", LocalCommand_mv_download(request, arguments), "Retrieve mapshot picture from the server") \
406 CLIENT_COMMAND("sendcvar", LocalCommand_sendcvar(request, arguments), "Send a cvar to the server (like weaponpriority)") \
407 CLIENT_COMMAND("settemp", LocalCommand_settemp(request, arguments), "Temporarily set a value to a cvar which is restored later") \
408 CLIENT_COMMAND("settemp_restore", LocalCommand_settemp_restore(request, arguments), "Restore all cvars set by settemp command") \
411 void LocalCommand_macro_help()
413 #define CLIENT_COMMAND(name,function,description) \
414 { print(" ^2", name, "^7: ", description, "\n"); }
416 CLIENT_COMMANDS(0, 0)
417 #undef CLIENT_COMMAND
422 float LocalCommand_macro_command(float argc)
424 #define CLIENT_COMMAND(name,function,description) \
425 { if(name == strtolower(argv(0))) { function; return TRUE; } }
427 CLIENT_COMMANDS(CMD_REQUEST_COMMAND, argc)
428 #undef CLIENT_COMMAND
433 float LocalCommand_macro_usage(float argc)
435 #define CLIENT_COMMAND(name,function,description) \
436 { if(name == strtolower(argv(1))) { function; return TRUE; } }
438 CLIENT_COMMANDS(CMD_REQUEST_USAGE, argc)
439 #undef CLIENT_COMMAND
445 // =========================================
446 // Main Function Called By Engine (cl_cmd)
447 // =========================================
448 // If this function exists, client code handles gamecommand instead of the engine code.
450 void GameCommand(string command)
452 float argc = tokenize_console(command);
454 // Guide for working with argc arguments by example:
455 // argc: 1 - 2 - 3 - 4
456 // argv: 0 - 1 - 2 - 3
457 // cmd vote - master - login - password
459 if(strtolower(argv(0)) == "help")
463 print("\nUsage:^3 cl_cmd COMMAND...^7, where possible commands are:\n");
464 LocalCommand_macro_help();
465 GameCommand_Generic("help");
466 print("For help about specific commands, type cl_cmd help COMMAND\n");
469 else if(LocalCommand_macro_usage(argc)) // Instead of trying to call a command, we're going to see detailed information about it
474 else if(GameCommand_Generic(command))
476 return; // handled by common/command/generic.qc
478 else if(LocalCommand_macro_command(argc)) // continue as usual and scan for normal commands
480 return; // handled by one of the above LocalCommand_* functions
483 // nothing above caught the command, must be invalid
484 print(((command != "") ? strcat("Unknown client command \"", command, "\"") : "No command provided"), ". For a list of supported commands, try cl_cmd help.\n");
490 // ===================================
491 // Macro system for console commands
492 // ===================================
494 // These functions are here specifically to add special + - commands to the game, and are not really normal commands.
495 // Please add client commands to the function above this, as this is only for special reasons.
496 #define CONSOLE_COMMANDS_NORMAL \
497 CONSOLE_COMMAND("+showscores", { scoreboard_showscores = TRUE; }) \
498 CONSOLE_COMMAND("-showscores", { scoreboard_showscores = FALSE; }) \
499 CONSOLE_COMMAND("+showaccuracy", { scoreboard_showaccuracy = TRUE; }) \
500 CONSOLE_COMMAND("-showaccuracy", { scoreboard_showaccuracy = FALSE; }) \
503 #define CONSOLE_COMMANDS_MOVEMENT \
504 CONSOLE_COMMAND("+forward", { ++camera_direction_x; }) \
505 CONSOLE_COMMAND("-forward", { --camera_direction_x; }) \
506 CONSOLE_COMMAND("+back", { --camera_direction_x; }) \
507 CONSOLE_COMMAND("-back", { ++camera_direction_x; }) \
508 CONSOLE_COMMAND("+moveup", { ++camera_direction_z; }) \
509 CONSOLE_COMMAND("-moveup", { --camera_direction_z; }) \
510 CONSOLE_COMMAND("+movedown", { --camera_direction_z; }) \
511 CONSOLE_COMMAND("-movedown", { ++camera_direction_z; }) \
512 CONSOLE_COMMAND("+moveright", { --camera_direction_y; }) \
513 CONSOLE_COMMAND("-moveright", { ++camera_direction_y; }) \
514 CONSOLE_COMMAND("+moveleft", { ++camera_direction_y; }) \
515 CONSOLE_COMMAND("-moveleft", { --camera_direction_y; }) \
516 CONSOLE_COMMAND("+roll_right", { ++camera_roll; }) \
517 CONSOLE_COMMAND("-roll_right", { --camera_roll; }) \
518 CONSOLE_COMMAND("+roll_left", { --camera_roll; }) \
519 CONSOLE_COMMAND("-roll_left", { ++camera_roll; }) \
522 void ConsoleCommand_macro_init()
524 // first init normal commands
525 #define CONSOLE_COMMAND(name,execution) \
526 { registercommand(name); }
528 CONSOLE_COMMANDS_NORMAL
529 #undef CONSOLE_COMMAND
531 // then init movement commands
536 #define CONSOLE_COMMAND(name,execution) \
537 { registercommand(name); }
539 CONSOLE_COMMANDS_MOVEMENT
540 #undef CONSOLE_COMMAND
548 float ConsoleCommand_macro_normal(float argc)
550 #define CONSOLE_COMMAND(name,execution) \
551 { if(name == strtolower(argv(0))) { { execution } return TRUE; } }
553 CONSOLE_COMMANDS_NORMAL
554 #undef CONSOLE_COMMAND
559 float ConsoleCommand_macro_movement(float argc)
563 #define CONSOLE_COMMAND(name,execution) \
564 { if(name == strtolower(argv(0))) { { execution } return TRUE; } }
566 CONSOLE_COMMANDS_MOVEMENT
567 #undef CONSOLE_COMMAND
574 // ======================================================
575 // Main Function Called By Engine (registered commands)
576 // ======================================================
577 // Used to parse commands in the console that have been registered with the "registercommand" function
579 float CSQC_ConsoleCommand(string command)
581 float argc = tokenize_console(command);
583 if(ConsoleCommand_macro_normal(argc))
587 else if(ConsoleCommand_macro_movement(argc))
592 // Return value should be 1 if CSQC handled the command, otherwise return 0 to have the engine handle it.