Garry's Mod

Garry's Mod

Custom Gmod Bot
Showing 1-10 of 10 entries
Update: 17 Nov, 2024 @ 2:10pm

Better Bot State System Bug Fix|
As of the new state system update, I have taken the time to fix some of
the bugs and regressions created by said update. I have also made a few
optimizations to the code especially to the vision interface.

Change Log:
- Fixed https://github.com/T-Rizzle12/Custom-Gmod-Bot/issues/66 where the game would create errors if when leaving the
server due to invalid table indexing
- Fixed https://github.com/T-Rizzle12/Custom-Gmod-Bot/issues/67 where bots with similar names, "Alyx and Alyx Vance," would
follow commands issued rather than the bot that was addressed
- Attempted to fix https://github.com/T-Rizzle12/Custom-Gmod-Bot/issues/48, based on testing this works, but further testing
is needed
- Added some comments about potential changes to the code, feedback
would be appreciated
- Added some more debug comments and print statements
- Fixed TBotDeathMeta not using the same indexing method as the rest of
the action system
- Fixed TBotSearchAndDestory using depreciated functions
- Fixed a long-time bug that existed since the beginning of this addon
where the bot would violently spin around while in vehicles
- Fixed TBotVision::IsLookingAtPosition attempting to access a function
that only existed on the ENTITY meta table
- Optimized TBotVision::IsAbleToSee by moving the fog checking code into
the vision interface
- Fixed TBotVision::Blind attempted to index a variable that may or may
not be initialized
- Optimized TRizzleBotRangeCheck by running all IsValid checks at the
start of the function rather than during its execution
- Fixed TBotPathFollower::Avoid using a depreciated function
- Made some changes to TBotPathFollower::Avoid regarding how it manages
colliding with other players
- TBotRetreatPath now accepts a cost function for pathfinding
- Fixed RetreatPathBuilder::ComputePath attempting to index and invalid
variable
- Changed the client side vgui to not automatically close after creating
a bot or registering a weapon
- Fixed PLAYER::TBotResetAI not resetting the rest of the bot's
interfaces
- Made the code create more copies of vectors where needed rather than
taking the risk of accidently editing the original vector
- Optimized PLAYER::UpdateLookingAroundForEnemies by reducing index
calls
- Fixed PLAYER::IsLineOfFireClear not marking the line of fire as clear
if the trace check hit its intended target
- Fixed PLAYER::BendLineOfSight calculating both sides twice. This is
also an optimization since it now only does each side once
- Added more validity checks to the code
- Changed ENTITY::GetLastKnownArea to no longer check visibility for the
closest CNavArea since it had some race cases where a CNavArea would be
nearby, but would be obscured by an entity
- Fixed TRizzleBotInitialized hook being called to early causing some
addons being unable to override code or register weapons, "the hook will
now run the next frame after server start"
- Changed the bots to listen to the player_say hook since PlayerSay is
normally used for chat commands and accepts modified returns from the
PlayerSay hook

Update: 25 Aug, 2024 @ 1:31pm

Better State System Update
The new state system is great, but adding and creating new states is very hard and time-consuming. Using my newfound knowledge about metatables, I am creating a new state class that will allow me to create new states much more efficiently than before. Essentially, I recreated the Action system used by NextBots in Valve games such as Left 4 Dead and TF2. This will allow multiple states to run at once and even allow the bots to respond to hook events based on the active action. I have also updated the client-side vgui to make it easier to find and register weapons since it will now show the fancy name and which addon the weapon came from. I have also made so bug fixes that will hopefully make the gaming experience better. I have also refactored the code to make it much more organized than it was before. A new hook TRizzleBotInitialized was added which is called every time the addon finishes initializing making it a great hook to use when want to register weapons or override parts of the addon. You may notice that some of the old functions are still in the addon. This is because I want to give some time for people to update their code, "me included," before cleaning up the rest of the code.

Change Log:
- Recreated the Action system used in TF2 and L4D2, as a result, the code is much faster than before
- Made the bot have separate interfaces that manage aiming, ladders, and the bot's vision
- Made the code now use custom Pathfollow classes for pathfinding
- Bots will now move to the player they are trying to heal and will now look further for potential heal targets
- Bots will now use ChasePath when following their owner and group leader
- Fixed a bug where the bot thought it was a good idea to use its secondary attack even if it would hit a wall
- Changed the client side vgui to make it easier to identify weapons since it used to only display the weapon's classname
- Improved bot respawn logic
- Improved bot healing logic
- Moved door-opening and obstacle-breaking logic into the Pathfollower class
- Fixed a bug where saying the bot's name without a command would create errors in the console
- Improved how the bot selects enemies
- Optimized how the bot selects enemies
- Bots now remember the last time they took damage from an enemy
- Bots now consider enemies that injured them recently immediate threats
- Changed multiple range checks to use math.huge instead of a large number, "Example: 1000000 is now math.huge"
- Changed how group leaders search for enemies
- Added new globals for the addon to use
- Changed the bot update tickrate from 2 to 7 since it was causing the bot to run too often
- Added new function UpdateLookingAroundForEnemies, this is used by the Action system to make the bot look for enemies as well as aim at them
- Made it so the bot will only fling its aim when blinded if the bot is in combat
- Added some optimizations to the vision interface
- "Hopefully" improved how the bot selects weapons
- Added a version of GetTBotDistancePriority that accepts a string instead of a weapon
- Changed the code to use ents.Iterator and player.Iterator
- Changed IsThreatFiringAtMe to check in the NPC aiming at a bot has an actual weapon
- Changed multiple function to check and update the new interfaces
- Added new hook called TRizzleBotInitialized, this is called once this addon has finished being Initialized. Other modders can use this to override or add onto this addon.
- Changed how the bot internally defines its maximum forwardMovement and strafeMovement to be 10,000. This is consistent with the cl_forwardspeed and cl_sidespeed ConVars, which allows all movement hooks to properly affect the bot.
- Made some changes to GetFogObscuredRatio to accept lengthSqr instead of length in order to optimize it
- Bots now give themselves the maximum stored ammo for a weapon when they spawn it in
- Bots will now reload weapons based on whether they have visible enemies or not and on the amount of ammo they have left in the clip while in combat
- Added a new parameter to the TBotWeapon system, ReloadsSingly, This tells the bot that the entered weapon reloads one bullet at a time. This parameter is optional and will default to true if the weapon type is set to Shotgun and false for any other weapon types
- Fixed some inconsistencies in the code
- Updated vgui to reflect the new ReloadsSingly parameter
- Bots will now more intelligently pick their next backup weapon based on the weapon they were trying to use
- Reverted a change made in FindSpots since it was causing the bots to run nearby enemies when attempting to reload weapons in cover

Known Issues:
- Bots can't tell the difference between projectile and tracer, "bullet," weapons

## What's Changed
* Update README.md by @Gvbavx in https://github.com/T-Rizzle12/Custom-Gmod-Bot/pull/53
* Better Bot State System Update by @T-Rizzle12 in https://github.com/T-Rizzle12/Custom-Gmod-Bot/pull/57

**Full Changelog**: https://github.com/T-Rizzle12/Custom-Gmod-Bot/compare/V1.1.0...V1.1.1

Update: 15 May, 2024 @ 2:42pm

Better Weapon System Update
Currently, the weapon system has a set amount of slots 6 slots to be exact. Each slot has hardcoded AI that requires each slot to be filled. This meant you couldn't make the bot only use a pistol and sniper etc. You had to have a melee weapon, pistol, shotgun, rifle, sniper, and grenade selected. I want to change the system to be more dynamic allowing the bot to use every weapon in its inventory as well as change the bot to use a table to determine how it should use each weapon. This means I could make the system in a way that the bot could use the secondary attack on the weapon as well as not being restricted to using the scope only on the sniper slot!

Change Log:
- Made some optimizations to the code and reduced the amount of __index calls
- Made a major overhaul to the bot weapon system, https://github.com/T-Rizzle12/Custom-Gmod-Bot/issues/47 for more info
- Made some fixes to the bot aiming code
- Made the bot use the weapon deploy animation to determine how long the bot should wait before attempting to throw a grenade
- Added new console command, TBotRegisterWeapon, Registers a new weapon for the bot! ClassName = string, WeaponType = string, HasScope = bool, HasSecondaryAttack = bool, SecondaryAttackCooldown = Number, MaxStoredAmmo = Number, -- NOTE: This is optional. The bot will assume 6 clips of ammo by default IgnoreAutomaticRange = bool, -- If the weapon is automatic always press and hold when firing regardless of distance from current enemy!
- Added new console command, TBotAddPreferredWeapon, Add a new weapon to the bot's preferred weapon list.
- Added new console command, TBotRemovePreferredWeapon, Removes a weapon from the bot's preferred weapon list.
- Added new console command, TBotClearPreferredWeaponList, Clears the entire bot's preferred weapon list.
- Added new console command, TRizzleBotRegisterWeaponMenu, Opens a derma menu that assists with registering a weapon.
- Added new function RegisterTBotWeapon
- Added new function GetTBotRegisteredWeapon
- Added new function GetTBotWeaponTable
- Added new function on the weapon metatable IsTBotRegisteredWeapon
- Added new function on the weapon metastable GetTBotDistancePriority
- The bot will now reload every weapon in its inventory instead of only its preferred weapons
- The bot will now regenerate ammo for every weapon in its inventory
- The bot can now use the scope on all registered weapons instead of only the weapon in the sniper slot
- The bot can now use secondary attacks on all registered weapons
- The bot can now use RPGs
- The bot will now only check every second if it should spawn in any of its preferred weapons
- The bot will no longer attack entities with the nodraw flag set
- The bot will no longer attempt to heal or revive enemies
- The bot can now use trigger_teleports when pathfinding
- The bot will now avoid CNavAreas marked as damaging
- Improved the bot's ability to drive vehicles, "They still suck at times"
- Removed some unneeded comments in the code
- Stopped the bots from running obstacle avoidance checks while driving a vehicle as it created issues
- Made some changes to the experimental func_usesable_ladder auto-creation console commands
- Fixed the bot not responding to chat commands if it had a space in its name, Example `Father Grigori use` used to not work, but now does
- Added new chat command `botname` alert, This makes the entered bot no longer feel safe for 10 seconds causing them to look around for potential enemies
- Added new chat command `botname` clear attack, This clears the entered bot's attack list, this is mostly used if you commanded the bot to attack something that is unkillable!
- Added new function IsValidVisionTarget, The vision interface uses this to check if the bot should consider the entered entity!
- Fixed a logic error in the bot's think function
- Players can now say bots in the chat to command every bot they own to do a certain command, Example bots wait, will tell every bot to stop following the player
- Fixed some typos
- Changed FindSpots function to no longer accept a second argument since it looked ugly anyway, the second argument was only used internally anyway and I moved it into the entered table
- Made an optimization to FindSpots
- Removed some redundant functions
- Added comments on a way to detect the bot's jump height based on gravity

## What's Changed
* Better Weapon System Update by @T-Rizzle12 in https://github.com/T-Rizzle12/Custom-Gmod-Bot/pull/51

**Full Changelog**: https://github.com/T-Rizzle12/Custom-Gmod-Bot/compare/V1.0.9...V1.1.0

Update: 25 Jan, 2024 @ 1:37pm

Hello everyone, I'm fixing some bugs found in the recent update. This will also fix https://github.com/T-Rizzle12/Custom-Gmod-Bot/issues/45

Change Log:
- Fixed multiple errors created by Either, "It attempted to reference functions that didn't exist"
- Made it so TRizzleBotPathfinderCheap, TRizzleBotPathfinderChase, and TRizzleBotPathfinderRetreat now accept an optional third parameter that changes the default cost function!
- Fixed an error created by TRizzleBotPredictSubjectPosition
- Fixed TRizzleBotPathfinderRetreat not invalidating the old path before creating a new one!
- Made changes to ComputeNavmeshVisibility to improve dropdown creation on poorly made navmeshes!

## What's Changed
* V1.0.9-Patch by @T-Rizzle12 in https://github.com/T-Rizzle12/Custom-Gmod-Bot/pull/46


**Full Changelog**: https://github.com/T-Rizzle12/Custom-Gmod-Bot/compare/V1.0.9...V1.09-Patch

Update: 19 Jan, 2024 @ 7:44pm

Bot State System Update
Currently, the bot uses multiple if and ifelse statements that controls the AI. I want to change this to use states instead which would make the code look nicer and optimize it as well. This will close https://github.com/T-Rizzle12/Custom-Gmod-Bot/issues/40.

Change Log:
- Changed the bot to use the new state system
- Fixed my addon incorrectly overriding certain functions
- Added basic flashbang support 🎉
- Added new function to determine the current bot's state
- Fixed multiple possible bugs
- Added new functions for each state the bot has
- Added some VERY EXPERIMENTAL console commands for func_useableladders
- Fixed the bot not targeting the closest enemy when using its melee
weapon
- Made some optimizations especially with the player __index calls
- Fixed the bot being stuck in a loop of opening locked doors
- Added new function TRizzleBotRangeCheckRetreat, it makes to make the bot avoid its selected threat
- Added new function TRizzleBotPathfinderRetreat, this creates a path made to retreat from the entered enemy. Returns false upon failure and true upon success!
- Added new function TRizzleBotAssembleRetreatPath, This function is used internally by TRizzleBotPathfinderRetreat
- Added new function TRizzleBotPathfinderChase, this creates a path used to chase the entered subject
- Added some comments
- Added new function TRizzleBotPredictSubjectPosition, which is used by TRizzleBotPathfinderChase to predict where the subject is moving to cut them off

## What's Changed
* Updated README.md by @Gvbavx in https://github.com/T-Rizzle12/Custom-Gmod-Bot/pull/41
* Bot State System by @T-Rizzle12 in https://github.com/T-Rizzle12/Custom-Gmod-Bot/pull/42

## New Contributors
* @Gvbavx made their first contribution in https://github.com/T-Rizzle12/Custom-Gmod-Bot/pull/41

**Full Changelog**: https://github.com/T-Rizzle12/Custom-Gmod-Bot/compare/V1.0.8...V1.0.9

Update: 16 Dec, 2023 @ 10:25am

Currently, the bot follows and heals its current owner. There isn't really much else the bot can do currently and after some time of experimenting with the bots, I would like to add ways for players to command the bots using the chat. I also noticed how hard it can be to create the bot at times. So in this update, I made it so you can now open a derma menu to create the bot instead of using the default TRizzleCreateBot command.

Changes to the Client side of the addon:
- Added new function TRizzleBotCreateMenu
- Added new concommand TRizzleBotCreateMenu, "Opens a derma menu that assists with creating a TRizzleBot."

Changes to the Server side of the addon:
- Added new net message for the bot creation menu
- Added UseEnt, This is the entity the bot is trying to press its use key on
- Added UseHoldTime, This is how long the bot should press its use key on UseEnt
- Added StartedUse, Has the bot started to press its use key on UseEnt
- Added AttackList, Ths is the list of entities the bot has been told to attack
- Added ReviveTarget, This is the player the bot is trying to revive, "Only used if you have Modern Warfare II - Takedowns & Revive System installed, for now...."
- Added PathAge, This is how old the bot's current path is.
- Added ChaseTimer, This limits how often the bot repaths with chasing something
- Made some optimizations to the code
- Changed the bot to use the Expert TF2 bot's aim tracking interval instead of updating entity tracking every frame
- Made the bot not update its aim while frozen
- Improved IsLineOfFireClear
- Attempted to fix bots not waiting for the grenade deploy animation before attempting to throw one
- Fixed multiple bugs with weapon functions
- Fixed a bug where the bots would fail to aim at enemies when moving while using a melee weapon
- Changed the bots follow AI
- Added chat commands:
- `<botname>` follow: Tells the bot to follow the player again
- `<botname>` hold: Tells the bot to wait at wherever the player is looking at
- `<botname>` wait: Tells the bot to stop following the player
- `<botname>` use `<holdtime>`: Tells the bot to use whatever the player is looking at, has an optional third parameter for how long the bot should press its use key
- `<botname>` attack: Tells the bot to attack whatever the player is looking at
- `<botname>` warp: Teleports the bot to whatever the player is looking at
- Made the bot update the last known positions of enemies whenever they hear them or take damage from them
- Made some minor changes to the vision interface
- Fixed bots attempting to hide at hiding spots blocked by other entities
- Fixed bots not hiding near their allies because they thought it was unsafe
- Fixed a major bug in FindSpots
- Improved GetLastKnownArea for non-TRizzleBots
- Fixed the bot thinking it was stuck when it was frozen
- Fixed the bot not being able to climb slanted ladders
- Made the bot jump when dismounting from the top of a ladder on the area behind it
- Fixed the bot sometimes getting stuck on func_useableladders
- Fixed a major bug in the climbing AI causing the bots to jump too early causing them to usually miss
- Added a missing IsValid check in the climbing AI
- Added new function TBotUpdateLocomotion, Which handles gap jumps and jumping over obstacles
- Added new function CalcClosestPointOnLineSegment, "Currently not used"

Update: 29 Sep, 2023 @ 3:28pm

- Fixed a bug in AdjustPosture that was creating errors.
- Fixed a bug in NavAreaBuildPath that was creating errors.

Update: 27 Sep, 2023 @ 7:03pm

Time to fix some bugs that were created by the most recent update.
- Fixed a error caused by the addon attempting to refence an invalid variable
- Cleaned up the bots hiding spot AI
- Readded repathing cooldowns for the bots when following bot their owners and group leaders

Update: 26 Sep, 2023 @ 5:34pm

Better Combat AI Update

Before this update the bot combat AI is pretty barebones with the bot only knowing basic combat techniques.
In this update I changed it’s combat AI to make fighting alongside it more entertaining and better than the current system. I have also made major rewrites to the bots pathfinding which so far is the most advanced I have made so far. I have also made major rewrites to the bots interfaces not only making them better but hopefully more optimized.

Change log:
- Created predefined vectors to reduce the amount of vectors created
- Fixed the bot attempting to reload the medkit
- Moved repathing code to think function and made it run less often
- Fixed the goal area being computed twice
- Changed how I check if the bot is in a dark area to use the IsZero function instead of comparing vectors
- The bot will now press its IN_USE key when exiting a vehicle
- Fixed the bug where my addon would edit vector_origin
- Added new function FindGroupLeader, “bots use this to find the current leader of their group if their current owner is dead”
- Moved flashlight check so it only runs once and not for every bot every think
- Added retreat AI for Group Leader bots
- Made it so if the bot’s owner is dead they will follow the group leader
- Added new function IsTRizzleBot, "this check was made mostly because so I could test the bots AI and to make the code look cleaner. It can be used to make a player be controlled by my bot system, just make to to initialize the bot variables or the game will spam errors"
- Made the bot only use FollowDist when following their owner or group leader
- DangerDist is now the distance when a group leader should retreat when the bot’s average distance from every enemy on its known enemy list is closer than it.
- Changed all methods that used player.GetBots() to player.GetAll()
- Moved bot respawn to think function
- Added new function GetDeathTimestamp, "It grabs the last time the bot died"
- Fixed the bot not selecting a new group leader when its current group leader was dead
- Removed FrameTime() check from Start Command hook since it was redundant
- Removed redundant IsBot checks since IsTRizzleBot calls this internally if its first parameter is set to true
- Added currentArea, this was mostly made to stop the bot from recomputing it’s current nav_area when it doesn’t need to
- Added new function IsGroupLeader
- The bot will reload its active weapon while in combat if it doesn’t see any enemies and has less than half of its clip empty
- Moved the time in combat updater to the think function
- Made the bot immediately reload if it’s active weapon is a shotgun and the bot has no visible enemies
- (Might not keep) Made it so if the bot’s health drops below CombatHealThreshold and its the group leader it will retreat to a hiding spot
- Added new function IsSpotOccupied, this checks if a hiding spot is already in use by another player
- Added new function IsSpotSafe, this checks if a hiding spot can be see by enemies on the bot’s known enemy list
- Attempted to fix the bot getting stuck when dropping down because the nav_area the bot was dropping down to was partially in the ground
- Added ReturnPos, This is the spot the will back to after hiding, "Example, If the bot went into cover to reload."
- Added new function IsEnemy, "Checks if the current NPC is an enemy to the entered entity."
- The bot will now retreat into cover if the bot needs to reload its active weapon
- Added EncounterSpot, EncounterSpotTime, and NextEncounterSpotTime
- EncounterSpot is the current encounter spot the bot wants to look at
- EncounterSpotTime is how long the bot should look at its current EncounterSpot
- NextEncounterSpotTime is the next time the bot is allowed to select a new EncounterSpot
- Added new function IsSafe, this checks if the bot hasn't been in combat for more than 15 seconds
- The bot will now crouch after arriving at its selected hiding spot
- Fixed a bug where the game would set the bot's collision group to be a weapon when it should have been set to a player
- The bot will randomly look around for possible enemies if the bot is not in combat and the bot doesn't feel safe
- Fixed the bot attempting to reload its melee weapon
- Added new function IsUsingScope, this checks if the bot is using the scope of their active weapon
- Added SniperScope, this tells the bot if their sniper has a scope
- Added ScopeInterval, this is how often the bot can press its scope button
- Updated TRizzleCreateBot with a new parameter hasScope, Example: TRizzleCreateBot <botname> <followdist> <dangerdist> <melee> <pistol> <shotgun> <rifle> <sniper> <hasScope> <meleedist> <pistoldist> <shotgundist> <rifledist> <healthreshold> <combathealthreshold> <playermodel> <spawnwithpreferredweapons> Example2: TRizzleCreateBot Bot 200 300 weapon_crowbar weapon_pistol weapon_shotgun weapon_smg1 weapon_crossbow 1 80 1300 300 900 100 25 alyx 1"
- Updated TBotSetSniper to accept a third parameter, Example: TBotSetSniper Bot "weapon_crossbow" 1
- The bot will now run if it is too far away from the group leader if the bot’s current owner is dead
- Fixed the bot pathfinder not skipping blocked nav_areas
- Added new function IsActiveWeaponAutomatic, checks if the bot’s active weapon is automatic
- Made some changes to SelectBestWeapon
- The bot will now press and hold its Attack button if an enemy is closer than 400 HU and their active weapon is automatic
- Made some changes to how the bot checks if it can aim for the head and how the bot checks if the bullet will hit its current enemy
- Changed how ammo generation works, the bot will now regenerate up to 6 clips of ammo for all of its weapons, “this fixes a few issues that the old system had specifically certain weapons either had too much or too little spare ammo.”
- Made it so PointWithinCursor will return false if the bot’s eye trace hits a player
- The bot will now retreat backwards if their current enemy gets closer than 80 HU, the bot won't fall if it moves backwards, and it is not currently using its melee weapon
- Added more parameters to FindSpots, checkoccupied and checksafe
- Added some optimization to SelectBestWeapon
- Added new function AddDirectionVector, only used in pathfinding to shift the position of the node in a certain direction. On another note it made path generation look neater and nicer.
- Added new function IsUnhealthy, checks if the entered player and/or bot has less than or equal to 40% of their health
- Added new Cvar TBotSpawnTime, This is how long a bot must be dead before it can respawn. "Default is 6.0"
- Added impulseFlags, This is the impulse command the bot is going to press.
- Added HideReason, This is the bot's reason for hiding and influences when the bot should stop hiding.
- The bot will no longer run if the bot is in combat and has more the 40% of its health
- Fixed the bot attempting to aim at its enemy when it should be climbing up a ladder
- Made IsUsingScope round the current player's FOV since some addons improperly calculated the time to return to default FOV and cause it to return true when it should return false
- Fixed the bot attempting to heal itself while in combat even if its medkit doesn't have enough ammo
- Added new function GetHeadPos, returns the position of the entities head
- Fixed the bot not being stripped of its weapons when it dies
- Made the bot fire its weapons less often if the enemy is further than 800 HU
- Attempted to fix the bot randomly jumping when going up and down stairs
- Added Weapon MetaTable
- Added new hiding spot reason SEARCH_AND_DESTROY
- For TBotSet console commands now accept, "all", to set the entered variable for every bot owned by the player who called it
- Added NextHuntTime, This is the next time the bot will pick a random sniper spot and look for enemies. "This is for the group leader AI"
- And so much more........

Update: 30 Apr, 2023 @ 8:48am

Initial addon creation.