Jump to content

[Solved] Change charater's texture, when he equips his custom item


Recommended Posts

Hello there!

I need a tiny bit of help about my custom character: I would like him to change his texture, while he's holding his custom item, and change it back to default, when he unequips it.

I've came up with the following coding, but it does nothing in the game (it does not crash though):

Spoiler

-- Tiger skin
    local function OnEquipCustom(inst, data)
        if data.item.prefab == "tigerpan" then
            inst.AnimState:SetBuild("thejanitiger")
        end
    end
    
    local function OnUnequipCustom(inst, data)
        if data.item.prefab == "tigerpan" then
            inst.AnimState:SetBuild("thejani")
        end
    end

I've put this into the character prefab's master postnit section. The "tigerpan" is the custom item, "thejanitiger" is the texture he should equip with the item (it has a full texture folder inside the export folder), and "thejani" is his default texture folder.

What do I do wrong?

Edited by BillTheCipher
Link to comment
Share on other sites

@thomas4846 When I run the autocomplier, it doesn't generate an anim ZIP file - neither into the "thejanitiger" export folder, neither into the anim folder.

This is the only two coding that currently contains "thejanitiger" (alias the equip skin):

Spoiler

local assets = {
    Asset("SCRIPT", "scripts/prefabs/player_common.lua"),
    Asset( "ANIM", "anim/thejanitiger.zip" ),
}

Spoiler

-- Tiger skin
    local function OnEquipCustom(inst, data)
        if data.item.prefab == "tigerpan" then
            inst.AnimState:SetBuild("thejanitiger")
        end
    end
    
    local function OnUnequipCustom(inst, data)
        if data.item.prefab == "tigerpan" then
            inst.AnimState:SetBuild("thejani")
        end
    end

Is there anywhere else I should reference the "thejanitiger" texture, or the problem is rooted in something else?

Link to comment
Share on other sites

	inst:ListenForEvent("equip", function(inst, data)
		if data.item.prefab == "tigerpan" then
			inst.AnimState:SetBuild("thejanitiger")
		end
	end)
	
	inst:ListenForEvent("unequip", function(inst, data)
		if data.item.prefab == "tigerpan" then
			inst.AnimState:SetBuild("thejani")
		end
	end)

you forgot to call the functions

  • Like 1
Link to comment
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
 Share

×
  • Create New...