Hyaciao Posted May 19, 2015 Share Posted May 19, 2015 (edited) So recently I was helped by the members of the forum here to help solve the problem of preventing a character from eating certain state of food. local old_pte = inst.components.eater.PrefersToEat --only eats fresh food inst.components.eater.PrefersToEat = function(self, inst) if inst.components.perishable then if inst.components.perishable:IsStale() or inst.components.perishable:IsSpoiled() then return end end if inst.prefab == "spoiled_food" then return end return old_pte(self, inst)end I tried to use this as a template as I looked up the possible component logic. However related components like equippable.lua does not seem to not possess what i'm looking for. And the rest of the functions are based on already equipped condition so i'm kind of stuck here. My goal is to make it so a character cannot equip certain class of items such as "tools" or "armor" I suspect it might look something like this but I'm probably in the wrong ball park. I'd appreciate any help thank you.local no_tools = inst.components.equippable.Equippable --can equip non tools & armor inst.components.equippable.Equippable = function(self, inst) if inst.components.sharp then if inst.components.tools then return end end if inst.prefab == "tools" then return endreturn no_tools(self,inst) endend Edited May 19, 2015 by Hyaciao Link to comment https://forums.kleientertainment.com/forums/topic/54167-help-disabling-the-ability-to-equip-certain-items-like-tools/ Share on other sites More sharing options...
Seiai Posted May 19, 2015 Share Posted May 19, 2015 (edited) @Hyaciao,well,the inventory component pushes the Equipevent:self.inst:PushEvent("equip", {item=item, eslot=eslot})u could have your character listen for that event, and if theres an item in the slot that u dont want him to have, call the the inventory's unequipfunction. Edited May 19, 2015 by Seiai Link to comment https://forums.kleientertainment.com/forums/topic/54167-help-disabling-the-ability-to-equip-certain-items-like-tools/#findComment-638800 Share on other sites More sharing options...
Kzisor Posted May 19, 2015 Share Posted May 19, 2015 @Hyaciao,well,the inventory component pushes the Equipevent:self.inst:PushEvent("equip", {item=item, eslot=eslot})u could have your character listen for that event, and if theres an item in the slot that u dont want him to have, call the the inventory's unequipfunction. That event isn't pushed on the instance of the player, it's pushed on the instance of the item. You would first need to AddComponentPostInit("equippable"), listen for the event and then push it on the owner of the item in order to actually get the event. I'm doing something similar and ran into that issue and had to create the work-around. Link to comment https://forums.kleientertainment.com/forums/topic/54167-help-disabling-the-ability-to-equip-certain-items-like-tools/#findComment-638810 Share on other sites More sharing options...
Seiai Posted May 19, 2015 Share Posted May 19, 2015 (edited) That event isn't pushed on the instance of the player, it's pushed on the instance of the item. You would first need to AddComponentPostInit("equippable"), listen for the event and then push it on the owner of the item in order to actually get the event. I'm doing something similar and ran into that issue and had to create the work-around.are u sure? inventory is a component of the player, and self.inst in a component that belongs to the player should refer to the player, shouldn't it?edit: i made it work with this in my characterprefab: inst:ListenForEvent("equip", function(inst,data) if data.item.prefab=="axe" then inst:DoTaskInTime(0,function(inst) inst.components.inventory:GiveItem(data.item) end) inst.components.talker:Say("F#§% axes!", 2.5) end end)i couldn't directly unequip it, when i receive the event, since this bugged out the equipslot, thats why i used the dotaskintime. Edited May 19, 2015 by Seiai Link to comment https://forums.kleientertainment.com/forums/topic/54167-help-disabling-the-ability-to-equip-certain-items-like-tools/#findComment-638858 Share on other sites More sharing options...
Kzisor Posted May 19, 2015 Share Posted May 19, 2015 @Seiai, my bad, I was listening for equipped and unequipped not equip and unequip. If you listen for equipped then no it won't work, that was my mistake. (It was late when I made that reply.) Link to comment https://forums.kleientertainment.com/forums/topic/54167-help-disabling-the-ability-to-equip-certain-items-like-tools/#findComment-638896 Share on other sites More sharing options...
Hyaciao Posted May 19, 2015 Author Share Posted May 19, 2015 (edited) Whoa. Thank you both! It worked.Just out of curiosity could it be possible to also modify this to deny unequip as well? inst:ListenForEvent("unequip", function(inst,data) if data.item.prefab=="axe" inst:DoTaskInTime(0,function(inst) inst.components.inventory:GiveItem(data.item) end) inst.components.talker:Say("I love my axes!", 2.5) end Edited May 19, 2015 by Hyaciao Link to comment https://forums.kleientertainment.com/forums/topic/54167-help-disabling-the-ability-to-equip-certain-items-like-tools/#findComment-638910 Share on other sites More sharing options...
Seiai Posted May 19, 2015 Share Posted May 19, 2015 (edited) @Hyaciao, probably, just look through the inventorycomponent, i guess the equip-function could work, or maybe a function to put an item into a specific slot. just make sure that the different ways to unequip it don't get bugged(removing it with the mouse, switching it with another item the mouse, it running out of charges and breaking, stuff like the bearger disarming u, etc) Edited May 19, 2015 by Seiai Link to comment https://forums.kleientertainment.com/forums/topic/54167-help-disabling-the-ability-to-equip-certain-items-like-tools/#findComment-638925 Share on other sites More sharing options...
Hyaciao Posted May 19, 2015 Author Share Posted May 19, 2015 (edited) @Seiai, thank you for the insight. Edited May 19, 2015 by Hyaciao Link to comment https://forums.kleientertainment.com/forums/topic/54167-help-disabling-the-ability-to-equip-certain-items-like-tools/#findComment-638934 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