smilz0 / Left4Bots

Improvements for the L4D2 survivor bots
https://steamcommunity.com/sharedfiles/filedetails/?id=3022416274
34 stars 4 forks source link

Make bots thinks every tick + Handle weapon and infected for better performance #49

Open 4512369781 opened 10 months ago

4512369781 commented 10 months ago

As the title says, I made a script file and everything is in it: left4bots_afterload.zip

On my laptop, it does reduce a lot of "SCRIPT PERF WARNING --- "" ran long at 1.650392ms" messages.

smilz0 commented 10 months ago

Thank you. I didn't know about the -1 interval. I will surely use it straight away as it makes more sense than my arbitrary 0.01 lol. As of the performance improvements i need some time to test it but i'm sure it will work. Btw i was thinking of implementing something similar to what you did but inside a dedicated think function of a dummy entity. Maybe doing it like i do in the bots main think function by splitting the work into several sub functions. For example FuncI = 1 would refresh the common infected, FuncI = 2 to refresh the weapons, FuncI = 3 for the cleaning and so on. Also, probably we can improve it even more by finding the weapon id ( Left4Utils.GetWeaponId(ent) ) directly in this weapons refresh function so to remove it from the bots think func. And maybe we could also check the distance between the common/weapon and the bots and only add them to the lists if whithin a certain range. Though i'm not sure it would make sense for the commons considering that the director already spawns them near the survivors. Anyway i will try to come up with something and i will post it here so we can try to improve it together.

4512369781 commented 10 months ago

Initially, I used "logic_timer" instead of "thinkfunc" for looping, but the “OnTimer” output of "logic_timer" is based on I/O events, which will cause time inconsistency. I tested it for a while and was still not satisfied. Only a few days ago I found more detailed information on the TF2 wiki, and this problem was solved.

About check distance, I guess that would be possible for weapons bucause they don't move. But the infected are always moving, and the distance still needs to be checked again when the bot needs to deal with them. And they get killed frequently, need updates list often, and the number of infected isn't too many, so I think it's better to let bot deal with them.

Now that the bots can think faster, I think it's time to complete the aiming function, when I finish it I'll open a new issue.