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_handlevote(float request, float argc)
163 case CMD_REQUEST_COMMAND:
165 float vote_selection;
170 case "yes": vote_selection = 2; vote_string = "yes"; break;
171 case "no": vote_selection = 1; vote_string = "no"; break;
177 if(uid2name_dialog) // handled by "uid2name" option
182 localcmd(strcat("setreport cl_allow_uid2name ", ftos(vote_selection - 1), "\n"));
185 else { localcmd(strcat("cmd vote ", vote_string, "\n")); }
192 print("Incorrect parameters for ^2handlevote^7\n");
193 case CMD_REQUEST_USAGE:
195 print("\nUsage:^3 cl_cmd handlevote vote\n");
196 print(" Where 'vote' is the selection for either the current poll or uid2name.\n");
202 void GameCommand_hud(float request, float argc) // TODO: Add aliases in commands.cfg
206 case CMD_REQUEST_COMMAND:
212 cvar_set("_hud_configure", ftos(!autocvar__hud_configure));
220 HUD_Panel_ExportCfg(argv(2));
225 break; // go to usage, we're missing the paramater needed here.
232 hud_panel_radar_maximized = (stof(argv(2)) != 0);
234 hud_panel_radar_maximized = !hud_panel_radar_maximized;
239 case "scoreboard_columns_set":
241 Cmd_HUD_SetFields(argc); // todo update this function
246 case "scoreboard_columns_help":
248 Cmd_HUD_Help(argc); // todo update this function
257 print("Incorrect parameters for ^2hud^7\n");
258 case CMD_REQUEST_USAGE:
260 print("\nUsage:^3 cl_cmd hud action [configname | radartoggle]\n");
261 print(" Where 'action' is the command to complete,\n");
262 print(" 'configname' is the name to save to for \"save\" action,\n");
263 print(" and 'radartoggle' is to control hud_panel_radar_maximized for \"radar\" action.\n");
264 print(" Full list of commands here: \"configure, save, radar.\"\n");
270 void GameCommand_mv_download(float request, float argc)
274 case CMD_REQUEST_COMMAND:
276 Cmd_MapVote_MapDownload(argc);
282 case CMD_REQUEST_USAGE:
284 print("\nUsage:^3 cl_cmd mapvote_download mapid\n");
285 print(" Where 'mapid' is the id number of the map to request an image of on the map vote selection menu.\n");
291 void GameCommand_sendcvar(float request, float argc)
295 case CMD_REQUEST_COMMAND:
297 // W_FixWeaponOrder will trash argv, so save what we need.
298 string thiscvar = strzone(argv(1));
299 string s = cvar_string(thiscvar);
301 if(thiscvar == "cl_weaponpriority")
302 s = W_FixWeaponOrder(W_NumberWeaponOrder(s), 1);
303 else if(substring(thiscvar, 0, 17) == "cl_weaponpriority" && strlen(thiscvar) == 18)
304 s = W_FixWeaponOrder(W_NumberWeaponOrder(s), 0);
306 localcmd("cmd sentcvar ", thiscvar, " \"", s, "\"\n");
313 case CMD_REQUEST_USAGE:
315 print("\nUsage:^3 cl_cmd sendcvar <cvar>\n");
316 print(" Where 'cvar' is the cvar plus arguments to send to the server.\n");
322 void GameCommand_settemp(float request, float argc)
326 case CMD_REQUEST_COMMAND:
328 if((argv(1) == "restore") && (argc == 3))
330 float i = cvar_clientsettemp_restore();
333 dprint("Restored ", ftos(i), " temporary cvar settings to their original values.\n");
335 dprint("Nothing to restore.\n");
339 if(cvar_clientsettemp(argv(1), argv(2)))
340 dprint("Creating new settemp tracker for ", argv(1), " and setting it to \"", argv(2), "\" temporarily.\n");
342 dprint("Already had a tracker for ", argv(1), ", updating it to \"", argv(2), "\".\n");
349 case CMD_REQUEST_USAGE:
351 print("\nUsage:^3 cl_cmd settemp <cvar> | [restore]\n");
352 print(" Where 'cvar' is the cvar plus arguments to send to the server,\n");
353 print(" or 'restore' allows you to restore all of the original temporary cvar values.\n");
359 /* use this when creating a new command, making sure to place it in alphabetical order.
360 void GameCommand_(float request)
364 case CMD_REQUEST_COMMAND:
371 case CMD_REQUEST_USAGE:
373 print("\nUsage:^3 cl_cmd \n");
374 print(" No arguments required.\n");
382 // ==================================
383 // Macro system for client commands
384 // ==================================
386 // Do not hard code aliases for these, instead create them in commands.cfg... also: keep in alphabetical order, please ;)
387 #define CLIENT_COMMANDS(request,arguments) \
388 CLIENT_COMMAND("blurtest", GameCommand_blurtest(request), "Feature for testing blur postprocessing") \
389 CLIENT_COMMAND("debugmodel", GameCommand_debugmodel(request, arguments), "Spawn a debug model manually") \
390 CLIENT_COMMAND("handlevote", GameCommand_handlevote(request, arguments), "System to handle selecting a vote or option") \
391 CLIENT_COMMAND("hud", GameCommand_hud(request, arguments), "Commands regarding/controlling the HUD system") \
392 CLIENT_COMMAND("mv_download", GameCommand_mv_download(request, arguments), "Retrieve mapshot picture from the server") \
393 CLIENT_COMMAND("sendcvar", GameCommand_sendcvar(request, arguments), "Send a cvar to the server (like weaponpriority)") \
394 CLIENT_COMMAND("settemp", GameCommand_settemp(request, arguments), "Temporarily set a value to a cvar which is restored by command or end of each match") \
397 void GameCommand_macro_help()
399 #define CLIENT_COMMAND(name,function,description) \
400 { print(" ^2", name, "^7: ", description, "\n"); }
402 CLIENT_COMMANDS(0, 0)
403 #undef CLIENT_COMMAND
408 float GameCommand_macro_command(float argc)
410 #define CLIENT_COMMAND(name,function,description) \
411 { if(name == strtolower(argv(0))) { function; return TRUE; } }
413 CLIENT_COMMANDS(CMD_REQUEST_COMMAND, argc)
414 #undef CLIENT_COMMAND
419 float GameCommand_macro_usage(float argc)
421 #define CLIENT_COMMAND(name,function,description) \
422 { if(name == strtolower(argv(1))) { function; return TRUE; } }
424 CLIENT_COMMANDS(CMD_REQUEST_USAGE, argc)
425 #undef CLIENT_COMMAND
431 // =========================================
432 // Main Function Called By Engine (cl_cmd)
433 // =========================================
434 // If this function exists, client code handles gamecommand instead of the engine code.
436 void GameCommand(string command)
438 float argc = tokenize_console(command);
440 if(strtolower(argv(0)) == "help")
444 print("\nUsage:^3 cl_cmd COMMAND...^7, where possible commands are:\n");
445 GameCommand_macro_help();
446 GameCommand_Generic("help");
447 print("For help about specific commands, type cl_cmd help COMMAND\n");
450 else if(GameCommand_macro_usage(argc)) // Instead of trying to call a command, we're going to see detailed information about it
455 else if(GameCommand_Generic(command))
457 return; // handled by common/gamecommand.qc
459 else if(GameCommand_macro_command(argc)) // continue as usual and scan for normal commands
461 return; // handled by one of the above GameCommand_* functions
464 // nothing above caught the command, must be invalid
465 print("Unknown client command", ((command != "") ? strcat(" \"", command, "\"") : ""), ". For a list of supported commands, try cl_cmd help.\n");
471 // ===================================
472 // Macro system for console commands
473 // ===================================
475 // These functions are here specifically to add special + - commands to the game, and are not really normal commands.
476 // Please add client commands to the function above this, as this is only for special reasons.
477 #define CONSOLE_COMMANDS_NORMAL \
478 CONSOLE_COMMAND("+showscores", { scoreboard_showscores = TRUE; }) \
479 CONSOLE_COMMAND("-showscores", { scoreboard_showscores = FALSE; }) \
480 CONSOLE_COMMAND("+showaccuracy", { scoreboard_showaccuracy = TRUE; }) \
481 CONSOLE_COMMAND("-showaccuracy", { scoreboard_showaccuracy = FALSE; }) \
484 #define CONSOLE_COMMANDS_MOVEMENT \
485 CONSOLE_COMMAND("+forward", { ++camera_direction_x; }) \
486 CONSOLE_COMMAND("-forward", { --camera_direction_x; }) \
487 CONSOLE_COMMAND("+back", { --camera_direction_x; }) \
488 CONSOLE_COMMAND("-back", { ++camera_direction_x; }) \
489 CONSOLE_COMMAND("+moveup", { ++camera_direction_z; }) \
490 CONSOLE_COMMAND("-moveup", { --camera_direction_z; }) \
491 CONSOLE_COMMAND("+movedown", { --camera_direction_z; }) \
492 CONSOLE_COMMAND("-movedown", { ++camera_direction_z; }) \
493 CONSOLE_COMMAND("+moveright", { --camera_direction_y; }) \
494 CONSOLE_COMMAND("-moveright", { ++camera_direction_y; }) \
495 CONSOLE_COMMAND("+moveleft", { ++camera_direction_y; }) \
496 CONSOLE_COMMAND("-moveleft", { --camera_direction_y; }) \
497 CONSOLE_COMMAND("+roll_right", { ++camera_roll; }) \
498 CONSOLE_COMMAND("-roll_right", { --camera_roll; }) \
499 CONSOLE_COMMAND("+roll_left", { --camera_roll; }) \
500 CONSOLE_COMMAND("-roll_left", { ++camera_roll; }) \
503 void ConsoleCommand_macro_init()
505 // first init normal commands
506 #define CONSOLE_COMMAND(name,execution) \
507 { registercommand(name); }
509 CONSOLE_COMMANDS_NORMAL
510 #undef CONSOLE_COMMAND
512 // then init movement commands
517 #define CONSOLE_COMMAND(name,execution) \
518 { registercommand(name); }
520 CONSOLE_COMMANDS_MOVEMENT
521 #undef CONSOLE_COMMAND
529 float ConsoleCommand_macro_normal(float argc)
531 #define CONSOLE_COMMAND(name,execution) \
532 { if(name == strtolower(argv(0))) { { execution } return TRUE; } }
534 CONSOLE_COMMANDS_NORMAL
535 #undef CONSOLE_COMMAND
540 float ConsoleCommand_macro_movement(float argc)
544 #define CONSOLE_COMMAND(name,execution) \
545 { if(name == strtolower(argv(0))) { { execution } return TRUE; } }
547 CONSOLE_COMMANDS_MOVEMENT
548 #undef CONSOLE_COMMAND
555 // ======================================================
556 // Main Function Called By Engine (registered commands)
557 // ======================================================
558 // Used to parse commands in the console that have been registered with the "registercommand" function
560 float CSQC_ConsoleCommand(string command)
562 float argc = tokenize_console(command);
564 if(ConsoleCommand_macro_normal(argc))
568 else if(ConsoleCommand_macro_movement(argc))
573 // Return value should be 1 if CSQC handled the command, otherwise return 0 to have the engine handle it.