Cunning fox Posted January 3, 2017 Share Posted January 3, 2017 (edited) Hey all! I'm trying to make a camouflage mod, but I have some trouble... I don't know how to set previous animation when camouflage is unequiped 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 January 3, 2017 by makar5000 1 Link to comment Share on other sites More sharing options...
Leonardo Cox Posted January 4, 2017 Share Posted January 4, 2017 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() Link to comment Share on other sites More sharing options...
Cunning fox Posted January 4, 2017 Author Share Posted January 4, 2017 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? 1 Link to comment Share on other sites More sharing options...
Leonardo Cox Posted January 4, 2017 Share Posted January 4, 2017 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. Link to comment Share on other sites More sharing options...
Cunning fox Posted January 4, 2017 Author Share Posted January 4, 2017 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 : But it must be working so when you unequip mask, character returns to his animation back. 1 Link to comment Share on other sites More sharing options...
Leonardo Cox Posted January 4, 2017 Share Posted January 4, 2017 (edited) 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 January 4, 2017 by DarkKingBoo Link to comment Share on other sites More sharing options...
Cunning fox Posted January 4, 2017 Author Share Posted January 4, 2017 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! 1 Link to comment 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