Jump to content

Recommended Posts

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 by Hyaciao

@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 by Seiai

@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.

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 by Seiai

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 by Hyaciao

@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 by Seiai

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
×
  • Create New...