Sinaboo Posted August 25, 2019 Share Posted August 25, 2019 I've made a custom item that revives the player when they haunt it as a ghost and that works fine, but i'd like to make it so that the item breaks or disappears so that it's a one-time use item because right now it has infinite uses and I don't want that. item script (lines 45-47 are the lines i used for resurrection) How can I make it so that my custom item breaks when I haunt it and resurrect? Link to comment Share on other sites More sharing options...
Serpens Posted August 25, 2019 Share Posted August 25, 2019 (edited) 2 hours ago, Sinaboo said: I've made a custom item that revives the player when they haunt it as a ghost and that works fine, but i'd like to make it so that the item breaks or disappears so that it's a one-time use item because right now it has infinite uses and I don't want that. item script (lines 45-47 are the lines i used for resurrection) How can I make it so that my custom item breaks when I haunt it and resurrect? take a look at the hauntable component file. There you see functions like SetOnHauntFn and SetOnUnHauntFn , you can use them to define a function that is called onhaunt or on unhaunt (when haunting expires). So you could give them a function that does "inst:Remove()" to remove the item. If you also want some effects you could spawn a "puff" prior to removing with SpawnPrefab("collapse_small").Transform:SetPosition((inst:GetPosition()):Get()) (code not tested, I think it works that way, but no 100% sure) See the notes from the devs within the component, the onhaunt function has to return true at the end. See the prefab resurrectionstone.lua for an example. Edited August 25, 2019 by Serpens Link to comment Share on other sites More sharing options...
Sinaboo Posted September 7, 2019 Author Share Posted September 7, 2019 On 8/25/2019 at 8:33 AM, Serpens said: take a look at the hauntable component file. There you see functions like SetOnHauntFn and SetOnUnHauntFn , you can use them to define a function that is called onhaunt or on unhaunt (when haunting expires). So you could give them a function that does "inst:Remove()" to remove the item. If you also want some effects you could spawn a "puff" prior to removing with SpawnPrefab("collapse_small").Transform:SetPosition((inst:GetPosition()):Get()) (code not tested, I think it works that way, but no 100% sure) See the notes from the devs within the component, the onhaunt function has to return true at the end. See the prefab resurrectionstone.lua for an example. local function OnHaunt(inst, haunter) SpawnPrefab("collapse_small").Transform:SetPosition((inst:GetPosition()):Get()) inst:Remove() end I've used this code for when my character haunts my item and the puff works and the item disappears but now whenever I haunt my item it doesn't resurrect my player. Do you know what might be causing this or is there something i'm missing that's supposed to go inside that function? I've tried looking in items that revive the player like touch stones, telltale hearts and the life giving amulet but I can't find out what I need to make my item resurrect my player again. Link to comment Share on other sites More sharing options...
Serpens Posted September 7, 2019 Share Posted September 7, 2019 I told you the function has to return true You can see why in the hauntable component, this is the function that is called there: function Hauntable:DoHaunt(doer) if self.onhaunt ~= nil then self.haunted = self.onhaunt(self.inst, doer) -- this is your function, and self.haunted will get the value your function returns if self.haunted then -- if your function returns nothing (nil) or false, this wont be executed if doer ~= nil then if self.hauntvalue == TUNING.HAUNT_INSTANT_REZ and doer:HasTag("playerghost") then -- and therefore also you ressecurect wont be executed doer:PushEvent("respawnfromghost", { source = self.inst }) end if not self.no_wipe_value then self.hauntvalue = nil end end if self.cooldown_on_successful_haunt then self.cooldowntimer = self.cooldown or TUNING.HAUNT_COOLDOWN_MEDIUM self:StartFX(true) self:StartShaderFx() self.inst:StartUpdatingComponent(self) end else self.haunted = true self.cooldowntimer = self.cooldown or TUNING.HAUNT_COOLDOWN_SMALL self:StartFX(true) self:StartShaderFx() self.inst:StartUpdatingComponent(self) end end end 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