Raised This Month: $ Target: $400
 0% 

[L4D2] Survivor Bot AI Improver


Post New Thread Reply   
 
Thread Tools Display Modes
Author
Emana202
Junior Member
Join Date: Apr 2019
Location: Naryn, Kyrgyzstan
Plugin ID:
8467
Plugin Version:
1.5
Plugin Category:
Gameplay
Plugin Game:
Left 4 Dead
Plugin Dependencies:
Servers with this Plugin:
 
Plugin Description:
Survivor Bots are a nightmare to play with, especially on Expert. But what if they were better?
Unapprover:
Reason for Unapproving:
Sounds like this plugin is broken and author vanished - see also: https://forums.alliedmods.net/showpost.php?p=2807226&postcount=65
Old 05-24-2023 , 07:41   [L4D2] Survivor Bot AI Improver
Reply With Quote #1

What's This?

This plugin attempts to improve the behavior of Survivor Bots as much as possible without giving them the huge cheat-like advantages, like godmode, infinite ammo, etc.

Demonstration Video #1
Demonstration Video #2
Noteable Features:
  • Bots now properly approach their melee target and switch between normal swings and bashing + ability for them to use chainsaws.
  • Bots can now pickup and use Tier 3 weapons without having to modify weapon scripts via addons and plugins.
  • You can set the weapon preferences for each survivor type (Coach, Zoey, etc.) using the "l4d2_improvedbots_weapon_preference_*" convars in the game console or plugin's config.
  • Bots that are near witches will slowwalk if the witch isn't close to become enraged.
  • You can make bots that carry props like gnome or gascans to not drop them in any circumstances whatsoever, unless they're incapacitated or grabbed by SI.
  • If the survivor team has too many same types of grenades or sub-types of weapons, they will swap their to the one that isn't.
  • Improved and configurable item scavenging system
  • Bots now avoid moving through areas that are covered in spit or fire and try to find another way to get to their destination. They also react faster to getting spit under them and escape much efficiently.
  • Bots will try to dodge the chargin' chargers and tank's rock that are thrown at them.
  • Bots now will deploy ammopacks if they have any primary weapon and defib dead survivors if they can.
  • Bots with shotguns will switch to their pistols if the target is too far away from them. Also, bots with sniper rifles now don't switch to pistols if target is close to them.
  • Bots with pump shotguns and CSS sniper rifles can shove upon firing to boost their firerate.
  • Bots shouldn't now completely ignore targets that are directly behind them and shoot at witch's feet at close range.
  • If the optional plugin is enabled, bots shouldn't now try to save a survivor if tanks are near them
  • Bots can now throw grenades at huge mob and tanks.
  • And other features that I forgot about due to too much work. Many of the features above can be disabled or tweaked in the config file.

ConVars:
PHP Code:
// If enabled, survivor bot will keep holding the prop it currently has unless it's swarmed by a mob, every teammate needs help, or it wants to use an item.
// -
// Default: "1"
// Minimum: "0.000000"
// Maximum: "1.000000"
l4d2_improvedbots_alwayscarryprop "1"

// Makes survivor bots automatically shove every nearby infected. <0: Disabled, 1: All infected, 2: Only if infected is behind them>
// -
// Default: "1"
// Minimum: "0.000000"
// Maximum: "2.000000"
l4d2_improvedbots_autoshove_enabled "1"

// If bots should avoid and retreat from tanks that are nearby punchable props like cars.
// -
// Default: "1"
// Minimum: "0.000000"
// Maximum: "1.000000"
l4d2_improvedbots_avoidtanksnearpunchableprops "1"

// Makes survivor bots change their grenade type if there's too much of the same one, Ex. Pipe-Bomb to Molotov.
// -
// Default: "1"
// Minimum: "0.000000"
// Maximum: "1.000000"
l4d2_improvedbots_changeweaponiftoomanysubtype_grenades "1"

// Makes survivor bots change their primary weapon subtype if there's too much of the same one, Ex. change AK-47 to M16 or SPAS-12 to Autoshotgun.
// -
// Default: "1"
// Minimum: "0.000000"
// Maximum: "1.000000"
l4d2_improvedbots_changeweaponiftoomanysubtype_primaries "1"

// Enables survivor bots's charger dodging behavior.
// -
// Default: "1"
// Minimum: "0.000000"
// Maximum: "1.000000"
l4d2_improvedbots_chargerevasion "1"

// Range at which survivor's dead body should be for bot to consider it reviveable.
// -
// Default: "2000"
// Minimum: "0.000000"
l4d2_improvedbots_defib_revive_distance "2000"

// Enable bots reviving dead players with defibrillators if they have one available.
// -
// Default: "1"
// Minimum: "0.000000"
// Maximum: "1.000000"
l4d2_improvedbots_defib_revive_enabled "1"

// If bots should deploy their upgrade pack when available and not in combat.
// -
// Default: "1"
// Minimum: "0.000000"
// Maximum: "1.000000"
l4d2_improvedbots_deployupgradepacks "1"

// If bots shouldn't switch to their pistol while they have sniper rifle equiped.
// -
// Default: "1"
// Minimum: "0.000000"
// Maximum: "1.000000"
l4d2_improvedbots_dontswitchtopistol "1"

// Enables survivor bots' improved spitter acid evasion
// -
// Default: "1"
// Minimum: "0.000000"
// Maximum: "1.000000"
l4d2_improvedbots_evadespitteracids "1"

// Chance at which survivor bot may shove after firing a bolt-action sniper rifle. <0: Disabled, 1: Always>
// -
// Default: "3"
// Minimum: "0.000000"
l4d2_improvedbots_fireshove_chance_css_sniperrifles "3"

// Chance at which survivor bot may shove after firing a pump-action shotgun. <0: Disabled, 1: Always>
// -
// Default: "4"
// Minimum: "0.000000"
l4d2_improvedbots_fireshove_chance_pumpshotguns "4"

// Enables survivor bots throwing grenades.
// -
// Default: "1"
// Minimum: "0.000000"
// Maximum: "1.000000"
l4d2_improvedbots_grenadethrowing_enabled "1"

// What grenades should survivor bots throw? <1: Pipe-Bomb, 2: Molotov, 4: Bile Bomb. Add numbers together.>
// -
// Default: "7"
// Minimum: "1.000000"
// Maximum: "7.000000"
l4d2_improvedbots_grenadethrowing_grenadetypes "7"

// Infected count required to throw grenade Multiplier (Value * SurvivorCount).
// -
// Default: "3.75"
// Minimum: "1.000000"
l4d2_improvedbots_grenadethrowing_horde_size_multiplier "3.75"

// Second number to pick to randomize next grenade throw time.
// -
// Default: "30"
// Minimum: "0.000000"
l4d2_improvedbots_grenadethrowing_next_throw_time_max "30"

// First number to pick to randomize next grenade throw time.
// -
// Default: "20"
// Minimum: "0.000000"
l4d2_improvedbots_grenadethrowing_next_throw_time_min "20"

// Range at which target needs to be for bot to throw grenade at it.
// -
// Default: "1500"
l4d2_improvedbots_grenadethrowing_throw_range "1500"

// Makes survivor bots force attack pinned survivor's SI if possible. <0: Disabled, 1: Shoot at attacker, 2: Shove the attacker if close enough. Add numbers together.>
// -
// Default: "3"
// Minimum: "0.000000"
// Maximum: "3.000000"
l4d2_improvedbots_help_pinnedfriend_enabled "3"

// Range at which bots will start firing at SI.
// -
// Default: "2000"
// Minimum: "0.000000"
l4d2_improvedbots_help_pinnedfriend_shootrange "2000"

// Range at which bots will start to bash SI.
// -
// Default: "75"
l4d2_improvedbots_help_pinnedfriend_shoverange "75"

// Enable improved bot item scavenging for specified items. <0: Disable, 1: Pipe Bomb, 2: Molotov, 4: Bile Bomb, 8: Medkit, 16: Defibrillator, 32: UpgradePack, 64: Pain Pills, 128: Adrenaline, 256: Laser Sights, 512: Ammopack, 1024: Ammopile, 2048: Chainsaw
// -
// Default: "16383"
// Minimum: "0.000000"
// Maximum: "16383.000000"
l4d2_improvedbots_itemscavenge_enabled "16383"

// How close should the item be to the survivor bot to able to count it when searching?
// -
// Default: "2500"
// Minimum: "0.000000"
l4d2_improvedbots_itemscavenge_mapsearchdistance "2500"

// The bots' scavenge distance is multiplied to this value when there's no human players left in the team.
// -
// Default: "3.0"
// Minimum: "0.000000"
l4d2_improvedbots_itemscavenge_nohumans_rangemultiplier "3.0"

// Distance at which item should be for bot to able to pick it up.
// -
// Default: "100"
// Minimum: "0.000000"
l4d2_improvedbots_itemscavenge_pickup_distance "100"

// Distance at which item should be for bot to move it.
// -
// Default: "300"
// Minimum: "0.000000"
l4d2_improvedbots_itemscavenge_scavenge_distance "300"

// Distance at which a visible item should be for bot to move it.
// -
// Default: "600"
// Minimum: "0.000000"
l4d2_improvedbots_itemscavenge_scavenge_visible_distance "600"

// If bots shouldn't stop moving in combat when there's no human players in team.
// -
// Default: "1"
// Minimum: "0.000000"
// Maximum: "1.000000"
l4d2_improvedbots_keepmovingincombat "1"

// Range at which bot's target should be to start taking aim at it.
// -
// Default: "125"
// Minimum: "0.000000"
l4d2_improvedbots_melee_aim_range "125"

// Range at which bot's target should be to approach it. <0: Disable Approaching>
// -
// Default: "400"
// Minimum: "0.000000"
l4d2_improvedbots_melee_approach_range "400"

// Range at which bot's target should be to start attacking it.
// -
// Default: "70"
// Minimum: "0.000000"
l4d2_improvedbots_melee_attack_range "70"

// The total number of chainsaws allowed on the team. <0: Bots never use chainsaw>
// -
// Default: "1"
// Minimum: "0.000000"
l4d2_improvedbots_melee_chainsaw_limit "1"

// The nearby infected count required for bot to switch to chainsaw.
// -
// Default: "6"
// Minimum: "1.000000"
l4d2_improvedbots_melee_chainsaw_switch_count "6"

// Enables survivor bots' improved melee behaviour.
// -
// Default: "1"
// Minimum: "0.000000"
// Maximum: "1.000000"
l4d2_improvedbots_melee_enabled "1"

// The total number of melee weapons allowed on the team. <0: Bots never use melee>
// -
// Default: "1"
// Minimum: "0.000000"
l4d2_improvedbots_melee_max_team "1"

// Chance for bot to bash target instead of attacking with melee. <0: Disable Bashing>
// -
// Default: "4"
// Minimum: "0.000000"
l4d2_improvedbots_melee_shove_chance "4"

// The nearby infected count required for bot to switch to their melee weapon.
// -
// Default: "3"
// Minimum: "1.000000"
l4d2_improvedbots_melee_switch_count "3"

// Range at which bot's target should be to switch to melee weapon.
// -
// Default: "250"
// Minimum: "0.000000"
l4d2_improvedbots_melee_switch_range "250"

// If enabled, survivor bots won't take fall damage if they were climbing a ladder just before that.
// -
// Default: "1"
// Minimum: "0.000000"
// Maximum: "1.000000"
l4d2_improvedbots_nofalldmgonladderfail "1"

// Bots' data computing time delay (infected count, nearby friends, etc). Increasing the value might help increasing the game performance, but slow down bots.
// -
// Default: "0.1"
// Minimum: "0.033000"
l4d2_improvedbots_process_time "0.1"

// Enables survivor bots shooting tank's thrown rocks.
// -
// Default: "1"
// Minimum: "0.000000"
// Maximum: "1.000000"
l4d2_improvedbots_shootattankrocks_enabled "1"

// Range at which rock needs to be for bot to start shooting at it.
// -
// Default: "1500"
// Minimum: "0.000000"
l4d2_improvedbots_shootattankrocks_range "1500"

// If bots should change their primary weapon to other one if they're using CSS weapons.
// -
// Default: "1"
// Minimum: "0.000000"
// Maximum: "1.000000"
l4d2_improvedbots_switchoffcssweapon "1"

// If bots should take cover from tank's thrown rocks.
// -
// Default: "1"
// Minimum: "0.000000"
// Maximum: "1.000000"
l4d2_improvedbots_takecoverfromtankrocks "1"

// Enables survivor bots' improved target selection.
// -
// Default: "1"
// Minimum: "0.000000"
// Maximum: "1.000000"
l4d2_improvedbots_targetselection_enabled "1"

// If bots shouldn't target common infected that are currently not attacking survivors.
// -
// Default: "1"
// Minimum: "0.000000"
// Maximum: "1.000000"
l4d2_improvedbots_targetselection_ignoredociles "1"

// Range at which target need to be for bots to start firing at it.
// -
// Default: "2000"
// Minimum: "0.000000"
l4d2_improvedbots_targetselection_shootrange "2000"

// Range at which target need to be for bots to start firing at it with secondary weapon.
// -
// Default: "1500"
// Minimum: "0.000000"
l4d2_improvedbots_targetselection_shootrange_pistol "1500"

// Range at which target need to be for bots to start firing at it with shotgun.
// -
// Default: "750"
// Minimum: "0.000000"
l4d2_improvedbots_targetselection_shootrange_shotgun "750"

// Range at which target need to be for bots to start firing at it with sniper rifle.
// -
// Default: "3000"
// Minimum: "0.000000"
l4d2_improvedbots_targetselection_shootrange_sniperrifle "3000"

// The total number of grenade launchers allowed on the team. <0: Bots never use grenade launcher>
// -
// Default: "1"
// Minimum: "0.000000"
l4d2_improvedbots_tier3weaponlimit_grenadelauncher "1"

// The total number of M60s allowed on the team. <0: Bots never use M60>
// -
// Default: "1"
// Minimum: "0.000000"
l4d2_improvedbots_tier3weaponlimit_m60 "1"

// The field of view of survivor bots.
// -
// Default: "60.0"
// Minimum: "0.000000"
// Maximum: "180.000000"
l4d2_improvedbots_vision_fieldofview "60.0"

// The time required for bots to notice enemy target is multiplied to this value.
// -
// Default: "1.1"
// Minimum: "0.000000"
// Maximum: "4.000000"
l4d2_improvedbots_vision_noticetimescale "1.1"

// Bot Bill's weapon preference. <0: Default, 1: Assault Rifle, 2: Shotgun, 3: Sniper Rifle, 4: SMG, 5: Secondary Weapon>
// -
// Default: "1"
// Minimum: "0.000000"
// Maximum: "5.000000"
l4d2_improvedbots_weapon_preference_bill "1"

// Bot Coach's weapon preference. <0: Default, 1: Assault Rifle, 2: Shotgun, 3: Sniper Rifle, 4: SMG, 5: Secondary Weapon>
// -
// Default: "2"
// Minimum: "0.000000"
// Maximum: "5.000000"
l4d2_improvedbots_weapon_preference_coach "2"

// Bot Ellis's weapon preference. <0: Default, 1: Assault Rifle, 2: Shotgun, 3: Sniper Rifle, 4: SMG, 5: Secondary Weapon>
// -
// Default: "3"
// Minimum: "0.000000"
// Maximum: "5.000000"
l4d2_improvedbots_weapon_preference_ellis "3"

// Bot Francis's weapon preference. <0: Default, 1: Assault Rifle, 2: Shotgun, 3: Sniper Rifle, 4: SMG, 5: Secondary Weapon>
// -
// Default: "2"
// Minimum: "0.000000"
// Maximum: "5.000000"
l4d2_improvedbots_weapon_preference_francis "2"

// Bot Louis's weapon preference. <0: Default, 1: Assault Rifle, 2: Shotgun, 3: Sniper Rifle, 4: SMG, 5: Secondary Weapon>
// -
// Default: "1"
// Minimum: "0.000000"
// Maximum: "5.000000"
l4d2_improvedbots_weapon_preference_louis "1"

// If every survivor bot should only use magnum instead of regular pistol if possible.
// -
// Default: "0"
// Minimum: "0.000000"
// Maximum: "1.000000"
l4d2_improvedbots_weapon_preference_magnums_only "0"

// Bot Nick's weapon preference. <0: Default, 1: Assault Rifle, 2: Shotgun, 3: Sniper Rifle, 4: SMG, 5: Secondary Weapon>
// -
// Default: "1"
// Minimum: "0.000000"
// Maximum: "5.000000"
l4d2_improvedbots_weapon_preference_nick "1"

// Bot Rochelle's weapon preference. <0: Default, 1: Assault Rifle, 2: Shotgun, 3: Sniper Rifle, 4: SMG, 5: Secondary Weapon>
// -
// Default: "1"
// Minimum: "0.000000"
// Maximum: "5.000000"
l4d2_improvedbots_weapon_preference_rochelle "1"

// Bot Zoey's weapon preference. <0: Default, 1: Assault Rifle, 2: Shotgun, 3: Sniper Rifle, 4: SMG, 5: Secondary Weapon>
// -
// Default: "3"
// Minimum: "0.000000"
// Maximum: "5.000000"
l4d2_improvedbots_weapon_preference_zoey "3"

// Allows survivor bots to crown witch on their path if they're holding any shotgun type weapon. <0: Disabled; 1: Only if survivor team doesn't have any human players; 2:Enabled>
// -
// Default: "1"
// Minimum: "0.000000"
// Maximum: "2.000000"
l4d2_improvedbots_witchbehavior_allowcrowning "1"

// Survivor bots will start walking near witch if they're this range near her and she's not disturbed. <0: Disabled>
// -
// Default: "500"
// Minimum: "0.000000"
l4d2_improvedbots_witchbehavior_walkwhennearby "500" 

Change Log:
Code:
1.5 (14-June-2023)
    - Changed how the "l4d2_improvedbots_alwayscarryprop" convar functions on bots. Check the convar's description in the config for info.
    - Implemented the map start checks from Silvers' edit. Should prevent the NavAreaBuildPath related crashes from happening.
    - Bots should now use the melee weapons against distracted SI more frequently.
    - Slightly adjusted where survivor bots aim at tongue'd teammate when the smoker is not on sight.

1.4 (6-June-2023)
    - Slightly tweaked the default ConVar values.
    - Added a setting that makes survivor bots to not take any fall damage if they previously were on a ladder seconds ago.
    - Added a setting that controls the range survivors bots scan the map for items and weapons.
    - Optimized some variable that contain ConVar distances by squaring them at the change
    - Replaced the redundant GetMass SDKCall with a new found way to detect tank props.
    - Bots shouldn't melee approach targets that are behind their flow's path or if they're in any checkpoint.
    - Fixed bots going after witch that too far from them, causing major performance issues due to path building.
    - Bots' avoid range for infected are slightly increased, plus doubled if they're carrying a prop in their hands.
    - Slightly improved bots' spitter acid escape method.
    - Fixed bots dropping of the ladders due to their behavior still running during that.

1.3 (1-June-2023)
    - Fixed target selection and other SI-related stuff not working due to their data not being updated in the code.
    - Applied the witch arraylist optimization suggested by Silvers earlier.
    - Slightly increased the safe area search range when under spitter acid.

1.2 (26-May-2023)
    - Applied some code optimization changes suggested by Silvers. Plugin should now work slightly faster than before.

1.1 (24-May-2023)
    - Fixed an issue with some edicts being counted as survivor's inventory weapon.

1.0 (24-May-2023)
    - Initial release.

Requirements:

Installation:
  1. Download the .smx file and put into the \addons\sourcemod\plugins folder.
  2. Download the .txt gamedata file and put into the \addons\sourcemod\gamedata folder.
Attached Files
File Type: txt l4d2_improved_bots.txt (4.3 KB, 3500 views)
File Type: smx l4d2_sb_ai_improver.smx (85.2 KB, 2530 views)
File Type: sp Get Plugin or Get Source (l4d2_sb_ai_improver.sp - 1406 views - 230.8 KB)

Last edited by Emana202; 06-14-2023 at 10:38. Reason: Plugin update
Emana202 is offline
Emana202
Junior Member
Join Date: Apr 2019
Location: Naryn, Kyrgyzstan
Old 05-24-2023 , 15:24   Re: [L4D2] Survivor Bot AI Improver
Reply With Quote #2

Quote:
Originally Posted by Maur0 View Post
Excellent plugin. The only thing that bothers me are these messages that repeatedly come out and do not stop coming out. I don't know what error it can cause:

Code:
L 05/24/2023 - 14:55:22: [SM] Blaming: left4dhooks.smx
L 05/24/2023 - 14:55:22: [SM] Call stack trace:
L 05/24/2023 - 14:55:22: [SM]   [0] ThrowNativeError
L 05/24/2023 - 14:55:22: [SM]   [1] Line 174, l4dd\l4dd_natives.sp::ValidateAddress
L 05/24/2023 - 14:55:22: [SM]   [2] Line 1740, l4dd\l4dd_natives.sp::Native_GetCurrentFinaleStage
L 05/24/2023 - 14:55:22: [SM]   [4] L4D2_GetCurrentFinaleStage
L 05/24/2023 - 14:55:22: [SM]   [5] Line 3944, F:\Games\Left 4 Dead 2\left4dead2\addons\sourcemod\scripting\l4d2_sb_ai_improver.sp::ShouldUseFlowDistance
L 05/24/2023 - 14:55:22: [SM]   [6] Line 1347, F:\Games\Left 4 Dead 2\left4dead2\addons\sourcemod\scripting\l4d2_sb_ai_improver.sp::SurvivorBotThink
L 05/24/2023 - 14:55:22: [SM]   [7] Line 1256, F:\Games\Left 4 Dead 2\left4dead2\addons\sourcemod\scripting\l4d2_sb_ai_improver.sp::OnPlayerRunCmd
L 05/24/2023 - 14:55:22: [SM] Exception reported: g_pScriptedEventManager not available (WIN/2/1.130).
And half that the function of the command to allow them to change the weapon does not work or is affected.
Do you have the latest version of Left 4 DHooks? If so, have you updated its gamedata with the one provided in the plugin's post?
Emana202 is offline
Maur0
Senior Member
Join Date: Aug 2020
Old 05-24-2023 , 16:05   Re: [L4D2] Survivor Bot AI Improver
Reply With Quote #3

Quote:
Originally Posted by Emana202 View Post
Do you have the latest version of Left 4 DHooks? If so, have you updated its gamedata with the one provided in the plugin's post?
Oh God! Since I haven't checked it before. I'm sorry, my bad. I had updated the version to date, but I didn't see about the new gamedate. Thank you very much and your plugin is great, it improves the bots much better.

For now, I don't see anything wrong. I'll let you know if I notice something strange.
Maur0 is offline
Sev
Veteran Member
Join Date: May 2010
Old 05-24-2023 , 17:28   Re: [L4D2] Survivor Bot AI Improver
Reply With Quote #4

Good work.
Sev is offline
TypicalType
Member
Join Date: Mar 2020
Location: Brazil
Old 05-24-2023 , 19:45   Re: [L4D2] Survivor Bot AI Improver
Reply With Quote #5

This plugin makes my server lag alot on the first level of Hard Rain and on the first and second levels of Dark Carnival and i don't know why that happens, only advancing further in the level makes the lag stop. And even removing some plugins doesn't help, maybe you could check it out?

Last edited by TypicalType; 05-24-2023 at 19:47.
TypicalType is offline
Franco20
Member
Join Date: Nov 2022
Old 05-25-2023 , 13:12   Re: [L4D2] Survivor Bot AI Improver
Reply With Quote #6

This addon is Compatible with the mod "Left 4 Bots (Improved A.I.)" from steam?
Franco20 is offline
Emana202
Junior Member
Join Date: Apr 2019
Location: Naryn, Kyrgyzstan
Old 05-25-2023 , 13:57   Re: [L4D2] Survivor Bot AI Improver
Reply With Quote #7

Quote:
Originally Posted by TypicalType View Post
This plugin makes my server lag alot on the first level of Hard Rain and on the first and second levels of Dark Carnival and i don't know why that happens, only advancing further in the level makes the lag stop. And even removing some plugins doesn't help, maybe you could check it out?
I checked on both of these campaigns and I didn't encounter any lags or issues. Maybe a dependency addon is outdated or something like that?
Emana202 is offline
Emana202
Junior Member
Join Date: Apr 2019
Location: Naryn, Kyrgyzstan
Old 05-25-2023 , 13:58   Re: [L4D2] Survivor Bot AI Improver
Reply With Quote #8

Quote:
Originally Posted by Franco20 View Post
This addon is Compatible with the mod "Left 4 Bots (Improved A.I.)" from steam?
It's compatible, but you have to adjust some settings from either this plugin or the mod in order for them to work without any conflicts.

Last edited by Emana202; 05-25-2023 at 13:59.
Emana202 is offline
Silvers
SourceMod Plugin Approver
Join Date: Aug 2010
Location: SpaceX
Old 05-25-2023 , 16:06   Re: [L4D2] Survivor Bot AI Improver
Reply With Quote #9

Since some players are mentioning performance issues I thought I would have a look and recommend some changes.


- You have some "FindConVar" within the think function and other places in code that you could place in plugin start to optimize the performance. Hooking the convar for change and using a variable instead of retrieving the value from the convar each time.


- "if (hWeaponList == null)delete hWeaponList;" and "if (hWepArray == null)delete hWepArray;" is not necessary, it's already null, no need to use delete here. Remove the whole line. Maybe there are other null checks you should remove, I only saw these skimming through.


- You should probably re-write "GetSurvivorTeamItemCount" and store the equipped weapons/items each player has when they equip it, instead of constantly looping through all clients and weapons checking what they have. Use SDKHook_WeaponEquipPost and store the weapon type in an array such as: "int g_iPlayerItems[MAXPLAYERS+1][6]" and instead of checking for the string, check for the weapon type ID instead. A list of weapon types and IDs can be found in left4dhooks.


- In some functions that are accessed a lot, especially from Think functions you could optimize the strings by changing "char" to "static char" so it's not re-created each time, unless (which I doubt anyway) you're expecting an empty string without writing data to it first before reading. You could probably change all the strings to this to save some CPU cycles.


- You don't need to use "strcopy" when assigning a string to something, for example:
PHP Code:
strcopy(sAimBonesizeof(sAimBone), (bIsUsingOldSkeleton "ValveBiped.Bip01_Head1" "bip_head")); 
you could just do:
PHP Code:
sAimBone = (bIsUsingOldSkeleton "ValveBiped.Bip01_Head1" "bip_head"); 

- In "OnPlayerRunCmd" you should probably move "if (!IsClientSurvivor(iClient)) return Plugin_Continue;" to the top before pulling the origin/nav area data.


- I don't know if the compiler optimizes for things like this, but instead of "500.0*500.0" just write "250000.0", there are multiple others like this.


- "GetWeaponMaxAmmo" could be optimized using a StringMap to search for the string and return the weapon ID instead, although I'm not sure the string checks are even necessary since you're using "GetWeaponAmmoType", looks like all the types are covered here. Again FindConVar here could be put into plugin start.


- "CheckEntityForItem" could be optimized to remove all the string checks, and match by weapon/item ID instead.


- "ShouldUseFlowDistance" could be optimized slightly to avoid calling the same native twice, by changing it to:
PHP Code:
bool ShouldUseFlowDistance()
{
    if( (!
L4D_IsSurvivalMode() && !L4D2_IsScavengeMode() )
    {
        
int stage L4D2_GetCurrentFinaleStage();
        if( (
stage == 18 || stage == 0) )
        {
            return 
true;
        }
    }

    return 
false;

Maybe applicable to other parts of the code to store a temporary variable instead of calling the same natives multiple times, I didn't check.


- It might be better to use "OnEntityCreated" instead of "ScanMapForEntities" in a timer since you're only checking for "witch" and "weapon_*" entities. Also: "FindEntityByClassname(-1, "*")" would probably be faster than looping through all entities as the function is currently doing. Or maybe: FindEntityByClassname(-1, "witch"); and: FindEntityByClassname(-1, "weapon*);
Might be a good idea to benchmark test and see which is the faster method.


- "g_hWitchList" could be initialized with "g_hWitchList = new ArrayList(2);" and set witch ref into index 0 and userid into index 1, instead of nesting multiple ArrayLists within the g_hWitchList ArrayList:
For example:
PHP Code:
int index g_hWitchList.Push(EntIndexToEntRef(iEntity));
g_hWitchList.Set(indexhEvent.GetInt("userid")); // or set to "0" as done when you initialize the array. 

- You might want to call "ClearEntityArrayLists" on "round_end" event too, for round restarts or versus 2nd round


- "Event_OnWeaponFire" could be optimized to use StringMap.ContainsKey or StringMap.GetValue to check if the weapon classname is correct. It might be optimized further by calling "GetRandomInt" for shotgun/sniper first then checking the strings if the value is 1. I would benchmark test if that's faster than comparing 2 strings that don't match. Also "static char" since its called often and you're filling the string data first before reading. The return within the if statement is unnecessary.


There are probably other areas that could be optimized, this is just what I noticed skimming through.

__________________

Last edited by Silvers; 05-25-2023 at 16:22.
Silvers is offline
Kanashimi
Junior Member
Join Date: Jan 2023
Old 05-25-2023 , 17:26   Re: [L4D2] Survivor Bot AI Improver
Reply With Quote #10

I keep getting this error on the command console. I have the latest DHooks and Actions installed.

Code:
L 05/25/2023 - 16:24:25: [SM] Exception reported: Native is not bound
L 05/25/2023 - 16:24:25: [SM] Blaming: g-misc\l4d2_sb_ai_improver.smx
L 05/25/2023 - 16:24:25: [SM] Call stack trace:
L 05/25/2023 - 16:24:25: [SM]   [0] __action_setlistener
L 05/25/2023 - 16:24:25: [SM]   [1] Line 901, actions_processors::BehaviorActionListeners.OnUpdatePost.set
L 05/25/2023 - 16:24:25: [SM]   [2] Line 5624, F:\Games\Left 4 Dead 2\left4dead2\addons\sourcemod\scripting\l4d2_sb_ai_improver.sp::OnActionCreated
Kanashimi is offline
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 04:10.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode