lakhnish Posted July 14, 2022 Share Posted July 14, 2022 (edited) I am trying to assign a tag to players only if they can eat a certain foodtype, as I want to use that tag later on. The problem is that the tag gets assigned to all players instead of the ones that can eat a certain foodtype in my AddPlayerPostInIt and I'm not sure why. if inst.components.eater ~= nil then for k, v in pairs(inst.components.eater.preferseating) do if inst.components.eater.preferseating[v] == GLOBAL.FOODTYPE.VEGGIE then inst:AddTag("vegetarianEater") end end end if inst:HasTag("vegetarianEater") then --my code end The reason I am not using foodgroups is because I want to check for specific foodtypes that is part of a foodgroup in the case of modded characters or for someone like Wigfrid. In the case above, I would do a c_announce to check if the character was getting the tag when they weren't supposed to (like Wigfrid in this case) and they were getting it. Edited July 14, 2022 by lakhnish Link to comment https://forums.kleientertainment.com/forums/topic/141686-how-to-assign-tags-based-on-what-the-diet-of-the-player-is/ Share on other sites More sharing options...
penguin0616 Posted July 15, 2022 Share Posted July 15, 2022 (edited) There's potentially some details I'm missing here, since I'm not sure why all players would be getting the tag based on your loop's conditional. The correct loop should probably be something like if inst.components.eater ~= nil then for k, v in pairs(inst.components.eater.preferseating) do if v == GLOBAL.FOODTYPE.VEGGIE or (v.types and table.contains(v.types, GLOBAL.FOODTYPE.VEGGIE)) then inst:AddTag("vegetarianEater") c_announce("Giving 'vegetarianEater' tag to " .. inst:GetDisplayName()) break end end end Since preferseating can have both foodgroups and foodtypes. Edited July 15, 2022 by penguin0616 2 Link to comment https://forums.kleientertainment.com/forums/topic/141686-how-to-assign-tags-based-on-what-the-diet-of-the-player-is/#findComment-1584912 Share on other sites More sharing options...
Hornete Posted July 15, 2022 Share Posted July 15, 2022 On 7/14/2022 at 2:20 PM, lakhnish said: [snip] The game already adds tags when the diet for an eater is set(This is how the player client is able to know if they can eat a certain food). In the case of a player that can eat veggies only, the "VEGGIE_eater" tag is added. You can see where the tags are added in the 'scripts/components/eater.lua' file, in the 'oncaneat' function. 1 Link to comment https://forums.kleientertainment.com/forums/topic/141686-how-to-assign-tags-based-on-what-the-diet-of-the-player-is/#findComment-1584953 Share on other sites More sharing options...
lakhnish Posted July 15, 2022 Author Share Posted July 15, 2022 (edited) 3 hours ago, penguin0616 said: There's potentially some details I'm missing here, since I'm not sure why all players would be getting the tag based on your loop's conditional. What I'm doing is making a diet restriction mod. I've organized foods into their own categories, assigned a tag to them and then made it so that players can only eat foods with that tag and they would refuse all other foods. The reason I needed these tags based on if the player can eat a specific foodtype is because not every diet can be eaten by every character, so those characters need to be excluded from the challenge so they can eat what they normally can so they don't starve. It's really more for modded characters since I could have just used tags that already exist for Wigfrid and Wurt, but this would future proof it as well in case a future character gets another specific diet. So after the tag assignment, it goes: AddPlayerPostInIt(function(inst) --Only those who can eat the veggie foodtype can participate in this challenge as the diet only contains veggies if inst.components.eater~=nil and inst:HasTag("vegetarianEater") then inst.components.eater:SetPrefersEatingTag("dietNameTag") end end) So with this tag assignment you provided (or with the VEGGIE_eater tag), Wilson and Wurt should only be part of the challenge but for some reason, Wigfrid has become a part of the challenge as well or they all decide that it's time for them to starve and I don't know why. I'm gonna have to investigate once I have more free time, as this is the only thing that's incomplete to make the mod fully functional Edit: I've figured out the problem, it was some other code I had that was interfering. Edited July 16, 2022 by lakhnish Link to comment https://forums.kleientertainment.com/forums/topic/141686-how-to-assign-tags-based-on-what-the-diet-of-the-player-is/#findComment-1584965 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