DerpTime Posted July 16, 2015 Share Posted July 16, 2015 So I have a problem and im hoping someone might at least be able to point me in the right direction.I have a character, and i want her to have her sanity drain when she loses or is not carrying her plushy in here inventory.2 major things I'm running in to for problems.Keeping in inventory on death.andDrain if not present.Any one got any ideas that might help push me in the right direction?I know there is stuff like this. inst:WatchWorldState("phase", updatedamage) updatedamage(inst, TheWorld.state.phase)that runs a function to update the damage every time the "phase" changes.Is there and event or a check i can exploit to make this work.second problem is the recovery of the item on Resurrection.and.... I actual dont have a clue where to start with that. Link to comment https://forums.kleientertainment.com/forums/topic/56225-do-function-if-character-isnt-carrying-a-spicific-item/ Share on other sites More sharing options...
Faerl Posted July 17, 2015 Share Posted July 17, 2015 Take a look at woodie's code. He has a 'beaverness' tag that's attached to him when he turns. Then during one of the periodic checks if he has that attribute his sanity etc decreases faster. You could do something similar on death so that you toggle some tag and if he's not dead do the sanity hit, if he is then don't. As for holding it in death you could cheat it. Assuming the code above works you don't care about him holding the item in death. What you'd need to do is spawn (or move) the item when he comes back to life. The tricky part would be to delete the item already existing in the world at the same time, otherwise you'll end up with duplicate items. Not sure how to do that but there should be some way, critters disappear all the time at night. Link to comment https://forums.kleientertainment.com/forums/topic/56225-do-function-if-character-isnt-carrying-a-spicific-item/#findComment-655016 Share on other sites More sharing options...
DarkXero Posted July 17, 2015 Share Posted July 17, 2015 (edited) local TUNING = GLOBAL.TUNING local myitem = "spear"local mycharacter = "wilson" AddPrefabPostInit(myitem, function(inst) if not GLOBAL.TheWorld.ismastersim then return end local function charge_flux(prev_owner, new_owner) if prev_owner then prev_owner:PushEvent("curseddischarge") end if new_owner then new_owner:PushEvent("cursedcharge") end end local old_set = inst.components.inventoryitem.SetOwner inst.components.inventoryitem.SetOwner = function(self, owner) local prev_owner = self.owner old_set(self, owner) charge_flux(prev_owner, self.owner) end local old_clear = inst.components.inventoryitem.ClearOwner inst.components.inventoryitem.ClearOwner = function(self, owner) local prev_owner = self.owner old_clear(self, owner) charge_flux(prev_owner, self.owner) endend)AddPrefabPostInit(mycharacter, function(inst) if not GLOBAL.TheWorld.ismastersim then return end inst.cursedcharges = 0 inst:ListenForEvent("curseddischarge", function(inst) inst.cursedcharges = inst.cursedcharges - 1 end) inst:ListenForEvent("cursedcharge", function(inst) inst.cursedcharges = inst.cursedcharges + 1 end) inst.components.sanity.custom_rate_fn = function(inst) return inst.cursedcharges > 0 and 0 or -TUNING.DAPPERNESS_MED end inst:ListenForEvent("dropitem", function(inst, data) if data.item.prefab == myitem and inst.components.health:IsDead() then inst.components.inventory:GiveItem(data.item, nil, inst:GetPosition()) end end)end)@DerpTime. Also alternative snippets to showcase that what you want in the title is possible:-- Code Alternatives-- 1local function CheckForPlushy(inst) local function fn(item) if item.prefab == "plushy" then return true end end local plushy = inst.components.inventory:FindItem(fn) if plushy == nil then return -TUNING.DAPPERNESS_MED end return 0endinst.components.sanity.custom_rate_fn = CheckForPlushy-- 2local function CheckForPlushy(inst) local has_plushy, total_found = inst.components.inventory:Has("plushy", 1) if has_plushy then return 0 end return -TUNING.DAPPERNESS_MEDendinst.components.sanity.custom_rate_fn = CheckForPlushyI just think that scanning the inventory each sanity tick is not optimized enough. It's better to make the item tell you if it enters or exits your inventory. Edited July 17, 2015 by DarkXero Link to comment https://forums.kleientertainment.com/forums/topic/56225-do-function-if-character-isnt-carrying-a-spicific-item/#findComment-655024 Share on other sites More sharing options...
DerpTime Posted July 20, 2015 Author Share Posted July 20, 2015 @DarkXeroYour a god.This is perfect,sorry for the late reply ...extended family came over and haven had a chance to try out some new stuff for my mod. Link to comment https://forums.kleientertainment.com/forums/topic/56225-do-function-if-character-isnt-carrying-a-spicific-item/#findComment-655843 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