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_sendcvar(int request, int argc)
358 case CMD_REQUEST_COMMAND:
362 // W_FixWeaponOrder will trash argv, so save what we need.
363 string thiscvar = strzone(argv(1));
364 string s = cvar_string(thiscvar);
366 if(thiscvar == "cl_weaponpriority")
367 s = W_FixWeaponOrder(W_NumberWeaponOrder(s), 1);
368 else if(substring(thiscvar, 0, 17) == "cl_weaponpriority" && strlen(thiscvar) == 18)
369 s = W_FixWeaponOrder(W_NumberWeaponOrder(s), 0);
371 localcmd("cmd sentcvar ", thiscvar, " \"", s, "\"\n");
378 print("Incorrect parameters for ^2sendcvar^7\n");
379 case CMD_REQUEST_USAGE:
381 print("\nUsage:^3 cl_cmd sendcvar <cvar>\n");
382 print(" Where 'cvar' is the cvar plus arguments to send to the server.\n");
388 /* use this when creating a new command, making sure to place it in alphabetical order... also,
389 ** ADD ALL NEW COMMANDS TO commands.cfg WITH PROPER ALIASES IN THE SAME FASHION!
390 void LocalCommand_(int request)
394 case CMD_REQUEST_COMMAND:
401 case CMD_REQUEST_USAGE:
403 print("\nUsage:^3 cl_cmd \n");
404 print(" No arguments required.\n");
412 // ==================================
413 // Macro system for client commands
414 // ==================================
416 // Normally do not hard code aliases for these, instead create them in commands.cfg... also: keep in alphabetical order, please ;)
417 #define CLIENT_COMMANDS(request,arguments) \
418 CLIENT_COMMAND("blurtest", LocalCommand_blurtest(request), "Feature for testing blur postprocessing") \
419 CLIENT_COMMAND("boxparticles", LocalCommand_boxparticles(request, arguments), "Spawn particles manually") \
420 CLIENT_COMMAND("create_scrshot_ent", LocalCommand_create_scrshot_ent(request), "Create an entity at this location for automatic screenshots") \
421 CLIENT_COMMAND("debugmodel", LocalCommand_debugmodel(request, arguments), "Spawn a debug model manually") \
422 CLIENT_COMMAND("handlevote", LocalCommand_handlevote(request, arguments), "System to handle selecting a vote or option") \
423 CLIENT_COMMAND("hud", LocalCommand_hud(request, arguments), "Commands regarding/controlling the HUD system") \
424 CLIENT_COMMAND("localprint", LocalCommand_localprint(request, arguments), "Create your own centerprint sent to yourself") \
425 CLIENT_COMMAND("mv_download", LocalCommand_mv_download(request, arguments), "Retrieve mapshot picture from the server") \
426 CLIENT_COMMAND("sendcvar", LocalCommand_sendcvar(request, arguments), "Send a cvar to the server (like weaponpriority)") \
429 void LocalCommand_macro_help()
431 #define CLIENT_COMMAND(name,function,description) \
432 { if(strtolower(description) != "") { print(" ^2", name, "^7: ", description, "\n"); } }
434 CLIENT_COMMANDS(0, 0);
435 #undef CLIENT_COMMAND
440 bool LocalCommand_macro_command(int argc)
442 #define CLIENT_COMMAND(name,function,description) \
443 { if(name == strtolower(argv(0))) { function; return true; } }
445 CLIENT_COMMANDS(CMD_REQUEST_COMMAND, argc);
446 #undef CLIENT_COMMAND
451 bool LocalCommand_macro_usage(int argc)
453 #define CLIENT_COMMAND(name,function,description) \
454 { if(name == strtolower(argv(1))) { function; return true; } }
456 CLIENT_COMMANDS(CMD_REQUEST_USAGE, argc);
457 #undef CLIENT_COMMAND
462 void LocalCommand_macro_write_aliases(int fh)
464 #define CLIENT_COMMAND(name,function,description) \
465 { if(strtolower(description) != "") { CMD_Write_Alias("qc_cmd_cl", name, description); } }
467 CLIENT_COMMANDS(0, 0);
468 #undef CLIENT_COMMAND
474 // =========================================
475 // Main Function Called By Engine (cl_cmd)
476 // =========================================
477 // If this function exists, client code handles gamecommand instead of the engine code.
479 void GameCommand(string command)
481 int argc = tokenize_console(command);
483 // Guide for working with argc arguments by example:
484 // argc: 1 - 2 - 3 - 4
485 // argv: 0 - 1 - 2 - 3
486 // cmd vote - master - login - password
488 if(strtolower(argv(0)) == "help")
492 print("\nClient console commands:\n");
493 LocalCommand_macro_help();
495 print("\nGeneric commands shared by all programs:\n");
496 GenericCommand_macro_help();
498 print("\nUsage:^3 cl_cmd COMMAND...^7, where possible commands are listed above.\n");
499 print("For help about a specific command, type cl_cmd help COMMAND\n");
503 else if(GenericCommand_macro_usage(argc)) // Instead of trying to call a command, we're going to see detailed information about it
507 else if(LocalCommand_macro_usage(argc)) // now try for normal commands too
512 else if(GenericCommand(command))
514 return; // handled by common/command/generic.qc
516 else if(LocalCommand_macro_command(argc)) // continue as usual and scan for normal commands
518 return; // handled by one of the above LocalCommand_* functions
521 // nothing above caught the command, must be invalid
522 print(((command != "") ? strcat("Unknown client command \"", command, "\"") : "No command provided"), ". For a list of supported commands, try cl_cmd help.\n");
528 // ===================================
529 // Macro system for console commands
530 // ===================================
532 // These functions are here specifically to add special + - commands to the game, and are not really normal commands.
533 // Please add client commands to the function above this, as this is only for special reasons.
534 #define CONSOLE_COMMANDS_NORMAL() \
535 CONSOLE_COMMAND("+showscores", { scoreboard_showscores = true; }) \
536 CONSOLE_COMMAND("-showscores", { scoreboard_showscores = false; }) \
537 CONSOLE_COMMAND("+showaccuracy", { scoreboard_showaccuracy = true; }) \
538 CONSOLE_COMMAND("-showaccuracy", { scoreboard_showaccuracy = false; }) \
541 #define CONSOLE_COMMANDS_MOVEMENT() \
542 CONSOLE_COMMAND("+forward", { ++camera_direction.x; }) \
543 CONSOLE_COMMAND("-forward", { --camera_direction.x; }) \
544 CONSOLE_COMMAND("+back", { --camera_direction.x; }) \
545 CONSOLE_COMMAND("-back", { ++camera_direction.x; }) \
546 CONSOLE_COMMAND("+moveup", { ++camera_direction.z; }) \
547 CONSOLE_COMMAND("-moveup", { --camera_direction.z; }) \
548 CONSOLE_COMMAND("+movedown", { --camera_direction.z; }) \
549 CONSOLE_COMMAND("-movedown", { ++camera_direction.z; }) \
550 CONSOLE_COMMAND("+moveright", { --camera_direction.y; }) \
551 CONSOLE_COMMAND("-moveright", { ++camera_direction.y; }) \
552 CONSOLE_COMMAND("+moveleft", { ++camera_direction.y; }) \
553 CONSOLE_COMMAND("-moveleft", { --camera_direction.y; }) \
554 CONSOLE_COMMAND("+roll_right", { ++camera_roll; }) \
555 CONSOLE_COMMAND("-roll_right", { --camera_roll; }) \
556 CONSOLE_COMMAND("+roll_left", { --camera_roll; }) \
557 CONSOLE_COMMAND("-roll_left", { ++camera_roll; }) \
560 void ConsoleCommand_macro_init()
562 // first init normal commands
563 #define CONSOLE_COMMAND(name,execution) \
564 { registercommand(name); }
566 CONSOLE_COMMANDS_NORMAL();
567 #undef CONSOLE_COMMAND
569 // then init movement commands
574 #define CONSOLE_COMMAND(name,execution) \
575 { registercommand(name); }
577 CONSOLE_COMMANDS_MOVEMENT();
578 #undef CONSOLE_COMMAND
586 bool ConsoleCommand_macro_normal(int argc)
588 #define CONSOLE_COMMAND(name,execution) \
589 { if(name == strtolower(argv(0))) { { execution } return true; } }
591 CONSOLE_COMMANDS_NORMAL();
592 #undef CONSOLE_COMMAND
597 bool ConsoleCommand_macro_movement(int argc)
601 #define CONSOLE_COMMAND(name,execution) \
602 { if(name == strtolower(argv(0))) { { execution } return true; } }
604 CONSOLE_COMMANDS_MOVEMENT();
605 #undef CONSOLE_COMMAND
612 // ======================================================
613 // Main Function Called By Engine (registered commands)
614 // ======================================================
615 // Used to parse commands in the console that have been registered with the "registercommand" function
617 bool CSQC_ConsoleCommand(string command)
619 int argc = tokenize_console(command);
621 if(ConsoleCommand_macro_normal(argc))
625 else if(ConsoleCommand_macro_movement(argc))
630 // Return value should be 1 if CSQC handled the command, otherwise return 0 to have the engine handle it.