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(int 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_boxparticles(int request, int argc)
64 case CMD_REQUEST_COMMAND:
68 int effect = particleeffectnum(argv(1));
71 int index = stoi(argv(2));
74 own = entitybyindex(-index);
76 own = findfloat(world, entnum, index);
77 vector org_from = stov(argv(3));
78 vector org_to = stov(argv(4));
79 vector dir_from = stov(argv(5));
80 vector dir_to = stov(argv(6));
81 int countmultiplier = stoi(argv(7));
82 int flags = stoi(argv(8));
83 boxparticles(effect, own, org_from, org_to, dir_from, dir_to, countmultiplier, flags);
90 print("Incorrect parameters for ^2boxparticles^7\n");
91 case CMD_REQUEST_USAGE:
93 print("\nUsage:^3 lv_cmd boxparticles effectname own org_from org_to, dir_from, dir_to, countmultiplier, flags\n");
94 print(" 'effectname' is the name of a particle effect in effectinfo.txt\n");
95 print(" 'own' is the entity number of the owner (negative for csqc ent, positive for svqc ent)\n");
96 print(" 'org_from' is the starting origin of the box\n");
97 print(" 'org_to' is the ending origin of the box\n");
98 print(" 'dir_from' is the minimum velocity\n");
99 print(" 'dir_to' is the maximum velocity\n");
100 print(" 'countmultiplier' defines a multiplier for the particle count (affects count only, not countabsolute or trailspacing)\n");
101 print(" 'flags' can contain:\n");
102 print(" 1 to respect globals particles_alphamin, particles_alphamax (set right before via prvm_globalset client)\n");
103 print(" 2 to respect globals particles_colormin, particles_colormax (set right before via prvm_globalset client)\n");
104 print(" 4 to respect globals particles_fade (set right before via prvm_globalset client)\n");
105 print(" 128 to draw a trail, not a box\n");
111 void LocalCommand_create_scrshot_ent(int request)
115 case CMD_REQUEST_COMMAND:
117 string filename = strcat(MapInfo_Map_bspname, "_scrshot_ent.txt");
118 int fh = fopen(filename, FILE_WRITE);
123 fputs(fh, strcat("\"classname\" \"info_autoscreenshot\"\n"));
124 fputs(fh, strcat("\"origin\" \"", strcat(ftos(view_origin.x), " ", ftos(view_origin.y), " ", ftos(view_origin.z)), "\"\n"));
125 fputs(fh, strcat("\"angles\" \"", strcat(ftos(view_angles.x), " ", ftos(view_angles.y), " ", ftos(view_angles.z)), "\"\n"));
128 print("Completed screenshot entity dump in ^2data/data/", MapInfo_Map_bspname, "_scrshot_ent.txt^7.\n");
134 print("^1Error: ^7Could not dump to file!\n");
140 case CMD_REQUEST_USAGE:
142 print("\nUsage:^3 cl_cmd create_scrshot_ent\n");
143 print(" No arguments required.\n");
149 void LocalCommand_debugmodel(int request, int argc)
153 case CMD_REQUEST_COMMAND:
155 string modelname = argv(1);
156 entity debugmodel_entity;
158 debugmodel_entity = spawn();
159 precache_model(modelname);
160 setmodel(debugmodel_entity, modelname);
161 setorigin(debugmodel_entity, view_origin);
162 debugmodel_entity.angles = view_angles;
163 debugmodel_entity.draw = DrawDebugModel;
164 debugmodel_entity.classname = "debugmodel";
170 case CMD_REQUEST_USAGE:
172 print("\nUsage:^3 cl_cmd debugmodel model\n");
173 print(" Where 'model' is a string of the model name to use for the debug model.\n");
179 void LocalCommand_handlevote(int request, int argc)
183 case CMD_REQUEST_COMMAND:
188 if(InterpretBoolean(argv(1)))
201 if(uid2name_dialog) // handled by "uid2name" option
206 localcmd(strcat("setreport cl_allow_uid2name ", ftos(vote_selection - 1), "\n"));
209 else { localcmd(strcat("cmd vote ", vote_string, "\n")); }
216 print("Incorrect parameters for ^2handlevote^7\n");
217 case CMD_REQUEST_USAGE:
219 print("\nUsage:^3 cl_cmd handlevote vote\n");
220 print(" Where 'vote' is the selection for either the current poll or uid2name.\n");
226 void LocalCommand_hud(int request, int argc)
230 case CMD_REQUEST_COMMAND:
236 cvar_set("_hud_configure", ftos(!autocvar__hud_configure));
244 HUD_Panel_ExportCfg(argv(2));
249 break; // go to usage, we're missing the paramater needed here.
253 case "scoreboard_columns_set":
255 Cmd_HUD_SetFields(argc);
259 case "scoreboard_columns_help":
268 hud_panel_radar_maximized = InterpretBoolean(argv(2));
270 hud_panel_radar_maximized = !hud_panel_radar_maximized;
277 print("Incorrect parameters for ^2hud^7\n");
278 case CMD_REQUEST_USAGE:
280 print("\nUsage:^3 cl_cmd hud action [configname | radartoggle | layout]\n");
281 print(" Where 'action' is the command to complete,\n");
282 print(" 'configname' is the name to save to for \"save\" action,\n");
283 print(" 'radartoggle' is to control hud_panel_radar_maximized for \"radar\" action,\n");
284 print(" and 'layout' is how to organize the scoreboard columns for the set action.\n");
285 print(" Full list of commands here: \"configure, save, scoreboard_columns_help, scoreboard_columns_set, radar.\"\n");
291 void LocalCommand_localprint(int request, int argc)
295 case CMD_REQUEST_COMMAND:
299 centerprint_hud(argv(1));
305 print("Incorrect parameters for ^2localprint^7\n");
306 case CMD_REQUEST_USAGE:
308 print("\nUsage:^3 cl_cmd localprint \"message\"\n");
309 print(" 'message' is the centerprint message to send to yourself.\n");
315 void LocalCommand_mv_download(int request, int argc)
319 case CMD_REQUEST_COMMAND:
323 Cmd_MapVote_MapDownload(argc);
329 print("Incorrect parameters for ^2mv_download^7\n");
330 case CMD_REQUEST_USAGE:
332 print("\nUsage:^3 cl_cmd mv_download mapid\n");
333 print(" Where 'mapid' is the id number of the map to request an image of on the map vote selection menu.\n");
339 void LocalCommand_sendcvar(int request, int argc)
343 case CMD_REQUEST_COMMAND:
347 // W_FixWeaponOrder will trash argv, so save what we need.
348 string thiscvar = strzone(argv(1));
349 string s = cvar_string(thiscvar);
351 if(thiscvar == "cl_weaponpriority")
352 s = W_FixWeaponOrder(W_NumberWeaponOrder(s), 1);
353 else if(substring(thiscvar, 0, 17) == "cl_weaponpriority" && strlen(thiscvar) == 18)
354 s = W_FixWeaponOrder(W_NumberWeaponOrder(s), 0);
356 localcmd("cmd sentcvar ", thiscvar, " \"", s, "\"\n");
363 print("Incorrect parameters for ^2sendcvar^7\n");
364 case CMD_REQUEST_USAGE:
366 print("\nUsage:^3 cl_cmd sendcvar <cvar>\n");
367 print(" Where 'cvar' is the cvar plus arguments to send to the server.\n");
373 /* use this when creating a new command, making sure to place it in alphabetical order... also,
374 ** ADD ALL NEW COMMANDS TO commands.cfg WITH PROPER ALIASES IN THE SAME FASHION!
375 void LocalCommand_(int request)
379 case CMD_REQUEST_COMMAND:
386 case CMD_REQUEST_USAGE:
388 print("\nUsage:^3 cl_cmd \n");
389 print(" No arguments required.\n");
397 // ==================================
398 // Macro system for client commands
399 // ==================================
401 // Normally do not hard code aliases for these, instead create them in commands.cfg... also: keep in alphabetical order, please ;)
402 #define CLIENT_COMMANDS(request,arguments) \
403 CLIENT_COMMAND("blurtest", LocalCommand_blurtest(request), "Feature for testing blur postprocessing") \
404 CLIENT_COMMAND("boxparticles", LocalCommand_boxparticles(request, arguments), "Spawn particles manually") \
405 CLIENT_COMMAND("create_scrshot_ent", LocalCommand_create_scrshot_ent(request), "Create an entity at this location for automatic screenshots") \
406 CLIENT_COMMAND("debugmodel", LocalCommand_debugmodel(request, arguments), "Spawn a debug model manually") \
407 CLIENT_COMMAND("handlevote", LocalCommand_handlevote(request, arguments), "System to handle selecting a vote or option") \
408 CLIENT_COMMAND("hud", LocalCommand_hud(request, arguments), "Commands regarding/controlling the HUD system") \
409 CLIENT_COMMAND("localprint", LocalCommand_localprint(request, arguments), "Create your own centerprint sent to yourself") \
410 CLIENT_COMMAND("mv_download", LocalCommand_mv_download(request, arguments), "Retrieve mapshot picture from the server") \
411 CLIENT_COMMAND("sendcvar", LocalCommand_sendcvar(request, arguments), "Send a cvar to the server (like weaponpriority)") \
414 void LocalCommand_macro_help()
416 #define CLIENT_COMMAND(name,function,description) \
417 { if(strtolower(description) != "") { print(" ^2", name, "^7: ", description, "\n"); } }
419 CLIENT_COMMANDS(0, 0)
420 #undef CLIENT_COMMAND
425 bool LocalCommand_macro_command(int argc)
427 #define CLIENT_COMMAND(name,function,description) \
428 { if(name == strtolower(argv(0))) { function; return true; } }
430 CLIENT_COMMANDS(CMD_REQUEST_COMMAND, argc)
431 #undef CLIENT_COMMAND
436 bool LocalCommand_macro_usage(int argc)
438 #define CLIENT_COMMAND(name,function,description) \
439 { if(name == strtolower(argv(1))) { function; return true; } }
441 CLIENT_COMMANDS(CMD_REQUEST_USAGE, argc)
442 #undef CLIENT_COMMAND
447 void LocalCommand_macro_write_aliases(int fh)
449 #define CLIENT_COMMAND(name,function,description) \
450 { if(strtolower(description) != "") { CMD_Write_Alias("qc_cmd_cl", name, description); } }
452 CLIENT_COMMANDS(0, 0)
453 #undef CLIENT_COMMAND
459 // =========================================
460 // Main Function Called By Engine (cl_cmd)
461 // =========================================
462 // If this function exists, client code handles gamecommand instead of the engine code.
464 void GameCommand(string command)
466 int argc = tokenize_console(command);
468 // Guide for working with argc arguments by example:
469 // argc: 1 - 2 - 3 - 4
470 // argv: 0 - 1 - 2 - 3
471 // cmd vote - master - login - password
473 if(strtolower(argv(0)) == "help")
477 print("\nClient console commands:\n");
478 LocalCommand_macro_help();
480 print("\nGeneric commands shared by all programs:\n");
481 GenericCommand_macro_help();
483 print("\nUsage:^3 cl_cmd COMMAND...^7, where possible commands are listed above.\n");
484 print("For help about a specific command, type cl_cmd help COMMAND\n");
488 else if(GenericCommand_macro_usage(argc)) // Instead of trying to call a command, we're going to see detailed information about it
492 else if(LocalCommand_macro_usage(argc)) // now try for normal commands too
497 else if(GenericCommand(command))
499 return; // handled by common/command/generic.qc
501 else if(LocalCommand_macro_command(argc)) // continue as usual and scan for normal commands
503 return; // handled by one of the above LocalCommand_* functions
506 // nothing above caught the command, must be invalid
507 print(((command != "") ? strcat("Unknown client command \"", command, "\"") : "No command provided"), ". For a list of supported commands, try cl_cmd help.\n");
513 // ===================================
514 // Macro system for console commands
515 // ===================================
517 // These functions are here specifically to add special + - commands to the game, and are not really normal commands.
518 // Please add client commands to the function above this, as this is only for special reasons.
519 #define CONSOLE_COMMANDS_NORMAL \
520 CONSOLE_COMMAND("+showscores", { scoreboard_showscores = true; }) \
521 CONSOLE_COMMAND("-showscores", { scoreboard_showscores = false; }) \
522 CONSOLE_COMMAND("+showaccuracy", { scoreboard_showaccuracy = true; }) \
523 CONSOLE_COMMAND("-showaccuracy", { scoreboard_showaccuracy = false; }) \
526 #define CONSOLE_COMMANDS_MOVEMENT \
527 CONSOLE_COMMAND("+forward", { ++camera_direction.x; }) \
528 CONSOLE_COMMAND("-forward", { --camera_direction.x; }) \
529 CONSOLE_COMMAND("+back", { --camera_direction.x; }) \
530 CONSOLE_COMMAND("-back", { ++camera_direction.x; }) \
531 CONSOLE_COMMAND("+moveup", { ++camera_direction.z; }) \
532 CONSOLE_COMMAND("-moveup", { --camera_direction.z; }) \
533 CONSOLE_COMMAND("+movedown", { --camera_direction.z; }) \
534 CONSOLE_COMMAND("-movedown", { ++camera_direction.z; }) \
535 CONSOLE_COMMAND("+moveright", { --camera_direction.y; }) \
536 CONSOLE_COMMAND("-moveright", { ++camera_direction.y; }) \
537 CONSOLE_COMMAND("+moveleft", { ++camera_direction.y; }) \
538 CONSOLE_COMMAND("-moveleft", { --camera_direction.y; }) \
539 CONSOLE_COMMAND("+roll_right", { ++camera_roll; }) \
540 CONSOLE_COMMAND("-roll_right", { --camera_roll; }) \
541 CONSOLE_COMMAND("+roll_left", { --camera_roll; }) \
542 CONSOLE_COMMAND("-roll_left", { ++camera_roll; }) \
545 void ConsoleCommand_macro_init()
547 // first init normal commands
548 #define CONSOLE_COMMAND(name,execution) \
549 { registercommand(name); }
551 CONSOLE_COMMANDS_NORMAL
552 #undef CONSOLE_COMMAND
554 // then init movement commands
559 #define CONSOLE_COMMAND(name,execution) \
560 { registercommand(name); }
562 CONSOLE_COMMANDS_MOVEMENT
563 #undef CONSOLE_COMMAND
571 bool ConsoleCommand_macro_normal(int argc)
573 #define CONSOLE_COMMAND(name,execution) \
574 { if(name == strtolower(argv(0))) { { execution } return true; } }
576 CONSOLE_COMMANDS_NORMAL
577 #undef CONSOLE_COMMAND
582 bool ConsoleCommand_macro_movement(int argc)
586 #define CONSOLE_COMMAND(name,execution) \
587 { if(name == strtolower(argv(0))) { { execution } return true; } }
589 CONSOLE_COMMANDS_MOVEMENT
590 #undef CONSOLE_COMMAND
597 // ======================================================
598 // Main Function Called By Engine (registered commands)
599 // ======================================================
600 // Used to parse commands in the console that have been registered with the "registercommand" function
602 bool CSQC_ConsoleCommand(string command)
604 int argc = tokenize_console(command);
606 if(ConsoleCommand_macro_normal(argc))
610 else if(ConsoleCommand_macro_movement(argc))
615 // Return value should be 1 if CSQC handled the command, otherwise return 0 to have the engine handle it.