. . . Posted May 16, 2016 Share Posted May 16, 2016 When my character becomes insane i'd like for it to make beefalo and possibly other animals to get scared off like a koalafant but when you hit them they fight back (if they could). So, does anyone know what I should do because I have no idea how I would go about this ... I would really appreciate if somebody can bestow their superior coding knowledge on me & thanks for reading ! Link to comment Share on other sites More sharing options...
CarlZalph Posted May 16, 2016 Share Posted May 16, 2016 Anything that controls the AI of an entity will be messing with the brain of the entity. A brain uses behaviours for mapping out responses to criteria. In your case you will want to use AddBrainPostInit to edit the brain of whatever you want to be scared, and put in a RunAway node with its hunterparams checking for your character's prefab and sanity levels. It sounds simple, but messing with premade brains can get pretty hairy, especially if you don't make assumptions about the layout of the brain beforehand for maximum mod compatibility. Link to comment Share on other sites More sharing options...
. . . Posted May 16, 2016 Author Share Posted May 16, 2016 I did something like this (it probably doesn't make sense, right?)... local AddBrainPostInit = function(inst) inst:ListenForEvent("goinsane", function(inst, data) local brain = require "brains/houndbrainInsane" end I tried putting it in and out of the local master_postinit = function(inst) in my character prefab but it just crashed the game . Do you think you can tell me the correct way to put AddBrainPostInit because I think I put it a very wrong way but don't know how to properly do it ... I would appreciate if you could tell me & thanks for reading ! Link to comment Share on other sites More sharing options...
DarkXero Posted May 16, 2016 Share Posted May 16, 2016 GLOBAL.require("behaviours/runaway") local function AddBeefaloFear(self) -- Beefalo entity, tag they run away from, distance they see spooker, distance to which they run away local fear = GLOBAL.RunAway(self.inst, "sparkspooker", 6, 12) fear.parent = self.bt.root -- Insert fear right after ChaseAndAttack table.insert(self.bt.root.children, 5, fear) end AddBrainPostInit("beefalobrain", AddBeefaloFear) local function ApplyFearTag(inst) inst:AddTag("sparkspooker") end local function RemoveFearTag(inst) inst:RemoveTag("sparkspooker") end local function AddBeefaloFearOnInsanity(inst) if inst.components.sanity then inst:ListenForEvent("goinsane", ApplyFearTag) inst:ListenForEvent("gosane", RemoveFearTag) end end AddPrefabPostInit("wilson", AddBeefaloFearOnInsanity) Put all of this in modmain. Edit "wilson" to your character prefab. This adds a new behaviour to beefalo brains. Link to comment Share on other sites More sharing options...
CarlZalph Posted May 16, 2016 Share Posted May 16, 2016 (edited) AddBrainPostInit("beefalobrain", function(self) if(self.bt and self.bt.root and self.bt.root.children) then for k, v in ipairs(self.bt.root.children) do if(v.name=="ChaseAndAttack") then GLOBAL.table.insert(self.bt.root.children, k+1, GLOBAL.RunAway(self.inst, "yourcustomtag", 6, 12) ) break end end end end ) AddPrefabPostInit("waxwell", function(inst) if(inst.components and inst.components.sanity) then inst:ListenForEvent("goinsane", function(inst) inst:AddTag("yourcustomtag") end ) inst:ListenForEvent("gosane", function(inst) inst:RemoveTag("yourcustomtag") end ) end end ) DarkXero beat me to the punch, but sleep and such. Though I like my method of injecting into the brain table better as it allows for higher mod compatibility, following the koalaphant's order of RunAway node logic. Not sure why DarkXero's requiring the behaviour, though- the patch applies fine without it on my end. Edited May 16, 2016 by CarlZalph Link to comment Share on other sites More sharing options...
. . . Posted May 16, 2016 Author Share Posted May 16, 2016 Thank you very much DarkXero, it worked so well!!! Thank you, thank you!!! Thank you too CarlZalph for your help too ! 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