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(float 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(float request, float argc)
64 case CMD_REQUEST_COMMAND:
68 float effect = particleeffectnum(argv(1));
71 float index = stof(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 float countmultiplier = stof(argv(7));
82 float flags = stof(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(float request)
115 case CMD_REQUEST_COMMAND:
118 string filename = strcat(MapInfo_Map_bspname, "_scrshot_ent.txt");
119 fh = fopen(filename, FILE_WRITE);
124 fputs(fh, strcat("\"classname\" \"info_autoscreenshot\"\n"));
125 fputs(fh, strcat("\"origin\" \"", strcat(ftos(view_origin_x), " ", ftos(view_origin_y), " ", ftos(view_origin_z)), "\"\n"));
126 fputs(fh, strcat("\"angles\" \"", strcat(ftos(view_angles_x), " ", ftos(view_angles_y), " ", ftos(view_angles_z)), "\"\n"));
129 print("Completed screenshot entity dump in ^2data/data/", MapInfo_Map_bspname, "_scrshot_ent.txt^7.\n");
135 print("^1Error: ^7Could not dump to file!\n");
141 case CMD_REQUEST_USAGE:
143 print("\nUsage:^3 cl_cmd create_scrshot_ent\n");
144 print(" No arguments required.\n");
150 void LocalCommand_debugmodel(float request, float argc)
154 case CMD_REQUEST_COMMAND:
156 string modelname = argv(1);
157 entity debugmodel_entity;
159 debugmodel_entity = spawn();
160 precache_model(modelname);
161 setmodel(debugmodel_entity, modelname);
162 setorigin(debugmodel_entity, view_origin);
163 debugmodel_entity.angles = view_angles;
164 debugmodel_entity.draw = DrawDebugModel;
165 debugmodel_entity.classname = "debugmodel";
171 case CMD_REQUEST_USAGE:
173 print("\nUsage:^3 cl_cmd debugmodel model\n");
174 print(" Where 'model' is a string of the model name to use for the debug model.\n");
180 void LocalCommand_handlevote(float request, float argc)
184 case CMD_REQUEST_COMMAND:
186 float vote_selection;
189 if(InterpretBoolean(argv(1)))
202 if(uid2name_dialog) // handled by "uid2name" option
207 localcmd(strcat("setreport cl_allow_uid2name ", ftos(vote_selection - 1), "\n"));
210 else { localcmd(strcat("cmd vote ", vote_string, "\n")); }
217 print("Incorrect parameters for ^2handlevote^7\n");
218 case CMD_REQUEST_USAGE:
220 print("\nUsage:^3 cl_cmd handlevote vote\n");
221 print(" Where 'vote' is the selection for either the current poll or uid2name.\n");
227 void LocalCommand_hud(float request, float argc)
231 case CMD_REQUEST_COMMAND:
237 cvar_set("_hud_configure", ftos(!autocvar__hud_configure));
243 if(HUD_QuickMenu_IsOpened())
244 HUD_QuickMenu_Close();
246 HUD_QuickMenu_Open(argv(2), argv(3)); // mode, submenu
254 HUD_Panel_ExportCfg(argv(2));
259 break; // go to usage, we're missing the paramater needed here.
263 case "scoreboard_columns_set":
265 Cmd_HUD_SetFields(argc);
269 case "scoreboard_columns_help":
278 hud_panel_radar_maximized = InterpretBoolean(argv(2));
280 hud_panel_radar_maximized = !hud_panel_radar_maximized;
287 print("Incorrect parameters for ^2hud^7\n");
288 case CMD_REQUEST_USAGE:
290 print("\nUsage:^3 cl_cmd hud action [configname | radartoggle | layout]\n");
291 print(" Where 'action' is the command to complete,\n");
292 print(" 'configname' is the name to save to for \"save\" action,\n");
293 print(" 'radartoggle' is to control hud_panel_radar_maximized for \"radar\" action,\n");
294 print(" and 'layout' is how to organize the scoreboard columns for the set action.\n");
295 print(" Full list of commands here: \"configure, quickmenu, save, scoreboard_columns_help, scoreboard_columns_set, radar.\"\n");
301 void LocalCommand_localprint(float request, float argc)
305 case CMD_REQUEST_COMMAND:
309 centerprint_hud(argv(1));
315 print("Incorrect parameters for ^2localprint^7\n");
316 case CMD_REQUEST_USAGE:
318 print("\nUsage:^3 cl_cmd localprint \"message\"\n");
319 print(" 'message' is the centerprint message to send to yourself.\n");
325 void LocalCommand_mv_download(float request, float argc)
329 case CMD_REQUEST_COMMAND:
333 Cmd_MapVote_MapDownload(argc);
339 print("Incorrect parameters for ^2mv_download^7\n");
340 case CMD_REQUEST_USAGE:
342 print("\nUsage:^3 cl_cmd mv_download mapid\n");
343 print(" Where 'mapid' is the id number of the map to request an image of on the map vote selection menu.\n");
349 void LocalCommand_sendcvar(float request, float argc)
353 case CMD_REQUEST_COMMAND:
357 // W_FixWeaponOrder will trash argv, so save what we need.
358 string thiscvar = strzone(argv(1));
359 string s = cvar_string(thiscvar);
361 if(thiscvar == "cl_weaponpriority")
362 s = W_FixWeaponOrder(W_NumberWeaponOrder(s), 1);
363 else if(substring(thiscvar, 0, 17) == "cl_weaponpriority" && strlen(thiscvar) == 18)
364 s = W_FixWeaponOrder(W_NumberWeaponOrder(s), 0);
366 localcmd("cmd sentcvar ", thiscvar, " \"", s, "\"\n");
373 print("Incorrect parameters for ^2sendcvar^7\n");
374 case CMD_REQUEST_USAGE:
376 print("\nUsage:^3 cl_cmd sendcvar <cvar>\n");
377 print(" Where 'cvar' is the cvar plus arguments to send to the server.\n");
383 /* use this when creating a new command, making sure to place it in alphabetical order... also,
384 ** ADD ALL NEW COMMANDS TO commands.cfg WITH PROPER ALIASES IN THE SAME FASHION!
385 void LocalCommand_(float request)
389 case CMD_REQUEST_COMMAND:
396 case CMD_REQUEST_USAGE:
398 print("\nUsage:^3 cl_cmd \n");
399 print(" No arguments required.\n");
407 // ==================================
408 // Macro system for client commands
409 // ==================================
411 // Normally do not hard code aliases for these, instead create them in commands.cfg... also: keep in alphabetical order, please ;)
412 #define CLIENT_COMMANDS(request,arguments) \
413 CLIENT_COMMAND("blurtest", LocalCommand_blurtest(request), "Feature for testing blur postprocessing") \
414 CLIENT_COMMAND("boxparticles", LocalCommand_boxparticles(request, arguments), "Spawn particles manually") \
415 CLIENT_COMMAND("create_scrshot_ent", LocalCommand_create_scrshot_ent(request), "Create an entity at this location for automatic screenshots") \
416 CLIENT_COMMAND("debugmodel", LocalCommand_debugmodel(request, arguments), "Spawn a debug model manually") \
417 CLIENT_COMMAND("handlevote", LocalCommand_handlevote(request, arguments), "System to handle selecting a vote or option") \
418 CLIENT_COMMAND("hud", LocalCommand_hud(request, arguments), "Commands regarding/controlling the HUD system") \
419 CLIENT_COMMAND("localprint", LocalCommand_localprint(request, arguments), "Create your own centerprint sent to yourself") \
420 CLIENT_COMMAND("mv_download", LocalCommand_mv_download(request, arguments), "Retrieve mapshot picture from the server") \
421 CLIENT_COMMAND("sendcvar", LocalCommand_sendcvar(request, arguments), "Send a cvar to the server (like weaponpriority)") \
424 void LocalCommand_macro_help()
426 #define CLIENT_COMMAND(name,function,description) \
427 { if(strtolower(description) != "") { print(" ^2", name, "^7: ", description, "\n"); } }
429 CLIENT_COMMANDS(0, 0)
430 #undef CLIENT_COMMAND
435 float LocalCommand_macro_command(float argc)
437 #define CLIENT_COMMAND(name,function,description) \
438 { if(name == strtolower(argv(0))) { function; return TRUE; } }
440 CLIENT_COMMANDS(CMD_REQUEST_COMMAND, argc)
441 #undef CLIENT_COMMAND
446 float LocalCommand_macro_usage(float argc)
448 #define CLIENT_COMMAND(name,function,description) \
449 { if(name == strtolower(argv(1))) { function; return TRUE; } }
451 CLIENT_COMMANDS(CMD_REQUEST_USAGE, argc)
452 #undef CLIENT_COMMAND
457 void LocalCommand_macro_write_aliases(float fh)
459 #define CLIENT_COMMAND(name,function,description) \
460 { if(strtolower(description) != "") { CMD_Write_Alias("qc_cmd_cl", name, description); } }
462 CLIENT_COMMANDS(0, 0)
463 #undef CLIENT_COMMAND
469 // =========================================
470 // Main Function Called By Engine (cl_cmd)
471 // =========================================
472 // If this function exists, client code handles gamecommand instead of the engine code.
474 void GameCommand(string command)
476 float argc = tokenize_console(command);
478 // Guide for working with argc arguments by example:
479 // argc: 1 - 2 - 3 - 4
480 // argv: 0 - 1 - 2 - 3
481 // cmd vote - master - login - password
483 if(strtolower(argv(0)) == "help")
487 print("\nClient console commands:\n");
488 LocalCommand_macro_help();
490 print("\nGeneric commands shared by all programs:\n");
491 GenericCommand_macro_help();
493 print("\nUsage:^3 cl_cmd COMMAND...^7, where possible commands are listed above.\n");
494 print("For help about a specific command, type cl_cmd help COMMAND\n");
498 else if(GenericCommand_macro_usage(argc)) // Instead of trying to call a command, we're going to see detailed information about it
502 else if(LocalCommand_macro_usage(argc)) // now try for normal commands too
507 else if(GenericCommand(command))
509 return; // handled by common/command/generic.qc
511 else if(LocalCommand_macro_command(argc)) // continue as usual and scan for normal commands
513 return; // handled by one of the above LocalCommand_* functions
516 // nothing above caught the command, must be invalid
517 print(((command != "") ? strcat("Unknown client command \"", command, "\"") : "No command provided"), ". For a list of supported commands, try cl_cmd help.\n");
523 // ===================================
524 // Macro system for console commands
525 // ===================================
527 // These functions are here specifically to add special + - commands to the game, and are not really normal commands.
528 // Please add client commands to the function above this, as this is only for special reasons.
529 #define CONSOLE_COMMANDS_NORMAL \
530 CONSOLE_COMMAND("+showscores", { scoreboard_showscores = TRUE; }) \
531 CONSOLE_COMMAND("-showscores", { scoreboard_showscores = FALSE; }) \
532 CONSOLE_COMMAND("+showaccuracy", { scoreboard_showaccuracy = TRUE; }) \
533 CONSOLE_COMMAND("-showaccuracy", { scoreboard_showaccuracy = FALSE; }) \
536 #define CONSOLE_COMMANDS_MOVEMENT \
537 CONSOLE_COMMAND("+forward", { ++camera_direction_x; }) \
538 CONSOLE_COMMAND("-forward", { --camera_direction_x; }) \
539 CONSOLE_COMMAND("+back", { --camera_direction_x; }) \
540 CONSOLE_COMMAND("-back", { ++camera_direction_x; }) \
541 CONSOLE_COMMAND("+moveup", { ++camera_direction_z; }) \
542 CONSOLE_COMMAND("-moveup", { --camera_direction_z; }) \
543 CONSOLE_COMMAND("+movedown", { --camera_direction_z; }) \
544 CONSOLE_COMMAND("-movedown", { ++camera_direction_z; }) \
545 CONSOLE_COMMAND("+moveright", { --camera_direction_y; }) \
546 CONSOLE_COMMAND("-moveright", { ++camera_direction_y; }) \
547 CONSOLE_COMMAND("+moveleft", { ++camera_direction_y; }) \
548 CONSOLE_COMMAND("-moveleft", { --camera_direction_y; }) \
549 CONSOLE_COMMAND("+roll_right", { ++camera_roll; }) \
550 CONSOLE_COMMAND("-roll_right", { --camera_roll; }) \
551 CONSOLE_COMMAND("+roll_left", { --camera_roll; }) \
552 CONSOLE_COMMAND("-roll_left", { ++camera_roll; }) \
555 void ConsoleCommand_macro_init()
557 // first init normal commands
558 #define CONSOLE_COMMAND(name,execution) \
559 { registercommand(name); }
561 CONSOLE_COMMANDS_NORMAL
562 #undef CONSOLE_COMMAND
564 // then init movement commands
569 #define CONSOLE_COMMAND(name,execution) \
570 { registercommand(name); }
572 CONSOLE_COMMANDS_MOVEMENT
573 #undef CONSOLE_COMMAND
581 float ConsoleCommand_macro_normal(float argc)
583 #define CONSOLE_COMMAND(name,execution) \
584 { if(name == strtolower(argv(0))) { { execution } return TRUE; } }
586 CONSOLE_COMMANDS_NORMAL
587 #undef CONSOLE_COMMAND
592 float ConsoleCommand_macro_movement(float argc)
596 #define CONSOLE_COMMAND(name,execution) \
597 { if(name == strtolower(argv(0))) { { execution } return TRUE; } }
599 CONSOLE_COMMANDS_MOVEMENT
600 #undef CONSOLE_COMMAND
607 // ======================================================
608 // Main Function Called By Engine (registered commands)
609 // ======================================================
610 // Used to parse commands in the console that have been registered with the "registercommand" function
612 float CSQC_ConsoleCommand(string command)
614 float argc = tokenize_console(command);
616 if(ConsoleCommand_macro_normal(argc))
620 else if(ConsoleCommand_macro_movement(argc))
625 // Return value should be 1 if CSQC handled the command, otherwise return 0 to have the engine handle it.