1 // ==============================================
2 // CSQC client commands code, written by Samual
3 // Last updated: December 28th, 2011
4 // ==============================================
8 if(time - floor(time) > 0.5)
16 self.drawmask = MASK_NORMAL;
21 // =======================
22 // Command Sub-Functions
23 // =======================
25 void LocalCommand_blurtest(float request)
27 // Simple command to work with postprocessing temporarily... possibly completely pointless, the glsl shader is used for a real feature now...
28 // Anyway, to enable it, just compile the client with -DBLURTEST and then you can use the command.
33 case CMD_REQUEST_COMMAND:
35 blurtest_time0 = time;
36 blurtest_time1 = time + stof(argv(1));
37 blurtest_radius = stof(argv(2));
38 blurtest_power = stof(argv(3));
39 print("Enabled blurtest\n");
44 case CMD_REQUEST_USAGE:
46 print("\nUsage:^3 cl_cmd blurtest\n");
47 print(" No arguments required.\n");
54 print("Blurtest is not enabled on this client.\n");
60 void LocalCommand_create_scrshot_ent(float request)
64 case CMD_REQUEST_COMMAND:
67 string filename = strcat(MapInfo_Map_bspname, "_scrshot_ent.txt");
68 fh = fopen(filename, FILE_WRITE);
73 fputs(fh, strcat("\"classname\" \"info_autoscreenshot\"\n"));
74 fputs(fh, strcat("\"origin\" \"", strcat(ftos(view_origin_x), " ", ftos(view_origin_y), " ", ftos(view_origin_z)), "\"\n"));
75 fputs(fh, strcat("\"angles\" \"", strcat(ftos(view_angles_x), " ", ftos(view_angles_y), " ", ftos(view_angles_z)), "\"\n"));
78 print("Completed screenshot entity dump in ^2data/data/", MapInfo_Map_bspname, "_scrshot_ent.txt^7.\n");
84 print("^1Error: ^7Could not dump to file!\n");
90 case CMD_REQUEST_USAGE:
92 print("\nUsage:^3 cl_cmd create_scrshot_ent\n");
93 print(" No arguments required.\n");
99 void LocalCommand_debugmodel(float request, float argc)
103 case CMD_REQUEST_COMMAND:
105 string modelname = argv(1);
106 entity debugmodel_entity;
108 debugmodel_entity = spawn();
109 precache_model(modelname);
110 setmodel(debugmodel_entity, modelname);
111 setorigin(debugmodel_entity, view_origin);
112 debugmodel_entity.angles = view_angles;
113 debugmodel_entity.draw = DrawDebugModel;
114 debugmodel_entity.classname = "debugmodel";
120 case CMD_REQUEST_USAGE:
122 print("\nUsage:^3 cl_cmd debugmodel model\n");
123 print(" Where 'model' is a string of the model name to use for the debug model.\n");
129 void LocalCommand_handlevote(float request, float argc)
133 case CMD_REQUEST_COMMAND:
135 float vote_selection;
138 if(InterpretBoolean(argv(1)))
151 if(uid2name_dialog) // handled by "uid2name" option
156 localcmd(strcat("setreport cl_allow_uid2name ", ftos(vote_selection - 1), "\n"));
159 else { localcmd(strcat("cmd vote ", vote_string, "\n")); }
166 print("Incorrect parameters for ^2handlevote^7\n");
167 case CMD_REQUEST_USAGE:
169 print("\nUsage:^3 cl_cmd handlevote vote\n");
170 print(" Where 'vote' is the selection for either the current poll or uid2name.\n");
176 void LocalCommand_hud(float request, float argc)
180 case CMD_REQUEST_COMMAND:
186 cvar_set("_hud_configure", ftos(!autocvar__hud_configure));
194 HUD_Panel_ExportCfg(argv(2));
199 break; // go to usage, we're missing the paramater needed here.
203 case "scoreboard_columns_set":
205 Cmd_HUD_SetFields(argc);
209 case "scoreboard_columns_help":
218 hud_panel_radar_maximized = InterpretBoolean(argv(2));
220 hud_panel_radar_maximized = !hud_panel_radar_maximized;
227 print("Incorrect parameters for ^2hud^7\n");
228 case CMD_REQUEST_USAGE:
230 print("\nUsage:^3 cl_cmd hud action [configname | radartoggle | layout]\n");
231 print(" Where 'action' is the command to complete,\n");
232 print(" 'configname' is the name to save to for \"save\" action,\n");
233 print(" 'radartoggle' is to control hud_panel_radar_maximized for \"radar\" action,\n");
234 print(" and 'layout' is how to organize the scoreboard columns for the set action.\n");
235 print(" Full list of commands here: \"configure, save, scoreboard_columns_help, scoreboard_columns_set, radar.\"\n");
241 void LocalCommand_localprint(float request, float argc)
245 case CMD_REQUEST_COMMAND:
249 centerprint_hud(argv(1));
255 print("Incorrect parameters for ^2localprint^7\n");
256 case CMD_REQUEST_USAGE:
258 print("\nUsage:^3 cl_cmd localprint \"message\"\n");
259 print(" 'message' is the centerprint message to send to yourself.\n");
265 void LocalCommand_mv_download(float request, float argc)
269 case CMD_REQUEST_COMMAND:
273 Cmd_MapVote_MapDownload(argc);
279 print("Incorrect parameters for ^2mv_download^7\n");
280 case CMD_REQUEST_USAGE:
282 print("\nUsage:^3 cl_cmd mv_download mapid\n");
283 print(" Where 'mapid' is the id number of the map to request an image of on the map vote selection menu.\n");
289 void LocalCommand_sendcvar(float request, float argc)
293 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 print("Incorrect parameters for ^2sendcvar^7\n");
314 case CMD_REQUEST_USAGE:
316 print("\nUsage:^3 cl_cmd sendcvar <cvar>\n");
317 print(" Where 'cvar' is the cvar plus arguments to send to the server.\n");
323 /* use this when creating a new command, making sure to place it in alphabetical order... also,
324 ** ADD ALL NEW COMMANDS TO commands.cfg WITH PROPER ALIASES IN THE SAME FASHION!
325 void LocalCommand_(float request)
329 case CMD_REQUEST_COMMAND:
336 case CMD_REQUEST_USAGE:
338 print("\nUsage:^3 cl_cmd \n");
339 print(" No arguments required.\n");
347 // ==================================
348 // Macro system for client commands
349 // ==================================
351 // Normally do not hard code aliases for these, instead create them in commands.cfg... also: keep in alphabetical order, please ;)
352 #define CLIENT_COMMANDS(request,arguments) \
353 CLIENT_COMMAND("blurtest", LocalCommand_blurtest(request), "Feature for testing blur postprocessing") \
354 CLIENT_COMMAND("create_scrshot_ent", LocalCommand_create_scrshot_ent(request), "Create an entity at this location for automatic screenshots") \
355 CLIENT_COMMAND("debugmodel", LocalCommand_debugmodel(request, arguments), "Spawn a debug model manually") \
356 CLIENT_COMMAND("handlevote", LocalCommand_handlevote(request, arguments), "System to handle selecting a vote or option") \
357 CLIENT_COMMAND("hud", LocalCommand_hud(request, arguments), "Commands regarding/controlling the HUD system") \
358 CLIENT_COMMAND("localprint", LocalCommand_localprint(request, arguments), "Create your own centerprint sent to yourself") \
359 CLIENT_COMMAND("mv_download", LocalCommand_mv_download(request, arguments), "Retrieve mapshot picture from the server") \
360 CLIENT_COMMAND("sendcvar", LocalCommand_sendcvar(request, arguments), "Send a cvar to the server (like weaponpriority)") \
363 void LocalCommand_macro_help()
365 #define CLIENT_COMMAND(name,function,description) \
366 { if(strtolower(description) != "") { print(" ^2", name, "^7: ", description, "\n"); } }
368 CLIENT_COMMANDS(0, 0)
369 #undef CLIENT_COMMAND
374 float LocalCommand_macro_command(float argc)
376 #define CLIENT_COMMAND(name,function,description) \
377 { if(name == strtolower(argv(0))) { function; return TRUE; } }
379 CLIENT_COMMANDS(CMD_REQUEST_COMMAND, argc)
380 #undef CLIENT_COMMAND
385 float LocalCommand_macro_usage(float argc)
387 #define CLIENT_COMMAND(name,function,description) \
388 { if(name == strtolower(argv(1))) { function; return TRUE; } }
390 CLIENT_COMMANDS(CMD_REQUEST_USAGE, argc)
391 #undef CLIENT_COMMAND
396 void LocalCommand_macro_write_aliases(float fh)
398 #define CLIENT_COMMAND(name,function,description) \
399 { if(strtolower(description) != "") { CMD_Write_Alias("qc_cmd_cl", name, description); } }
401 CLIENT_COMMANDS(0, 0)
402 #undef CLIENT_COMMAND
408 // =========================================
409 // Main Function Called By Engine (cl_cmd)
410 // =========================================
411 // If this function exists, client code handles gamecommand instead of the engine code.
413 void GameCommand(string command)
415 float argc = tokenize_console(command);
417 // Guide for working with argc arguments by example:
418 // argc: 1 - 2 - 3 - 4
419 // argv: 0 - 1 - 2 - 3
420 // cmd vote - master - login - password
422 if(strtolower(argv(0)) == "help")
426 print("\nClient console commands:\n");
427 LocalCommand_macro_help();
429 print("\nGeneric commands shared by all programs:\n");
430 GenericCommand_macro_help();
432 print("\nUsage:^3 cl_cmd COMMAND...^7, where possible commands are listed above.\n");
433 print("For help about a specific command, type cl_cmd help COMMAND\n");
437 else if(GenericCommand_macro_usage(argc)) // Instead of trying to call a command, we're going to see detailed information about it
441 else if(LocalCommand_macro_usage(argc)) // now try for normal commands too
446 else if(GenericCommand(command))
448 return; // handled by common/command/generic.qc
450 else if(LocalCommand_macro_command(argc)) // continue as usual and scan for normal commands
452 return; // handled by one of the above LocalCommand_* functions
455 // nothing above caught the command, must be invalid
456 print(((command != "") ? strcat("Unknown client command \"", command, "\"") : "No command provided"), ". For a list of supported commands, try cl_cmd help.\n");
462 // ===================================
463 // Macro system for console commands
464 // ===================================
466 // These functions are here specifically to add special + - commands to the game, and are not really normal commands.
467 // Please add client commands to the function above this, as this is only for special reasons.
468 #define CONSOLE_COMMANDS_NORMAL \
469 CONSOLE_COMMAND("+showscores", { scoreboard_showscores = TRUE; }) \
470 CONSOLE_COMMAND("-showscores", { scoreboard_showscores = FALSE; }) \
471 CONSOLE_COMMAND("+showaccuracy", { scoreboard_showaccuracy = TRUE; }) \
472 CONSOLE_COMMAND("-showaccuracy", { scoreboard_showaccuracy = FALSE; }) \
475 #define CONSOLE_COMMANDS_MOVEMENT \
476 CONSOLE_COMMAND("+forward", { ++camera_direction_x; }) \
477 CONSOLE_COMMAND("-forward", { --camera_direction_x; }) \
478 CONSOLE_COMMAND("+back", { --camera_direction_x; }) \
479 CONSOLE_COMMAND("-back", { ++camera_direction_x; }) \
480 CONSOLE_COMMAND("+moveup", { ++camera_direction_z; }) \
481 CONSOLE_COMMAND("-moveup", { --camera_direction_z; }) \
482 CONSOLE_COMMAND("+movedown", { --camera_direction_z; }) \
483 CONSOLE_COMMAND("-movedown", { ++camera_direction_z; }) \
484 CONSOLE_COMMAND("+moveright", { --camera_direction_y; }) \
485 CONSOLE_COMMAND("-moveright", { ++camera_direction_y; }) \
486 CONSOLE_COMMAND("+moveleft", { ++camera_direction_y; }) \
487 CONSOLE_COMMAND("-moveleft", { --camera_direction_y; }) \
488 CONSOLE_COMMAND("+roll_right", { ++camera_roll; }) \
489 CONSOLE_COMMAND("-roll_right", { --camera_roll; }) \
490 CONSOLE_COMMAND("+roll_left", { --camera_roll; }) \
491 CONSOLE_COMMAND("-roll_left", { ++camera_roll; }) \
494 void ConsoleCommand_macro_init()
496 // first init normal commands
497 #define CONSOLE_COMMAND(name,execution) \
498 { registercommand(name); }
500 CONSOLE_COMMANDS_NORMAL
501 #undef CONSOLE_COMMAND
503 // then init movement commands
508 #define CONSOLE_COMMAND(name,execution) \
509 { registercommand(name); }
511 CONSOLE_COMMANDS_MOVEMENT
512 #undef CONSOLE_COMMAND
520 float ConsoleCommand_macro_normal(float argc)
522 #define CONSOLE_COMMAND(name,execution) \
523 { if(name == strtolower(argv(0))) { { execution } return TRUE; } }
525 CONSOLE_COMMANDS_NORMAL
526 #undef CONSOLE_COMMAND
531 float ConsoleCommand_macro_movement(float argc)
535 #define CONSOLE_COMMAND(name,execution) \
536 { if(name == strtolower(argv(0))) { { execution } return TRUE; } }
538 CONSOLE_COMMANDS_MOVEMENT
539 #undef CONSOLE_COMMAND
546 // ======================================================
547 // Main Function Called By Engine (registered commands)
548 // ======================================================
549 // Used to parse commands in the console that have been registered with the "registercommand" function
551 float CSQC_ConsoleCommand(string command)
553 float argc = tokenize_console(command);
555 if(ConsoleCommand_macro_normal(argc))
559 else if(ConsoleCommand_macro_movement(argc))
564 // Return value should be 1 if CSQC handled the command, otherwise return 0 to have the engine handle it.