The code checks if the mod setting "NPC_NEED_AMMO" is not...

December 7, 2023 at 11:08 PM

if not SettingAPI.GetModSettingValue("ProjectHumanoid", "NPC_NEED_AMMO") then local container = self.character:getInventory() for j=1, container:getItems():size() do local weapon = container:getItems():get(j-1) if instanceof(weapon, "HandWeapon") and weapon:isAimedFirearm() then if(weapon:getMagazineType()) then if weapon:isContainsClip() then local ammoCount = self.character:getInventory():getItemCountRecurse(weapon:getAmmoType()) + weapon:getCurrentAmmoCount() if ammoCount < 10 then for i=ammoCount, 10 do self.character:getInventory():AddItem(weapon:getAmmoType()) end end else local ammoCount = self.character:getInventory():getItemCountRecurse(weapon:getAmmoType()) local magazine = self.character:getInventory():getFirstTypeRecurse(weapon:getMagazineType()) if magazine == nil then self.character:getInventory():AddItem(weapon:getMagazineType()) else ammoCount = ammoCount + magazine:getCurrentAmmoCount() end if ammoCount < 10 then for i=ammoCount, 10 do self.character:getInventory():AddItem(weapon:getAmmoType()) end end end else local ammoCount = self.character:getInventory():getItemCountRecurse(weapon:getAmmoType()) + weapon:getCurrentAmmoCount() if ammoCount < 10 then for i=ammoCount, 10 do self.character:getInventory():AddItem(weapon:getAmmoType()) end end end end end end end

The code checks if the mod setting "NPC_NEED_AMMO" is not set. If it is not set, it retrieves the character's inventory and iterates through each item in the inventory. For each item, it checks if it is a hand weapon and if it is an aimed firearm. If it is, it further checks if the weapon has a magazine type.

If the weapon has a magazine type, it checks if the weapon contains a clip. If it does, it calculates the total ammo count by adding the ammo count of the weapon and the ammo count in the character's inventory. If the total ammo count is less than 10, it adds the weapon's ammo type to the character's inventory until the ammo count reaches 10.

If the weapon does not contain a clip, it calculates the total ammo count by adding the ammo count in the character's inventory and the ammo count in the magazine. If the total ammo count is less than 10, it adds the weapon's ammo type to the character's inventory until the ammo count reaches 10.

If the weapon does not have a magazine type, it calculates the total ammo count by adding the ammo count in the character's inventory and the ammo count of the weapon. If the total ammo count is less than 10, it adds the weapon's ammo type to the character's inventory until the ammo count reaches 10.

Generate your own explanations
Download our vscode extension
Read other generated explanations

Built by @thebuilderjr
Sponsored by beam analytics
Read our terms and privacy policy
Forked from openai-quickstart-node