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 GameCommand_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 GameCommand_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 GameCommand_handlevote(float request, float argc)
136 case CMD_REQUEST_COMMAND:
138 float vote_selection;
143 case "yes": vote_selection = 2; vote_string = "yes"; break;
144 case "no": vote_selection = 1; vote_string = "no"; break;
150 if(uid2name_dialog) // handled by "uid2name" option
155 localcmd(strcat("setreport cl_allow_uid2name ", ftos(vote_selection - 1), "\n"));
158 else { localcmd(strcat("cmd vote ", vote_string, "\n")); }
165 print("Incorrect parameters for ^2handlevote^7\n");
166 case CMD_REQUEST_USAGE:
168 print("\nUsage:^3 cl_cmd handlevote vote\n");
169 print(" Where 'vote' is the selection for either the current poll or uid2name.\n");
175 void GameCommand_hud(float request, float argc) // TODO: Add aliases in commands.cfg
179 case CMD_REQUEST_COMMAND:
185 cvar_set("_hud_configure", ftos(!autocvar__hud_configure));
193 HUD_Panel_ExportCfg(argv(2));
198 break; // go to usage, we're missing the paramater needed here.
205 hud_panel_radar_maximized = (stof(argv(2)) != 0);
207 hud_panel_radar_maximized = !hud_panel_radar_maximized;
212 case "scoreboard_columns_set":
214 Cmd_HUD_SetFields(argc); // todo update this function
219 case "scoreboard_columns_help":
221 Cmd_HUD_Help(argc); // todo update this function
230 print("Incorrect parameters for ^2hud^7\n");
231 case CMD_REQUEST_USAGE:
233 print("\nUsage:^3 cl_cmd hud action [configname | radartoggle]\n");
234 print(" Where 'action' is the command to complete,\n");
235 print(" 'configname' is the name to save to for \"save\" action,\n");
236 print(" and 'radartoggle' is to control hud_panel_radar_maximized for \"radar\" action.\n");
237 print(" Full list of commands here: \"configure, save, radar.\"\n");
243 void GameCommand_mv_download(float request, float argc)
247 case CMD_REQUEST_COMMAND:
249 Cmd_MapVote_MapDownload(argc);
255 case CMD_REQUEST_USAGE:
257 print("\nUsage:^3 cl_cmd mapvote_download mapid\n");
258 print(" Where 'mapid' is the id number of the map to request an image of on the map vote selection menu.\n");
264 void GameCommand_sendcvar(float request, float argc)
268 case CMD_REQUEST_COMMAND:
270 // W_FixWeaponOrder will trash argv, so save what we need.
271 string thiscvar = strzone(argv(1));
272 string s = cvar_string(thiscvar);
274 if(thiscvar == "cl_weaponpriority")
275 s = W_FixWeaponOrder(W_NumberWeaponOrder(s), 1);
276 else if(substring(thiscvar, 0, 17) == "cl_weaponpriority" && strlen(thiscvar) == 18)
277 s = W_FixWeaponOrder(W_NumberWeaponOrder(s), 0);
279 localcmd("cmd sentcvar ", thiscvar, " \"", s, "\"\n");
286 case CMD_REQUEST_USAGE:
288 print("\nUsage:^3 cl_cmd sendcvar <cvar>\n");
289 print(" Where 'cvar' is the cvar plus arguments to send to the server.\n");
295 void GameCommand_settemp(float request, float argc)
299 case CMD_REQUEST_COMMAND:
301 if((argv(1) == "restore") && (argc == 2))
303 float i = cvar_clientsettemp_restore();
306 dprint("Restored ", ftos(i), " temporary cvar settings to their original values.\n");
308 dprint("Nothing to restore.\n");
314 if(cvar_clientsettemp(argv(1), argv(2)))
315 dprint("Creating new settemp tracker for ", argv(1), " and setting it to \"", argv(2), "\" temporarily.\n");
317 dprint("Already had a tracker for ", argv(1), ", updating it to \"", argv(2), "\".\n");
324 print("Incorrect parameters for ^2settemp^7\n");
325 case CMD_REQUEST_USAGE:
327 print("\nUsage:^3 cl_cmd settemp <cvar> | [restore]\n");
328 print(" Where 'cvar' is the cvar plus arguments to send to the server,\n");
329 print(" or 'restore' allows you to restore all of the original temporary cvar values.\n");
335 /* use this when creating a new command, making sure to place it in alphabetical order.
336 void GameCommand_(float request)
340 case CMD_REQUEST_COMMAND:
347 case CMD_REQUEST_USAGE:
349 print("\nUsage:^3 cl_cmd \n");
350 print(" No arguments required.\n");
358 // ==================================
359 // Macro system for client commands
360 // ==================================
362 // Do not hard code aliases for these, instead create them in commands.cfg... also: keep in alphabetical order, please ;)
363 #define CLIENT_COMMANDS(request,arguments) \
364 CLIENT_COMMAND("blurtest", GameCommand_blurtest(request), "Feature for testing blur postprocessing") \
365 CLIENT_COMMAND("debugmodel", GameCommand_debugmodel(request, arguments), "Spawn a debug model manually") \
366 CLIENT_COMMAND("handlevote", GameCommand_handlevote(request, arguments), "System to handle selecting a vote or option") \
367 CLIENT_COMMAND("hud", GameCommand_hud(request, arguments), "Commands regarding/controlling the HUD system") \
368 CLIENT_COMMAND("mv_download", GameCommand_mv_download(request, arguments), "Retrieve mapshot picture from the server") \
369 CLIENT_COMMAND("sendcvar", GameCommand_sendcvar(request, arguments), "Send a cvar to the server (like weaponpriority)") \
370 CLIENT_COMMAND("settemp", GameCommand_settemp(request, arguments), "Temporarily set a value to a cvar which is restored by command or end of each match") \
373 void GameCommand_macro_help()
375 #define CLIENT_COMMAND(name,function,description) \
376 { print(" ^2", name, "^7: ", description, "\n"); }
378 CLIENT_COMMANDS(0, 0)
379 #undef CLIENT_COMMAND
384 float GameCommand_macro_command(float argc)
386 #define CLIENT_COMMAND(name,function,description) \
387 { if(name == strtolower(argv(0))) { function; return TRUE; } }
389 CLIENT_COMMANDS(CMD_REQUEST_COMMAND, argc)
390 #undef CLIENT_COMMAND
395 float GameCommand_macro_usage(float argc)
397 #define CLIENT_COMMAND(name,function,description) \
398 { if(name == strtolower(argv(1))) { function; return TRUE; } }
400 CLIENT_COMMANDS(CMD_REQUEST_USAGE, argc)
401 #undef CLIENT_COMMAND
407 // =========================================
408 // Main Function Called By Engine (cl_cmd)
409 // =========================================
410 // If this function exists, client code handles gamecommand instead of the engine code.
412 void GameCommand(string command)
414 float argc = tokenize_console(command);
416 if(strtolower(argv(0)) == "help")
420 print("\nUsage:^3 cl_cmd COMMAND...^7, where possible commands are:\n");
421 GameCommand_macro_help();
422 GameCommand_Generic("help");
423 print("For help about specific commands, type cl_cmd help COMMAND\n");
426 else if(GameCommand_macro_usage(argc)) // Instead of trying to call a command, we're going to see detailed information about it
431 else if(GameCommand_Generic(command))
433 return; // handled by common/gamecommand.qc
435 else if(GameCommand_macro_command(argc)) // continue as usual and scan for normal commands
437 return; // handled by one of the above GameCommand_* functions
440 // nothing above caught the command, must be invalid
441 print("Unknown client command", ((command != "") ? strcat(" \"", command, "\"") : ""), ". For a list of supported commands, try cl_cmd help.\n");
447 // ===================================
448 // Macro system for console commands
449 // ===================================
451 // These functions are here specifically to add special + - commands to the game, and are not really normal commands.
452 // Please add client commands to the function above this, as this is only for special reasons.
453 #define CONSOLE_COMMANDS_NORMAL \
454 CONSOLE_COMMAND("+showscores", { scoreboard_showscores = TRUE; }) \
455 CONSOLE_COMMAND("-showscores", { scoreboard_showscores = FALSE; }) \
456 CONSOLE_COMMAND("+showaccuracy", { scoreboard_showaccuracy = TRUE; }) \
457 CONSOLE_COMMAND("-showaccuracy", { scoreboard_showaccuracy = FALSE; }) \
460 #define CONSOLE_COMMANDS_MOVEMENT \
461 CONSOLE_COMMAND("+forward", { ++camera_direction_x; }) \
462 CONSOLE_COMMAND("-forward", { --camera_direction_x; }) \
463 CONSOLE_COMMAND("+back", { --camera_direction_x; }) \
464 CONSOLE_COMMAND("-back", { ++camera_direction_x; }) \
465 CONSOLE_COMMAND("+moveup", { ++camera_direction_z; }) \
466 CONSOLE_COMMAND("-moveup", { --camera_direction_z; }) \
467 CONSOLE_COMMAND("+movedown", { --camera_direction_z; }) \
468 CONSOLE_COMMAND("-movedown", { ++camera_direction_z; }) \
469 CONSOLE_COMMAND("+moveright", { --camera_direction_y; }) \
470 CONSOLE_COMMAND("-moveright", { ++camera_direction_y; }) \
471 CONSOLE_COMMAND("+moveleft", { ++camera_direction_y; }) \
472 CONSOLE_COMMAND("-moveleft", { --camera_direction_y; }) \
473 CONSOLE_COMMAND("+roll_right", { ++camera_roll; }) \
474 CONSOLE_COMMAND("-roll_right", { --camera_roll; }) \
475 CONSOLE_COMMAND("+roll_left", { --camera_roll; }) \
476 CONSOLE_COMMAND("-roll_left", { ++camera_roll; }) \
479 void ConsoleCommand_macro_init()
481 // first init normal commands
482 #define CONSOLE_COMMAND(name,execution) \
483 { registercommand(name); }
485 CONSOLE_COMMANDS_NORMAL
486 #undef CONSOLE_COMMAND
488 // then init movement commands
493 #define CONSOLE_COMMAND(name,execution) \
494 { registercommand(name); }
496 CONSOLE_COMMANDS_MOVEMENT
497 #undef CONSOLE_COMMAND
505 float ConsoleCommand_macro_normal(float argc)
507 #define CONSOLE_COMMAND(name,execution) \
508 { if(name == strtolower(argv(0))) { { execution } return TRUE; } }
510 CONSOLE_COMMANDS_NORMAL
511 #undef CONSOLE_COMMAND
516 float ConsoleCommand_macro_movement(float argc)
520 #define CONSOLE_COMMAND(name,execution) \
521 { if(name == strtolower(argv(0))) { { execution } return TRUE; } }
523 CONSOLE_COMMANDS_MOVEMENT
524 #undef CONSOLE_COMMAND
531 // ======================================================
532 // Main Function Called By Engine (registered commands)
533 // ======================================================
534 // Used to parse commands in the console that have been registered with the "registercommand" function
536 float CSQC_ConsoleCommand(string command)
538 float argc = tokenize_console(command);
540 if(ConsoleCommand_macro_normal(argc))
544 else if(ConsoleCommand_macro_movement(argc))
549 // Return value should be 1 if CSQC handled the command, otherwise return 0 to have the engine handle it.