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 "../../common/mapinfo.qh"
19 #include "../../common/command/generic.qh"
23 if(time - floor(time) > 0.5)
31 self.drawmask = MASK_NORMAL;
36 // =======================
37 // Command Sub-Functions
38 // =======================
40 void LocalCommand_blurtest(int request)
42 // Simple command to work with postprocessing temporarily... possibly completely pointless, the glsl shader is used for a real feature now...
43 // Anyway, to enable it, just compile the client with -DBLURTEST and then you can use the command.
48 case CMD_REQUEST_COMMAND:
50 blurtest_time0 = time;
51 blurtest_time1 = time + stof(argv(1));
52 blurtest_radius = stof(argv(2));
53 blurtest_power = stof(argv(3));
54 print("Enabled blurtest\n");
59 case CMD_REQUEST_USAGE:
61 print("\nUsage:^3 cl_cmd blurtest\n");
62 print(" No arguments required.\n");
69 print("Blurtest is not enabled on this client.\n");
75 void LocalCommand_boxparticles(int request, int argc)
79 case CMD_REQUEST_COMMAND:
83 int effect = particleeffectnum(argv(1));
86 int index = stoi(argv(2));
89 own = entitybyindex(-index);
91 own = findfloat(world, entnum, index);
92 vector org_from = stov(argv(3));
93 vector org_to = stov(argv(4));
94 vector dir_from = stov(argv(5));
95 vector dir_to = stov(argv(6));
96 int countmultiplier = stoi(argv(7));
97 int flags = stoi(argv(8));
98 boxparticles(effect, own, org_from, org_to, dir_from, dir_to, countmultiplier, flags);
105 print("Incorrect parameters for ^2boxparticles^7\n");
106 case CMD_REQUEST_USAGE:
108 print("\nUsage:^3 lv_cmd boxparticles effectname own org_from org_to, dir_from, dir_to, countmultiplier, flags\n");
109 print(" 'effectname' is the name of a particle effect in effectinfo.txt\n");
110 print(" 'own' is the entity number of the owner (negative for csqc ent, positive for svqc ent)\n");
111 print(" 'org_from' is the starting origin of the box\n");
112 print(" 'org_to' is the ending origin of the box\n");
113 print(" 'dir_from' is the minimum velocity\n");
114 print(" 'dir_to' is the maximum velocity\n");
115 print(" 'countmultiplier' defines a multiplier for the particle count (affects count only, not countabsolute or trailspacing)\n");
116 print(" 'flags' can contain:\n");
117 print(" 1 to respect globals particles_alphamin, particles_alphamax (set right before via prvm_globalset client)\n");
118 print(" 2 to respect globals particles_colormin, particles_colormax (set right before via prvm_globalset client)\n");
119 print(" 4 to respect globals particles_fade (set right before via prvm_globalset client)\n");
120 print(" 128 to draw a trail, not a box\n");
126 void LocalCommand_create_scrshot_ent(int request)
130 case CMD_REQUEST_COMMAND:
132 string filename = strcat(MapInfo_Map_bspname, "_scrshot_ent.txt");
133 int fh = fopen(filename, FILE_WRITE);
138 fputs(fh, strcat("\"classname\" \"info_autoscreenshot\"\n"));
139 fputs(fh, strcat("\"origin\" \"", strcat(ftos(view_origin.x), " ", ftos(view_origin.y), " ", ftos(view_origin.z)), "\"\n"));
140 fputs(fh, strcat("\"angles\" \"", strcat(ftos(view_angles.x), " ", ftos(view_angles.y), " ", ftos(view_angles.z)), "\"\n"));
143 print("Completed screenshot entity dump in ^2data/data/", MapInfo_Map_bspname, "_scrshot_ent.txt^7.\n");
149 print("^1Error: ^7Could not dump to file!\n");
155 case CMD_REQUEST_USAGE:
157 print("\nUsage:^3 cl_cmd create_scrshot_ent\n");
158 print(" No arguments required.\n");
164 void LocalCommand_debugmodel(int request, int argc)
168 case CMD_REQUEST_COMMAND:
170 string modelname = argv(1);
171 entity debugmodel_entity;
173 debugmodel_entity = spawn();
174 precache_model(modelname);
175 setmodel(debugmodel_entity, modelname);
176 setorigin(debugmodel_entity, view_origin);
177 debugmodel_entity.angles = view_angles;
178 debugmodel_entity.draw = DrawDebugModel;
179 debugmodel_entity.classname = "debugmodel";
185 case CMD_REQUEST_USAGE:
187 print("\nUsage:^3 cl_cmd debugmodel model\n");
188 print(" Where 'model' is a string of the model name to use for the debug model.\n");
194 void LocalCommand_handlevote(int request, int argc)
198 case CMD_REQUEST_COMMAND:
203 if(InterpretBoolean(argv(1)))
216 if(uid2name_dialog) // handled by "uid2name" option
221 localcmd(strcat("setreport cl_allow_uid2name ", ftos(vote_selection - 1), "\n"));
224 else { localcmd(strcat("cmd vote ", vote_string, "\n")); }
231 print("Incorrect parameters for ^2handlevote^7\n");
232 case CMD_REQUEST_USAGE:
234 print("\nUsage:^3 cl_cmd handlevote vote\n");
235 print(" Where 'vote' is the selection for either the current poll or uid2name.\n");
241 void LocalCommand_hud(int request, int argc)
245 case CMD_REQUEST_COMMAND:
251 cvar_set("_hud_configure", ftos(!autocvar__hud_configure));
259 HUD_Panel_ExportCfg(argv(2));
264 break; // go to usage, we're missing the paramater needed here.
268 case "scoreboard_columns_set":
270 Cmd_HUD_SetFields(argc);
274 case "scoreboard_columns_help":
283 hud_panel_radar_maximized = InterpretBoolean(argv(2));
285 hud_panel_radar_maximized = !hud_panel_radar_maximized;
292 print("Incorrect parameters for ^2hud^7\n");
293 case CMD_REQUEST_USAGE:
295 print("\nUsage:^3 cl_cmd hud action [configname | radartoggle | layout]\n");
296 print(" Where 'action' is the command to complete,\n");
297 print(" 'configname' is the name to save to for \"save\" action,\n");
298 print(" 'radartoggle' is to control hud_panel_radar_maximized for \"radar\" action,\n");
299 print(" and 'layout' is how to organize the scoreboard columns for the set action.\n");
300 print(" Full list of commands here: \"configure, save, scoreboard_columns_help, scoreboard_columns_set, radar.\"\n");
306 void LocalCommand_localprint(int request, int argc)
310 case CMD_REQUEST_COMMAND:
314 centerprint_hud(argv(1));
320 print("Incorrect parameters for ^2localprint^7\n");
321 case CMD_REQUEST_USAGE:
323 print("\nUsage:^3 cl_cmd localprint \"message\"\n");
324 print(" 'message' is the centerprint message to send to yourself.\n");
330 void LocalCommand_mv_download(int request, int argc)
334 case CMD_REQUEST_COMMAND:
338 Cmd_MapVote_MapDownload(argc);
344 print("Incorrect parameters for ^2mv_download^7\n");
345 case CMD_REQUEST_USAGE:
347 print("\nUsage:^3 cl_cmd mv_download mapid\n");
348 print(" Where 'mapid' is the id number of the map to request an image of on the map vote selection menu.\n");
354 void LocalCommand_find(int request, int argc)
358 case CMD_REQUEST_COMMAND:
362 for(client = world; (client = find(client, classname, argv(1))); )
363 print(etos(client), "\n");
369 print("Incorrect parameters for ^2find^7\n");
370 case CMD_REQUEST_USAGE:
372 print("\nUsage:^3 cl_cmd find classname\n");
373 print(" Where 'classname' is the classname to search for.\n");
379 void LocalCommand_sendcvar(int request, int argc)
383 case CMD_REQUEST_COMMAND:
387 // W_FixWeaponOrder will trash argv, so save what we need.
388 string thiscvar = strzone(argv(1));
389 string s = cvar_string(thiscvar);
391 if(thiscvar == "cl_weaponpriority")
392 s = W_FixWeaponOrder(W_NumberWeaponOrder(s), 1);
393 else if(substring(thiscvar, 0, 17) == "cl_weaponpriority" && strlen(thiscvar) == 18)
394 s = W_FixWeaponOrder(W_NumberWeaponOrder(s), 0);
396 localcmd("cmd sentcvar ", thiscvar, " \"", s, "\"\n");
403 print("Incorrect parameters for ^2sendcvar^7\n");
404 case CMD_REQUEST_USAGE:
406 print("\nUsage:^3 cl_cmd sendcvar <cvar>\n");
407 print(" Where 'cvar' is the cvar plus arguments to send to the server.\n");
413 /* use this when creating a new command, making sure to place it in alphabetical order... also,
414 ** ADD ALL NEW COMMANDS TO commands.cfg WITH PROPER ALIASES IN THE SAME FASHION!
415 void LocalCommand_(int request)
419 case CMD_REQUEST_COMMAND:
426 case CMD_REQUEST_USAGE:
428 print("\nUsage:^3 cl_cmd \n");
429 print(" No arguments required.\n");
437 // ==================================
438 // Macro system for client commands
439 // ==================================
441 // Normally do not hard code aliases for these, instead create them in commands.cfg... also: keep in alphabetical order, please ;)
442 #define CLIENT_COMMANDS(request,arguments) \
443 CLIENT_COMMAND("blurtest", LocalCommand_blurtest(request), "Feature for testing blur postprocessing") \
444 CLIENT_COMMAND("boxparticles", LocalCommand_boxparticles(request, arguments), "Spawn particles manually") \
445 CLIENT_COMMAND("create_scrshot_ent", LocalCommand_create_scrshot_ent(request), "Create an entity at this location for automatic screenshots") \
446 CLIENT_COMMAND("debugmodel", LocalCommand_debugmodel(request, arguments), "Spawn a debug model manually") \
447 CLIENT_COMMAND("handlevote", LocalCommand_handlevote(request, arguments), "System to handle selecting a vote or option") \
448 CLIENT_COMMAND("hud", LocalCommand_hud(request, arguments), "Commands regarding/controlling the HUD system") \
449 CLIENT_COMMAND("localprint", LocalCommand_localprint(request, arguments), "Create your own centerprint sent to yourself") \
450 CLIENT_COMMAND("find", LocalCommand_find(request, arguments), "Search through entities for matching classname") \
451 CLIENT_COMMAND("mv_download", LocalCommand_mv_download(request, arguments), "Retrieve mapshot picture from the server") \
452 CLIENT_COMMAND("sendcvar", LocalCommand_sendcvar(request, arguments), "Send a cvar to the server (like weaponpriority)") \
455 void LocalCommand_macro_help()
457 #define CLIENT_COMMAND(name,function,description) \
458 { if(strtolower(description) != "") { print(" ^2", name, "^7: ", description, "\n"); } }
460 CLIENT_COMMANDS(0, 0);
461 #undef CLIENT_COMMAND
466 bool LocalCommand_macro_command(int argc)
468 #define CLIENT_COMMAND(name,function,description) \
469 { if(name == strtolower(argv(0))) { function; return true; } }
471 CLIENT_COMMANDS(CMD_REQUEST_COMMAND, argc);
472 #undef CLIENT_COMMAND
477 bool LocalCommand_macro_usage(int argc)
479 #define CLIENT_COMMAND(name,function,description) \
480 { if(name == strtolower(argv(1))) { function; return true; } }
482 CLIENT_COMMANDS(CMD_REQUEST_USAGE, argc);
483 #undef CLIENT_COMMAND
488 void LocalCommand_macro_write_aliases(int fh)
490 #define CLIENT_COMMAND(name,function,description) \
491 { if(strtolower(description) != "") { CMD_Write_Alias("qc_cmd_cl", name, description); } }
493 CLIENT_COMMANDS(0, 0);
494 #undef CLIENT_COMMAND
500 // =========================================
501 // Main Function Called By Engine (cl_cmd)
502 // =========================================
503 // If this function exists, client code handles gamecommand instead of the engine code.
505 void GameCommand(string command)
507 int argc = tokenize_console(command);
509 // Guide for working with argc arguments by example:
510 // argc: 1 - 2 - 3 - 4
511 // argv: 0 - 1 - 2 - 3
512 // cmd vote - master - login - password
514 if(strtolower(argv(0)) == "help")
518 print("\nClient console commands:\n");
519 LocalCommand_macro_help();
521 print("\nGeneric commands shared by all programs:\n");
522 GenericCommand_macro_help();
524 print("\nUsage:^3 cl_cmd COMMAND...^7, where possible commands are listed above.\n");
525 print("For help about a specific command, type cl_cmd help COMMAND\n");
529 else if(GenericCommand_macro_usage(argc)) // Instead of trying to call a command, we're going to see detailed information about it
533 else if(LocalCommand_macro_usage(argc)) // now try for normal commands too
538 else if(GenericCommand(command))
540 return; // handled by common/command/generic.qc
542 else if(LocalCommand_macro_command(argc)) // continue as usual and scan for normal commands
544 return; // handled by one of the above LocalCommand_* functions
547 // nothing above caught the command, must be invalid
548 print(((command != "") ? strcat("Unknown client command \"", command, "\"") : "No command provided"), ". For a list of supported commands, try cl_cmd help.\n");
554 // ===================================
555 // Macro system for console commands
556 // ===================================
558 // These functions are here specifically to add special + - commands to the game, and are not really normal commands.
559 // Please add client commands to the function above this, as this is only for special reasons.
560 #define CONSOLE_COMMANDS_NORMAL() \
561 CONSOLE_COMMAND("+showscores", { scoreboard_showscores = true; }) \
562 CONSOLE_COMMAND("-showscores", { scoreboard_showscores = false; }) \
563 CONSOLE_COMMAND("+showaccuracy", { scoreboard_showaccuracy = true; }) \
564 CONSOLE_COMMAND("-showaccuracy", { scoreboard_showaccuracy = false; }) \
567 #define CONSOLE_COMMANDS_MOVEMENT() \
568 CONSOLE_COMMAND("+forward", { ++camera_direction.x; }) \
569 CONSOLE_COMMAND("-forward", { --camera_direction.x; }) \
570 CONSOLE_COMMAND("+back", { --camera_direction.x; }) \
571 CONSOLE_COMMAND("-back", { ++camera_direction.x; }) \
572 CONSOLE_COMMAND("+moveup", { ++camera_direction.z; }) \
573 CONSOLE_COMMAND("-moveup", { --camera_direction.z; }) \
574 CONSOLE_COMMAND("+movedown", { --camera_direction.z; }) \
575 CONSOLE_COMMAND("-movedown", { ++camera_direction.z; }) \
576 CONSOLE_COMMAND("+moveright", { --camera_direction.y; }) \
577 CONSOLE_COMMAND("-moveright", { ++camera_direction.y; }) \
578 CONSOLE_COMMAND("+moveleft", { ++camera_direction.y; }) \
579 CONSOLE_COMMAND("-moveleft", { --camera_direction.y; }) \
580 CONSOLE_COMMAND("+roll_right", { ++camera_roll; }) \
581 CONSOLE_COMMAND("-roll_right", { --camera_roll; }) \
582 CONSOLE_COMMAND("+roll_left", { --camera_roll; }) \
583 CONSOLE_COMMAND("-roll_left", { ++camera_roll; }) \
586 void ConsoleCommand_macro_init()
588 // first init normal commands
589 #define CONSOLE_COMMAND(name,execution) \
590 { registercommand(name); }
592 CONSOLE_COMMANDS_NORMAL();
593 #undef CONSOLE_COMMAND
595 // then init movement commands
600 #define CONSOLE_COMMAND(name,execution) \
601 { registercommand(name); }
603 CONSOLE_COMMANDS_MOVEMENT();
604 #undef CONSOLE_COMMAND
612 bool ConsoleCommand_macro_normal(int argc)
614 #define CONSOLE_COMMAND(name,execution) \
615 { if(name == strtolower(argv(0))) { { execution } return true; } }
617 CONSOLE_COMMANDS_NORMAL();
618 #undef CONSOLE_COMMAND
623 bool ConsoleCommand_macro_movement(int argc)
627 #define CONSOLE_COMMAND(name,execution) \
628 { if(name == strtolower(argv(0))) { { execution } return true; } }
630 CONSOLE_COMMANDS_MOVEMENT();
631 #undef CONSOLE_COMMAND
638 // ======================================================
639 // Main Function Called By Engine (registered commands)
640 // ======================================================
641 // Used to parse commands in the console that have been registered with the "registercommand" function
643 bool CSQC_ConsoleCommand(string command)
645 int argc = tokenize_console(command);
647 if(ConsoleCommand_macro_normal(argc))
651 else if(ConsoleCommand_macro_movement(argc))
656 // Return value should be 1 if CSQC handled the command, otherwise return 0 to have the engine handle it.