From f24c32b82b09e9965cb9b746dc2af0c7666f4899 Mon Sep 17 00:00:00 2001 From: Chenterito <64875738+Chenterito@users.noreply.github.com> Date: Wed, 1 Nov 2023 21:43:57 -0500 Subject: [PATCH 1/3] Add flymode command Command that gives the player the possibility of flying, establishing the session options from player to spectator. During this mode the player cannot use weapons. It is the spectator mode in game. --- chat_commands/chat_command_fly_mode.gsc | 93 +++++++++++++++++++++++++ 1 file changed, 93 insertions(+) create mode 100644 chat_commands/chat_command_fly_mode.gsc diff --git a/chat_commands/chat_command_fly_mode.gsc b/chat_commands/chat_command_fly_mode.gsc new file mode 100644 index 0000000..18e1d7b --- /dev/null +++ b/chat_commands/chat_command_fly_mode.gsc @@ -0,0 +1,93 @@ +#include scripts\chat_commands; + +Init() +{ + CreateCommand(level.chat_commands["ports"], "flymode", "function", ::FlyModeCommand, 3, ["default_help_one_player"], ["fly"]); +} + + + +/* Command section */ + +FlyModeCommand(args) +{ + if (args.size < 1) + { + return NotEnoughArgsError(1); + } + + error = ToggleFlyMode(args[0]); + + if (IsDefined(error)) + { + return error; + } +} + + + +/* Logic section */ + +ToggleFlyMode(playerName) +{ + player = FindPlayerByName(playerName); + + if (!IsDefined(player)) + { + return PlayerDoesNotExistError(playerName); + } + + commandName = "fly"; + + ToggleStatus(commandName, "Fly Mode", player); + + if (GetStatus(commandName, player)) + { + player DoFlyMode(true); + player thread ThreadFlyMode(); + } + else + { + player DoFlyMode(false); + player notify("chat_commands_fly_mode_off"); + } +} + +ThreadFlyMode() +{ + self endon("disconnect"); + self endon("chat_commands_fly_mode_off"); + + for(;;) + { + self waittill("spawned_player"); + + self DoFlyMode(true); + } +} + +DoFlyMode(enabled) +{ + if (enabled) + { + if ( self.sessionstate == "playing" ) + { + self allowSpectateTeam( "freelook", true ); + self.sessionstate = "spectator"; + } else { + self.sessionstate = "playing"; + self allowSpectateTeam( "freelook", false ); + } + } + else + { + if ( self.sessionstate == "playing" ) + { + self allowSpectateTeam( "freelook", true ); + self.sessionstate = "spectator"; + } else { + self.sessionstate = "playing"; + self allowSpectateTeam( "freelook", false ); + } + } +} \ No newline at end of file From 3c424d6a95ae8ca8af4d587354db2d1d67b24421 Mon Sep 17 00:00:00 2001 From: Chenterito <64875738+Chenterito@users.noreply.github.com> Date: Sat, 4 Nov 2023 17:00:26 -0500 Subject: [PATCH 2/3] Update chat_commands.gsc --- chat_commands/chat_commands.gsc | 73 +++++++++++++++++++++++++++++++-- 1 file changed, 70 insertions(+), 3 deletions(-) diff --git a/chat_commands/chat_commands.gsc b/chat_commands/chat_commands.gsc index b3b07c0..edfb634 100644 --- a/chat_commands/chat_commands.gsc +++ b/chat_commands/chat_commands.gsc @@ -476,6 +476,11 @@ PlayerDoesNotExistError(playerName) return ["Player " + playerName + " was not found"]; } +TeamDoesNotExistError(teamName) +{ + return ["Team " + teamName + " was not found"]; +} + DvarDoesNotExistError(dvarName) { return ["The dvar " + dvarName + " doesn't exist"]; @@ -492,20 +497,82 @@ CamoDoesNotExistError(camoName) FindPlayerByName(name) { - if (name == "me") + if (ToLower(name) == "me") { return self; } + potentialPlayersFound = 0; + foundPlayer = undefined; + foreach (player in level.players) { - if (ToLower(player.name) == ToLower(name)) + if (ToLower(player.name) == ToLower(name)) // if we get an exact match return the player { return player; } + + if (ToLower(GetSubStr(player.name, 0, name.size)) == ToLower(name)) // found a player who's name starts with the given text + { + potentialPlayersFound++; + } + + if (potentialPlayersFound == 1 && !IsDefined(foundPlayer)) // store the first player we find, since we only return one if and only if it only finds one + { + foundPlayer = player; + } + } + + if (potentialPlayersFound == 1) // we only found one player who's name starts with the given text so it's safe to return the player we found + { + return foundPlayer; } } + +FindTeamByName(name) +{ + + name = ToLower(name); + + if (name == "me" || name == "friends") + { + return self.sessionteam; + } + + if( name == "allies" && getDvar("g_gametype") != "infect") + { + return self.sessionteam; + } + + switch (name) + { + case "axis": + case "inf": + case "infected": + name = "axis"; + break; + case "allies": + case "sur": + case "survivors": + name = "allies"; + break; + case "enemies": + if(self.sessionteam == "allies") + name = "axis"; + else + name = "allies"; + break; + default: + name = undefined; + break; + } + + return name; +} + + + ToggleStatus(commandName, commandDisplayName, player) { SetStatus(commandName, player, !GetStatus(commandName, player)); @@ -739,4 +806,4 @@ DebugIsOn() PermissionIsEnabled() { return GetDvarInt("cc_permission_enabled"); -} \ No newline at end of file +} From 98605afc0439a840926bd986448980a7dac0309e Mon Sep 17 00:00:00 2001 From: Chenterito <64875738+Chenterito@users.noreply.github.com> Date: Sat, 4 Nov 2023 17:01:16 -0500 Subject: [PATCH 3/3] Update chat_command_give.gsc --- chat_commands/chat_command_give.gsc | 35 ++++++++++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) diff --git a/chat_commands/chat_command_give.gsc b/chat_commands/chat_command_give.gsc index 5f97074..04ee542 100644 --- a/chat_commands/chat_command_give.gsc +++ b/chat_commands/chat_command_give.gsc @@ -3,6 +3,7 @@ Init() { CreateCommand(level.chat_commands["ports"], "giveweapon", "function", ::GiveWeaponCommand, 2); + CreateCommand(level.chat_commands["ports"], "giveweaponteam", "function", ::GiveWeaponTeamCommand, 2); CreateCommand(level.chat_commands["ports"], "givekillstreak", "function", ::GiveKillstreakCommand, 3); CreateCommand(level.chat_commands["ports"], "givecamo", "function", ::GiveCamoCommand, 2); } @@ -86,6 +87,38 @@ GivePlayerWeapon(targetedPlayerName, weaponName, takeCurrentWeapon, playSwitchAn } } +GiveTeamWeapon(targetedTeamName, weaponName, takeCurrentWeapon, playSwitchAnimation) +{ + team = FindTeamByName(targetedTeamName); + + if (!IsDefined(team)) + { + return TeamDoesNotExistError(targetedTeamName); + } + + foreach ( p in level.players ) + { + if ( p.sessionteam == team ) + { + if (IsDefined(takeCurrentWeapon) && takeCurrentWeapon) + { + p TakeWeapon(p GetCurrentWeapon()); + } + + p GiveWeapon(weaponName); + + if (IsDefined(playSwitchAnimation) && playSwitchAnimation) + { + p SwitchToWeapon(weaponName); + } + else + { + p SetSpawnWeapon(weaponName); + } + } + } +} + GivePlayerKillstreak(targetedPlayerName, killstreakName) { player = FindPlayerByName(targetedPlayerName); @@ -134,4 +167,4 @@ GivePlayerCamo(targetedPlayerName, camoName, playSwitchAnimation) } } } -} \ No newline at end of file +}