732758_1452793731 Posted July 16, 2017 Share Posted July 16, 2017 Greetings to all. I need help. I want to create a character who will refuse to eat spoiled food and monster meat and raw meat. How can I do that? Link to comment Share on other sites More sharing options...
Yabumi Posted July 16, 2017 Share Posted July 16, 2017 (edited) Overwrite ACTIONS.FEEDPLAYER somewhere in your mod. ACTIONS.FEEDPLAYER.fn = function(act) if act.target ~= nil and act.target:IsValid() and act.target.sg:HasStateTag("idle") and not (act.target.sg:HasStateTag("busy") or act.target.sg:HasStateTag("attacking") or act.target.sg:HasStateTag("sleeping") or act.target:HasTag("playerghost")) and act.target.components.eater ~= nil and act.invobject.components.edible ~= nil and act.target.components.eater:CanEat(act.invobject) and (TheNet:GetPVPEnabled() or not (act.invobject:HasTag("badfood") or act.invobject:HasTag("spoiled"))) then if act.target.components.eater:PrefersToEat(act.invobject) or (act.doer.HasTag("pickyeater") and (not (act.target.components.perishable:IsStale() or act.target.components.perishable:IsSpoiled())) or act.target.prefab ~= "monstermeat") then local food = act.invobject.components.inventoryitem:RemoveFromOwner() if food ~= nil then act.target:AddChild(food) food:RemoveFromScene() food.components.inventoryitem:HibernateLivingItem() food.persists = false act.target.sg:GoToState( (act.target:HasTag("beaver") and "beavereat") or (food.components.edible.foodtype == FOODTYPE.MEAT and "eat") or "quickeat", {feed=food,feeder=act.doer} ) return true end else act.target:PushEvent("wonteatfood", { food = act.invobject }) return true -- the action still "succeeded", there's just no result on this end end end end This is what was changed about the above: if act.target.components.eater:PrefersToEat(act.invobject) or (act.doer.HasTag("pickyeater") and (not (act.target.components.perishable:IsStale() or act.target.components.perishable:IsSpoiled())) or act.target.prefab ~= "monstermeat") then Add the relevant tag to your mod (you can change this, I just chose "pickyeater" arbitrarily). inst:AddTag("pickyeater") This should go in your common_postinit if you're using Dleiwolf's Extended Sample Character template. If not, it should go in whatever function is your fourth argument to MakePlayerCharacter. To make it so you can't eat raw meat, add this: inst.components.eater:SetDiet({ FOODGROUP.OMNI }, { FOODTYPE.MEAT, FOODTYPE.VEGGIES, FOODTYPE.INSECTS, FOODTYPE.SEEDS, FOODTYPE.GOODIES }) To your master_postinit (or fifth argument to MakePlayerCharacter). Alternatively, I think you can overwrite Eater:PrefersToEat. I'm not really sure unless I actually test it. Edited July 16, 2017 by Yabumi Forgot some parts. Link to comment Share on other sites More sharing options...
732758_1452793731 Posted July 17, 2017 Author Share Posted July 17, 2017 (edited) 12 hours ago, Yabumi said: ACTIONS.FEEDPLAYER.fn = function(act) if act.target ~= nil and act.target:IsValid() and act.target.sg:HasStateTag("idle") and not (act.target.sg:HasStateTag("busy") or act.target.sg:HasStateTag("attacking") or act.target.sg:HasStateTag("sleeping") or act.target:HasTag("playerghost")) and act.target.components.eater ~= nil and act.invobject.components.edible ~= nil and act.target.components.eater:CanEat(act.invobject) and (TheNet:GetPVPEnabled() or not (act.invobject:HasTag("badfood") or act.invobject:HasTag("spoiled"))) then if act.target.components.eater:PrefersToEat(act.invobject) or (act.doer.HasTag("pickyeater") and (not (act.target.components.perishable:IsStale() or act.target.components.perishable:IsSpoiled())) or act.target.prefab ~= "monstermeat") then local food = act.invobject.components.inventoryitem:RemoveFromOwner() if food ~= nil then act.target:AddChild(food) food:RemoveFromScene() food.components.inventoryitem:HibernateLivingItem() food.persists = false act.target.sg:GoToState( (act.target:HasTag("beaver") and "beavereat") or (food.components.edible.foodtype == FOODTYPE.MEAT and "eat") or "quickeat", {feed=food,feeder=act.doer} ) return true end else act.target:PushEvent("wonteatfood", { food = act.invobject }) return true -- the action still "succeeded", there's just no result on this end end end end After adding this code, my character refuses to eat vegetables. But monster meat and raw meat he eats. I didn't want this. Edited July 17, 2017 by 732758_1452793731 Link to comment Share on other sites More sharing options...
Yabumi Posted July 17, 2017 Share Posted July 17, 2017 (edited) Sorry about that. I should've put a disclaimer that I hadn't tested it. This one I did test (attached file). It probably has a __MACOSX folder in it but you can ignore that since it does nothing on Windows. scripts.zip local common_postinit = function(inst) inst.MiniMapEntity:SetIcon( "esctemplate.tex" ) inst:AddTag("pickyeater") end local master_postinit = function(inst) inst.soundsname = "willow" inst.components.health:SetMaxHealth(150) inst.components.hunger:SetMax(150) inst.components.sanity:SetMax(200) inst.components.combat.damagemultiplier = 1 inst.components.hunger.hungerrate = 1 * TUNING.WILSON_HUNGER_RATE inst.OnLoad = onload inst.OnNewSpawn = onload inst.components.eater.PrefersToEat = function(self, inst) --V2C: fruitcake hack. see how long this code stays untouched - _-" return not (inst.prefab == "winter_food4" and self.inst:HasTag("player")) and self:TestFood(inst, self.preferseating) and not (self.inst:HasTag("pickyeater") and ((inst.components.perishable:IsStale() or inst.components.perishable:IsSpoiled()) or inst.prefab == "monstermeat" or inst.prefab == "cookedmonstermeat" or inst.prefab == "monsterlasagna" or inst.prefab == "monstermeat_dried" or (inst:HasTag("edible_MEAT") and inst:HasTag("cookable")))) end end Edited July 17, 2017 by Yabumi Added the code to the post so downloads aren't really required. Link to comment Share on other sites More sharing options...
732758_1452793731 Posted July 18, 2017 Author Share Posted July 18, 2017 12 hours ago, Yabumi said: Sorry about that. I should've put a disclaimer that I hadn't tested it. This one I did test (attached file). It probably has a __MACOSX folder in it but you can ignore that since it does nothing on Windows. scripts.zip local common_postinit = function(inst) inst.MiniMapEntity:SetIcon( "esctemplate.tex" ) inst:AddTag("pickyeater") end local master_postinit = function(inst) inst.soundsname = "willow" inst.components.health:SetMaxHealth(150) inst.components.hunger:SetMax(150) inst.components.sanity:SetMax(200) inst.components.combat.damagemultiplier = 1 inst.components.hunger.hungerrate = 1 * TUNING.WILSON_HUNGER_RATE inst.OnLoad = onload inst.OnNewSpawn = onload inst.components.eater.PrefersToEat = function(self, inst) --V2C: fruitcake hack. see how long this code stays untouched - _-" return not (inst.prefab == "winter_food4" and self.inst:HasTag("player")) and self:TestFood(inst, self.preferseating) and not (self.inst:HasTag("pickyeater") and ((inst.components.perishable:IsStale() or inst.components.perishable:IsSpoiled()) or inst.prefab == "monstermeat" or inst.prefab == "cookedmonstermeat" or inst.prefab == "monsterlasagna" or inst.prefab == "monstermeat_dried" or (inst:HasTag("edible_MEAT") and inst:HasTag("cookable")))) end end thank you very much. It really works. Link to comment Share on other sites More sharing options...
Kronas Posted July 21, 2017 Share Posted July 21, 2017 UHHH wait how do i make him eat MEAT ONLY not veg i really am looking for that but UGH can't find anything that can help so please ;w;" want my character to eat meat only i added strong stomach so its fine with monster meat Link to comment Share on other sites More sharing options...
Kronas Posted July 21, 2017 Share Posted July 21, 2017 On 7/17/2017 at 10:49 PM, Yabumi said: Sorry about that. I should've put a disclaimer that I hadn't tested it. This one I did test (attached file). It probably has a __MACOSX folder in it but you can ignore that since it does nothing on Windows. scripts.zip local common_postinit = function(inst) inst.MiniMapEntity:SetIcon( "esctemplate.tex" ) inst:AddTag("pickyeater") end local master_postinit = function(inst) inst.soundsname = "willow" inst.components.health:SetMaxHealth(150) inst.components.hunger:SetMax(150) inst.components.sanity:SetMax(200) inst.components.combat.damagemultiplier = 1 inst.components.hunger.hungerrate = 1 * TUNING.WILSON_HUNGER_RATE inst.OnLoad = onload inst.OnNewSpawn = onload inst.components.eater.PrefersToEat = function(self, inst) --V2C: fruitcake hack. see how long this code stays untouched - _-" return not (inst.prefab == "winter_food4" and self.inst:HasTag("player")) and self:TestFood(inst, self.preferseating) and not (self.inst:HasTag("pickyeater") and ((inst.components.perishable:IsStale() or inst.components.perishable:IsSpoiled()) or inst.prefab == "monstermeat" or inst.prefab == "cookedmonstermeat" or inst.prefab == "monsterlasagna" or inst.prefab == "monstermeat_dried" or (inst:HasTag("edible_MEAT") and inst:HasTag("cookable")))) end end UHHH wait how do i make him eat MEAT ONLY not veg i really am looking for that but UGH can't find anything that can help so please ;w;" want my character to eat meat only i added strong stomach so its fine with monster meat Link to comment Share on other sites More sharing options...
. . . Posted July 21, 2017 Share Posted July 21, 2017 2 hours ago, Kronas said: UHHH wait how do i make him eat MEAT ONLY not veg Put this code in YOURCHARACTER.lua inside the "master_postinit" inst.components.eater:SetDiet({ FOODGROUP.OMNI }, { FOODTYPE.MEAT }) Link to comment Share on other sites More sharing options...
Kronas Posted July 22, 2017 Share Posted July 22, 2017 (edited) 1 hour ago, SuperDavid said: Put this code in YOURCHARACTER.lua inside the "master_postinit" inst.components.eater:SetDiet({ FOODGROUP.OMNI }, { FOODTYPE.MEAT }) OH MY GOD you ARE still around , i was losing hope thinking no helpful peeps around anymore so i kept seeking info as muhc as possible there is also a big issue i have you see i created 3 character mods all of them work smoothly with no bugs but the only issue is i can't enable more then 1 of them yes i used esctemplate example to create them all but for some reason they don't start a server together like i can only turn on 1 of them other wise the game will stop responding when i start generating the world what could be the possible issues you may think of ? i'm really dying for an answer to this issue Edited July 22, 2017 by Kronas 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