Garry's Mod

Garry's Mod

Team Fortress 2 Bots [2022]
Fix for insane lag this mod can cause even without bots spawned
After testing every addon I have installed, I figured out that this addon was what was causing my fps to crater from 60 to 2 whenever I had a bunch of npcs on the map.

Basically, the addon creates a new infinitely repeating timer for every npc that spawns that is constantly doing table actions and searching the entities list in every individual instance even when there are no tf2 bots on the map. The complexity is multiplied for every npc on the map until your fps is destroyed.

I have rewritten that part of the code into a think hook with a coroutine that doesn't need to run in every npc. i also noticed the code wasn't setting mvm bot relationships for citizens, but the way i coded this should fix all that

How to (Two ways to replace addon files):
a) Extract the whole addon (with anything that can, such as a steam workshop downloader) and place the addon folder into garrysmod/addons/ and then replace the relevant files in there.
Note: Linux and Mac users must rename addon folders placed in addons/ to all lowercase characters or they will not work.

b) Make a new file with the name of the file to replace, with the code in it, and place it in the garrysmod directory directly. In this case you would place it in garrysmod/lua/autorun/server/
You will have to make the directories in the lua folder if they don't exist.


lua/autorun/server/sv_tf2ainpc_relationships.lua
https://pastebin.com/raw/nWSM3Zk4

edit: added onentitycreated hook
e2: minor edit
e3: added instructions and also took out some debug stuff i accidentally left in, woops
e4 oct22: replaced code block with link to correct code. brackets in code might have messed up the code block
Last edited by sockpuppetclock; 22 Oct, 2021 @ 3:16pm
< >
Showing 1-15 of 18 comments
IvanVladimir0435 15 Apr, 2021 @ 7:12am 
Interesting, I'll try it out and see how it goes
IvanVladimir0435 15 Apr, 2021 @ 7:13am 
You could also try setting the relationships when the NPC/NextBot is created, might lag a bit more when spawning them initially, but would reduce greatly the lag mid battle
sockpuppetclock 15 Apr, 2021 @ 7:19am 
yeah i could probably edit it so that it only bothers checking the ents list if a new npc was made since the last check
IvanVladimir0435 15 Apr, 2021 @ 7:26am 
Originally posted by sockpuppetclock:
yeah i could probably edit it so that it only bothers checking the ents list if a new npc was made since the last check
There's a hook called OnEntityCreated
Should help you with it
sockpuppetclock 15 Apr, 2021 @ 7:37am 
alright, done
Garry :3 18 Apr, 2021 @ 2:22am 
thanks im gonna try it
Garry :3 18 Apr, 2021 @ 2:42am 
uh i don't see the "sv_tf2ainpc_relationships.lua"
Gintarjo 18 Apr, 2021 @ 11:33am 
Originally posted by GARRYTALE:
uh i don't see the "sv_tf2ainpc_relationships.lua"
I'm going to guess that I had to make the file and put it in the directory...
IvanVladimir0435 18 Apr, 2021 @ 12:18pm 
Originally posted by Gintarjo:
Originally posted by GARRYTALE:
uh i don't see the "sv_tf2ainpc_relationships.lua"
I'm going to guess that I had to make the file and put it in the directory...
It's in the autorun folder
sockpuppetclock 19 Apr, 2021 @ 4:39pm 
even though i'm not 100% sure how files work, you can either

a) extract the whole addon (with anything that can, such as a steam workshop downloader) and place the addon folder into garrysmod/addons/ and then replace the relevant files

b) place it in the garrysmod directory directly. garrysmod/lua/autorun/server/

i'll add instructions to the op
Last edited by sockpuppetclock; 19 Apr, 2021 @ 4:39pm
sockpuppetclock 19 Apr, 2021 @ 5:02pm 
also updated the code, i took out some debug print()'s that i accidentally left in the code and also commented out the cvar that doesn't exist yet (_other_fof) that i uncommented out for some reason
MrNiceGuy518  [developer] 24 Apr, 2021 @ 3:08pm 
Wow, nicely done!
sockpuppetclock 25 Apr, 2021 @ 12:26pm 
Would you be willing to update the addon with this? Most people probably won't find this thread
MAKEMEDEEP45 21 May, 2021 @ 8:44am 
Originally posted by sockpuppetclock:
Would you be willing to update the addon with this? Most people probably won't find this thread
Imma guess thats a no
wowzers193 22 May, 2021 @ 3:49pm 
BUG LAG: If, you put a bot 2 fps at will Thats all.
< >
Showing 1-15 of 18 comments
Per page: 1530 50