rons0n Posted April 23, 2015 Share Posted April 23, 2015 So I actually have two requests, sorry if it's a little demanding. I want my character to only be fed by forcefeed. And two, I want my character to attack a Beefalo which will trigger the other beefalos to run away from the attacker. (But the attacked beefalo staying aggro'ed on you) Much is appreciated as always! Link to comment Share on other sites More sharing options...
DarkXero Posted April 23, 2015 Share Posted April 23, 2015 Modmain:local old = GLOBAL.ACTIONS.EAT.fnGLOBAL.ACTIONS.EAT.fn = function(act) if act.doer.prefab == "wilson" then return end return old(act)endAddPrefabPostInit("beefalo", function(inst) local self = inst.components.combat local old = self.ShareTarget function self:ShareTarget(target, range, fn, maxnum) if target and target.prefab == "wilson" then local x, y, z = self.inst.Transform:GetWorldPosition() local ents = GLOBAL.TheSim:FindEntities(x, y, z, GLOBAL.SpringCombatMod(range), { "_combat" }) for i, v in ipairs(ents) do if v ~= self.inst and v.prefab == "beefalo" and v.components.hauntable then v.components.hauntable:Panic(10) end end return end return old(self, target, range, fn, maxnum) endend)There you go! Link to comment Share on other sites More sharing options...
rons0n Posted April 23, 2015 Author Share Posted April 23, 2015 I'm not suprised that it's you to help out. xDI'm going to give you a shoutout when I release this character! Thanks again as usual! Link to comment Share on other sites More sharing options...
rons0n Posted April 23, 2015 Author Share Posted April 23, 2015 @DarkXero, Looks like I got all jumpity all too soon. As a Host, getting near a beefalo herd and killing it is fine. As a client though, the moment she gets close to the herd the game freezes saying that "Don't Starve Together Has Run Out of Memory and Must shut down" We did some messing around and think the second part of the code provided could be it. Link to comment Share on other sites More sharing options...
DarkXero Posted April 23, 2015 Share Posted April 23, 2015 Yes, sorry.AddPrefabPostInit("beefalo", function(inst) if GLOBAL.TheWorld.ismastersim then local self = inst.components.combat local old = self.ShareTarget function self:ShareTarget(target, range, fn, maxnum) if target and target.prefab == "wilson" then local x, y, z = self.inst.Transform:GetWorldPosition() local ents = GLOBAL.TheSim:FindEntities(x, y, z, GLOBAL.SpringCombatMod(range), { "_combat" }) for i, v in ipairs(ents) do if v ~= self.inst and v.prefab == "beefalo" and v.components.hauntable then v.components.hauntable:Panic(10) end end return end return old(self, target, range, fn, maxnum) end endend) Link to comment Share on other sites More sharing options...
rons0n Posted April 23, 2015 Author Share Posted April 23, 2015 Fixed liked a charm! Thanks Link to comment Share on other sites More sharing options...
rons0n Posted April 25, 2015 Author Share Posted April 25, 2015 I was going to make another thread but i think the question sorta relates: For this particular character I want it so she can be forcefed by anything even in regards that it'd give negative values. As I have the code that negates all those negatives(Atleast for raw meat). How would I do this? Also, even though this was a very, VERY, VERY rare occurance, a client of mine still received the "Out-Of-Memory" bug, but this was like 30mins in our 5+ hours gameplay today. Dunno if this meant anything or just a hiccup. Link to comment Share on other sites More sharing options...
DarkXero Posted April 25, 2015 Share Posted April 25, 2015 (edited) I see you published many characters in the workshop.Loading many assets into the game may cause it to run out of memory.But this would happen with say, having Up N Away and Hero in The Dark at the same time.Perhaps, maybe having that postinit on every single beefalo is a bit too much and I can't realize it. However, I got a more sensible option. You can put this:inst.components.combat.onhitotherfn = function(attacker, target, damage, stimuli) if target.prefab == "beefalo" then local x, y, z = target.Transform:GetWorldPosition() local ents = TheSim:FindEntities(x, y, z, SpringCombatMod(33), { "_combat" }) for i, v in ipairs(ents) do if v ~= target and v.prefab == "beefalo" then v.components.combat:SetTarget(nil) v.components.hauntable:Panic(10) end end endendinside anime tiger's master_postinit to get the same effect as the AddPrefabPostInit. See if this solves the memory issue. For the feed thing, try this in modmain:local FOODTYPE = GLOBAL.FOODTYPElocal old = GLOBAL.ACTIONS.FEEDPLAYER.fnGLOBAL.ACTIONS.FEEDPLAYER.fn = function(act) if act.target and act.target.prefab ~= "tiger" then return old(act) else if act.target:IsValid() and not (act.target.sg:HasStateTag("attacking") or act.target.sg:HasStateTag("sleeping") or act.target:HasTag("playerghost")) and act.target.components.eater and act.invobject.components.edible and act.target.components.eater:CanEat(act.invobject) then if act.target.components.eater:PrefersToEat(act.invobject) then local food = act.invobject.components.inventoryitem:RemoveFromOwner() if food then act.target:AddChild(food) food:RemoveFromScene() food.components.inventoryitem:HibernateLivingItem() food.persists = false if food.components.edible.foodtype == FOODTYPE.MEAT then act.target.sg:GoToState("eat", food, true) else act.target.sg:GoToState("quickeat", food, true) end return true end else act.target:PushEvent("wonteatfood", {food=act.invobject}) return true end end endend Edited April 25, 2015 by DarkXero Link to comment Share on other sites More sharing options...
rons0n Posted April 25, 2015 Author Share Posted April 25, 2015 I see you published many characters in the workshop.Loading many assets into the game may cause it to run out of memory.But this would happen with say, having Up N Away and Hero in The Dark at the same time.Perhaps, maybe having that postinit on every single beefalo is a bit too much and I can't realize it. However, I got a more sensible option. You can put this:inst.components.combat.onhitotherfn = function(attacker, target, damage, stimuli) if target.prefab == "beefalo" then local x, y, z = target.Transform:GetWorldPosition() local ents = TheSim:FindEntities(x, y, z, SpringCombatMod(33), { "_combat" }) for i, v in ipairs(ents) do if v ~= target and v.prefab == "beefalo" then v.components.combat:SetTarget(nil) v.components.hauntable:Panic(10) end end endendinside anime tiger's master_postinit to get the same effect as the AddPrefabPostInit. See if this solves the memory issue. For the feed thing, try this in modmain:local FOODTYPE = GLOBAL.FOODTYPElocal old = GLOBAL.ACTIONS.FEEDPLAYER.fnGLOBAL.ACTIONS.FEEDPLAYER.fn = function(act) if act.target and act.target.prefab ~= "tiger" then return old(act) else if act.target:IsValid() and not (act.target.sg:HasStateTag("attacking") or act.target.sg:HasStateTag("sleeping") or act.target:HasTag("playerghost")) and act.target.components.eater and act.invobject.components.edible and act.target.components.eater:CanEat(act.invobject) then if act.target.components.eater:PrefersToEat(act.invobject) then local food = act.invobject.components.inventoryitem:RemoveFromOwner() if food then act.target:AddChild(food) food:RemoveFromScene() food.components.inventoryitem:HibernateLivingItem() food.persists = false if food.components.edible.foodtype == FOODTYPE.MEAT then act.target.sg:GoToState("eat", food, true) else act.target.sg:GoToState("quickeat", food, true) end return true end else act.target:PushEvent("wonteatfood", {food=act.invobject}) return true end end endend Much is appreciated. Though I don't know how to properly reenact the Out-of-Memory crash as it was a rare hiccup, but it seems everything is working as intended! Regarding the food tidbit, I totally did not consider the exploitation of people simply not feeding my character, thus, simply dying to starvation. So I'm probably going to scrap that for now or make it configurable on and off in the future. I'm sorry for wasting your time x_x. As a consolation, I'll add more O's to your shoutout. "DarkXero is coooooooooooooooooooooooooooool!" 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