Jump to content

Help getting follower to change brain on event?


Recommended Posts

Hello, I need the help of the coding masters here on Klei Forums!!! So you see, I have made a Mossling follower and want to make it swap it's brain when a certain event happens, I tried putting this in the mossling prefab file but it didn't work :(... 

inst:ListenForEvent("wonteatfood", function(inst, data)
local brain = require "brains/mosslingbrainAdamTamedIdiot"
end)
	
inst:ListenForEvent("makefriend", function(inst, data)
local brain = require "brains/mosslingbrainAdamTamed"
end)

My goal was to make a sort of waiting system for my AI followers where in their Idiot brains there's nothing but a Stand Still Behavior which would activate upon the event "wonteatfood" <-- I'm assuming that means they reject a food they can't eat? And if you give them a correct food to eat they revert back to the follower brain, now the idea seemed like it would work 100% to me but it didn't work not even a crash... So I had no other choice but to ask for help on the Klei Forums again :(, I hope somebody can help me figure this out :) & thanks for taking the time to read this :D!

Link to comment
Share on other sites

31 minutes ago, SuperDavid said:

Hello, I need the help of the coding masters here on Klei Forums!!! So you see, I have made a Mossling follower and want to make it swap it's brain when a certain event happens, I tried putting this in the mossling prefab file but it didn't work :(... 


inst:ListenForEvent("wonteatfood", function(inst, data)
local brain = require "brains/mosslingbrainAdamTamedIdiot"
end)
	
inst:ListenForEvent("makefriend", function(inst, data)
local brain = require "brains/mosslingbrainAdamTamed"
end)

My goal was to make a sort of waiting system for my AI followers where in their Idiot brains there's nothing but a Stand Still Behavior which would activate upon the event "wonteatfood" <-- I'm assuming that means they reject a food they can't eat? And if you give them a correct food to eat they revert back to the follower brain, now the idea seemed like it would work 100% to me but it didn't work not even a crash... So I had no other choice but to ask for help on the Klei Forums again :(, I hope somebody can help me figure this out :) & thanks for taking the time to read this :D!

if your goal is to make the mob not move, can you can do inst.brain:Stop() and maybe add a listener so when it gets atked, it activates it back (inst.brain:Start())

the Stop() function makes it literally stop using its brain, which I believe means it wont react to people hitting it and such, which is why you would add a listener so when it gets attacked, it gets its brain back

Edited by Aquaterion
Link to comment
Share on other sites

Thanks Aquaterion  it works :D but do you think you can help me again :?? So, I want my followers to inst.brain:Start() when they're befriended and if you befriend them again they go inst.brain:Stop() (so every time they eat a piece of food they'll swap between inst.brain:Start() & inst.brain:Stop()) but is it even possible to have 2 of the same event doing different things? Like this

inst:ListenForEvent("makefriend", function(inst, data)
inst.brain:Stop()
end)
inst:ListenForEvent("makefriend", function(inst, data)
inst.brain:Start()
end)

Also, would you know how I can set a limit on how many mossling followers you can have, like 5? It's okay if you don't know the answer to this questions but please help with the brain stopping and starting :)!

 

PS. Is there a file in the Don't Starve Together Scripts that contains all events? It make it so much easier & thanks for reading :D!

Link to comment
Share on other sites

13 minutes ago, SuperDavid said:

Thanks Aquaterion  it works :D but do you think you can help me again :?? So, I want my followers to inst.brain:Start() when they're befriended and if you befriend them again they go inst.brain:Stop() (so every time they eat a piece of food they'll swap between inst.brain:Start() & inst.brain:Stop()) but is it even possible to have 2 of the same event doing different things? Like this

Also, would you know how I can set a limit on how many mossling followers you can have, like 5? It's okay if you don't know the answer to this questions but please help with the brain stopping and starting :)!

 

PS. Is there a file in the Don't Starve Together Scripts that contains all events? It make it so much easier & thanks for reading :D!

 

inst:ListenForEvent("makefriend", function(inst, data)
  if inst.brain.stopped then
      inst.brain:Start()
  else
	  inst.brain:Stop()
  end
end)

 

not sure if there is a simple cap system for followers but the character can count how many followers with tag it has;

inst.components.leader:CountFollowers("mossling")

you could probably use some "if"s to deny more followers if the count is more than a certain limit

 

Link to comment
Share on other sites

Would I do something like this in modmain, character prefab or follower prefab? 

if inst.components.leader:CountFollowers("mossling, 5") then return
local function RefuseItem(inst, item)
    inst.sg:GoToState("taunt")
    if inst.components.sleeper:IsAsleep() then
    inst.components.sleeper:WakeUp()
    end

AHHH!!! I have no idea where to put it or how the code should even be, ...please help, Aquaterion :), please! I'm sorry I ask your help after you being so kind but I need it!

Link to comment
Share on other sites

2 hours ago, SuperDavid said:

PS. Is there a file in the Don't Starve Together Scripts that contains all events? It make it so much easier & thanks for reading :D!

There is no such file. Searching for PushEvent in all files yielded this list for me:

Spoiler

actionfailed
activateresurrection
addfuel
armorbroke
armordamaged
attacked
attackedbygrue
attackstart
attuned
attunedresurrector
attunementlost
awayfromgame
axepossessedbyplayer
axerejectedotheraxe
axerejectedowner
beargerkilled
beargerremoved
beavernessdelta
beginregrowth
beingridden
blocked
brushed
bucked
builditem
buildstructure
buildsuccess
burnt
burntup
cancelcatch
cancelmovementprediction
cantbuild
catch
caught
ccoverrides
ccphasefn
clocksegschanged
clocktick
closecontainer
colourtweener_end
colourtweener_start
cometo
consumehealthcost
consumeingredients
containergotitem
continuefrompause
coveredinbees
creepactivate
cycleschanged
damaged
death
deciduousleaffx
deployitem
despawnedfromhaunt
detachchild
dismount
doattack
dolure
domesticated
domesticationdelta
donetalking
doneteleporting
dropitem
droppedtarget
eat
emerge
emote
enabledynamicmusic
endquake
entercharacterselect
enterlimbo
entermood
entershield
entity_death
equip
equipped
equipskinneditem
exitlimbo
exitshield
explosion
finishedwork
firedamage
firemelt
fishingcancel
fishingcatch
fishingcollect
fishingloserod
fishingnibble
fishingstrain
fly_back
flyaway
forgetinventoryitem
freeze
freshspawn
fueltaken
full_retreat
ghostdissipated
ghostvision
giftreceiverupdate
givetarget
giveuptarget
gohome
goinghome
goinsane
goneferal
gosane
gotnewattunement
gotnewitem
gotosleep
growfrombutterfly
harvestsomething
harvesttrap
hasslerkilled
hasslerremoved
haunt
healthdelta
heardhorn
heargrue
hidebait
hidevotedialog
hideworldreset
hostileprojectile
hungerdelta
huntbeastnearby
huntlosttrail
changearea
childgoinghome
ifnotchanceloot
imagechange
inducedinsanity
inventoryclosed
inventoryfull
invincibletoggle
itemget
itemlose
itemranout
killed
knockedout
learnrecipe
leavemood
lightningdamageavoided
lightningstrike
locomote
loseloyalty
losttarget
makefriend
makeplayerghost
makerecipe
master_autosaverupdate
master_clockupdate
master_seasonsupdate
master_worldresetupdate
MaxwellThreat
migration_activate
migration_activate_other
migration_available
migration_full
migration_unavailable
minhealth
minimapAFK
minionchange
moistureceilchanged
moisturedelta
monkeydanger
moonphasechanged
morph
mount
mounthurt
mountwounded
mouseout
mouseover
ms_addgiftreceiver
ms_advanceseason
ms_becameghost
ms_closepopups
ms_closewardrobe
ms_cyclecomplete
ms_deltamoisture
ms_deltawetness
ms_doneopengift
ms_enableresourcerenewal
ms_forceprecipitation
ms_forcequake
ms_giftopened
ms_miniquake
ms_newmastersessionid
ms_newplayercharacterspawned
ms_nextnightmarephase
ms_nextphase
ms_opengift
ms_overcharge
ms_playercounts
ms_playerdespawn
ms_playerdespawnanddelete
ms_playerdespawnandmigrate
ms_playerdisconnected
ms_playerjoined
ms_playerleft
ms_playerspawn
ms_quakefrequencymultiplier
ms_registermigrationportal
ms_registerspawnpoint
ms_removegiftreceiver
ms_respawnedfromghost
ms_retreatseason
ms_save
ms_sendlightningstrike
ms_setautosaveenabled
ms_setclocksegs
ms_setfrograinchance
ms_setfrograinlocalfrogs
ms_setlightningdelay
ms_setlightningmode
ms_setmoisturescale
ms_setphase
ms_setprecipitationmode
ms_setseason
ms_setseasonlength
ms_setseasonsegmodifier
ms_setsnowlevel
ms_setspawnmode
ms_setwildfirechance
ms_setworldresettime
ms_skeletonspawn
ms_worldreset
newactiveitem
newcombattarget
newstate
nightmareclocktick
nightmarephasechanged
nightmarevision
nightstickranout
nightvision
notfree
obediencedelta
onareaattackother
onattackother
onbuilt
onburnt
onclose
ondropped
oneat
oneaten
onextinguish
onhitother
onignite
onmissother
onopen
onpickup
onpickupitem
onputininventory
onreachdestination
onreflectdamage
onremove
onstolen
ontalk
onthaw
onthrown
ontrapped
onunpin
onwakeup
onwenthome
opencontainer
overrideambientsound
overridecolourcube
overridecolourmodifier
panic
peek
percentusedchange
performaction
perished
perishchange
phasechange
phasechanged
picked
picksomething
pinned
playeractivated
playerdeactivated
playerdied
playerentered
playerexited
popdsp
possessedaxe
powerdown
powerup
precipitationchanged
pushdsp
putoutfire
quit
rampingspawner_death
rampingspawner_spawn
ready
refresh
refreshcrafting
refreshinventory
refuseitem
repair
respawnfromghost
retract
returntogame
rez_player
riderchanged
saddle
saddlechanged
safetospawn
sanitydelta
screenflash
seasonlengthschanged
seasontick
setambientsounddaytime
setoverflow
SetUpSpringSmallBird
shaved
sheltered
showvotedialog
showworldreset
sizetweener_end
sizetweener_start
slave_autosaverupdate
slave_clockupdate
slave_seasonsupdate
slave_worldresetupdate
snowcoveredchanged
spawnedfromhaunt
spentfuel
springtrap
stackitemdirty
stacksizechange
stacksizepreview
startaction
startaura
startbeaver
startfiredamage
startfollowing
startfreezing
startlongaction
startoverheating
startquake
startstarving
starttravelsound
stopaura
stopbeaver
stopfiredamage
stopfiremelt
stopfollowing
stopfreezing
stopoverheating
stopstarving
storehassler
stun_finished
stunned
suggest_tree_target
summonsdelta
sway
talkedto
techlevelchange
techtreechange
temperaturedelta
temperaturetick
thorns
threatnear
timerdone
toolbroke
torchranout
trade
transform
transform_person
transform_werebeaver
transformnormal
transformwere
trapped
turnedoff
turnedon
twitchloginresult
twitchmessage
twitchstatusupdate
umbrellaranout
unequip
unequipped
unequipskinneditem
unfreeze
unlockrecipe
unpinned
usedtouchstone
usereviver
vote_screen_closed
warninglevelchanged
warnquake
weathertick
wetchanged
wetnesschange
windchange
wonteatfood
worked
workfinished
working
worldresettick
wormholetravel
yawn

To make use of any of them, you still need to find exact place(s), so you know when it's pushed and what possible additional data it can provide.

If you search for ListenForEvent("{eventname}", you could find where it's already used, to use it as an example.

Link to comment
Share on other sites

1 hour ago, SuperDavid said:

Would I do something like this in modmain, character prefab or follower prefab? 


if inst.components.leader:CountFollowers("mossling, 5") then return
local function RefuseItem(inst, item)
    inst.sg:GoToState("taunt")
    if inst.components.sleeper:IsAsleep() then
    inst.components.sleeper:WakeUp()
    end

AHHH!!! I have no idea where to put it or how the code should even be, ...please help, Aquaterion :), please! I'm sorry I ask your help after you being so kind but I need it!

yea the code should be in the character, in the place where mosslings are made.

also this is how you use countfollowers:

if inst.components.leader:CountFollowers("mossling") > 5 then 
	return--if 5 were found, stop here, so summon code isnt called
end

--normal summon code

 

Link to comment
Share on other sites

I'm so sorry to bug you again Aquaterion but I put this code into my character prefab like you said but nothing happens :(...

if inst.components.leader:CountFollowers("mossling") > 5 then 
return inst:RemoveTag("mosslingwhisperer")
end

I also tried putting it into my Mossling.lua prefab like this 

if inst.components.leader:CountFollowers("mossling") > 5 then 
return inst:RemoveComponent("trader")
end

But it just crashes the game saying "attempt to index field 'leader' (a nil value)" i'm sorry Aquaterion but I need your help again :), please!!!!!

 

And thanks Muche for the events, it makes my life so much easier knowing all the events now :)!

Link to comment
Share on other sites

Aqua, I keep trying to work with that inst.components.leader:CountFollowers you gave me, I did this with it in my character prefab 

if inst.components.leader:CountFollowers("mossling") > 5 then 
    return inst.components.locomotor.runspeed = 8.25 * TUNING.WILSON_RUN_SPEED
	else
	return inst.components.locomotor.runspeed = 1 * TUNING.WILSON_RUN_SPEED
	end
  --the top code crashes no matter what unless I remove return like the one on the bottom

if inst.components.leader:CountFollowers("mossling") > 5 then 
    inst.components.locomotor.runspeed = 8.25 * TUNING.WILSON_RUN_SPEED --doesn't work
	else
	inst.components.locomotor.runspeed = 1 * TUNING.WILSON_RUN_SPEED --only this works
	end
--when I remove the returns it doesn't crash anymore but only the bottom works if I put > or the top only works if I put <

no matter what I do it keeps crashing now and says "'end' expected (to close 'if' at line 432) near '=' I beg you please tell me what i;m doing wrong! I've been trying everything for 2 hours, i'm starting to go insane :shock:!!

Link to comment
Share on other sites

4 hours ago, SuperDavid said:

Aqua, I keep trying to work with that inst.components.leader:CountFollowers you gave me, I did this with it in my character prefab 


if inst.components.leader:CountFollowers("mossling") > 5 then 
    return inst.components.locomotor.runspeed = 8.25 * TUNING.WILSON_RUN_SPEED
	else
	return inst.components.locomotor.runspeed = 1 * TUNING.WILSON_RUN_SPEED
	end
  --the top code crashes no matter what unless I remove return like the one on the bottom

if inst.components.leader:CountFollowers("mossling") > 5 then 
    inst.components.locomotor.runspeed = 8.25 * TUNING.WILSON_RUN_SPEED --doesn't work
	else
	inst.components.locomotor.runspeed = 1 * TUNING.WILSON_RUN_SPEED --only this works
	end
--when I remove the returns it doesn't crash anymore but only the bottom works if I put > or the top only works if I put <

no matter what I do it keeps crashing now and says "'end' expected (to close 'if' at line 432) near '=' I beg you please tell me what i;m doing wrong! I've been trying everything for 2 hours, i'm starting to go insane :shock:!!

ye ur using "return" wrong. as for the 2nd 1, that's because you're only calling that code on load, you have to call it when you summon/get a pet, I already told you this

Link to comment
Share on other sites

Aquaterion i'd like to ask a question from you, I want make my followers be able to wait in place after I give them food so you gave me code for that 

inst:ListenForEvent("makefriend", function(inst, data)
  if inst.brain.stopped then
      inst.brain:Start()
  else
	  inst.brain:Stop()
  end
end)

but I then realized that the followers even though their brain stops they will teleport to you if you go really far away which I don't want that so I tried doing this 

inst:ListenForEvent("trade", function(inst, data)
            if inst.brain.stopped then
            inst.brain:Start()
			inst:AddComponent("follower")
            else
	        inst.brain:Stop()
			inst:RemoveComponent("follower")
            end
            end)
            end

I tried removing there follower component when their brain stops then they stop teleporting but it seems when I remove the follower component they can't get it back :(. Do you know any other way I can make them stand in place or remove the follower component and make them regain it back somehow :)? I would really appreciate your guidance of course if you don't know what I could do that's fine too :D! Also, I got the follower cap to work thanks to you, really thanks so much :D!!!

Edited by SuperDavid
Link to comment
Share on other sites

Looking into follower component, it seems the teleporting is done in OnEntitySleep function, which gets assigned to entitysleep event in StartLeashing.

Try inst.components.follower:StopLeashing() when you want it to stop teleporting and inst.components.follower:StartLeashing() when you want it to start teleporting again.

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...