1 // ==============================================
2 // CSQC client commands code, written by Samual
3 // Last updated: December 28th, 2011
4 // ==============================================
8 #include "../autocvars.qh"
11 #include "../hud_config.qh"
13 #include "../mapvoting.qh"
14 #include "../miscfunctions.qh"
15 #include "../scoreboard.qh"
16 #include "../../common/command/generic.qh"
17 #include "../../common/command/shared_defs.qh"
18 #include "../../common/mapinfo.qh"
22 if(time - floor(time) > 0.5)
30 self.drawmask = MASK_NORMAL;
35 // =======================
36 // Command Sub-Functions
37 // =======================
39 void LocalCommand_blurtest(int request)
41 // Simple command to work with postprocessing temporarily... possibly completely pointless, the glsl shader is used for a real feature now...
42 // Anyway, to enable it, just compile the client with -DBLURTEST and then you can use the command.
47 case CMD_REQUEST_COMMAND:
49 blurtest_time0 = time;
50 blurtest_time1 = time + stof(argv(1));
51 blurtest_radius = stof(argv(2));
52 blurtest_power = stof(argv(3));
53 print("Enabled blurtest\n");
58 case CMD_REQUEST_USAGE:
60 print("\nUsage:^3 cl_cmd blurtest\n");
61 print(" No arguments required.\n");
68 print("Blurtest is not enabled on this client.\n");
74 void LocalCommand_boxparticles(int request, int argc)
78 case CMD_REQUEST_COMMAND:
82 int effect = particleeffectnum(argv(1));
85 int index = stoi(argv(2));
88 own = entitybyindex(-index);
90 own = findfloat(world, entnum, index);
91 vector org_from = stov(argv(3));
92 vector org_to = stov(argv(4));
93 vector dir_from = stov(argv(5));
94 vector dir_to = stov(argv(6));
95 int countmultiplier = stoi(argv(7));
96 int flags = stoi(argv(8));
97 boxparticles(effect, own, org_from, org_to, dir_from, dir_to, countmultiplier, flags);
104 print("Incorrect parameters for ^2boxparticles^7\n");
105 case CMD_REQUEST_USAGE:
107 print("\nUsage:^3 lv_cmd boxparticles effectname own org_from org_to, dir_from, dir_to, countmultiplier, flags\n");
108 print(" 'effectname' is the name of a particle effect in effectinfo.txt\n");
109 print(" 'own' is the entity number of the owner (negative for csqc ent, positive for svqc ent)\n");
110 print(" 'org_from' is the starting origin of the box\n");
111 print(" 'org_to' is the ending origin of the box\n");
112 print(" 'dir_from' is the minimum velocity\n");
113 print(" 'dir_to' is the maximum velocity\n");
114 print(" 'countmultiplier' defines a multiplier for the particle count (affects count only, not countabsolute or trailspacing)\n");
115 print(" 'flags' can contain:\n");
116 print(" 1 to respect globals particles_alphamin, particles_alphamax (set right before via prvm_globalset client)\n");
117 print(" 2 to respect globals particles_colormin, particles_colormax (set right before via prvm_globalset client)\n");
118 print(" 4 to respect globals particles_fade (set right before via prvm_globalset client)\n");
119 print(" 128 to draw a trail, not a box\n");
125 void LocalCommand_create_scrshot_ent(int request)
129 case CMD_REQUEST_COMMAND:
131 string filename = strcat(MapInfo_Map_bspname, "_scrshot_ent.txt");
132 int fh = fopen(filename, FILE_WRITE);
137 fputs(fh, strcat("\"classname\" \"info_autoscreenshot\"\n"));
138 fputs(fh, strcat("\"origin\" \"", strcat(ftos(view_origin.x), " ", ftos(view_origin.y), " ", ftos(view_origin.z)), "\"\n"));
139 fputs(fh, strcat("\"angles\" \"", strcat(ftos(view_angles.x), " ", ftos(view_angles.y), " ", ftos(view_angles.z)), "\"\n"));
142 print("Completed screenshot entity dump in ^2data/data/", MapInfo_Map_bspname, "_scrshot_ent.txt^7.\n");
148 print("^1Error: ^7Could not dump to file!\n");
154 case CMD_REQUEST_USAGE:
156 print("\nUsage:^3 cl_cmd create_scrshot_ent\n");
157 print(" No arguments required.\n");
163 void LocalCommand_debugmodel(int request, int argc)
167 case CMD_REQUEST_COMMAND:
169 string modelname = argv(1);
170 entity debugmodel_entity;
172 debugmodel_entity = spawn();
173 precache_model(modelname);
174 setmodel(debugmodel_entity, modelname);
175 setorigin(debugmodel_entity, view_origin);
176 debugmodel_entity.angles = view_angles;
177 debugmodel_entity.draw = DrawDebugModel;
178 debugmodel_entity.classname = "debugmodel";
184 case CMD_REQUEST_USAGE:
186 print("\nUsage:^3 cl_cmd debugmodel model\n");
187 print(" Where 'model' is a string of the model name to use for the debug model.\n");
193 void LocalCommand_handlevote(int request, int argc)
197 case CMD_REQUEST_COMMAND:
202 if(InterpretBoolean(argv(1)))
215 if(uid2name_dialog) // handled by "uid2name" option
220 localcmd(strcat("setreport cl_allow_uid2name ", ftos(vote_selection - 1), "\n"));
223 else { localcmd(strcat("cmd vote ", vote_string, "\n")); }
230 print("Incorrect parameters for ^2handlevote^7\n");
231 case CMD_REQUEST_USAGE:
233 print("\nUsage:^3 cl_cmd handlevote vote\n");
234 print(" Where 'vote' is the selection for either the current poll or uid2name.\n");
240 void LocalCommand_hud(int request, int argc)
244 case CMD_REQUEST_COMMAND:
250 cvar_set("_hud_configure", ftos(!autocvar__hud_configure));
258 HUD_Panel_ExportCfg(argv(2));
263 break; // go to usage, we're missing the paramater needed here.
267 case "scoreboard_columns_set":
269 Cmd_HUD_SetFields(argc);
273 case "scoreboard_columns_help":
282 hud_panel_radar_maximized = InterpretBoolean(argv(2));
284 hud_panel_radar_maximized = !hud_panel_radar_maximized;
291 print("Incorrect parameters for ^2hud^7\n");
292 case CMD_REQUEST_USAGE:
294 print("\nUsage:^3 cl_cmd hud action [configname | radartoggle | layout]\n");
295 print(" Where 'action' is the command to complete,\n");
296 print(" 'configname' is the name to save to for \"save\" action,\n");
297 print(" 'radartoggle' is to control hud_panel_radar_maximized for \"radar\" action,\n");
298 print(" and 'layout' is how to organize the scoreboard columns for the set action.\n");
299 print(" Full list of commands here: \"configure, save, scoreboard_columns_help, scoreboard_columns_set, radar.\"\n");
305 void LocalCommand_localprint(int request, int argc)
309 case CMD_REQUEST_COMMAND:
313 centerprint_hud(argv(1));
319 print("Incorrect parameters for ^2localprint^7\n");
320 case CMD_REQUEST_USAGE:
322 print("\nUsage:^3 cl_cmd localprint \"message\"\n");
323 print(" 'message' is the centerprint message to send to yourself.\n");
329 void LocalCommand_mv_download(int request, int argc)
333 case CMD_REQUEST_COMMAND:
337 Cmd_MapVote_MapDownload(argc);
343 print("Incorrect parameters for ^2mv_download^7\n");
344 case CMD_REQUEST_USAGE:
346 print("\nUsage:^3 cl_cmd mv_download mapid\n");
347 print(" Where 'mapid' is the id number of the map to request an image of on the map vote selection menu.\n");
353 void LocalCommand_sendcvar(int request, int argc)
357 case CMD_REQUEST_COMMAND:
361 // W_FixWeaponOrder will trash argv, so save what we need.
362 string thiscvar = strzone(argv(1));
363 string s = cvar_string(thiscvar);
365 if(thiscvar == "cl_weaponpriority")
366 s = W_FixWeaponOrder(W_NumberWeaponOrder(s), 1);
367 else if(substring(thiscvar, 0, 17) == "cl_weaponpriority" && strlen(thiscvar) == 18)
368 s = W_FixWeaponOrder(W_NumberWeaponOrder(s), 0);
370 localcmd("cmd sentcvar ", thiscvar, " \"", s, "\"\n");
377 print("Incorrect parameters for ^2sendcvar^7\n");
378 case CMD_REQUEST_USAGE:
380 print("\nUsage:^3 cl_cmd sendcvar <cvar>\n");
381 print(" Where 'cvar' is the cvar plus arguments to send to the server.\n");
387 /* use this when creating a new command, making sure to place it in alphabetical order... also,
388 ** ADD ALL NEW COMMANDS TO commands.cfg WITH PROPER ALIASES IN THE SAME FASHION!
389 void LocalCommand_(int request)
393 case CMD_REQUEST_COMMAND:
400 case CMD_REQUEST_USAGE:
402 print("\nUsage:^3 cl_cmd \n");
403 print(" No arguments required.\n");
411 // ==================================
412 // Macro system for client commands
413 // ==================================
415 // Normally do not hard code aliases for these, instead create them in commands.cfg... also: keep in alphabetical order, please ;)
416 #define CLIENT_COMMANDS(request,arguments) \
417 CLIENT_COMMAND("blurtest", LocalCommand_blurtest(request), "Feature for testing blur postprocessing") \
418 CLIENT_COMMAND("boxparticles", LocalCommand_boxparticles(request, arguments), "Spawn particles manually") \
419 CLIENT_COMMAND("create_scrshot_ent", LocalCommand_create_scrshot_ent(request), "Create an entity at this location for automatic screenshots") \
420 CLIENT_COMMAND("debugmodel", LocalCommand_debugmodel(request, arguments), "Spawn a debug model manually") \
421 CLIENT_COMMAND("handlevote", LocalCommand_handlevote(request, arguments), "System to handle selecting a vote or option") \
422 CLIENT_COMMAND("hud", LocalCommand_hud(request, arguments), "Commands regarding/controlling the HUD system") \
423 CLIENT_COMMAND("localprint", LocalCommand_localprint(request, arguments), "Create your own centerprint sent to yourself") \
424 CLIENT_COMMAND("mv_download", LocalCommand_mv_download(request, arguments), "Retrieve mapshot picture from the server") \
425 CLIENT_COMMAND("sendcvar", LocalCommand_sendcvar(request, arguments), "Send a cvar to the server (like weaponpriority)") \
428 void LocalCommand_macro_help()
430 #define CLIENT_COMMAND(name,function,description) \
431 { if(strtolower(description) != "") { print(" ^2", name, "^7: ", description, "\n"); } }
433 CLIENT_COMMANDS(0, 0);
434 #undef CLIENT_COMMAND
439 bool LocalCommand_macro_command(int argc)
441 #define CLIENT_COMMAND(name,function,description) \
442 { if(name == strtolower(argv(0))) { function; return true; } }
444 CLIENT_COMMANDS(CMD_REQUEST_COMMAND, argc);
445 #undef CLIENT_COMMAND
450 bool LocalCommand_macro_usage(int argc)
452 #define CLIENT_COMMAND(name,function,description) \
453 { if(name == strtolower(argv(1))) { function; return true; } }
455 CLIENT_COMMANDS(CMD_REQUEST_USAGE, argc);
456 #undef CLIENT_COMMAND
461 void LocalCommand_macro_write_aliases(int fh)
463 #define CLIENT_COMMAND(name,function,description) \
464 { if(strtolower(description) != "") { CMD_Write_Alias("qc_cmd_cl", name, description); } }
466 CLIENT_COMMANDS(0, 0);
467 #undef CLIENT_COMMAND
473 // =========================================
474 // Main Function Called By Engine (cl_cmd)
475 // =========================================
476 // If this function exists, client code handles gamecommand instead of the engine code.
478 void GameCommand(string command)
480 int argc = tokenize_console(command);
482 // Guide for working with argc arguments by example:
483 // argc: 1 - 2 - 3 - 4
484 // argv: 0 - 1 - 2 - 3
485 // cmd vote - master - login - password
487 if(strtolower(argv(0)) == "help")
491 print("\nClient console commands:\n");
492 LocalCommand_macro_help();
494 print("\nGeneric commands shared by all programs:\n");
495 GenericCommand_macro_help();
497 print("\nUsage:^3 cl_cmd COMMAND...^7, where possible commands are listed above.\n");
498 print("For help about a specific command, type cl_cmd help COMMAND\n");
502 else if(GenericCommand_macro_usage(argc)) // Instead of trying to call a command, we're going to see detailed information about it
506 else if(LocalCommand_macro_usage(argc)) // now try for normal commands too
511 else if(GenericCommand(command))
513 return; // handled by common/command/generic.qc
515 else if(LocalCommand_macro_command(argc)) // continue as usual and scan for normal commands
517 return; // handled by one of the above LocalCommand_* functions
520 // nothing above caught the command, must be invalid
521 print(((command != "") ? strcat("Unknown client command \"", command, "\"") : "No command provided"), ". For a list of supported commands, try cl_cmd help.\n");
527 // ===================================
528 // Macro system for console commands
529 // ===================================
531 // These functions are here specifically to add special + - commands to the game, and are not really normal commands.
532 // Please add client commands to the function above this, as this is only for special reasons.
533 #define CONSOLE_COMMANDS_NORMAL() \
534 CONSOLE_COMMAND("+showscores", { scoreboard_showscores = true; }) \
535 CONSOLE_COMMAND("-showscores", { scoreboard_showscores = false; }) \
536 CONSOLE_COMMAND("+showaccuracy", { scoreboard_showaccuracy = true; }) \
537 CONSOLE_COMMAND("-showaccuracy", { scoreboard_showaccuracy = false; }) \
540 #define CONSOLE_COMMANDS_MOVEMENT() \
541 CONSOLE_COMMAND("+forward", { ++camera_direction.x; }) \
542 CONSOLE_COMMAND("-forward", { --camera_direction.x; }) \
543 CONSOLE_COMMAND("+back", { --camera_direction.x; }) \
544 CONSOLE_COMMAND("-back", { ++camera_direction.x; }) \
545 CONSOLE_COMMAND("+moveup", { ++camera_direction.z; }) \
546 CONSOLE_COMMAND("-moveup", { --camera_direction.z; }) \
547 CONSOLE_COMMAND("+movedown", { --camera_direction.z; }) \
548 CONSOLE_COMMAND("-movedown", { ++camera_direction.z; }) \
549 CONSOLE_COMMAND("+moveright", { --camera_direction.y; }) \
550 CONSOLE_COMMAND("-moveright", { ++camera_direction.y; }) \
551 CONSOLE_COMMAND("+moveleft", { ++camera_direction.y; }) \
552 CONSOLE_COMMAND("-moveleft", { --camera_direction.y; }) \
553 CONSOLE_COMMAND("+roll_right", { ++camera_roll; }) \
554 CONSOLE_COMMAND("-roll_right", { --camera_roll; }) \
555 CONSOLE_COMMAND("+roll_left", { --camera_roll; }) \
556 CONSOLE_COMMAND("-roll_left", { ++camera_roll; }) \
559 void ConsoleCommand_macro_init()
561 // first init normal commands
562 #define CONSOLE_COMMAND(name,execution) \
563 { registercommand(name); }
565 CONSOLE_COMMANDS_NORMAL();
566 #undef CONSOLE_COMMAND
568 // then init movement commands
573 #define CONSOLE_COMMAND(name,execution) \
574 { registercommand(name); }
576 CONSOLE_COMMANDS_MOVEMENT();
577 #undef CONSOLE_COMMAND
585 bool ConsoleCommand_macro_normal(int argc)
587 #define CONSOLE_COMMAND(name,execution) \
588 { if(name == strtolower(argv(0))) { { execution } return true; } }
590 CONSOLE_COMMANDS_NORMAL();
591 #undef CONSOLE_COMMAND
596 bool ConsoleCommand_macro_movement(int argc)
600 #define CONSOLE_COMMAND(name,execution) \
601 { if(name == strtolower(argv(0))) { { execution } return true; } }
603 CONSOLE_COMMANDS_MOVEMENT();
604 #undef CONSOLE_COMMAND
611 // ======================================================
612 // Main Function Called By Engine (registered commands)
613 // ======================================================
614 // Used to parse commands in the console that have been registered with the "registercommand" function
616 bool CSQC_ConsoleCommand(string command)
618 int argc = tokenize_console(command);
620 if(ConsoleCommand_macro_normal(argc))
624 else if(ConsoleCommand_macro_movement(argc))
629 // Return value should be 1 if CSQC handled the command, otherwise return 0 to have the engine handle it.