SirDoggo Posted May 6, 2019 Share Posted May 6, 2019 I have some code in the character that doesn't allow them to wear armour but allows them to wear backpacks and carry suspicious marbles. However it doesn't allow them to wear amulets, how would I change it so they can wear amulets? Here is the code: local function drop(inst) local body = inst.components.inventory:GetEquippedItem(EQUIPSLOTS.BODY) if body then if not body:HasTag("backpack") then if not body:HasTag("heavy") then if not body:HasTag("tag") inst:DoTaskInTime(0.1, function() local item = inst.components.inventory:Unequip(EQUIPSLOTS.BODY) if inst and inst.components.talker then inst.components.talker:Say("It does not fit me.") end inst.components.inventory:GiveItem(item) inst.AnimState:OverrideSymbol("swap_body", "nil", "nil") end) end end end end Link to comment https://forums.kleientertainment.com/forums/topic/105753-how-would-a-character-wear-amulets-but-not-armour/ Share on other sites More sharing options...
CarlZalph Posted May 6, 2019 Share Posted May 6, 2019 (edited) Not every check must be done through tags- I personally opt more towards prefabs in specific if I only want certain things to take effect. In your case all of the base game code's prefabs for the amulets all contain 'amulet' in it. So adding in the check: a.prefab and (a.prefab:find("amulet") == nil) Would make it exclude amulets. The 'a.prefab' check is to ensure that some other mod didn't destroy the prefab name by making it nil. You can also set the DoTaskInTime with time of 0 to make it be called on the next logic tick. This is how I'd have your code setup and formatted: local function drop(inst) local body = inst.components.inventory:GetEquippedItem(EQUIPSLOTS.BODY) if not ( body and ( body:HasTag("backpack") or body:HasTag("heavy") or body:HasTag("tag") or (body.prefab and (body.prefab:find("amulet") ~= nil)) )) then inst:DoTaskInTime( 0, function() if not inst:IsValid() then return end if inst.components.talker then inst.components.talker:Say("It does not fit me.") -- Fixme: Use localization string tables here! end local item = inst.components.inventory:Unequip(EQUIPSLOTS.BODY) if item then inst.components.inventory:GiveItem(item) inst.AnimState:OverrideSymbol("swap_body", "nil", "nil") end end ) end end Though I'm not sure if you need to do the override symbol call manually, I'd think that the unequip callback would handle such things. This may not be the case, I didn't look. Edited May 6, 2019 by CarlZalph Negation Link to comment https://forums.kleientertainment.com/forums/topic/105753-how-would-a-character-wear-amulets-but-not-armour/#findComment-1189757 Share on other sites More sharing options...
SirDoggo Posted May 6, 2019 Author Share Posted May 6, 2019 (edited) It works! I did change (body.prefab and (body.prefab:find("amulet") == nil)) to this (body.prefab and (body.prefab:find("amulet") )) and it works. The only problem is when he puts on a hat the dialog is triggered when it shouldn't be. I can just remove the dialogue as it's an extra feature. Now he can equip amulets and can't equip armour which is what i was going for. Thank you! Edited May 6, 2019 by SirDoggo Link to comment https://forums.kleientertainment.com/forums/topic/105753-how-would-a-character-wear-amulets-but-not-armour/#findComment-1189774 Share on other sites More sharing options...
CarlZalph Posted May 6, 2019 Share Posted May 6, 2019 (edited) 3 hours ago, SirDoggo said: It works! I did change (body.prefab and (body.prefab:find("amulet") == nil)) to this (body.prefab and (body.prefab:find("amulet") )) and it works. The only problem is when he puts on a hat the dialog is triggered when it shouldn't be. I can just remove the dialogue as it's an extra feature. Now he can equip amulets and can't equip armour which is what i was going for. Thank you! Ah yup, was supposed to be "~=" for the not equals. Your change or the explicit check both will work fine. As for the hat triggering, are you listening to the 'equip' event? If so, then you can check for if it was the body via the event's data: if data.eslot == EQUIPSLOTS.BODY then drop(inst) end Likewise the data.item would be used, so you could edit the function 'drop' to change it from getting the item to using the item passed directly. Edited May 6, 2019 by CarlZalph Link to comment https://forums.kleientertainment.com/forums/topic/105753-how-would-a-character-wear-amulets-but-not-armour/#findComment-1189843 Share on other sites More sharing options...
SirDoggo Posted May 7, 2019 Author Share Posted May 7, 2019 On 5/6/2019 at 8:52 PM, CarlZalph said: if data.eslot == EQUIPSLOTS.BODY then drop(inst) end I'm not sure where this is meant to go. I've put it in different places and it causes the game to crash. Lua file is in the post. I've got this error: [string "scripts/mainfunctions.lua"]:150: Error loading file prefabs/frank [string "../mods/Frank/scripts/prefabs/frank.lua"]:53: 'then' expected near 'if' frank.lua Link to comment https://forums.kleientertainment.com/forums/topic/105753-how-would-a-character-wear-amulets-but-not-armour/#findComment-1190546 Share on other sites More sharing options...
Ultroman Posted May 7, 2019 Share Posted May 7, 2019 (edited) You have not closed your function or if-statement. Look at the red line on the left-hand side, which shows where the "thing" starting at the cursor ends. Your function is never closed, meaning you're missing an "end" somewhere. Get yourself Notepad++ or something similar with this kind of highlighting, so you can see these problems. I can highly recommend keeping your indentation tidy, as well. It really helps with the overview of what's happening, and it would even have helped you see this error, even without highlighting. I think this works.frank.lua I changed how your checks are done a bit, for clarity. Also made use of the "data" parameter that CarlZalph was talking about. Edited May 7, 2019 by Ultroman Link to comment https://forums.kleientertainment.com/forums/topic/105753-how-would-a-character-wear-amulets-but-not-armour/#findComment-1190565 Share on other sites More sharing options...
SirDoggo Posted May 8, 2019 Author Share Posted May 8, 2019 I used the code and got this error [string "../mods/Frank/scripts/prefabs/frank.lua"]:48: 'then' expected near '!' i added the "then" it wanted and it said unexpected symbol. Tried "=" instead still didn't work. Link to comment https://forums.kleientertainment.com/forums/topic/105753-how-would-a-character-wear-amulets-but-not-armour/#findComment-1191140 Share on other sites More sharing options...
Ultroman Posted May 8, 2019 Share Posted May 8, 2019 It didn't need a "then". I accidentally used != instead of ~=. frank.lua Link to comment https://forums.kleientertainment.com/forums/topic/105753-how-would-a-character-wear-amulets-but-not-armour/#findComment-1191155 Share on other sites More sharing options...
SirDoggo Posted May 8, 2019 Author Share Posted May 8, 2019 It works now! Thanks for helping me! Link to comment https://forums.kleientertainment.com/forums/topic/105753-how-would-a-character-wear-amulets-but-not-armour/#findComment-1191168 Share on other sites More sharing options...
Ultroman Posted May 8, 2019 Share Posted May 8, 2019 I'm glad You're welcome, sir! Link to comment https://forums.kleientertainment.com/forums/topic/105753-how-would-a-character-wear-amulets-but-not-armour/#findComment-1191284 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