Jump to content

Rabbit won't run away when carrot in inventory


Recommended Posts

You will need to overwrite/duplicate (ewww) the rabbit brain file (rabbitbrain.lua):

function RabbitBrain:OnStart()
......
RunAway(self.inst, "scarytoprey", AVOID_PLAYER_DIST, AVOID_PLAYER_STOP),
RunAway(self.inst, "scarytoprey", SEE_PLAYER_DIST, STOP_RUN_DIST, nil, true),
......
end

and I believe you will need to overwrite/duplicate "runaway.lua" (ewww) or add a custom action that checks the character type. 

 

 

Link to comment
Share on other sites

On ‎2‎/‎2‎/‎2018 at 5:51 PM, secXsQuared said:

You will need to overwrite/duplicate (ewww) the rabbit brain file (rabbitbrain.lua):

function RabbitBrain:OnStart()
......
RunAway(self.inst, "scarytoprey", AVOID_PLAYER_DIST, AVOID_PLAYER_STOP),
RunAway(self.inst, "scarytoprey", SEE_PLAYER_DIST, STOP_RUN_DIST, nil, true),
......
end

and I believe you will need to overwrite/duplicate "runaway.lua" (ewww) or add a custom action that checks the character type. 

 

 

that sounds really complicated. I'm afraid I can't do it by myself. I'm just an artist and don't really understand coding correctly :(

Link to comment
Share on other sites

8 hours ago, Ray025 said:

that sounds really complicated. I'm afraid I can't do it by myself. I'm just an artist and don't really understand coding correctly :(

Unfortunately, I don't have much time to help. I doubt most people here have time/are willing to write actual code for you. I do recommend that you look into it yourself. It's a mostly(?) enjoyable learning process until the game's APIs start to bite you. Plus, understanding the code helps you debug and update your mod in the future too. :)

Link to comment
Share on other sites

this may be able do similar to what you want, put it inside YOURCHAR.lua in the master_postinit

Spoiler

local x, y, z = inst.Transform:GetWorldPosition()
local rabbit = TheSim:FindEntities(x, y, z, 6, { "rabbit"})
inst:DoPeriodicTask(1, function()
	if rabbit and inst.components.inventory:Has("carrot", 1) then
		inst:RemoveTag("scarytoprey")
	else
		inst:AddTag("scarytoprey")
	end
end)

 

 

Link to comment
Share on other sites

34 minutes ago, SuperDavid said:

this may be able do similar to what you want, put it inside YOURCHAR.lua in the master_postinit

  Hide contents


local x, y, z = inst.Transform:GetWorldPosition()
local rabbit = TheSim:FindEntities(x, y, z, 6, { "rabbit"})
inst:DoPeriodicTask(1, function()
	if rabbit and inst.components.inventory:Has("carrot", 1) then
		inst:RemoveTag("scarytoprey")
	else
		inst:AddTag("scarytoprey")
	end
end)

 

 

1

Wouldn't that also make the rabbit not run away when other characters are around? Maybe change the period to 0.1 to make it smoother. Nice workaround though.

 

EDIT: 

oops my bad. I thought you removed the tag from rabbits. But then you won't scare others away? as in you have both a rabbit and a koalaphant within radius 6.

Edited by secXsQuared
Link to comment
Share on other sites

54 minutes ago, secXsQuared said:

Wouldn't that also make the rabbit not run away when other characters are around?

The rabbit will still run away from something which is scarytoprey even if you're standing close to it.

54 minutes ago, secXsQuared said:

Maybe change the period to 0.1 to make it smoother.

Well shorter periods may cause lag on weaker computers most likely, but if the op has a good pc then yes he could it to something faster than 1 second!

 

54 minutes ago, secXsQuared said:

But then you won't scare others away? as in you have both a rabbit and a koalaphant within radius 6.

Unfortunately, I do not know of any better ways to do this... & unless anyone else wants to make a code for rabbits to specifically not run away from a player with carrot in inventory (which will probably require editing rabbitbrain which brains are pretty complicated code) for the op then my help is closest to what he wants to achieve ;).

Edited by SuperDavid
Link to comment
Share on other sites

On ‎2‎/‎8‎/‎2018 at 8:48 AM, SuperDavid said:

this may be able do similar to what you want, put it inside YOURCHAR.lua in the master_postinit

  Hide contents


local x, y, z = inst.Transform:GetWorldPosition()
local rabbit = TheSim:FindEntities(x, y, z, 6, { "rabbit"})
inst:DoPeriodicTask(1, function()
	if rabbit and inst.components.inventory:Has("carrot", 1) then
		inst:RemoveTag("scarytoprey")
	else
		inst:AddTag("scarytoprey")
	end
end)

 

 

I've added it to my character's master_posit but it doesn't seem to do the trick

Link to comment
Share on other sites

1 minute ago, SuperDavid said:

I just tested it out and it works, are you sure you put it in YOURCHAR.lua inside master_postinit?

sorry my bad :p it works perfectly fine. I put it in to a wrong character, no wonder it didn't do anything. Thanks you so much!

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