Barotrauma icon indicating copy to clipboard operation
Barotrauma copied to clipboard

Requireditem RequireEmpty="true" does not work if the inventory is... empty

Open Regalis11 opened this issue 6 months ago • 1 comments

Discussed in https://github.com/FakeFishGames/Barotrauma/discussions/16238

Originally posted by ubertpendragon June 22, 2025

Disclaimers

  • [X] I have searched the issue tracker to check if the issue has already been reported.
  • [ ] My issue happened while using mods.

What happened?

For some reason, in the Requireditem conditional, RequireEmpty="true" does not in fact work if an item is NOT in the inventory. It only works if the item is IN the inventory at 0 condition

Example: Defensebot is supposed to flee when "empty"; but in reality it only flees when the ammo is at 0% condition If the inventory is empty, the bot still tries to attack

image

Reproduction steps

  1. Go in sub editor
  2. Place down defense bot item and 0% defensebot ammo box
  3. Remove ammo box from defense bot
  4. Spawn crawler
  5. Defense bot is aggressive
  6. Insert 0% box
  7. Defense bot flees

Or try this affliction in water with either clothes, a suit, or both.

    <Affliction name="NakedTESTaffliction"
      identifier="NakedTESTaffliction"
      description="Go in water without clothes"
      type="bugged"
      limbspecific="false"
      indicatorlimb="Torso"
      hideiconafterdelay="false"
      iconcolors="0,180,0,255;180,0,0,255"
      activationthreshold="0"
      showiconthreshold="0"
      showinhealthscannerthreshold="0"
      maxstrength="100">
      <Effect minstrength="0" maxstrength="100"
        strengthchange="0">
        <!-- particles -->
        <StatusEffect target="Character" >
          <ParticleEmitter particle="acidmist" anglemin="80" anglemax="100" particlespersecond="3" velocitymin="30" velocitymax="50" scalemin="0.1" scalemax="0.2" scalemultiplier="1,0.3" lifetimemultiplier="0.1" colormultiplier="255,255,255,120"/>
        </StatusEffect>
        <!-- This should trigger if you have NEITHER clothes or diving suit, but it does -->
        <StatusEffect target="Character" interval="1" disabledeltatime="true" comparison="And">
          <RequiredItem item="clothing" type="Equipped" requireempty="true" CharacterInventorySlotType="InnerClothes" />
          <RequiredItem item="deepdiving" type="Equipped" requireempty="true" CharacterInventorySlotType="OuterClothes" />
          <Conditional InWater="true" />
          <Affliction identifier="gunshotwound" amount="15.05" />
        </StatusEffect>
      </Effect>
      <icon texture="Content/UI/MainIconsAtlas.png" sourcerect="256,640,128,128" color="150,26,26,255" origin="0,0" />
    </Affliction>

Version

v1.9.7.0 (Summer Update 2025)

Regalis11 avatar Jun 22 '25 10:06 Regalis11

And it's overall unclear what works and what doesnt as well, like how stun batons (despite not playing the error message) SE will activate based with requireditem on use, but actually using a Holdable will not pass a simple "Equipped" or "Picked" check

Example: opening a tomato can with a knife by checking if it's equipped in the other hand of the character

      <Holdable canbepicked="true" characterusable="true" slots="Any,RightHand,LeftHand" handle1="0,-7" aimpos="35,-10" swingwhenusing="true" msg="ItemMsgPickUpSelect">
        <StatusEffect type="OnUse" target="This,Parent" comparison="And" condition="-1" disabledeltatime="true" oneshot="true" >
          <RequiredItem items="sharptool" type="picked" />
          <Sound file="%ModDir%/Content/Sounds/Items/Food/Unwrap.ogg" loop="false" range="200" volume="5.0" />
        </StatusEffect>
      </Holdable>

https://github.com/FakeFishGames/Barotrauma/blob/fd34473640a3f84b108299d55c36065eeda809c7/Barotrauma/BarotraumaShared/SharedSource/Items/RelatedItem.cs#L174-L177

I've been losing hair since I started working on Hungry Europans 😓

ubertpendragon avatar Jun 22 '25 16:06 ubertpendragon

Fixed in https://github.com/FakeFishGames/Barotrauma-development/pull/6777, closing

Regalis11 avatar Jun 25 '25 11:06 Regalis11