. . . Posted November 2, 2016 Author Share Posted November 2, 2016 @Serpens Can I ask you one last question? If you don't wanna help then that's fine i'll just give up on this . So, I tried doing something like AddPlayerPostInit(function(inst) inst:ListenForEvent("equip", function(inst, data) local item = data.item if item.prefab == "earmuffshat" and not inst.HasTag("perfect") then inst.components.talker:Say("my ears are safe.") inst.soundproof = true elseif not item.prefab == "earmuffshat" then return end end) end) and I get this crash, what did I do wrong? Spoiler Also, what's the event for unequipping a item ? Link to comment https://forums.kleientertainment.com/forums/topic/71320-solved-how-to-check-if-character-has-something-equipped-on-head/page/2/#findComment-832135 Share on other sites More sharing options...
Serpens Posted November 2, 2016 Share Posted November 2, 2016 (edited) 13 hours ago, SuperDavid said: @Serpens Can I ask you one last question? If you don't wanna help then that's fine i'll just give up on this . So, I tried doing something like AddPlayerPostInit(function(inst) inst:ListenForEvent("equip", function(inst, data) local item = data.item if item.prefab == "earmuffshat" and not inst.HasTag("perfect") then inst.components.talker:Say("my ears are safe.") inst.soundproof = true elseif not item.prefab == "earmuffshat" then return end end) end) and I get this crash, what did I do wrong? Reveal hidden contents Also, what's the event for unequipping a item ? "unequip" try to find out the error yourself This time the log error does not show the exact error in your script. But you know that something might be nil. "index something" mostly mean, that you try to make eg. "data.item" while data is nil. Or item.prefab, while prefab is nil. So you could check, if one of them is nil. The easiest way to test it, is to put print statements in your code like print("data: "..tostring(data)) Then you can hit CTRL+L ingame to see the logs and see what data and all the other stuff is. But if data or item would be nil, the error log would not include entityscript. So now you go into scripts/entityscript.lua and go to line 492. There you see it is the function "HasTag" that throws the error. So you have to check, if something about "HasTag" is wrong in your code. Most likely you will notice, that item/inst is not nil, so it should work. What else could be wrong with "inst.HasTag("perfect")" ? It is a typo Edited November 2, 2016 by Serpens Link to comment https://forums.kleientertainment.com/forums/topic/71320-solved-how-to-check-if-character-has-something-equipped-on-head/page/2/#findComment-832259 Share on other sites More sharing options...
. . . Posted November 2, 2016 Author Share Posted November 2, 2016 @Serpens Serpens, thanks so much for your guidance ! I figured out what the error was... "inst.HasTag("perfect")" this was a typo thanks for the hint, looks like it's not good to code when you're sleepy, haha! So, I did something like this AddPlayerPostInit(function(inst, data) inst:ListenForEvent("equip", function(inst, data) local item = data.item if item.prefab == "earmuffshat" and not inst:HasTag("perfect") then inst.components.talker:Say("safensnsasz.") inst.soundproof = true elseif not item.prefab == "earmuffshat" then return end end) inst:ListenForEvent("unequip", function(inst, data) local item = data.item if item.prefab == "earmuffshat" and not inst:HasTag("perfect") then inst.components.talker:Say("No more protection foir me.") inst.soundproof = nil elseif not item.prefab == "earmuffshat" then return end end) end) and put a check for inst.soundproof on my code & it works just like I intended ! I have no idea why the equip code didn't work though? But whatever this code works just as fine & I couldn't have done it without you Serpens, really thanks so much! Link to comment https://forums.kleientertainment.com/forums/topic/71320-solved-how-to-check-if-character-has-something-equipped-on-head/page/2/#findComment-832314 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