1 // ==============================================
2 // CSQC client commands code, written by Samual
3 // Last updated: December 28th, 2011
4 // ==============================================
6 #include "../../common/command/generic.qh"
7 #include "../../common/command/shared_defs.qh"
11 if(time - floor(time) > 0.5)
19 self.drawmask = MASK_NORMAL;
24 // =======================
25 // Command Sub-Functions
26 // =======================
28 void LocalCommand_blurtest(int request)
30 // Simple command to work with postprocessing temporarily... possibly completely pointless, the glsl shader is used for a real feature now...
31 // Anyway, to enable it, just compile the client with -DBLURTEST and then you can use the command.
36 case CMD_REQUEST_COMMAND:
38 blurtest_time0 = time;
39 blurtest_time1 = time + stof(argv(1));
40 blurtest_radius = stof(argv(2));
41 blurtest_power = stof(argv(3));
42 print("Enabled blurtest\n");
47 case CMD_REQUEST_USAGE:
49 print("\nUsage:^3 cl_cmd blurtest\n");
50 print(" No arguments required.\n");
57 print("Blurtest is not enabled on this client.\n");
63 void LocalCommand_boxparticles(int request, int argc)
67 case CMD_REQUEST_COMMAND:
71 int effect = particleeffectnum(argv(1));
74 int index = stoi(argv(2));
77 own = entitybyindex(-index);
79 own = findfloat(world, entnum, index);
80 vector org_from = stov(argv(3));
81 vector org_to = stov(argv(4));
82 vector dir_from = stov(argv(5));
83 vector dir_to = stov(argv(6));
84 int countmultiplier = stoi(argv(7));
85 int flags = stoi(argv(8));
86 boxparticles(effect, own, org_from, org_to, dir_from, dir_to, countmultiplier, flags);
93 print("Incorrect parameters for ^2boxparticles^7\n");
94 case CMD_REQUEST_USAGE:
96 print("\nUsage:^3 lv_cmd boxparticles effectname own org_from org_to, dir_from, dir_to, countmultiplier, flags\n");
97 print(" 'effectname' is the name of a particle effect in effectinfo.txt\n");
98 print(" 'own' is the entity number of the owner (negative for csqc ent, positive for svqc ent)\n");
99 print(" 'org_from' is the starting origin of the box\n");
100 print(" 'org_to' is the ending origin of the box\n");
101 print(" 'dir_from' is the minimum velocity\n");
102 print(" 'dir_to' is the maximum velocity\n");
103 print(" 'countmultiplier' defines a multiplier for the particle count (affects count only, not countabsolute or trailspacing)\n");
104 print(" 'flags' can contain:\n");
105 print(" 1 to respect globals particles_alphamin, particles_alphamax (set right before via prvm_globalset client)\n");
106 print(" 2 to respect globals particles_colormin, particles_colormax (set right before via prvm_globalset client)\n");
107 print(" 4 to respect globals particles_fade (set right before via prvm_globalset client)\n");
108 print(" 128 to draw a trail, not a box\n");
114 void LocalCommand_create_scrshot_ent(int request)
118 case CMD_REQUEST_COMMAND:
120 string filename = strcat(MapInfo_Map_bspname, "_scrshot_ent.txt");
121 int fh = fopen(filename, FILE_WRITE);
126 fputs(fh, strcat("\"classname\" \"info_autoscreenshot\"\n"));
127 fputs(fh, strcat("\"origin\" \"", strcat(ftos(view_origin.x), " ", ftos(view_origin.y), " ", ftos(view_origin.z)), "\"\n"));
128 fputs(fh, strcat("\"angles\" \"", strcat(ftos(view_angles.x), " ", ftos(view_angles.y), " ", ftos(view_angles.z)), "\"\n"));
131 print("Completed screenshot entity dump in ^2data/data/", MapInfo_Map_bspname, "_scrshot_ent.txt^7.\n");
137 print("^1Error: ^7Could not dump to file!\n");
143 case CMD_REQUEST_USAGE:
145 print("\nUsage:^3 cl_cmd create_scrshot_ent\n");
146 print(" No arguments required.\n");
152 void LocalCommand_debugmodel(int request, int argc)
156 case CMD_REQUEST_COMMAND:
158 string modelname = argv(1);
159 entity debugmodel_entity;
161 debugmodel_entity = spawn();
162 precache_model(modelname);
163 setmodel(debugmodel_entity, modelname);
164 setorigin(debugmodel_entity, view_origin);
165 debugmodel_entity.angles = view_angles;
166 debugmodel_entity.draw = DrawDebugModel;
167 debugmodel_entity.classname = "debugmodel";
173 case CMD_REQUEST_USAGE:
175 print("\nUsage:^3 cl_cmd debugmodel model\n");
176 print(" Where 'model' is a string of the model name to use for the debug model.\n");
182 void LocalCommand_handlevote(int request, int argc)
186 case CMD_REQUEST_COMMAND:
191 if(InterpretBoolean(argv(1)))
204 if(uid2name_dialog) // handled by "uid2name" option
209 localcmd(strcat("setreport cl_allow_uid2name ", ftos(vote_selection - 1), "\n"));
212 else { localcmd(strcat("cmd vote ", vote_string, "\n")); }
219 print("Incorrect parameters for ^2handlevote^7\n");
220 case CMD_REQUEST_USAGE:
222 print("\nUsage:^3 cl_cmd handlevote vote\n");
223 print(" Where 'vote' is the selection for either the current poll or uid2name.\n");
229 void LocalCommand_hud(int request, int argc)
233 case CMD_REQUEST_COMMAND:
239 cvar_set("_hud_configure", ftos(!autocvar__hud_configure));
247 HUD_Panel_ExportCfg(argv(2));
252 break; // go to usage, we're missing the paramater needed here.
256 case "scoreboard_columns_set":
258 Cmd_HUD_SetFields(argc);
262 case "scoreboard_columns_help":
271 HUD_Radar_Show_Maximized(InterpretBoolean(argv(2)),0);
273 HUD_Radar_Show_Maximized(!hud_panel_radar_maximized,0);
279 HUD_Radar_Show_Maximized(!hud_panel_radar_mouse,1);
286 print("Incorrect parameters for ^2hud^7\n");
287 case CMD_REQUEST_USAGE:
289 print("\nUsage:^3 cl_cmd hud action [configname | radartoggle | layout]\n");
290 print(" Where 'action' is the command to complete,\n");
291 print(" 'configname' is the name to save to for \"save\" action,\n");
292 print(" 'radartoggle' is to control hud_panel_radar_maximized for \"radar\" action,\n");
293 print(" and 'layout' is how to organize the scoreboard columns for the set action.\n");
294 print(" Full list of commands here: \"configure, save, scoreboard_columns_help, scoreboard_columns_set, radar.\"\n");
300 void LocalCommand_localprint(int request, int argc)
304 case CMD_REQUEST_COMMAND:
308 centerprint_hud(argv(1));
314 print("Incorrect parameters for ^2localprint^7\n");
315 case CMD_REQUEST_USAGE:
317 print("\nUsage:^3 cl_cmd localprint \"message\"\n");
318 print(" 'message' is the centerprint message to send to yourself.\n");
324 void LocalCommand_mv_download(int request, int argc)
328 case CMD_REQUEST_COMMAND:
332 Cmd_MapVote_MapDownload(argc);
338 print("Incorrect parameters for ^2mv_download^7\n");
339 case CMD_REQUEST_USAGE:
341 print("\nUsage:^3 cl_cmd mv_download mapid\n");
342 print(" Where 'mapid' is the id number of the map to request an image of on the map vote selection menu.\n");
348 void LocalCommand_sendcvar(int request, int argc)
352 case CMD_REQUEST_COMMAND:
356 // W_FixWeaponOrder will trash argv, so save what we need.
357 string thiscvar = strzone(argv(1));
358 string s = cvar_string(thiscvar);
360 if(thiscvar == "cl_weaponpriority")
361 s = W_FixWeaponOrder(W_NumberWeaponOrder(s), 1);
362 else if(substring(thiscvar, 0, 17) == "cl_weaponpriority" && strlen(thiscvar) == 18)
363 s = W_FixWeaponOrder(W_NumberWeaponOrder(s), 0);
365 localcmd("cmd sentcvar ", thiscvar, " \"", s, "\"\n");
372 print("Incorrect parameters for ^2sendcvar^7\n");
373 case CMD_REQUEST_USAGE:
375 print("\nUsage:^3 cl_cmd sendcvar <cvar>\n");
376 print(" Where 'cvar' is the cvar plus arguments to send to the server.\n");
382 /* use this when creating a new command, making sure to place it in alphabetical order... also,
383 ** ADD ALL NEW COMMANDS TO commands.cfg WITH PROPER ALIASES IN THE SAME FASHION!
384 void LocalCommand_(int request)
388 case CMD_REQUEST_COMMAND:
395 case CMD_REQUEST_USAGE:
397 print("\nUsage:^3 cl_cmd \n");
398 print(" No arguments required.\n");
406 // ==================================
407 // Macro system for client commands
408 // ==================================
410 // Normally do not hard code aliases for these, instead create them in commands.cfg... also: keep in alphabetical order, please ;)
411 #define CLIENT_COMMANDS(request,arguments) \
412 CLIENT_COMMAND("blurtest", LocalCommand_blurtest(request), "Feature for testing blur postprocessing") \
413 CLIENT_COMMAND("boxparticles", LocalCommand_boxparticles(request, arguments), "Spawn particles manually") \
414 CLIENT_COMMAND("create_scrshot_ent", LocalCommand_create_scrshot_ent(request), "Create an entity at this location for automatic screenshots") \
415 CLIENT_COMMAND("debugmodel", LocalCommand_debugmodel(request, arguments), "Spawn a debug model manually") \
416 CLIENT_COMMAND("handlevote", LocalCommand_handlevote(request, arguments), "System to handle selecting a vote or option") \
417 CLIENT_COMMAND("hud", LocalCommand_hud(request, arguments), "Commands regarding/controlling the HUD system") \
418 CLIENT_COMMAND("localprint", LocalCommand_localprint(request, arguments), "Create your own centerprint sent to yourself") \
419 CLIENT_COMMAND("mv_download", LocalCommand_mv_download(request, arguments), "Retrieve mapshot picture from the server") \
420 CLIENT_COMMAND("sendcvar", LocalCommand_sendcvar(request, arguments), "Send a cvar to the server (like weaponpriority)") \
423 void LocalCommand_macro_help()
425 #define CLIENT_COMMAND(name,function,description) \
426 { if(strtolower(description) != "") { print(" ^2", name, "^7: ", description, "\n"); } }
428 CLIENT_COMMANDS(0, 0);
429 #undef CLIENT_COMMAND
434 bool LocalCommand_macro_command(int argc)
436 #define CLIENT_COMMAND(name,function,description) \
437 { if(name == strtolower(argv(0))) { function; return true; } }
439 CLIENT_COMMANDS(CMD_REQUEST_COMMAND, argc);
440 #undef CLIENT_COMMAND
445 bool LocalCommand_macro_usage(int argc)
447 #define CLIENT_COMMAND(name,function,description) \
448 { if(name == strtolower(argv(1))) { function; return true; } }
450 CLIENT_COMMANDS(CMD_REQUEST_USAGE, argc);
451 #undef CLIENT_COMMAND
456 void LocalCommand_macro_write_aliases(int fh)
458 #define CLIENT_COMMAND(name,function,description) \
459 { if(strtolower(description) != "") { CMD_Write_Alias("qc_cmd_cl", name, description); } }
461 CLIENT_COMMANDS(0, 0);
462 #undef CLIENT_COMMAND
468 // =========================================
469 // Main Function Called By Engine (cl_cmd)
470 // =========================================
471 // If this function exists, client code handles gamecommand instead of the engine code.
473 void GameCommand(string command)
475 int argc = tokenize_console(command);
477 // Guide for working with argc arguments by example:
478 // argc: 1 - 2 - 3 - 4
479 // argv: 0 - 1 - 2 - 3
480 // cmd vote - master - login - password
482 if(strtolower(argv(0)) == "help")
486 print("\nClient console commands:\n");
487 LocalCommand_macro_help();
489 print("\nGeneric commands shared by all programs:\n");
490 GenericCommand_macro_help();
492 print("\nUsage:^3 cl_cmd COMMAND...^7, where possible commands are listed above.\n");
493 print("For help about a specific command, type cl_cmd help COMMAND\n");
497 else if(GenericCommand_macro_usage(argc)) // Instead of trying to call a command, we're going to see detailed information about it
501 else if(LocalCommand_macro_usage(argc)) // now try for normal commands too
506 else if(GenericCommand(command))
508 return; // handled by common/command/generic.qc
510 else if(LocalCommand_macro_command(argc)) // continue as usual and scan for normal commands
512 return; // handled by one of the above LocalCommand_* functions
515 // nothing above caught the command, must be invalid
516 print(((command != "") ? strcat("Unknown client command \"", command, "\"") : "No command provided"), ". For a list of supported commands, try cl_cmd help.\n");
522 // ===================================
523 // Macro system for console commands
524 // ===================================
526 // These functions are here specifically to add special + - commands to the game, and are not really normal commands.
527 // Please add client commands to the function above this, as this is only for special reasons.
528 #define CONSOLE_COMMANDS_NORMAL() \
529 CONSOLE_COMMAND("+showscores", { scoreboard_showscores = true; }) \
530 CONSOLE_COMMAND("-showscores", { scoreboard_showscores = false; }) \
531 CONSOLE_COMMAND("+showaccuracy", { scoreboard_showaccuracy = true; }) \
532 CONSOLE_COMMAND("-showaccuracy", { scoreboard_showaccuracy = false; }) \
535 #define CONSOLE_COMMANDS_MOVEMENT() \
536 CONSOLE_COMMAND("+forward", { ++camera_direction.x; }) \
537 CONSOLE_COMMAND("-forward", { --camera_direction.x; }) \
538 CONSOLE_COMMAND("+back", { --camera_direction.x; }) \
539 CONSOLE_COMMAND("-back", { ++camera_direction.x; }) \
540 CONSOLE_COMMAND("+moveup", { ++camera_direction.z; }) \
541 CONSOLE_COMMAND("-moveup", { --camera_direction.z; }) \
542 CONSOLE_COMMAND("+movedown", { --camera_direction.z; }) \
543 CONSOLE_COMMAND("-movedown", { ++camera_direction.z; }) \
544 CONSOLE_COMMAND("+moveright", { --camera_direction.y; }) \
545 CONSOLE_COMMAND("-moveright", { ++camera_direction.y; }) \
546 CONSOLE_COMMAND("+moveleft", { ++camera_direction.y; }) \
547 CONSOLE_COMMAND("-moveleft", { --camera_direction.y; }) \
548 CONSOLE_COMMAND("+roll_right", { ++camera_roll; }) \
549 CONSOLE_COMMAND("-roll_right", { --camera_roll; }) \
550 CONSOLE_COMMAND("+roll_left", { --camera_roll; }) \
551 CONSOLE_COMMAND("-roll_left", { ++camera_roll; }) \
554 void ConsoleCommand_macro_init()
556 // first init normal commands
557 #define CONSOLE_COMMAND(name,execution) \
558 { registercommand(name); }
560 CONSOLE_COMMANDS_NORMAL();
561 #undef CONSOLE_COMMAND
563 // then init movement commands
568 #define CONSOLE_COMMAND(name,execution) \
569 { registercommand(name); }
571 CONSOLE_COMMANDS_MOVEMENT();
572 #undef CONSOLE_COMMAND
580 bool ConsoleCommand_macro_normal(int argc)
582 #define CONSOLE_COMMAND(name,execution) \
583 { if(name == strtolower(argv(0))) { { execution } return true; } }
585 CONSOLE_COMMANDS_NORMAL();
586 #undef CONSOLE_COMMAND
591 bool ConsoleCommand_macro_movement(int argc)
595 #define CONSOLE_COMMAND(name,execution) \
596 { if(name == strtolower(argv(0))) { { execution } return true; } }
598 CONSOLE_COMMANDS_MOVEMENT();
599 #undef CONSOLE_COMMAND
606 // ======================================================
607 // Main Function Called By Engine (registered commands)
608 // ======================================================
609 // Used to parse commands in the console that have been registered with the "registercommand" function
611 bool CSQC_ConsoleCommand(string command)
613 int argc = tokenize_console(command);
615 if(ConsoleCommand_macro_normal(argc))
619 else if(ConsoleCommand_macro_movement(argc))
624 // Return value should be 1 if CSQC handled the command, otherwise return 0 to have the engine handle it.