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)
10 for(e = world; (e = find(e, classname, "saved_cvar_value")); )
11 if(e.netname == tmp_cvar)
14 // creating a new entity to keep track of this cvar
16 e.classname = "saved_cvar_value";
17 e.netname = strzone(tmp_cvar);
18 e.message = strzone(cvar_string(tmp_cvar));
21 // an entity for this cvar already exists, update the value
23 cvar_set(tmp_cvar, value);
27 float cvar_clientsettemp_restore()
32 for(e = world; (e = find(e, classname, "saved_cvar_value")); )
33 { cvar_set(e.netname, e.message); ++i; }
40 if(time - floor(time) > 0.5)
48 self.drawmask = MASK_NORMAL;
53 // =======================
54 // Command Sub-Functions
55 // =======================
57 void GameCommand_blurtest(float request)
59 // Simple command to work with postprocessing temporarily... possibly completely pointless, the glsl shader is used for a real feature now...
60 // Anyway, to enable it, just compile the client with -DBLURTEST and then you can use the command.
65 case CMD_REQUEST_COMMAND:
67 blurtest_time0 = time;
68 blurtest_time1 = time + stof(argv(1));
69 blurtest_radius = stof(argv(2));
70 blurtest_power = stof(argv(3));
71 print("Enabled blurtest\n");
76 case CMD_REQUEST_USAGE:
78 print("\nUsage:^3 cl_cmd blurtest\n");
79 print(" No arguments required.\n");
86 print("Blurtest is not enabled on this client.\n");
92 void GameCommand_debugmodel(float request, float argc)
96 case CMD_REQUEST_COMMAND:
98 string modelname = argv(1);
99 entity debugmodel_entity;
101 debugmodel_entity = spawn();
102 precache_model(modelname);
103 setmodel(debugmodel_entity, modelname);
104 setorigin(debugmodel_entity, view_origin);
105 debugmodel_entity.angles = view_angles;
106 debugmodel_entity.draw = DrawDebugModel;
107 debugmodel_entity.classname = "debugmodel";
113 case CMD_REQUEST_USAGE:
115 print("\nUsage:^3 cl_cmd debugmodel model\n");
116 print(" Where 'model' is a string of the model name to use for the debug model.\n");
122 void GameCommand_handlevote(float request, float argc)
126 case CMD_REQUEST_COMMAND:
128 float vote_selection;
133 case "yes": vote_selection = 2; vote_string = "yes"; break;
134 case "no": vote_selection = 1; vote_string = "no"; break;
140 if(uid2name_dialog) // handled by "uid2name" option
145 localcmd(strcat("setreport cl_allow_uid2name ", ftos(vote_selection - 1), "\n"));
148 else { localcmd(strcat("cmd vote ", vote_string, "\n")); }
155 print("Incorrect parameters for ^2handlevote^7\n");
156 case CMD_REQUEST_USAGE:
158 print("\nUsage:^3 cl_cmd handlevote vote\n");
159 print(" Where 'vote' is the selection for either the current poll or uid2name.\n");
165 void GameCommand_hud(float request, float argc) // TODO: Add aliases in commands.cfg
169 case CMD_REQUEST_COMMAND:
175 cvar_set("_hud_configure", ftos(!autocvar__hud_configure));
183 HUD_Panel_ExportCfg(argv(2));
188 break; // go to usage, we're missing the paramater needed here.
195 hud_panel_radar_maximized = (stof(argv(2)) != 0);
197 hud_panel_radar_maximized = !hud_panel_radar_maximized;
202 case "scoreboard_columns_set":
204 Cmd_HUD_SetFields(argc); // todo update this function
209 case "scoreboard_columns_help":
211 Cmd_HUD_Help(argc); // todo update this function
220 print("Incorrect parameters for ^2hud^7\n");
221 case CMD_REQUEST_USAGE:
223 print("\nUsage:^3 cl_cmd hud action [configname | radartoggle]\n");
224 print(" Where 'action' is the command to complete,\n");
225 print(" 'configname' is the name to save to for \"save\" action,\n");
226 print(" and 'radartoggle' is to control hud_panel_radar_maximized for \"radar\" action.\n");
227 print(" Full list of commands here: \"configure, save, radar.\"\n");
233 void GameCommand_mv_download(float request, float argc)
237 case CMD_REQUEST_COMMAND:
239 Cmd_MapVote_MapDownload(argc);
245 case CMD_REQUEST_USAGE:
247 print("\nUsage:^3 cl_cmd mapvote_download mapid\n");
248 print(" Where 'mapid' is the id number of the map to request an image of on the map vote selection menu.\n");
254 void GameCommand_sendcvar(float request, float argc)
258 case CMD_REQUEST_COMMAND:
260 // W_FixWeaponOrder will trash argv, so save what we need.
261 string thiscvar = strzone(argv(1));
262 string s = cvar_string(thiscvar);
264 if(thiscvar == "cl_weaponpriority")
265 s = W_FixWeaponOrder(W_NumberWeaponOrder(s), 1);
266 else if(substring(thiscvar, 0, 17) == "cl_weaponpriority" && strlen(thiscvar) == 18)
267 s = W_FixWeaponOrder(W_NumberWeaponOrder(s), 0);
269 localcmd("cmd sentcvar ", thiscvar, " \"", s, "\"\n");
276 case CMD_REQUEST_USAGE:
278 print("\nUsage:^3 cl_cmd sendcvar <cvar>\n");
279 print(" Where 'cvar' is the cvar plus arguments to send to the server.\n");
285 void GameCommand_settemp(float request, float argc)
289 case CMD_REQUEST_COMMAND:
291 if((argv(1) == "restore") && (argc == 3))
293 float i = cvar_clientsettemp_restore();
296 dprint("Restored ", ftos(i), " temporary cvar settings to their original values.\n");
298 dprint("Nothing to restore.\n");
302 if(cvar_clientsettemp(argv(1), argv(2)))
303 dprint("Creating new settemp tracker for ", argv(1), " and setting it to \"", argv(2), "\" temporarily.\n");
305 dprint("Already had a tracker for ", argv(1), ", updating it to \"", argv(2), "\".\n");
312 case CMD_REQUEST_USAGE:
314 print("\nUsage:^3 cl_cmd settemp <cvar> | [restore]\n");
315 print(" Where 'cvar' is the cvar plus arguments to send to the server,\n");
316 print(" or 'restore' allows you to restore all of the original temporary cvar values.\n");
322 /* use this when creating a new command, making sure to place it in alphabetical order.
323 void GameCommand_(float request)
327 case CMD_REQUEST_COMMAND:
334 case CMD_REQUEST_USAGE:
336 print("\nUsage:^3 cl_cmd \n");
337 print(" No arguments required.\n");
345 // ==================================
346 // Macro system for client commands
347 // ==================================
349 // Do not hard code aliases for these, instead create them in commands.cfg... also: keep in alphabetical order, please ;)
350 #define CLIENT_COMMANDS(request,arguments) \
351 CLIENT_COMMAND("blurtest", GameCommand_blurtest(request), "Feature for testing blur postprocessing") \
352 CLIENT_COMMAND("debugmodel", GameCommand_debugmodel(request, arguments), "Spawn a debug model manually") \
353 CLIENT_COMMAND("handlevote", GameCommand_handlevote(request, arguments), "System to handle selecting a vote or option") \
354 CLIENT_COMMAND("hud", GameCommand_hud(request, arguments), "Commands regarding/controlling the HUD system") \
355 CLIENT_COMMAND("mv_download", GameCommand_mv_download(request, arguments), "Retrieve mapshot picture from the server") \
356 CLIENT_COMMAND("sendcvar", GameCommand_sendcvar(request, arguments), "Send a cvar to the server (like weaponpriority)") \
357 CLIENT_COMMAND("settemp", GameCommand_settemp(request, arguments), "Temporarily set a value to a cvar which is restored by command or end of each match") \
360 void GameCommand_macro_help()
362 #define CLIENT_COMMAND(name,function,description) \
363 { print(" ^2", name, "^7: ", description, "\n"); }
365 CLIENT_COMMANDS(0, 0)
366 #undef CLIENT_COMMAND
371 float GameCommand_macro_command(float argc)
373 #define CLIENT_COMMAND(name,function,description) \
374 { if(name == strtolower(argv(0))) { function; return TRUE; } }
376 CLIENT_COMMANDS(CMD_REQUEST_COMMAND, argc)
377 #undef CLIENT_COMMAND
382 float GameCommand_macro_usage(float argc)
384 #define CLIENT_COMMAND(name,function,description) \
385 { if(name == strtolower(argv(1))) { function; return TRUE; } }
387 CLIENT_COMMANDS(CMD_REQUEST_USAGE, argc)
388 #undef CLIENT_COMMAND
394 // =========================================
395 // Main Function Called By Engine (cl_cmd)
396 // =========================================
397 // If this function exists, client code handles gamecommand instead of the engine code.
399 void GameCommand(string command)
401 float argc = tokenize_console(command);
403 if(strtolower(argv(0)) == "help")
407 print("\nUsage:^3 cl_cmd COMMAND...^7, where possible commands are:\n");
408 GameCommand_macro_help();
409 GameCommand_Generic("help");
410 print("For help about specific commands, type cl_cmd help COMMAND\n");
413 else if(GameCommand_macro_usage(argc)) // Instead of trying to call a command, we're going to see detailed information about it
418 else if(GameCommand_Generic(command))
420 return; // handled by common/gamecommand.qc
422 else if(GameCommand_macro_command(argc)) // continue as usual and scan for normal commands
424 return; // handled by one of the above GameCommand_* functions
427 // nothing above caught the command, must be invalid
428 print("Unknown client command", ((command != "") ? strcat(" \"", command, "\"") : ""), ". For a list of supported commands, try cl_cmd help.\n");
434 // ===================================
435 // Macro system for console commands
436 // ===================================
438 // These functions are here specifically to add special + - commands to the game, and are not really normal commands.
439 // Please add client commands to the function above this, as this is only for special reasons.
440 #define CONSOLE_COMMANDS_NORMAL \
441 CONSOLE_COMMAND("+showscores", { scoreboard_showscores = TRUE; }) \
442 CONSOLE_COMMAND("-showscores", { scoreboard_showscores = FALSE; }) \
443 CONSOLE_COMMAND("+showaccuracy", { scoreboard_showaccuracy = TRUE; }) \
444 CONSOLE_COMMAND("-showaccuracy", { scoreboard_showaccuracy = FALSE; }) \
447 #define CONSOLE_COMMANDS_MOVEMENT \
448 CONSOLE_COMMAND("+forward", { ++camera_direction_x; }) \
449 CONSOLE_COMMAND("-forward", { --camera_direction_x; }) \
450 CONSOLE_COMMAND("+back", { --camera_direction_x; }) \
451 CONSOLE_COMMAND("-back", { ++camera_direction_x; }) \
452 CONSOLE_COMMAND("+moveup", { ++camera_direction_z; }) \
453 CONSOLE_COMMAND("-moveup", { --camera_direction_z; }) \
454 CONSOLE_COMMAND("+movedown", { --camera_direction_z; }) \
455 CONSOLE_COMMAND("-movedown", { ++camera_direction_z; }) \
456 CONSOLE_COMMAND("+moveright", { --camera_direction_y; }) \
457 CONSOLE_COMMAND("-moveright", { ++camera_direction_y; }) \
458 CONSOLE_COMMAND("+moveleft", { ++camera_direction_y; }) \
459 CONSOLE_COMMAND("-moveleft", { --camera_direction_y; }) \
460 CONSOLE_COMMAND("+roll_right", { ++camera_roll; }) \
461 CONSOLE_COMMAND("-roll_right", { --camera_roll; }) \
462 CONSOLE_COMMAND("+roll_left", { --camera_roll; }) \
463 CONSOLE_COMMAND("-roll_left", { ++camera_roll; }) \
466 void ConsoleCommand_macro_init()
468 // first init normal commands
469 #define CONSOLE_COMMAND(name,execution) \
470 { registercommand(name); }
472 CONSOLE_COMMANDS_NORMAL
473 #undef CONSOLE_COMMAND
475 // then init movement commands
480 #define CONSOLE_COMMAND(name,execution) \
481 { registercommand(name); }
483 CONSOLE_COMMANDS_MOVEMENT
484 #undef CONSOLE_COMMAND
492 float ConsoleCommand_macro_normal(float argc)
494 #define CONSOLE_COMMAND(name,execution) \
495 { if(name == strtolower(argv(0))) { { execution } return TRUE; } }
497 CONSOLE_COMMANDS_NORMAL
498 #undef CONSOLE_COMMAND
503 float ConsoleCommand_macro_movement(float argc)
507 #define CONSOLE_COMMAND(name,execution) \
508 { if(name == strtolower(argv(0))) { { execution } return TRUE; } }
510 CONSOLE_COMMANDS_MOVEMENT
511 #undef CONSOLE_COMMAND
518 // ======================================================
519 // Main Function Called By Engine (registered commands)
520 // ======================================================
521 // Used to parse commands in the console that have been registered with the "registercommand" function
523 float CSQC_ConsoleCommand(string command)
525 float argc = tokenize_console(command);
527 if(ConsoleCommand_macro_normal(argc))
531 else if(ConsoleCommand_macro_movement(argc))
536 // Return value should be 1 if CSQC handled the command, otherwise return 0 to have the engine handle it.