QuartzBeam Posted March 19, 2021 Share Posted March 19, 2021 I wanna modify a certain item to provide freezing insulation so long as its kept in the inventory. Kinda like winter clothing you don't have to equip. Generally, I wanna be able to make items give special effects from being held. From insulation to wetness proofing and so on. I'm just not how to go about this... My first thought was to apply the effect with the OnPutInInventoryFn() and remove it with OnDroppedFn() (and I assume there's a similar function I could use for when the item spoils?). But I don't know how OnDroppedFn() works. Would the item still have an owner I could access during this function? I can't seem to think of an existing item that works like this either, so can't get inspiration the old fashioned way. Link to comment Share on other sites More sharing options...
Combustiblemon Posted March 19, 2021 Share Posted March 19, 2021 item will(probably?) remember it's owner. you could access it by: inst.components.inventoryitem.owner so code will be like: local function OnDropLostInsulation(inst) local owner = inst.components.inventoryitem.owner or nil if owner == nil then print("oopsie") return end --codes about losing insulation end ============================================ inst.components.inventoryitem:SetOnDroppedFn(OnDropLostInsulation) Link to comment Share on other sites More sharing options...
QuartzBeam Posted March 19, 2021 Author Share Posted March 19, 2021 @Combustiblemon Yeah, that is pretty much what I did. But there's one major issue: I can make the item do things when it's added to the inventory, but I cannot make it undo them when it's dropped/removed. I assume that's because the relevant functions run after it's being removed, meaning it no longer has an owner to access. Link to comment Share on other sites More sharing options...
Combustiblemon Posted March 19, 2021 Share Posted March 19, 2021 Then maybe you could force-add owner that will not reset on dropped or removed to item? like adding these codes: local function onequip(inst, owner) inst._owner = owner --codes end local function ondrop(inst) if inst._owner then --codes inst._owner = nil end end local function onremoved(inst) inst._owner = nil end 1 Link to comment Share on other sites More sharing options...
QuartzBeam Posted March 19, 2021 Author Share Posted March 19, 2021 13 minutes ago, Combustiblemon said: Then maybe you could force-add owner that will not reset on dropped or removed to item? like adding these codes: local function onequip(inst, owner) inst._owner = owner --codes end local function ondrop(inst) if inst._owner then --codes inst._owner = nil end end local function onremoved(inst) inst._owner = nil end So I can create a new variable inside that particular instance of the component that's attached to the item? Link to comment Share on other sites More sharing options...
QuartzBeam Posted March 20, 2021 Author Share Posted March 20, 2021 Update: SetOnDroppedFn() only applies for when the item is dropped to the ground, but not when it's moved to another container or when it spoils or when it's murdered. Presumably, it's only meant to apply certain changes to them item based on whether or not it's on the ground, like emitting light or flopping (in conjunction with SetOnPutInInventoryFn()). I also couldn't find any way to set a general purpose "OnRemoveFromInventory" function. The inventoryitem component has an OnRemoved function, but it's local and cannot be modified. Not to mention it probably wouldn't work for spoiling or murdering either. So here's what I ended up doing: when a Fallounder (the item in question) is placed in the inventory, it checks if it's the only one and applies a buff if it is (cause I don't want multiple Fallounders to stack buffs). Then it makes the owner periodically check their inventory and if at some point the owner discovers it doesn't have a Fallounder anymore, it removes the buff. Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now