Jump to content

Camouflage mod


Recommended Posts

Hey all! I'm trying to make a camouflage mod, but I have some trouble...

  1. I don't know how to set previous animation when camouflage  is unequiped
  2. I can't set drop animation. It crashes with 
    attempt to index field 'AnimState' (a nil value)

     

Myitem.lua is here

local assets =
{
	Asset( "ANIM", "anim/waxwell.zip" ),
	Asset( "ANIM", "anim/skins_ground.zip" ),
	
    Asset("ATLAS", "images/inventoryimages/wilson_switch.xml"),
    Asset("IMAGE", "images/inventoryimages/wilson_switch.tex"),
}

local function  OnEquip(inst, builder)
	SetSkinMode(builder.AnimState, "waxwell", "waxwell", builder.components.skinner:GetClothing(), nil, "waxwell")
	inst.soundsname = "waxwell"
end

local function OnUnequip(inst, builder) 

end

local function ondropped(inst)
	inst.AnimState:SetBank("skins_ground")
    inst.AnimState:SetBuild("skins_ground")
    inst.AnimState:PlayAnimation("wilson")
end

local function fn()
	local inst = CreateEntity()

	inst.entity:AddTransform()
	inst:AddTag("hat")

	if not TheWorld.ismastersim then
		return inst
	end
	
	inst:AddComponent("inspectable")
	
    inst:AddComponent("inventoryitem")
    inst.components.inventoryitem.imagename = "wilson_switch"
    inst.components.inventoryitem.atlasname = "images/inventoryimages/wilson_switch.xml"
	
	inst:AddComponent("equippable")
    inst.components.equippable.equipslot = EQUIPSLOTS.HEAD
    inst.components.equippable:SetOnEquip(OnEquip)
    inst.components.equippable:SetOnUnequip(OnUnequip)
	
	inst:ListenForEvent("ondropped", ondropped)

	return inst
end

return Prefab("wilson_switch", fn, assets)

If some'll help, I'll give em some reward! :)

Thanks to anyone who can help me out with this!

Edited by makar5000
  • Like 1
Link to comment
Share on other sites

7 hours ago, DarkKingBoo said:

You need to add:

inst.entity:AddTransform()
inst.entity:AddAnimState()
inst.entity:AddSoundEmitter()
inst.entity:AddNetwork()

in your fn() function.

Also I would add this above TheWorld.ismastersim statement:

 

inst.entity:SetPristine()

Now it stopped crashing, thanks! But... Do you know how to set previous animation when it Unequiped?

  • Like 1
Link to comment
Share on other sites

10 minutes ago, DarkKingBoo said:

Hmm, do you mean previous anim before the thing got equipped or after it got equipped?

Kind of need to know what you're going for.

Right. It's working now like this

:1h22og.gif

But it must be working so when you unequip mask, character returns to his animation back.

  • Like 1
Link to comment
Share on other sites

There is probably a cleaner way to do this, and by that I mean a way to check what your bank/build are before disguise but what you can probably use for now is this:

in your unequip function: 

local player = builder.prefab

print("The player is "..player) --for debugging purposes, if my code doesn't work come back and tell me what this was printed in the console.

builder.AnimState:SetBank("wilson")
builder.AnimState:SetBuild(player)

 

Edited by DarkKingBoo
Link to comment
Share on other sites

22 minutes ago, DarkKingBoo said:

There is probably a cleaner way to do this, and by that I mean a way to check what your bank/build are before disguise but what you can probably use for now is this:

in your unequip function: 

local player = builder.prefab

print("The player is "..player) --for debugging purposes, if my code doesn't work come back and tell me what this was printed in the console.

builder.AnimState:SetBank("wilson")
builder.AnimState:SetBuild(player)

 

Yeah thanks! It's working! :) Give me your steam trade link, so I can give you your reward! :) 

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