This fix removes the bug of immobile NPCs when using someone else's weapons.
The essence of the bug is quite simple - NPCs can shoot weapons unlimitedly, but the condition must be met that they have the appropriate ammo in their inventory. When a character appears in the game, he is given ammo along with the weapon, but when he picks up a weapon of a different type, with a different type of ammo, he will also consider it as a solid weapon and continue shooting. As a result, it turns out that the NPC is firing from an empty gun - this is how I understood and identified this error. In this archive, I have included two script files that differ in the implementation of this fix: in the first, NPCs do not select weapons with missing ammo, and in the second, they are given ammo for their new weapon.
OPTIONAL: I noticed this error while developing "Ekidona magazines" - due to the removal of "false ammo" from NPCs, it led to just such a bug. I quickly corrected this mistake (yes, you can't tell by the dates), but "this mistake could have happened in the original, theoretically", and in the end it turned out to be so. In the screenshot, I deliberately left an image of this bug - the bandit picked up an RPG7 and shot at the player, and froze in this position (the reason is described above).
17.10.22: Another bug related to using someone else's weapons has been fixed - if the NPC thinks of a broken weapon (which can happen), then he will try to shoot from it, testing a permanent wedge. Unfortunately, it is impossible to force an NPC NOT to select a weapon, since issuing "nil" in the "update_best_weapon" function leads to the execution of the built-in weapon selection algorithm (and it cannot be changed, if anything). For this reason, I decided to make it so that the selected weapon is automatically repaired in the hands of the NPC. I know, not the best option, but for the original it will do (this algorithm can really be done better, but in order not to edit other scripts - I implemented it this way).
17.10.22: 23:05(JST): The first version of the fix has a new fix - if the NPC has a weapon, but no ammo for it, and no other weapon, then the character is given a standard knife, which he chooses. If this knife is not available, then the NPC will choose a weapon without ammo.03.11.22: 17:00(JST): Thanks to a comment by *Pixel*, it was revealed that it is possible to enable full weapon selection control via the API, so you can now forget about the previous knife spawn update.
22.11.22: 4:03(JST): Now, when choosing a weapon, upgrades with a change in caliber are taken into account.
10.03.23: 19:52(JST): Fixed one bug (first version) related to "use_single_item_rule". The fact is that NPC merchants, due to its use, simply throw away the "extra" weapon (the name of the parameter speaks for itself). It was decided that the merchants "use_single_item_rule" would be disabled, and if there were no weapons, the "plug with a knife" would work.
16.05.23: 6:54(JST): Due to the peculiarities of "use_single_item_rule", it was decided to abandon this version of the algorithm. I rewrote the script with a number of my edits and, it seems, I managed to completely fix this problem: now the characters are guided in the choice of weapons AND do not throw them away when replacing them.
WARNING: "m_stalker" must have the above mentioned parameter disabled. If you put a bugfix and did not change the corresponding config, then you can simply delete it - now this algorithm "works by itself".
23.06.23: 5:00 (JST): Well, another update. The previous algorithm was only half written, so it did not fully function. I had to come up with the option of despawning "unnecessary weapons" and respawning them at the right time. The despawn algorithm works directly, but for respawn it was necessary to convert "death_manager.script" - meh. You need to understand that such an algorithm may not be compatible with some addons. And yes, don't forget the second version, which works great with the original DA system.
23.06.23: 8:55 (JST): Fixed a bug with the "extra" respawn weapons (if you come across such a bug - report).
04.07.23: 12:58 (JST): Using despawn is a big mistake. The solution to the problem was on the surface: "transfer_item". Yes, it sucks, but it works.
11.12.23: 19:21 (UTC+3): Fixed a bug with timings, because of which in the second version of the script there was excessive ammo spawning from NPCs. When playing for a long time it caused game crash due to filling the game with objects.
Average
102 votes submitted.
"...since issuing "nil" in the "update_best_weapon" function leads to the execution of the built-in weapon selection algorithm (and it cannot be changed, if anything)..."
Try to turn on use_single_item_rule = on in m_stalker.ltx file, it has to forbid executing built-in (engine) weapon selection algorithm (at least in vanilla games, I don't know about CoC and Dead Air).
Thanks - didn't know about that. Now then I will rewrite the first version of this script a bit and check it. Wait for an update.