Jump to content

scripts/brains surgery time! Making nightmares fear you.


Recommended Posts

Time for me to work with brains for the first time, yay.

 

So looking at guides regarding brains and the examples I've been given in the past this should be fairly simple and I can probably figure it out by myself.  However, I'd like to make sure my work is approved by the other doctors on the forum as well, I wouldn't want my first delve into opening a monsters noggin to be a messy one.

 

 

So basically I have this custom item that my custom character is going to wear, while they are wearing it and their sanity is at least above hostility levels then... get this... The nightmare creatures will run away from him in fear.  Since it requires my characters sanity to be above hostility levels for it to even work, this means that it is perfect for protecting insane friends in don't starve together.  YAY friendship.

 

So from what I learned about brains I realized all I really have to do is add a "runaway like a little scared nightmare baby that you are" node above their ChaseAndAttack node in their priority node.  

 
So step 1, find or create a runaway node for the nightmare creatures that checks for my custom item and parameters.
 
Step 2, do a AddBrainPostInit( "nightmarecreaturebrain", func) and add the node where it belongs smack dab on top.
 
Step 3, slap myself for using the word "So" to start with so many times.
 
Step 4, test it and see if it works.
 
Step 5, whether it works or not, post the code here for advice and feedback.
 
Okay, here's how I did, let me show the list of vict... I mean patients.
 
--My attempt at adjusting a brain base off of DarkXero's rabbitbrain example.--Experimenting with rabbits... appropriate?AddBrainPostInit("nightmarecreaturebrain", function(self)	self.bt.root.children[3] = self.bt.root.children[2] --Hard coding    self.bt.root.children[2] = self.bt.root.children[1] --Hard Coding	self.bt.root.children[1] = RunAway(self.inst, "scarydoctor", 5, 8)end)--gotta move the other nodes down the list I'm guessing

RunAway nil value crash, NEXT PATIENT

require "behaviours/runaway"--Added above the code

Still RunAway nil value, well that's not how it's fixed.  NEXT PATIENT

--Copied entire runaway.lua above code

BehaviorNode nil value, I must be doing this at the wrong angle, NEXT

--Gets tired and forgets what was tried next

Okay a bit of nightmare fuel still left on the floor but I feel like I'm close.  Going to head off to sleep for now.

 

At the moment I'm trying to figure out how to add a priority node to the top of the nightmarecreaturebrain but apparently when I put this into my modmain.lua it has no idea what RunAway is.  I could just recreate all the functions but that seems excessive so I'm probably just missing something small.

 

The hard coding was just for testing, I was going to change it to a proper for loop which moves every node down by 1 spot in the event of mod's adding them in.  But I wanted to see if I can add the RunAway node and test it first.

 

My attempts gave me the error's everytime I spawned in a "crawlingnightmare" so I must be missing whatever it is that makes it know what RunAway is.  That or I'm way off.

 

Gonna get some sleep and try again later, assistance appreciated.  Though the brain portion is the only part I really need help with, the item and stuff afterwards I can handle no problem.

 

Link to comment
Share on other sites

Nightmare creatures are the shadows of the caves/ruins. They don't even have an AddNetwork.

Unless you are planning into bringing nightmare creatures to the shadow creature realm.

I tested the code with shadow creatures.

 

I believe the problem you are having is that you are requiring the RunAway, but not the BehaviourNode, so it doesn't get constructed appropriately, because there is no local BehaviourNode.

AddBrainPostInit("shadowcreaturebrain", function(self)	for i = 4, 2, -1 do		self.bt.root.children[i] = self.bt.root.children[i - 1]	end	self.bt.root.children[1] = GLOBAL.RunAway(self.inst, "scarydoctor", 5, 8)end)

Instead of double requiring, this also works.

Edited by DarkXero
Link to comment
Share on other sites

For other mod compatibility helping you also might want to look into #table for size to use instead of hardcoding the size of it.

 

Or better yet use table.insert.

 

So the code would be:

AddBrainPostInit("nightmarecreaturebrain",    function(self)        GLOBAL.table.insert(self.bt.root.children, 1, GLOBAL.RunAway(self.inst, "scarydoctor", 5, 8))    end)

Do note that if the player in question is insane the first behaviour to attack takes precedence and so the insane person will be attacked by their own shadow creatures.

 

Also there's a difference between shadowcreatures and nightmarecreatures.

Not sure which one is for the shades other people get, but for the local client they're shadowcreatures and you can make them runaway take priority.

 

 

The following is for 'shadowcreatures' and not 'nightmarecreatures'.

 

So here's what inserting at index 1 does:

Before:     >Priority - READY <READY> ()>0.00>   >ChaseAndAttack - READY <READY> ()>0.00>   >Follow - READY <READY> ()>0.00>   >Wander - READY <READY> ()>0.00    After:     >Priority - READY <READY> ()>0.00>   >RunAway - READY <READY> ()>0.00>   >ChaseAndAttack - READY <READY> ()>0.00>   >Follow - READY <READY> ()>0.00>   >Wander - READY <READY> ()>0.00

And what inserting at index 2 does:

Before:     >Priority - READY <READY> ()>0.00>   >ChaseAndAttack - READY <READY> ()>0.00>   >Follow - READY <READY> ()>0.00>   >Wander - READY <READY> ()>0.00    After:     >Priority - READY <READY> ()>0.00>   >ChaseAndAttack - READY <READY> ()>0.00>   >RunAway - READY <READY> ()>0.00>   >Follow - READY <READY> ()>0.00>   >Wander - READY <READY> ()>0.00

It's up to you what you want it to do.

Index 1 makes it so that the shadow creature will always run from 'scarydoctor' tagged players, even if the shadows are after the tagged player.

Index 2 makes it so that the shadow creature won't run away from tagged players.

Edited by CarlZalph
Link to comment
Share on other sites

Do note that if the player in question is insane the first behaviour to attack takes precedence and so the insane person will be attacked by their own shadow creatures.

 

Unless you replace 5, 8 for 20, 30.

Then watch shadows flee your monitor, and even when you go smack them, they will still try to run away.

Link to comment
Share on other sites

Nightmare creatures are the shadows of the caves/ruins. They don't even have an AddNetwork. Unless you are planning into bringing nightmare creatures to the shadow creature realm.

Ya know what, I was thinking that too, I did realize the shadow creatures and nightmare creatures had different names.  However I wasn't getting an error related to that I was getting it for trying to change the brain.  I would have fixed it after I noticed a difference.

 

Though when ruins get added in the future, I was going to add both of those creatures to this perk as well.

 

All I had to do was put Global.?  Well I knew I was close, didn't think I overlooked it that bad..

 

AddBrainPostInit("nightmarecreaturebrain",    function(self)        GLOBAL.table.insert(self.bt.root.children, 1, GLOBAL.RunAway(self.inst, "scarydoctor", 5, 8))    end)

Oh ho, so that puts the node at number 1 immediately? Saves me the effort then of pushing everything down.

 

Okay I'm revitalized, gonna go find my scalpel.

Edited by Zackreaver
Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
  • Create New...