Sleeping Mobs Can't Be Traded With (Exception Is Merms)


lakhnish
  • Pending

The TL;DR

If a sleeping mob you can trade with is not a Merm, they don't wake up to accept or refuse items the player is trying to trade, despite their attempts in the code to try to.

I don't know if these are the causes, all I know is that these are the differences that exist between Merms and the other mobs.

OnRefuseItem:

The following traders have the following OnRefuseItem function where if they are sleeping, they should wake up and refuse the item yet don't do that:

  1. Pigmen
  2. Bunnyman
  3. Spiders
  4. Rock Lobsters
  5. Beefalos
  6. Gnarwail
  7. Catcoon

The OnRefuseItem function ONLY works for Merms.

What I've noticed is that there is a check for the sleeper component for the Merm's OnRefuseItem function. 

Birdcages don't have a sleep check at all for this function, which will be relevant later.

Code here with the relevant parts:

Spoiler

What Merms Have:

Spoiler


local function OnRefuseItem(inst, item)
    inst.sg:GoToState("refuse")

    if inst.components.sleeper and inst.components.sleeper:IsAsleep() then --has check for sleeper component
        inst.components.sleeper:WakeUp()
    end
end

 

What Mobs 1-7 Have:

Spoiler


local function OnRefuseItem(inst, item)
    inst.sg:GoToState("refuse")
  
    if inst.components.sleeper:IsAsleep() then --missing check for sleeper component
        inst.components.sleeper:WakeUp()
    end
end

 

Birdcages:

Spoiler


local function OnRefuseItem(inst, item)
--no sleep check at all. Is relevant later for accepting items
end

 

 

OnGetItemFromPlayer

Unfortunately, this one is the complicated  because the function varies greatly between the mobs. 

The following traders have the following OnGetItemFromPlayer function where if they are sleeping, they should wake up and accept the item yet don't do that:

  1. Pigmen
  2. Bunnyman
  3. Spiders
  4. Rock Lobsters
  5. Gnarwail
  6. Catcoon
  7. Birdcages

I've noticed three differences b/w the listed mobs and with Merms.

  1. Merms have their sleep check is in ShouldAcceptItem function instead of their GetItemFromPlayer function.
  2. The ShouldAcceptItem for Merms has an extra parameter giver while the other mobs don't have that parameter. 
    • Spiders and Gnarwails are an exception and have the giver parameter in said function.
    • For a lot of the mobs, if a giver check is present in OnGetItemFromPlayer(), they are in different orders (inst,item,giver) vs (inst,giver,item). Don't know if that has any impact.
  3. Merms have an extra check for their sleeper component 

Birdcages have the same sleep check as Merms surprisingly, but it doesn't work for reason 1 (and has the same difference from merms in reason 2). 

Beefalos are a little different as don't take sleeping into account at all. Idk what's Klei's intentions are for beefalos and sleeping due to past changes [1] [2] [3].

Code here with the relevant parts:

Spoiler

What Merms Have:

Spoiler


local function ShouldAcceptItem(inst, item, giver) --(1) uses ShouldAcceptItem() + (2) has giver parameter

    if inst.components.sleeper and inst.components.sleeper:IsAsleep() then --(3) sleeper component check
        inst.components.sleeper:WakeUp()
    end
end

local function OnGetItemFromPlayer(inst, giver, item) -- (1) NOT using OnGetItemFromPlayer for the sleep check
--nothing of relevance to sleeping and accepting items
end  

 

What Mobs 1-6 Have:

Spoiler


local function ShouldAcceptItem(inst, item) --(2) no giver check
--- (3) nothing of relevance to sleeping and accepting items, should be here based on merm.lua
end

local function OnGetItemFromPlayer(inst, item)
    if inst.components.sleeper:IsAsleep() then   --(3) Missing sleep component check  + (1) is in different function than Merms
        inst.components.sleeper:WakeUp()
    end

 

What Birdcages Have:

Spoiler


local function ShouldAcceptItem(inst, item) --(2) no giver parameter
--- (3) nothing of relevance to sleeping and accepting items, should be here based on merm.lua
end

local function OnGetItem(inst, giver, item) 
    --If you're sleeping, wake up. <- The dev comment that started this bug report
  
    if inst.components.sleeper and inst.components.sleeper:IsAsleep() then -- (1) is in different function than Merms; has same sleeper check as Merms though
        inst.components.sleeper:WakeUp()
    end
end

 What Beefalo Lack:

Spoiler


local function ShouldAcceptItem(inst, item) --(2) No giver parameter
--(3) No Sleep check at all, should be here if added based on merm.lua
end

local function OnGetItemFromPlayer(inst, giver, item)
--(3) No sleep check at all and shouldn't be here based on merm.lua if added
end

 

 


Steps to Reproduce

See the dev comment in birdcage.lua that suggests that trader mobs should wake up when getting an item.

Try to give sleeping mobs an item where applicable (aka do they have a trader component).

See that only Merms will wake up to accept or refuse items.

Go down the rabbit hole and find the above.

  • Like 2


User Feedback


Note: The way I checked the prefabs was I did an entire folder search to see if each file had the following code inst.components.sleeper:IsAsleep() and then just checked to see if they were doing some sort of trade.

Edit: There may be some other mobs I missed along the way (I guess Dust Moths?)

Edited by lakhnish
  • Like 1

Share this comment


Link to comment
Share on other sites


Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now