Sign in to follow this  
reims9875

How to prevent my character from wearing some hats.

Recommended Posts

reims9875    0

How to prevent my character from wearing some hats. My character has horns when he puts on his hat horns are cut off.

Share this post


Link to post
Share on other sites
C_Thun    62

Hey there!

This coding makes your character to refuse to wear any type of headgear:

Spoiler

 

local _Equip = inst.components.inventory.Equip    

    inst.components.inventory.Equip = function(self, item, old_to_active)
        if not item or not item.components.equippable or not item:IsValid() then
            return        
        end        
    
        if item.components.equippable.equipslot == EQUIPSLOTS.HEAD then        
            self:DropItem(item)
            self:GiveItem(item)
            if inst and inst.components.talker then
                inst.components.talker:Say("My horns are in the way!")
            end
            return
        end        
        return _Equip(self, item, old_to_active)    
    end

 

You have to put this into your character's prefab file, inside local master_postinit = function(inst)

You can replace the purple line with any other announce line. If you don't want your character to say anything when they decline a hat, just delete the green and the purple lines.

If you want your character to only refuse specific hats, replace the orange line with this one:

Spoiler

if item.prefab == "eyebrellahat" or item.prefab == "footballhat" then

This example makes the character to refuse the Eyebrella and the Football Helmet, but you can replace these with any other hat.

Let me know if I've messed up something, but I think it's foolproof.

Cheerio!

Edited by C_Thun
  • Like 1

Share this post


Link to post
Share on other sites

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
Sign in to follow this