Jump to content

[Solved] Generating items on wakeup


Recommended Posts

Hello, I'm a bit new to modding and decided to create a character as a first project.
One perk I wanted my character to have was to generate an item when they were asleep, but I can't figure out how to do it.

What I've tried is this:

local function OnWakeUpDelta(inst, data)
    print("hello")
    if inst:HasTag("zoe") and player.components.inventory then
        self.inst.components.inventory:GiveItem(spawnprefab("dreamstuff"))
    end  
end

inst:ListenForEvent("onwakeup", OnWakeUpDelta)

The problem seems to be that the code does not react to waking up, and that's about everything I've been able to gather.

Thanks in advance!

Link to comment
Share on other sites

"OnWakeup"

I think is called by sleeper component, which I don't think players use.
Players use grogginess and sleepingbaguser from what i remember but only 1 uses event so something like maybe.

 

local function OnWakeUpDelta(inst)
    print("hello")
    if inst:HasTag("zoe") and inst.components.inventory then --inst not player i think
       inst.components.inventory:GiveItem(spawnprefab("dreamstuff")) --self.inst should already be formed into inst so easier to manage
    end  
end

    inst:ListenForEvent("cometo", OnWakeUpDelta) --event listener

	inst._OnWakeUp = inst.components.sleepingbaguser.DoWakeUp --saving oringinal code
	inst.components.sleepingbaguser.DoWakeUp = function (self , nostatechange) --replacing the code
          OnWakeUpDelta(inst)  --inputting your code
          inst._OnWakeUp (self , nostatechange) --inputing the old code
     end

 

Edited by Thomas Die
  • Like 1
Link to comment
Share on other sites

It worked! But now it crashes with the error message "variable 'spawnprefab' is not declared" when I'm about to wake up.

Wait, I'm dumb. It's SpawnPrefab, not spawnprefab.

It works now, thanks for everything!

  • Big Ups 1
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
 Share

×
×
  • Create New...