1 // ==============================================
2 // CSQC client commands code, written by Samual
3 // Last updated: December 28th, 2011
4 // ==============================================
6 #include "../../common/command/command.qh"
9 #include "../autocvars.qh"
12 #include "../hud_config.qh"
14 #include "../mapvoting.qh"
15 #include "../miscfunctions.qh"
17 #include "../mutators/events.qh"
19 #include "../../common/mapinfo.qh"
21 #include "../../common/command/generic.qh"
25 if(time - floor(time) > 0.5)
33 self.drawmask = MASK_NORMAL;
38 // =======================
39 // Command Sub-Functions
40 // =======================
42 void LocalCommand_blurtest(int request)
44 // Simple command to work with postprocessing temporarily... possibly completely pointless, the glsl shader is used for a real feature now...
45 // Anyway, to enable it, just compile the client with -DBLURTEST and then you can use the command.
50 case CMD_REQUEST_COMMAND:
52 blurtest_time0 = time;
53 blurtest_time1 = time + stof(argv(1));
54 blurtest_radius = stof(argv(2));
55 blurtest_power = stof(argv(3));
56 print("Enabled blurtest\n");
61 case CMD_REQUEST_USAGE:
63 print("\nUsage:^3 cl_cmd blurtest\n");
64 print(" No arguments required.\n");
71 print("Blurtest is not enabled on this client.\n");
77 void LocalCommand_boxparticles(int request, int argc)
81 case CMD_REQUEST_COMMAND:
85 int effect = particleeffectnum(argv(1));
88 int index = stoi(argv(2));
91 own = entitybyindex(-index);
93 own = findfloat(world, entnum, index);
94 vector org_from = stov(argv(3));
95 vector org_to = stov(argv(4));
96 vector dir_from = stov(argv(5));
97 vector dir_to = stov(argv(6));
98 int countmultiplier = stoi(argv(7));
99 int flags = stoi(argv(8));
100 boxparticles(effect, own, org_from, org_to, dir_from, dir_to, countmultiplier, flags);
107 print("Incorrect parameters for ^2boxparticles^7\n");
108 case CMD_REQUEST_USAGE:
110 print("\nUsage:^3 lv_cmd boxparticles effectname own org_from org_to, dir_from, dir_to, countmultiplier, flags\n");
111 print(" 'effectname' is the name of a particle effect in effectinfo.txt\n");
112 print(" 'own' is the entity number of the owner (negative for csqc ent, positive for svqc ent)\n");
113 print(" 'org_from' is the starting origin of the box\n");
114 print(" 'org_to' is the ending origin of the box\n");
115 print(" 'dir_from' is the minimum velocity\n");
116 print(" 'dir_to' is the maximum velocity\n");
117 print(" 'countmultiplier' defines a multiplier for the particle count (affects count only, not countabsolute or trailspacing)\n");
118 print(" 'flags' can contain:\n");
119 print(" 1 to respect globals particles_alphamin, particles_alphamax (set right before via prvm_globalset client)\n");
120 print(" 2 to respect globals particles_colormin, particles_colormax (set right before via prvm_globalset client)\n");
121 print(" 4 to respect globals particles_fade (set right before via prvm_globalset client)\n");
122 print(" 128 to draw a trail, not a box\n");
128 void LocalCommand_create_scrshot_ent(int request)
132 case CMD_REQUEST_COMMAND:
134 string filename = strcat(MapInfo_Map_bspname, "_scrshot_ent.txt");
135 int fh = fopen(filename, FILE_WRITE);
140 fputs(fh, strcat("\"classname\" \"info_autoscreenshot\"\n"));
141 fputs(fh, strcat("\"origin\" \"", strcat(ftos(view_origin.x), " ", ftos(view_origin.y), " ", ftos(view_origin.z)), "\"\n"));
142 fputs(fh, strcat("\"angles\" \"", strcat(ftos(view_angles.x), " ", ftos(view_angles.y), " ", ftos(view_angles.z)), "\"\n"));
145 print("Completed screenshot entity dump in ^2data/data/", MapInfo_Map_bspname, "_scrshot_ent.txt^7.\n");
151 print("^1Error: ^7Could not dump to file!\n");
157 case CMD_REQUEST_USAGE:
159 print("\nUsage:^3 cl_cmd create_scrshot_ent\n");
160 print(" No arguments required.\n");
166 void LocalCommand_debugmodel(int request, int argc)
170 case CMD_REQUEST_COMMAND:
172 string modelname = argv(1);
173 entity debugmodel_entity;
175 debugmodel_entity = spawn();
176 precache_model(modelname);
177 setmodel(debugmodel_entity, modelname);
178 setorigin(debugmodel_entity, view_origin);
179 debugmodel_entity.angles = view_angles;
180 debugmodel_entity.draw = DrawDebugModel;
181 debugmodel_entity.classname = "debugmodel";
187 case CMD_REQUEST_USAGE:
189 print("\nUsage:^3 cl_cmd debugmodel model\n");
190 print(" Where 'model' is a string of the model name to use for the debug model.\n");
196 void LocalCommand_handlevote(int request, int argc)
200 case CMD_REQUEST_COMMAND:
205 if(InterpretBoolean(argv(1)))
218 if(uid2name_dialog) // handled by "uid2name" option
223 localcmd(strcat("setreport cl_allow_uid2name ", ftos(vote_selection - 1), "\n"));
226 else { localcmd(strcat("cmd vote ", vote_string, "\n")); }
233 print("Incorrect parameters for ^2handlevote^7\n");
234 case CMD_REQUEST_USAGE:
236 print("\nUsage:^3 cl_cmd handlevote vote\n");
237 print(" Where 'vote' is the selection for either the current poll or uid2name.\n");
243 void LocalCommand_hud(int request, int argc)
247 case CMD_REQUEST_COMMAND:
253 cvar_set("_hud_configure", ftos(!autocvar__hud_configure));
259 if(QuickMenu_IsOpened())
262 QuickMenu_Open(argv(2), argv(3)); // mode, submenu
268 if(HUD_MinigameMenu_IsOpened())
269 HUD_MinigameMenu_Close();
271 HUD_MinigameMenu_Open();
279 HUD_Panel_ExportCfg(argv(2));
284 break; // go to usage, we're missing the paramater needed here.
288 case "scoreboard_columns_set":
290 Cmd_HUD_SetFields(argc);
294 case "scoreboard_columns_help":
303 HUD_Radar_Show_Maximized(InterpretBoolean(argv(2)),0);
305 HUD_Radar_Show_Maximized(!hud_panel_radar_maximized,0);
311 HUD_Radar_Show_Maximized(!hud_panel_radar_mouse,1);
318 print("Incorrect parameters for ^2hud^7\n");
319 case CMD_REQUEST_USAGE:
321 print("\nUsage:^3 cl_cmd hud action [configname | radartoggle | layout]\n");
322 print(" Where 'action' is the command to complete,\n");
323 print(" 'configname' is the name to save to for \"save\" action,\n");
324 print(" 'radartoggle' is to control hud_panel_radar_maximized for \"radar\" action,\n");
325 print(" and 'layout' is how to organize the scoreboard columns for the set action.\n");
326 print(" Full list of commands here: \"configure, quickmenu, minigame, save, scoreboard_columns_help, scoreboard_columns_set, radar.\"\n");
332 void LocalCommand_localprint(int request, int argc)
336 case CMD_REQUEST_COMMAND:
340 centerprint_hud(argv(1));
346 print("Incorrect parameters for ^2localprint^7\n");
347 case CMD_REQUEST_USAGE:
349 print("\nUsage:^3 cl_cmd localprint \"message\"\n");
350 print(" 'message' is the centerprint message to send to yourself.\n");
356 void LocalCommand_mv_download(int request, int argc)
360 case CMD_REQUEST_COMMAND:
364 Cmd_MapVote_MapDownload(argc);
370 print("Incorrect parameters for ^2mv_download^7\n");
371 case CMD_REQUEST_USAGE:
373 print("\nUsage:^3 cl_cmd mv_download mapid\n");
374 print(" Where 'mapid' is the id number of the map to request an image of on the map vote selection menu.\n");
380 void LocalCommand_find(int request, int argc)
384 case CMD_REQUEST_COMMAND:
388 for(client = world; (client = find(client, classname, argv(1))); )
389 print(etos(client), "\n");
395 print("Incorrect parameters for ^2find^7\n");
396 case CMD_REQUEST_USAGE:
398 print("\nUsage:^3 cl_cmd find classname\n");
399 print(" Where 'classname' is the classname to search for.\n");
405 void LocalCommand_sendcvar(int request, int argc)
409 case CMD_REQUEST_COMMAND:
413 // W_FixWeaponOrder will trash argv, so save what we need.
414 string thiscvar = strzone(argv(1));
415 string s = cvar_string(thiscvar);
417 if(thiscvar == "cl_weaponpriority")
418 s = W_FixWeaponOrder(W_NumberWeaponOrder(s), 1);
419 else if(substring(thiscvar, 0, 17) == "cl_weaponpriority" && strlen(thiscvar) == 18)
420 s = W_FixWeaponOrder(W_NumberWeaponOrder(s), 0);
422 localcmd("cmd sentcvar ", thiscvar, " \"", s, "\"\n");
429 print("Incorrect parameters for ^2sendcvar^7\n");
430 case CMD_REQUEST_USAGE:
432 print("\nUsage:^3 cl_cmd sendcvar <cvar>\n");
433 print(" Where 'cvar' is the cvar plus arguments to send to the server.\n");
439 /* use this when creating a new command, making sure to place it in alphabetical order... also,
440 ** ADD ALL NEW COMMANDS TO commands.cfg WITH PROPER ALIASES IN THE SAME FASHION!
441 void LocalCommand_(int request)
445 case CMD_REQUEST_COMMAND:
452 case CMD_REQUEST_USAGE:
454 print("\nUsage:^3 cl_cmd \n");
455 print(" No arguments required.\n");
463 // ==================================
464 // Macro system for client commands
465 // ==================================
467 // Normally do not hard code aliases for these, instead create them in commands.cfg... also: keep in alphabetical order, please ;)
468 #define CLIENT_COMMANDS(request,arguments) \
469 CLIENT_COMMAND("blurtest", LocalCommand_blurtest(request), "Feature for testing blur postprocessing") \
470 CLIENT_COMMAND("boxparticles", LocalCommand_boxparticles(request, arguments), "Spawn particles manually") \
471 CLIENT_COMMAND("create_scrshot_ent", LocalCommand_create_scrshot_ent(request), "Create an entity at this location for automatic screenshots") \
472 CLIENT_COMMAND("debugmodel", LocalCommand_debugmodel(request, arguments), "Spawn a debug model manually") \
473 CLIENT_COMMAND("handlevote", LocalCommand_handlevote(request, arguments), "System to handle selecting a vote or option") \
474 CLIENT_COMMAND("hud", LocalCommand_hud(request, arguments), "Commands regarding/controlling the HUD system") \
475 CLIENT_COMMAND("localprint", LocalCommand_localprint(request, arguments), "Create your own centerprint sent to yourself") \
476 CLIENT_COMMAND("find", LocalCommand_find(request, arguments), "Search through entities for matching classname") \
477 CLIENT_COMMAND("mv_download", LocalCommand_mv_download(request, arguments), "Retrieve mapshot picture from the server") \
478 CLIENT_COMMAND("sendcvar", LocalCommand_sendcvar(request, arguments), "Send a cvar to the server (like weaponpriority)") \
481 void LocalCommand_macro_help()
483 #define CLIENT_COMMAND(name,function,description) \
484 { if(strtolower(description) != "") { print(" ^2", name, "^7: ", description, "\n"); } }
486 CLIENT_COMMANDS(0, 0);
487 #undef CLIENT_COMMAND
492 bool LocalCommand_macro_command(int argc)
494 #define CLIENT_COMMAND(name,function,description) \
495 { if(name == strtolower(argv(0))) { function; return true; } }
497 CLIENT_COMMANDS(CMD_REQUEST_COMMAND, argc);
498 #undef CLIENT_COMMAND
503 bool LocalCommand_macro_usage(int argc)
505 #define CLIENT_COMMAND(name,function,description) \
506 { if(name == strtolower(argv(1))) { function; return true; } }
508 CLIENT_COMMANDS(CMD_REQUEST_USAGE, argc);
509 #undef CLIENT_COMMAND
514 void LocalCommand_macro_write_aliases(int fh)
516 #define CLIENT_COMMAND(name,function,description) \
517 { if(strtolower(description) != "") { CMD_Write_Alias("qc_cmd_cl", name, description); } }
519 CLIENT_COMMANDS(0, 0);
520 #undef CLIENT_COMMAND
526 // =========================================
527 // Main Function Called By Engine (cl_cmd)
528 // =========================================
529 // If this function exists, client code handles gamecommand instead of the engine code.
531 void GameCommand(string command)
533 int argc = tokenize_console(command);
535 // Guide for working with argc arguments by example:
536 // argc: 1 - 2 - 3 - 4
537 // argv: 0 - 1 - 2 - 3
538 // cmd vote - master - login - password
539 string s = strtolower(argv(0));
544 print("\nClient console commands:\n");
545 LocalCommand_macro_help();
547 print("\nGeneric commands shared by all programs:\n");
548 GenericCommand_macro_help();
550 print("\nUsage:^3 cl_cmd COMMAND...^7, where possible commands are listed above.\n");
551 print("For help about a specific command, type cl_cmd help COMMAND\n");
555 else if(GenericCommand_macro_usage(argc)) // Instead of trying to call a command, we're going to see detailed information about it
559 else if(LocalCommand_macro_usage(argc)) // now try for normal commands too
564 // continue as usual and scan for normal commands
565 if (GenericCommand(command)// handled by common/command/generic.qc
566 || LocalCommand_macro_command(argc) // handled by one of the above LocalCommand_* functions
567 || MUTATOR_CALLHOOK(CSQC_ConsoleCommand, s, argc, command) // handled by a mutator
570 // nothing above caught the command, must be invalid
571 print(((command != "") ? strcat("Unknown client command \"", command, "\"") : "No command provided"), ". For a list of supported commands, try cl_cmd help.\n");
577 // ===================================
578 // Macro system for console commands
579 // ===================================
581 // These functions are here specifically to add special + - commands to the game, and are not really normal commands.
582 // Please add client commands to the function above this, as this is only for special reasons.
583 #define CONSOLE_COMMANDS_NORMAL() \
584 CONSOLE_COMMAND("+showscores", { scoreboard_showscores = true; }) \
585 CONSOLE_COMMAND("-showscores", { scoreboard_showscores = false; }) \
586 CONSOLE_COMMAND("+showaccuracy", { scoreboard_showaccuracy = true; }) \
587 CONSOLE_COMMAND("-showaccuracy", { scoreboard_showaccuracy = false; }) \
590 #define CONSOLE_COMMANDS_MOVEMENT() \
591 CONSOLE_COMMAND("+forward", { ++camera_direction.x; }) \
592 CONSOLE_COMMAND("-forward", { --camera_direction.x; }) \
593 CONSOLE_COMMAND("+back", { --camera_direction.x; }) \
594 CONSOLE_COMMAND("-back", { ++camera_direction.x; }) \
595 CONSOLE_COMMAND("+moveup", { ++camera_direction.z; }) \
596 CONSOLE_COMMAND("-moveup", { --camera_direction.z; }) \
597 CONSOLE_COMMAND("+movedown", { --camera_direction.z; }) \
598 CONSOLE_COMMAND("-movedown", { ++camera_direction.z; }) \
599 CONSOLE_COMMAND("+moveright", { --camera_direction.y; }) \
600 CONSOLE_COMMAND("-moveright", { ++camera_direction.y; }) \
601 CONSOLE_COMMAND("+moveleft", { ++camera_direction.y; }) \
602 CONSOLE_COMMAND("-moveleft", { --camera_direction.y; }) \
603 CONSOLE_COMMAND("+roll_right", { ++camera_roll; }) \
604 CONSOLE_COMMAND("-roll_right", { --camera_roll; }) \
605 CONSOLE_COMMAND("+roll_left", { --camera_roll; }) \
606 CONSOLE_COMMAND("-roll_left", { ++camera_roll; }) \
609 void ConsoleCommand_macro_init()
611 // first init normal commands
612 #define CONSOLE_COMMAND(name,execution) \
613 { registercommand(name); }
615 CONSOLE_COMMANDS_NORMAL();
616 #undef CONSOLE_COMMAND
618 // then init movement commands
623 #define CONSOLE_COMMAND(name,execution) \
624 { registercommand(name); }
626 CONSOLE_COMMANDS_MOVEMENT();
627 #undef CONSOLE_COMMAND
633 bool ConsoleCommand_macro_normal(string s, int argc)
635 #define CONSOLE_COMMAND(name,execution) \
636 { if (name == s) { { execution } return true; } }
638 CONSOLE_COMMANDS_NORMAL();
639 #undef CONSOLE_COMMAND
644 bool ConsoleCommand_macro_movement(string s, int argc)
648 #define CONSOLE_COMMAND(name,execution) \
649 { if (name == s) { { execution } return true; } }
651 CONSOLE_COMMANDS_MOVEMENT();
652 #undef CONSOLE_COMMAND
659 // ======================================================
660 // Main Function Called By Engine (registered commands)
661 // ======================================================
662 // Used to parse commands in the console that have been registered with the "registercommand" function
664 bool CSQC_ConsoleCommand(string command)
666 int argc = tokenize_console(command);
667 string s = strtolower(argv(0));
668 // Return value should be true if CSQC handled the command, otherwise return false to have the engine handle it.
669 return (ConsoleCommand_macro_normal(s, argc)
670 || ConsoleCommand_macro_movement(s, argc)