Kaira Posted May 18, 2016 Share Posted May 18, 2016 (edited) Right, so: inst:ListenForEvent("equip", function() inst.AnimState:Show("hair_hat")inst.AnimState:Hide("hair") end) This is very very close to what I want, but I don't know how to tell the game to only look at the head slot for the anim change. I've tried inserting EQUIPSLOTS.HEAD into various spots, but it usually ends with the entire line being voided or simply crashing on startup. Also, what exactly is the inst function? Edited May 18, 2016 by Kaira Link to comment Share on other sites More sharing options...
DarkXero Posted May 18, 2016 Share Posted May 18, 2016 14 hours ago, Kaira said: Also, what exactly is the inst function? inst is not a function, it's a table. What inst:ListenForEvent("equip", fn) does is store the fn on a table, so that when you do inst:PushEvent("equip", extra_data) the game will go to the table where the fn was, and will run fn(inst, extra_data) If you search for the "equip" event in the player inventory component (which generates them), you find self.inst:PushEvent("equip", { item = item, eslot = eslot }) self is the inventory. self.inst is the inst assigned to the inventory, which is a player. Then you see the event pushed, and a table of information which gets sent along. In this case, the item entity equipped, and the equipslots where it was equipped get sent. So you do local function my_equip_fn(inst, data) if data.eslot == EQUIPSLOTS.HEAD then inst.AnimState:Show("hair_hat") inst.AnimState:Hide("hair") end end inst:ListenForEvent("equip", my_equip_fn) data is the argument name we give to the table I showed you. If you are using this in modmain, you will need to use GLOBAL.EQUIPSLOTS instead of EQUIPSLOTS, to reference it properly. Link to comment Share on other sites More sharing options...
Kaira Posted May 19, 2016 Author Share Posted May 19, 2016 (edited) Sorry, I really should've elaborated and added everything I've got for what I'm attempting so far :B I'm trying to have my character's ears flatten while equipping a hat, so this was the full snip of code I was trying to use to accomplish that- Quote inst:ListenForEvent("equip", function() inst.AnimState:Show("hair_hat")inst.AnimState:Hide("hair") end) inst:ListenForEvent("unequip", function() inst.AnimState:Hide("hair_hat")inst.AnimState:Show("hair") end) I thought it would be a simple "put this here" that I wasn't quite able to get down, and I could just add that into both snips. The example above works better than what I've been able to come up with thus far, buuut leaves my charrie with double ears like a few of my first attempts :B; Edited May 19, 2016 by Kaira Link to comment Share on other sites More sharing options...
DarkXero Posted May 19, 2016 Share Posted May 19, 2016 43 minutes ago, Kaira said: I thought it would be a simple "put this here" that I wasn't quite able to get down, and I could just add that into both snips. The example above works better than what I've been able to come up with thus far, buuut leaves my charrie with double ears like a few of my first attempts :B; You mean like inst:ListenForEvent("equip", function(inst, data) if data.eslot == EQUIPSLOTS.HEAD then inst.AnimState:Show("hair_hat") inst.AnimState:Hide("hair") end end) inst:ListenForEvent("unequip", function(inst, data) if data.eslot == EQUIPSLOTS.HEAD then inst.AnimState:Hide("hair_hat") inst.AnimState:Show("hair") end end) Link to comment Share on other sites More sharing options...
Kaira Posted May 19, 2016 Author Share Posted May 19, 2016 Yesss~ Thank you so much~ 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