Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

made compatible with iw4x and added a few cmds #3

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ The permission level is set per-player using the [`scr_permissions`](#scr_permis
| **give** | | [name] <item> | Give an item to a player | 50 |
| **take** | | [name] <item> | Take an item from a player | 50 |
| **teleport** | tp | [name] [name] | Teleport to players or a location | 50 |
| **teleportall** | tpall | [source=*] [target=name] | Teleport all players to a target or yourself | 50 |
| **up** | | [name] | Teleport upwards | 50 |
| **down** | dn | [name] | Teleport downwards | 50 |
| **velocity** | jump j | [name] <z \| forwards z \| x y z> | Set a player's velocity | 50 |
Expand All @@ -71,6 +72,23 @@ The permission level is set per-player using the [`scr_permissions`](#scr_permis
| **dvar** | | <dvar> [value] | Get or set a dvar value | 100 |
| **rcon** | | <command> | Execute rcon command | 100 |
| **quit** | | | Close the server | 100 |
| **alert** | | | Alerts a player, team or everyone | 50 |
| **nvp** | | [target player] | Toggles nightvision for a player | 50 |
| **laserp** | | [target player] | Toggles laser for a player | 50 |
| **fpsb** | | [target player] | Toggles r_fullbright for a player | 50 |
| **ammo** | | [weapon] [target player] | Gives max ammo | 50 |
| **harrier** | | | LOL | 100 |
| **godmode** | god | | LOL | 100 |
| **planecrash** | crash | | Crashes two AC-130s | 100 |
| **flare** | | | Gives you a flare | 100 |
| **op** | | | Gives you all perks | 100 |
| **trampoline** | | | Spawns a trampoline | 100 |
| **jericho** | | | jericho | 100 |
| **airdrop** | drop | | Toggle insane airdrops | 100 |
| **cvar** | clientvar seta | | Set your own dvar value | 100 |
| **pvar** | playervar | | Set a players dvar value | 100 |

* source can be any of `all/bots/players/spectators/opfor/axis/marines/allies/team/enemies` (Default is `all`)

### Related DVars
| **DVar** | Default Value | Description |
Expand Down
18 changes: 14 additions & 4 deletions scripts/_utility.gsc
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,18 @@ arrayToString(array)
return str;
}

arrayToOptions(arr) {
opts = "^9<";
for (i = 0; i < arr.size; i++)
{
opts += "^7" + arr[i];
if (i < arr.size - 1)
opts += "^9/";
}
opts += "^9>";
return opts;
}

stringStartsWith(str, startstr)
{
return (getSubStr(str, 0, startstr.size) == startstr);
Expand Down Expand Up @@ -396,8 +408,7 @@ stringSplit(str, delim)
return array;
}

stringRemoveColors(str)
{
stringRemoveColors(str) {
parts = strTok(str, "^");
foreach (i, part in parts)
{
Expand Down Expand Up @@ -425,8 +436,7 @@ stringRemoveColors(str)
return result;
}

stringEncodeDiscord(str)
{
stringEncodeDiscord(str) {
chars = [];
chars[0] = "\\"; // Must be first!
chars[1] = "_";
Expand Down
89 changes: 57 additions & 32 deletions scripts/commands.gsc
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@ init()
setDvarIfUninitialized("scr_commands_set_client_dvars_chat", false);
setDvarIfUninitialized("scr_commands_prefix", "!");
setDvarIfUninitialized("scr_commands_info", getDvar("sv_motd"));
setDvarIfUninitialized("scr_commands_report_webhook_url", "");
setDvarIfUninitialized("scr_commands_report_cooldown", 20);
setDvarIfUninitialized("scr_commands_report_chat_log_max_age", 5 * 60);

if (!getDvarInt("scr_commands_enable"))
return;
Expand All @@ -19,34 +16,58 @@ init()
level.commands.commandList = [];
level.commands.commandMap = [];

registerCommand("help ? commands", scripts\commands\help::cmd, 0, "Display available commands");
registerCommand("help ? commands", scripts\commands\help::cmd, 0, "Display available commands","");
if (getDvar("scr_commands_info") != "")
registerCommand("info i contact", scripts\commands\info::cmd, 0, "Display server info");
if (getDvar("scr_commands_report_webhook_url") != "")
registerCommand("report r", scripts\commands\report::cmd, 0, "Report a player");
registerCommand("history chat", scripts\commands\history::cmd, 0, "View chat history");
registerCommand("items", scripts\commands\items::cmd, 10, "Print items for use with other commands");
registerCommand("suicide sc", scripts\commands\suicide::cmd, 20, "Kill yourself");
registerCommand("fastrestart restart fr", scripts\commands\fastrestart::cmd, 40, "Restart the map");
registerCommand("maprestart mr", scripts\commands\maprestart::cmd, 40, "Reload and restart the map");
registerCommand("map", scripts\commands\map::cmd, 40, "Change the current map");
registerCommand("kill", scripts\commands\kill::cmd, 50, "Kill a specified player");
registerCommand("give", scripts\commands\give::cmd, 50, "Give an item to a player");
registerCommand("take", scripts\commands\take::cmd, 50, "Take an item from a player");
registerCommand("teleport tp", scripts\commands\teleport::cmd, 50, "Teleport to players or a location");
registerCommand("up", scripts\commands\up::cmd, 50, "Teleport upwards");
registerCommand("down dn", scripts\commands\down::cmd, 50, "Teleport downwards");
registerCommand("velocity jump j", scripts\commands\velocity::cmd, 50, "Set a player's velocity");
registerCommand("freelook fly", scripts\commands\freelook::cmd, 50, "Temporary freelook spectating");
registerCommand("spectate spec spy", scripts\commands\spectate::cmd, 50, "Quietly spectate target");
registerCommand("esp wallhack wh", scripts\commands\esp::cmd, 50, "Show players through walls");
registerCommand("vision vis", scripts\commands\vision::cmd, 50, "Set or reset a player's vision");
registerCommand("spawnbot sb", scripts\commands\spawnbot::cmd, 70, "Spawn a number of bots");
registerCommand("kick", scripts\commands\kick::cmd, 80, "Kick a client from the server");
registerCommand("ban", scripts\commands\ban::cmd, 90, "Permanently ban a client from the server");
registerCommand("dvar", scripts\commands\dvar::cmd, 100, "Get or set a dvar value");
registerCommand("rcon", scripts\commands\rcon::cmd, 100, "Execute rcon command");
registerCommand("quit exit", scripts\commands\quit::cmd, 100, "Close the server");
registerCommand("info i contact", scripts\commands\info::cmd, 0, "Display server info","");
registerCommand("history chat", scripts\commands\history::cmd, 0, "View chat history","");
registerCommand("items", scripts\commands\items::cmd, 0, "Print items for use with other commands","");
registerCommand("suicide sc", scripts\commands\suicide::cmd, 0, "Kill yourself","");
registerCommand("fpsboost fullbright fb fps", scripts\commands\fpsboost::cmdself, 0, "Toggles r_fullbright for yourself to increase fps","");
registerCommand("nightvision nvg nv", scripts\commands\nightvision::cmdself, 0, "Toggles nightvision for yourself","");
registerCommand("laser", scripts\commands\laser::cmdself, 0, "Toggles laser for yourself","");

registerCommand("fastrestart restart fr", scripts\commands\fastrestart::cmd, 40, "Restart the map","");
registerCommand("maprestart mr", scripts\commands\maprestart::cmd, 40, "Reload and restart the map","");
registerCommand("endgame end", scripts\commands\endgame::cmd, 40, "Ends the map","");
registerCommand("map", scripts\commands\map::cmd, 40, "Change the current map","");

registerCommand("alert", scripts\commands\alert::cmd, 50, "Alerts a player, team or everyone","");
registerCommand("kill", scripts\commands\kill::cmd, 50, "Kill a specified player","");
registerCommand("give", scripts\commands\give::cmd, 50, "Give an item to a player","");
registerCommand("take", scripts\commands\take::cmd, 50, "Take an item from a player","");
registerCommand("teleport tp", scripts\commands\teleport::cmd, 50, "Teleport to players or a location","");
registerCommand("teleportall tpall", scripts\commands\teleportall::cmd, 50, "Teleport all players","<all/spectators/opfor/allies/bots/team/enemies> [target player]");
registerCommand("up", scripts\commands\up::cmd, 50, "Teleport upwards","");
registerCommand("down dn", scripts\commands\down::cmd, 50, "Teleport downwards","");
registerCommand("velocity jump j", scripts\commands\velocity::cmd, 50, "Set a player's velocity","");
registerCommand("freelook fly", scripts\commands\freelook::cmd, 50, "Temporary freelook spectating","");
registerCommand("spectate spec spy", scripts\commands\spectate::cmd, 50, "Quietly spectate target","");
registerCommand("esp wallhack wh", scripts\commands\esp::cmd, 50, "Show players through walls","");
registerCommand("vision vis", scripts\commands\vision::cmd, 50, "Set or reset a player's vision","");
registerCommand("nvp", scripts\commands\nightvision::cmd, 50, "Toggles nightvision for a player","[target player]");
registerCommand("laserp", scripts\commands\laser::cmd, 50, "Toggles laser for a player","[target player]");
registerCommand("fpsb", scripts\commands\fpsboost::cmd, 50, "Toggles r_fullbright for a player","[target player]");
registerCommand("ammo ammonition maxammo", scripts\commands\ammo::cmd, 50, "Gives max ammo","[weapon] [target player]");

registerCommand("spawnbot sb", scripts\commands\spawnbot::cmd, 70, "Spawn a number of bots","");

registerCommand("kick", scripts\commands\kick::cmd, 80, "Kick a client from the server","");

registerCommand("ban", scripts\commands\ban::cmd, 90, "Permanently ban a client from the server","");

registerCommand("harrier", scripts\commands\harrier::cmd, 100, "LOL","");
registerCommand("godmode god", scripts\commands\god::cmd, 100, "LOL","");
registerCommand("planecrash crash", scripts\commands\planecrash::cmd, 100, "Crashes two AC-130s","");
registerCommand("flare", scripts\commands\flare::cmd, 100, "Gives you a flare","");
registerCommand("op", scripts\commands\op::cmd, 100, "Gives you all perks","");
registerCommand("trampoline", scripts\commands\trampoline::cmd, 100, "Spawns a trampoline","");
registerCommand("jericho", scripts\commands\jericho::cmd, 100, "jericho","");
registerCommand("airdrop drop", scripts\commands\quit::cmd, 100, "Toggle insane airdrops","");
registerCommand("dvar svar servervar var set", scripts\commands\dvar::cmd, 100, "Get or set a dvar value","");
registerCommand("cvar clientvar seta", scripts\commands\cvar::cmd, 100, "Set your own dvar value","");
registerCommand("pvar playervar", scripts\commands\pvar::cmd, 100, "Set a players dvar value","");
registerCommand("rcon exec eval", scripts\commands\rcon::cmd, 100, "Execute rcon command","");
registerCommand("quit exit", scripts\commands\quit::cmd, 100, "Close the server","");

level thread OnPlayerConnected();
level thread OnPlayerSaid();
Expand Down Expand Up @@ -80,6 +101,8 @@ OnPlayerSaid()
prefix = getDvar("scr_commands_prefix");
if (!stringStartsWith(text, prefix))
continue;
if (getDvar("sv_iw4madmin_serverid", "") != "")
continue;

textNoPrefix = getSubStr(text, prefix.size, text.size);
args = strTok(textNoPrefix, " ");
Expand All @@ -99,7 +122,7 @@ OnPlayerSaid()
continue;
}

player thread [[cmd.func]](args, prefix);
player thread [[cmd.func]](args, prefix, cmd);
}
}

Expand Down Expand Up @@ -137,13 +160,15 @@ hasPermForCmd(cmd)
return (self getPermLvl() >= cmd.permLvl);
}

registerCommand(aliasesStr, func, permLvl, desc)
registerCommand(aliasesStr, func, permLvl, desc, usage)
{
prefix = getDvar("scr_commands_prefix");
cmd = spawnStruct();
cmd.func = func;
cmd.permLvl = coalesce(permLvl, 0);
cmd.aliases = strTok(aliasesStr, " ");
cmd.desc = desc;
cmd.usage = "^9Usage: ^7" + prefix + arrayToOptions(cmd.aliases) + " " + usage;
level.commands.commandList[level.commands.commandList.size] = cmd;

foreach (alias in cmd.aliases)
Expand Down
18 changes: 18 additions & 0 deletions scripts/commands/airdrop.gsc
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#include scripts\_utility;

cmd(args, prefix, cmd)
{
if (getDvar("scr_airdrop_ac130") > 3) {
setDvar("scr_airdrop_ac130", 3);
// setDvar("scr_airdrop_emp", 2);
setDvar("scr_airdrop_helicopter_minigun", 3);
setDvar("scr_airdrop_nuke", 1);
self respond("^2Airdrops are now ^3normal^2.");
} else {
setDvar("scr_airdrop_ac130", 99);
// setDvar("scr_airdrop_emp", 99);
setDvar("scr_airdrop_helicopter_minigun", 99);
setDvar("scr_airdrop_nuke", 99);
self respond("^2Airdrops are now ^1insane^2.");
}
}
43 changes: 43 additions & 0 deletions scripts/commands/alert.gsc
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#include scripts\_utility;

cmd(args, prefix, cmd)
{
if (args.size < 2)
{
self respond("^1Usage: " + prefix + args[0] + " <all/marines/opfor/player name> <text>");
return;
}

target = args[1];
self respond("^2Alerting ^7\"" + target + "\"^2.");

shout = spawnstruct();
shout.titleText = arrayJoin(arraySlice(args, 2), " ");
shout.glowColor = (0,.4,.9);

if (target == "all") {
foreach(player in level.players) {
player thread maps\mp\gametypes\_hud_message::notifyMessage( shout );
}
} else if (target == "marines") {
foreach(player in level.players) {
if (player.team == "allies")
player thread maps\mp\gametypes\_hud_message::notifyMessage( shout );
}
} else if (target == "opfor") {
foreach(player in level.players) {
if (player.team == "axis")
player thread maps\mp\gametypes\_hud_message::notifyMessage( shout );
}
} else {
target = getPlayerByName(args[1]);
if (!isDefined(target))
{
self respond("^1Target could not be found.");
return;
}
target thread maps\mp\gametypes\_hud_message::notifyMessage( shout );
}

self respond("^2Alerted ^7" + target + "^2.");
}
30 changes: 30 additions & 0 deletions scripts/commands/ammo.gsc
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#include scripts\_utility;

cmd(args, prefix, cmd)
{
if (args.size < 1)
{
self respond("^1Usage: " + prefix + args[0] + "[weapon] [target]");
return;
}

target = self;
if (args.size > 2) {
target = getPlayerByName(args[3]);
}
if (!isDefined(target))
{
self respond("^1Target could not be found.");
return;
}

weapon = target getCurrentWeapon();
if (args.size > 1) {
weapon = args[1];
}

self respond("Giving " + target.name + " max ammo for " + weapon.name + ".");
target giveMaxAmmo(weapon);
target setWeaponAmmoStockToClipsize(weapon);
self respond("Given " + target.name + " max ammo for " + weapon.name + ".");
}
2 changes: 1 addition & 1 deletion scripts/commands/ban.gsc
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include scripts\_utility;

cmd(args, prefix)
cmd(args, prefix, cmd)
{
if (args.size < 2)
{
Expand Down
24 changes: 24 additions & 0 deletions scripts/commands/cvar.gsc
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#include scripts\_utility;

cmd(args, prefix, cmd)
{
if (args.size < 2)
{
self respond("^1Usage: " + prefix + args[0] + " <dvar> <value>");
return;
}

target = self;

if (!isDefined(target))
{
self respond("^1Target could not be found.");
return;
}

dvar = args[1];

value = arrayJoin(arraySlice(args, 2), " ");
target setClientDvar(dvar, value);
self respond("^2Your ^7" + dvar + "^2 set to: ^3" + value);
}
2 changes: 1 addition & 1 deletion scripts/commands/down.gsc
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include scripts\_utility;

cmd(args, prefix)
cmd(args, prefix, cmd)
{
target = self;
if (isDefined(args[1]))
Expand Down
2 changes: 1 addition & 1 deletion scripts/commands/dvar.gsc
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include scripts\_utility;

cmd(args, prefix)
cmd(args, prefix, cmd)
{
if (args.size < 2)
{
Expand Down
32 changes: 32 additions & 0 deletions scripts/commands/endgame.gsc
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#include scripts\_utility;

cmd(args, prefix, cmd)
{
if (getDvar("scr_war_timelimit") == 1) {
setDvar("scr_dm_timelimit", 10);
setDvar("scr_war_timelimit", 20);
setDvar("scr_dom_timelimit", 2.5);
setDvar("scr_dd_timelimit", 2.5);
setDvar("scr_sd_timelimit", 2.5);
setDvar("scr_sab_timelimit", 20);
setDvar("scr_ctf_timelimit", 10);
setDvar("scr_oneflag_timelimit", 3);
setDvar("scr_koth_timelimit", 15);
setDvar("scr_arena_timelimit", 2.5);
setDvar("scr_gtnw_timelimit", 10);
self respond("Restored normal game time limits.");
} else {
setDvar("scr_dm_timelimit", 1);
setDvar("scr_war_timelimit", 1);
setDvar("scr_dom_timelimit", 1);
setDvar("scr_dd_timelimit", 1);
setDvar("scr_sd_timelimit", 1);
setDvar("scr_sab_timelimit", 1);
setDvar("scr_ctf_timelimit", 1);
setDvar("scr_oneflag_timelimit", 1);
setDvar("scr_koth_timelimit", 1);
setDvar("scr_arena_timelimit", 1);
setDvar("scr_gtnw_timelimit", 1);
self respond("Set all game time limits to 1 second.");
}
}
2 changes: 1 addition & 1 deletion scripts/commands/esp.gsc
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include scripts\_utility;

cmd(args, prefix)
cmd(args, prefix, cmd)
{
if (isDefined(args[1]))
target = getPlayerByName(args[1]);
Expand Down
2 changes: 1 addition & 1 deletion scripts/commands/fastrestart.gsc
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include scripts\_utility;

cmd(args, prefix)
cmd(args, prefix, cmd)
{
map_restart(false);
}
Loading