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;
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 LocalCommand_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.
202 case "scoreboard_columns_set":
204 Cmd_HUD_SetFields(argc);
209 case "scoreboard_columns_help":
219 hud_panel_radar_maximized = (stof(argv(2)) != 0);
221 hud_panel_radar_maximized = !hud_panel_radar_maximized;
229 print("Incorrect parameters for ^2hud^7\n");
230 case CMD_REQUEST_USAGE:
232 print("\nUsage:^3 cl_cmd hud action [configname | radartoggle | layout]\n");
233 print(" Where 'action' is the command to complete,\n");
234 print(" 'configname' is the name to save to for \"save\" action,\n");
235 print(" 'radartoggle' is to control hud_panel_radar_maximized for \"radar\" action,\n");
236 print(" and 'layout' is how to organize the scoreboard columns for the set action.\n");
237 print(" Full list of commands here: \"configure, save, scoreboard_columns_help, scoreboard_columns_set, radar.\"\n");
243 void LocalCommand_localprint(float request, float argc)
247 case CMD_REQUEST_COMMAND:
251 centerprint_hud(argv(1));
257 print("Incorrect parameters for ^2localprint^7\n");
258 case CMD_REQUEST_USAGE:
260 print("\nUsage:^3 cl_cmd localprint \"message\"\n");
261 print(" 'message' is the centerprint message to send to yourself.\n");
267 void LocalCommand_mv_download(float request, float argc)
271 case CMD_REQUEST_COMMAND:
273 Cmd_MapVote_MapDownload(argc);
279 case CMD_REQUEST_USAGE:
281 print("\nUsage:^3 cl_cmd mv_download mapid\n");
282 print(" Where 'mapid' is the id number of the map to request an image of on the map vote selection menu.\n");
288 void LocalCommand_sendcvar(float request, float argc)
292 case CMD_REQUEST_COMMAND:
294 // W_FixWeaponOrder will trash argv, so save what we need.
295 string thiscvar = strzone(argv(1));
296 string s = cvar_string(thiscvar);
298 if(thiscvar == "cl_weaponpriority")
299 s = W_FixWeaponOrder(W_NumberWeaponOrder(s), 1);
300 else if(substring(thiscvar, 0, 17) == "cl_weaponpriority" && strlen(thiscvar) == 18)
301 s = W_FixWeaponOrder(W_NumberWeaponOrder(s), 0);
303 localcmd("cmd sentcvar ", thiscvar, " \"", s, "\"\n");
310 case CMD_REQUEST_USAGE:
312 print("\nUsage:^3 cl_cmd sendcvar <cvar>\n");
313 print(" Where 'cvar' is the cvar plus arguments to send to the server.\n");
319 void LocalCommand_settemp(float request, float argc)
323 case CMD_REQUEST_COMMAND:
325 if((argv(1) == "restore") && (argc == 2))
327 float i = cvar_clientsettemp_restore();
330 dprint("Restored ", ftos(i), " temporary cvar settings to their original values.\n");
332 dprint("Nothing to restore.\n");
338 if(cvar_clientsettemp(argv(1), argv(2)))
339 dprint("Creating new settemp tracker for ", argv(1), " and setting it to \"", argv(2), "\" temporarily.\n");
341 dprint("Already had a tracker for ", argv(1), ", updating it to \"", argv(2), "\".\n");
348 print("Incorrect parameters for ^2settemp^7\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 LocalCommand_(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", LocalCommand_blurtest(request), "Feature for testing blur postprocessing") \
389 CLIENT_COMMAND("debugmodel", LocalCommand_debugmodel(request, arguments), "Spawn a debug model manually") \
390 CLIENT_COMMAND("handlevote", LocalCommand_handlevote(request, arguments), "System to handle selecting a vote or option") \
391 CLIENT_COMMAND("hud", LocalCommand_hud(request, arguments), "Commands regarding/controlling the HUD system") \
392 CLIENT_COMMAND("localprint", LocalCommand_localprint(request, arguments), "Create your own centerprint sent to yourself") \
393 CLIENT_COMMAND("mv_download", LocalCommand_mv_download(request, arguments), "Retrieve mapshot picture from the server") \
394 CLIENT_COMMAND("sendcvar", LocalCommand_sendcvar(request, arguments), "Send a cvar to the server (like weaponpriority)") \
395 CLIENT_COMMAND("settemp", LocalCommand_settemp(request, arguments), "Temporarily set a value to a cvar which is restored by command or end of each match") \
398 void LocalCommand_macro_help()
400 #define CLIENT_COMMAND(name,function,description) \
401 { print(" ^2", name, "^7: ", description, "\n"); }
403 CLIENT_COMMANDS(0, 0)
404 #undef CLIENT_COMMAND
409 float LocalCommand_macro_command(float argc)
411 #define CLIENT_COMMAND(name,function,description) \
412 { if(name == strtolower(argv(0))) { function; return TRUE; } }
414 CLIENT_COMMANDS(CMD_REQUEST_COMMAND, argc)
415 #undef CLIENT_COMMAND
420 float LocalCommand_macro_usage(float argc)
422 #define CLIENT_COMMAND(name,function,description) \
423 { if(name == strtolower(argv(1))) { function; return TRUE; } }
425 CLIENT_COMMANDS(CMD_REQUEST_USAGE, argc)
426 #undef CLIENT_COMMAND
432 // =========================================
433 // Main Function Called By Engine (cl_cmd)
434 // =========================================
435 // If this function exists, client code handles gamecommand instead of the engine code.
437 void GameCommand(string command)
439 float argc = tokenize_console(command);
441 if(strtolower(argv(0)) == "help")
445 print("\nUsage:^3 cl_cmd COMMAND...^7, where possible commands are:\n");
446 LocalCommand_macro_help();
447 GameCommand_Generic("help");
448 print("For help about specific commands, type cl_cmd help COMMAND\n");
451 else if(LocalCommand_macro_usage(argc)) // Instead of trying to call a command, we're going to see detailed information about it
456 else if(GameCommand_Generic(command))
458 return; // handled by common/command/generic.qc
460 else if(LocalCommand_macro_command(argc)) // continue as usual and scan for normal commands
462 return; // handled by one of the above LocalCommand_* functions
465 // nothing above caught the command, must be invalid
466 print(((command != "") ? strcat("Unknown client command \"", command, "\"") : "No command provided"), ". For a list of supported commands, try cl_cmd help.\n");
472 // ===================================
473 // Macro system for console commands
474 // ===================================
476 // These functions are here specifically to add special + - commands to the game, and are not really normal commands.
477 // Please add client commands to the function above this, as this is only for special reasons.
478 #define CONSOLE_COMMANDS_NORMAL \
479 CONSOLE_COMMAND("+showscores", { scoreboard_showscores = TRUE; }) \
480 CONSOLE_COMMAND("-showscores", { scoreboard_showscores = FALSE; }) \
481 CONSOLE_COMMAND("+showaccuracy", { scoreboard_showaccuracy = TRUE; }) \
482 CONSOLE_COMMAND("-showaccuracy", { scoreboard_showaccuracy = FALSE; }) \
485 #define CONSOLE_COMMANDS_MOVEMENT \
486 CONSOLE_COMMAND("+forward", { ++camera_direction_x; }) \
487 CONSOLE_COMMAND("-forward", { --camera_direction_x; }) \
488 CONSOLE_COMMAND("+back", { --camera_direction_x; }) \
489 CONSOLE_COMMAND("-back", { ++camera_direction_x; }) \
490 CONSOLE_COMMAND("+moveup", { ++camera_direction_z; }) \
491 CONSOLE_COMMAND("-moveup", { --camera_direction_z; }) \
492 CONSOLE_COMMAND("+movedown", { --camera_direction_z; }) \
493 CONSOLE_COMMAND("-movedown", { ++camera_direction_z; }) \
494 CONSOLE_COMMAND("+moveright", { --camera_direction_y; }) \
495 CONSOLE_COMMAND("-moveright", { ++camera_direction_y; }) \
496 CONSOLE_COMMAND("+moveleft", { ++camera_direction_y; }) \
497 CONSOLE_COMMAND("-moveleft", { --camera_direction_y; }) \
498 CONSOLE_COMMAND("+roll_right", { ++camera_roll; }) \
499 CONSOLE_COMMAND("-roll_right", { --camera_roll; }) \
500 CONSOLE_COMMAND("+roll_left", { --camera_roll; }) \
501 CONSOLE_COMMAND("-roll_left", { ++camera_roll; }) \
504 void ConsoleCommand_macro_init()
506 // first init normal commands
507 #define CONSOLE_COMMAND(name,execution) \
508 { registercommand(name); }
510 CONSOLE_COMMANDS_NORMAL
511 #undef CONSOLE_COMMAND
513 // then init movement commands
518 #define CONSOLE_COMMAND(name,execution) \
519 { registercommand(name); }
521 CONSOLE_COMMANDS_MOVEMENT
522 #undef CONSOLE_COMMAND
530 float ConsoleCommand_macro_normal(float argc)
532 #define CONSOLE_COMMAND(name,execution) \
533 { if(name == strtolower(argv(0))) { { execution } return TRUE; } }
535 CONSOLE_COMMANDS_NORMAL
536 #undef CONSOLE_COMMAND
541 float ConsoleCommand_macro_movement(float argc)
545 #define CONSOLE_COMMAND(name,execution) \
546 { if(name == strtolower(argv(0))) { { execution } return TRUE; } }
548 CONSOLE_COMMANDS_MOVEMENT
549 #undef CONSOLE_COMMAND
556 // ======================================================
557 // Main Function Called By Engine (registered commands)
558 // ======================================================
559 // Used to parse commands in the console that have been registered with the "registercommand" function
561 float CSQC_ConsoleCommand(string command)
563 float argc = tokenize_console(command);
565 if(ConsoleCommand_macro_normal(argc))
569 else if(ConsoleCommand_macro_movement(argc))
574 // Return value should be 1 if CSQC handled the command, otherwise return 0 to have the engine handle it.