ScallyCat Posted March 17, 2015 Share Posted March 17, 2015 I'm making my first character mod and i've stumbled across an issue I can't solve by either looking through the game code or here on the forums.Basically I want to create a function that says this: "If I equip a certain hat, remove the monster tag from my character. If I unequip said hat, add the monster tag back to my character, and remove all followers with the tag pig. Else, keep the monster tag."I've been fiddling around with some code I've found here on the forums but I don't think it's worth showing since it doesn't make much sense from what I have done to it. From what I understand I need to make a prefab that chooses which hats will remove the monster tag, and then test when one of those hats is equipped. My main problem is that I don't know what code I can use to actually test what is in the (hat?) slot, and I don't know if this code should be going in my modmain or character lua. I also don't know how to go about using this function since it is a lot different from my other perks. Link to comment https://forums.kleientertainment.com/forums/topic/52127-testing-hats/ Share on other sites More sharing options...
Kzisor Posted March 17, 2015 Share Posted March 17, 2015 I'm making my first character mod and i've stumbled across an issue I can't solve by either looking through the game code or here on the forums.Basically I want to create a function that says this:"If I equip a certain hat, remove the monster tag from my character. If I unequip said hat, add the monster tag back to my character, and remove all followers with the tag pig. Else, keep the monster tag."I've been fiddling around with some code I've found here on the forums but I don't think it's worth showing since it doesn't make much sense from what I have done to it. From what I understand I need to make a prefab that chooses which hats will remove the monster tag, and then test when one of those hats is equipped. My main problem is that I don't know what code I can use to actually test what is in the (hat?) slot, and I don't know if this code should be going in my modmain or character lua. I also don't know how to go about using this function since it is a lot different from my other perks. Here is a sample code: local function OnEquip(inst, owner) owner.AnimState:OverrideSymbol("swap_hat", "hat_bee_bw_swap", "swap_hat") owner.AnimState:Show("HAT") owner.AnimState:Show("HAT_HAIR") owner.AnimState:Hide("HAIR_NOHAT") owner.AnimState:Hide("HAIR") if owner:HasTag("player") then owner.AnimState:Hide("HEAD") owner.AnimState:Show("HEAD_HAIR") end if owner:HasTag("monster") then owner:RemoveTag("monster") endendlocal function OnUnequip(inst, owner) owner.AnimState:Hide("HAT") owner.AnimState:Hide("HAT_HAIR") owner.AnimState:Show("HAIR_NOHAT") owner.AnimState:Show("HAIR") if owner:HasTag("player") then owner.AnimState:Show("HEAD") owner.AnimState:Hide("HEAD_HAIR") end owner:AddTag("monster") if inst.components.leader then inst.components.leader:RemoveFollowersByTag("pig") endend Link to comment https://forums.kleientertainment.com/forums/topic/52127-testing-hats/#findComment-622552 Share on other sites More sharing options...
ScallyCat Posted March 18, 2015 Author Share Posted March 18, 2015 Here is a sample code:local function OnEquip(inst, owner) owner.AnimState:OverrideSymbol("swap_hat", "hat_bee_bw_swap", "swap_hat") owner.AnimState:Show("HAT") owner.AnimState:Show("HAT_HAIR") owner.AnimState:Hide("HAIR_NOHAT") owner.AnimState:Hide("HAIR") if owner:HasTag("player") then owner.AnimState:Hide("HEAD") owner.AnimState:Show("HEAD_HAIR") end if owner:HasTag("monster") then owner:RemoveTag("monster") endendlocal function OnUnequip(inst, owner) owner.AnimState:Hide("HAT") owner.AnimState:Hide("HAT_HAIR") owner.AnimState:Show("HAIR_NOHAT") owner.AnimState:Show("HAIR") if owner:HasTag("player") then owner.AnimState:Show("HEAD") owner.AnimState:Hide("HEAD_HAIR") end owner:AddTag("monster") if inst.components.leader then inst.components.leader:RemoveFollowersByTag("pig") endendWow thanks for this. I'll get back to you tommorrow on whether or not I've figured it out. Link to comment https://forums.kleientertainment.com/forums/topic/52127-testing-hats/#findComment-622589 Share on other sites More sharing options...
ScallyCat Posted March 18, 2015 Author Share Posted March 18, 2015 Here is a sample code:local function OnEquip(inst, owner) owner.AnimState:OverrideSymbol("swap_hat", "hat_bee_bw_swap", "swap_hat") owner.AnimState:Show("HAT") owner.AnimState:Show("HAT_HAIR") owner.AnimState:Hide("HAIR_NOHAT") owner.AnimState:Hide("HAIR") if owner:HasTag("player") then owner.AnimState:Hide("HEAD") owner.AnimState:Show("HEAD_HAIR") end if owner:HasTag("monster") then owner:RemoveTag("monster") endendlocal function OnUnequip(inst, owner) owner.AnimState:Hide("HAT") owner.AnimState:Hide("HAT_HAIR") owner.AnimState:Show("HAIR_NOHAT") owner.AnimState:Show("HAIR") if owner:HasTag("player") then owner.AnimState:Show("HEAD") owner.AnimState:Hide("HEAD_HAIR") end owner:AddTag("monster") if inst.components.leader then inst.components.leader:RemoveFollowersByTag("pig") endendSo I've added this code into my characters .lua file but I'm having difficulty figuring out how to implement it when I, for example, equip a straw hat. Do you mind giving me some more pointers? Would I have to use a "ListenForEvent"? Looking at the beefalo hat code in "hats.lua" there are seperate functions for equipping and unequipping (like the code you gave me) and then both of those functions are used in one function with the code "inst.components.equippable.SetOnEquip() / SetOnUnequip()." I made a function that does just that but I'm still not sure how to call it and if that is all there is to it? How would I go about using those functions to test specific hats? Link to comment https://forums.kleientertainment.com/forums/topic/52127-testing-hats/#findComment-622844 Share on other sites More sharing options...
Kzisor Posted March 18, 2015 Share Posted March 18, 2015 @ScallyCat, you will need to call it through AddPrefabPostInit(PrefabName, FunctionToCall) . Link to comment https://forums.kleientertainment.com/forums/topic/52127-testing-hats/#findComment-622858 Share on other sites More sharing options...
ScallyCat Posted March 18, 2015 Author Share Posted March 18, 2015 @ScallyCat, you will need to call it through AddPrefabPostInit(PrefabName, FunctionToCall) .Ok awesome! It works! Except for some reason when I put on the straw hat it's invisible...Any idea why that might be happening? Link to comment https://forums.kleientertainment.com/forums/topic/52127-testing-hats/#findComment-622877 Share on other sites More sharing options...
Kzisor Posted March 18, 2015 Share Posted March 18, 2015 @ScallyCat, you're using the wrong animation bank and build. Look at scripts/prefabs/hats to see what bank and build it uses. Link to comment https://forums.kleientertainment.com/forums/topic/52127-testing-hats/#findComment-622880 Share on other sites More sharing options...
ScallyCat Posted March 18, 2015 Author Share Posted March 18, 2015 (edited) By that do you mean inst.AnimState:SetBank() and inst.AnimState:SetBuild() ? Would I have to add an asset to this file? (Sorry this is completely alien to me) Edited March 18, 2015 by ScallyCat Link to comment https://forums.kleientertainment.com/forums/topic/52127-testing-hats/#findComment-622887 Share on other sites More sharing options...
Kzisor Posted March 19, 2015 Share Posted March 19, 2015 By that do you mean inst.AnimState:SetBank() and inst.AnimState:SetBuild() ? Would I have to add an asset to this file? (Sorry this is completely alien to me) This line:owner.AnimState:OverrideSymbol("swap_hat", "hat_bee_bw_swap", "swap_hat") Link to comment https://forums.kleientertainment.com/forums/topic/52127-testing-hats/#findComment-622921 Share on other sites More sharing options...
ScallyCat Posted March 19, 2015 Author Share Posted March 19, 2015 This line:owner.AnimState:OverrideSymbol("swap_hat", "hat_bee_bw_swap", "swap_hat")Sorry for being a pain but I'm really confused right now. I need to replace "hat_bee_bw_swap" right? I've been trying everything I can think of but I can't get it to work... Link to comment https://forums.kleientertainment.com/forums/topic/52127-testing-hats/#findComment-623152 Share on other sites More sharing options...
Kzisor Posted March 19, 2015 Share Posted March 19, 2015 @ScallyCat, post your code so I can help further. Link to comment https://forums.kleientertainment.com/forums/topic/52127-testing-hats/#findComment-623167 Share on other sites More sharing options...
ScallyCat Posted March 19, 2015 Author Share Posted March 19, 2015 @ScallyCat, post your code so I can help further. local function OnEquip(inst, owner,) local fname = "hat_"..name local build = fname_override or fname owner.AnimState:OverrideSymbol("swap_hat", build, "swap_hat") owner.AnimState:Show("HAT") owner.AnimState:Show("HAT_HAIR") owner.AnimState:Hide("HAIR_NOHAT") owner.AnimState:Hide("HAIR") if owner:HasTag("player") then owner.AnimState:Hide("HEAD") owner.AnimState:Show("HEAD_HAIR") end if owner:HasTag("monster") then owner:RemoveTag("monster") endendlocal function onUnequip(inst, owner) owner.AnimState:Hide("HAT") owner.AnimState:Hide("HAT_HAIR") owner.AnimState:Show("HAIR_NOHAT") owner.AnimState:Show("HAIR") if owner:HasTag("player") then owner.AnimState:Show("HEAD") owner.AnimState:Hide("HEAD_HAIR") end owner:AddTag("monster") if inst.components.leader then inst.components.leader:RemoveFollowersByTag("pig") endendlocal function TestHat(inst, owner) inst.components.equippable:SetOnEquip(OnEquip) inst.components.equippable:SetOnUnequip(onUnequip)endThe "local fname" and "local build" were just copied from hats.lua. I was just playing around with them to see what would work. Link to comment https://forums.kleientertainment.com/forums/topic/52127-testing-hats/#findComment-623174 Share on other sites More sharing options...
ScallyCat Posted March 19, 2015 Author Share Posted March 19, 2015 And then I call it with this:AddPrefabPostInit("strawhat", TestHat) Link to comment https://forums.kleientertainment.com/forums/topic/52127-testing-hats/#findComment-623177 Share on other sites More sharing options...
Kzisor Posted March 19, 2015 Share Posted March 19, 2015 (edited) @ScallyCat, you shouldn't overwrite the functions like that. While it is there for you to do you should do something like: local function OnEquip(inst, owner, fname_override) inst.components.equippable:_OnEquip(inst, owner, fname_override) if owner:HasTag("monster") then owner:RemoveTag("monster") endend local function onUnequip(inst, owner) inst.components.equippable:_OnUnequip(inst, owner) owner:AddTag("monster") if inst.components.leader then inst.components.leader:RemoveFollowersByTag("pig") endend local function TestHat(inst, owner) inst.components.equippable._OnEquip = inst.components.equippable.onequipfn inst.components.equippable:SetOnEquip(OnEquip) inst.components.equippable._OnUnequip = inst.components.equippable.onunequipfn inst.components.equippable:SetOnUnequip(onUnequip) end Edited March 22, 2015 by Kzisor Link to comment https://forums.kleientertainment.com/forums/topic/52127-testing-hats/#findComment-623178 Share on other sites More sharing options...
ScallyCat Posted March 19, 2015 Author Share Posted March 19, 2015 @ScallyCat, you shouldn't overwrite the functions like that. While it is there for you to do you should do something like: local function OnEquip(inst, owner,) inst.components.equippable:_OnEquip(inst, owner) if owner:HasTag("monster") then owner:RemoveTag("monster") endend local function onUnequip(inst, owner) inst.components.equippable:_OnUnequip(inst, owner) owner:AddTag("monster") if inst.components.leader then inst.components.leader:RemoveFollowersByTag("pig") endend local function TestHat(inst, owner) inst.components.equippable._OnEquip = inst.compoennts.equippable.onequip inst.components.equippable:SetOnEquip(OnEquip) inst.components.equippable._OnUnequip = inst.components.equippable.onunequip inst.components.equippable:SetOnUnequip(onUnequip) end When I equip the straw hat, it gives me this error: "...modmain.lua:77: attempt to call a method '_OnEquip' (a nil value)" Line 77 being:inst.components.equippable:_OnEquip(inst, owner)Not really sure what the underscores are for but even without those I get the same error. Link to comment https://forums.kleientertainment.com/forums/topic/52127-testing-hats/#findComment-623194 Share on other sites More sharing options...
Kzisor Posted March 19, 2015 Share Posted March 19, 2015 @ScallyCat, Sorry, I've updated the code, it should work now. Link to comment https://forums.kleientertainment.com/forums/topic/52127-testing-hats/#findComment-623195 Share on other sites More sharing options...
ScallyCat Posted March 20, 2015 Author Share Posted March 20, 2015 @ScallyCat, Sorry, I've updated the code, it should work now. Hmm now I get an error that says: "...hats.lua:29: bad argument #1 to 'OverrideSymbol' (string expected, got table)" The 29th line of hats.lua being:owner.AnimState:OverrideSymbol("swap_hat", build, "swap_hat") Link to comment https://forums.kleientertainment.com/forums/topic/52127-testing-hats/#findComment-623211 Share on other sites More sharing options...
Kzisor Posted March 20, 2015 Share Posted March 20, 2015 (edited) Hmm now I get an error that says: "...hats.lua:29: bad argument #1 to 'OverrideSymbol' (string expected, got table)" The 29th line of hats.lua being:owner.AnimState:OverrideSymbol("swap_hat", build, "swap_hat") No this is the updated code that you need: local function OnEquip(inst, owner, fname_override) inst.components.equippable:_OnEquip(inst, owner, fname_override) if owner:HasTag("monster") then owner:RemoveTag("monster") endend local function onUnequip(inst, owner) inst.components.equippable:_OnUnequip(inst, owner) owner:AddTag("monster") if inst.components.leader then inst.components.leader:RemoveFollowersByTag("pig") endend local function TestHat(inst, owner) inst.components.equippable._OnEquip = inst.compoennts.equippable.onequipfn inst.components.equippable:SetOnEquip(OnEquip) inst.components.equippable._OnUnequip = inst.components.equippable.onunequipfn inst.components.equippable:SetOnUnequip(onUnequip) end Edited March 20, 2015 by Kzisor Link to comment https://forums.kleientertainment.com/forums/topic/52127-testing-hats/#findComment-623223 Share on other sites More sharing options...
ScallyCat Posted March 20, 2015 Author Share Posted March 20, 2015 No this is the updated code that you need: local function OnEquip(inst, owner,) inst.components.equippable:_OnEquip(inst, owner) if owner:HasTag("monster") then owner:RemoveTag("monster") endend local function onUnequip(inst, owner) inst.components.equippable:_OnUnequip(inst, owner) owner:AddTag("monster") if inst.components.leader then inst.components.leader:RemoveFollowersByTag("pig") endend local function TestHat(inst, owner) inst.components.equippable._OnEquip = inst.compoennts.equippable.onequipfn inst.components.equippable:SetOnEquip(OnEquip) inst.components.equippable._OnUnequip = inst.components.equippable.onunequipfn inst.components.equippable:SetOnUnequip(onUnequip) end Sorry I should have clarified, I used the same exact code as you provided. Here's the error traceback: http://imgur.com/MTVJzwL Link to comment https://forums.kleientertainment.com/forums/topic/52127-testing-hats/#findComment-623236 Share on other sites More sharing options...
Kzisor Posted March 20, 2015 Share Posted March 20, 2015 (edited) Sorry I should have clarified, I used the same exact code as you provided. Here's the error traceback: http://imgur.com/MTVJzwL Ohh, that is because the third parameter did not show up properly. I've updated both code blocks with the correct third parameter. Sorry about that, not sure why it got left off on both codes. Simply add ", fname_override" behind owner in the equip function and when you call _OnEquip inside the same function. Edit: Spelling Edited March 20, 2015 by Kzisor Link to comment https://forums.kleientertainment.com/forums/topic/52127-testing-hats/#findComment-623238 Share on other sites More sharing options...
ScallyCat Posted March 20, 2015 Author Share Posted March 20, 2015 Ohh, that is because the third parameter did not show up properly. I've updated both code blocks with the correct third parameter. Sorry about that, not sure why it got left off on both codes.Simply add ", fname_override" behind owner in the equip function and when you call _OnEquip inside the same function.Edit: SpellingOkay cool, it might be a couple days before I can back to you on whether or not this works but either way I'll let you know Link to comment https://forums.kleientertainment.com/forums/topic/52127-testing-hats/#findComment-623242 Share on other sites More sharing options...
ScallyCat Posted March 22, 2015 Author Share Posted March 22, 2015 Ohh, that is because the third parameter did not show up properly. I've updated both code blocks with the correct third parameter. Sorry about that, not sure why it got left off on both codes.Simply add ", fname_override" behind owner in the equip function and when you call _OnEquip inside the same function.Edit: SpellingHmm I'm still getting the same error message... Link to comment https://forums.kleientertainment.com/forums/topic/52127-testing-hats/#findComment-624053 Share on other sites More sharing options...
Kzisor Posted March 22, 2015 Share Posted March 22, 2015 Hmm I'm still getting the same error message... Make sure you spell check everything, one of the components is spell incorrectly. (Line 21 specifically in the code I provided.) Link to comment https://forums.kleientertainment.com/forums/topic/52127-testing-hats/#findComment-624055 Share on other sites More sharing options...
ScallyCat Posted March 22, 2015 Author Share Posted March 22, 2015 (edited) Make sure you spell check everything, one of the components is spell incorrectly. (Line 21 specifically in the code I provided.)Yeah I had noticed that early on but I ckecked everything again thoroughly and it all seems to match. Like I said its the same error message as the picture I sent before. Something about expecting a string but recieving a table? Edited March 22, 2015 by ScallyCat Link to comment https://forums.kleientertainment.com/forums/topic/52127-testing-hats/#findComment-624060 Share on other sites More sharing options...
Kzisor Posted March 22, 2015 Share Posted March 22, 2015 Yeah I had noticed that early on but I ckecked everything again thoroughly and it all seems to match. Like I said its the same error message as the picture I sent before. Something about expecting a string but recieving a table? Please post your entire modmain.lua file so I can look at it. Link to comment https://forums.kleientertainment.com/forums/topic/52127-testing-hats/#findComment-624086 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