Jump to content

Could you do this?


Rosten

Recommended Posts

I dont know the specifics but thats what the brain does. Its a graph of 'needs' that each creature processes in order. If a need isnt met it does that action. If its met it check the next Need in the list.  Pigs for example have a 'run around like headles chicken when on fire' need that is really high priority. It is a higher priority than the 'chase nearby spider' need.  This means if a pig is on fire it will be worried about itself and less about nearby enemies which is a logical reaction.

 

Basically if you insert the  'desire to follow player' at a higher priority than the 'desire to follow mother' then the player is the one who will be followed.

2 questions, 1 so that means, by default the baby will follow the mother, but if i come on by and use the item, then it'll follow me instead of her, and then whenever it wears off, if we're close enough to another beefalo it will try and wander back to it?

2. How does the whole priority work? is it an actual numerical value you assign to certain actions, or is it just whatevers placed higher up in the code is what has higher priority?

Link to comment
Share on other sites

The thing about modding that makes it a bit more difficult then creating most other forms of media is because all you're doing is building off of something someone else made, you don't know how the game works, because the way its coded is unique to that game, so there can never be a universal guide for modding because each game has different functions, components, prefabs etc. that you can use.

I probably have no idea what im talking about, but if i do then well, go me i guess xD
0
Link to comment
Share on other sites

Ill try and keep that in mind when im selecting the candidates for followers,

 

Also, i think i remember seeing one mod where you could have a hound friend, but whenever a pack of hounds came it would become hostile towards you again and when you killed off the rest of the pack it would become friendly again, i forgot what it was, might have been Wulfe, That sounds pretty similar to what im talking about

 

That'd be the hound in my summons mod.

Link to comment
Share on other sites

2 questions, 1 so that means, by default the baby will follow the mother, but if i come on by and use the item, then it'll follow me instead of her, and then whenever it wears off, if we're close enough to another beefalo it will try and wander back to it?

2. How does the whole priority work? is it an actual numerical value you assign to certain actions, or is it just whatevers placed higher up in the code is what has higher priority?

Just open up one of the brain files and you'll see.  Higher up has priority.

Link to comment
Share on other sites

  • Developer

Hmm, lets pick a few out of there that seem promising

Abigail

Knight 

Bishop ( I imagine that these two are from the damaged clockworks when you repair them?)

Spider/Cavespider

Hound (Didn't know they had a follower component)

----------------------------------------------------------------------------------

That seems like a pretty good list of candidates

I made an example mod which makes all creatures in the game follow you :).  To be fair you'd probably have to do some hand tuning for certain creatures as all their brains are different.  But you could change it to only make creatures that have a follower component start following you or choose different spots in their brains to add the follow logic.  

 

http://forums.kleientertainment.com/index.php?/files/file/377-script-example-follow-the-leader/

Link to comment
Share on other sites

I made an example mod which makes all creatures in the game follow you :-).  To be fair you'd probably have to do some hand tuning for certain creatures as all their brains are different.  But you could change it to only make creatures that have a follower component start following you or choose different spots in their brains to add the follow logic.  

 

http://forums.kleientertainment.com/index.php?/files/file/377-script-example-follow-the-leader/

This is hilarious to actually play with, the bunnies cant decide whether they want to follow, or runaway from me xD

Also, i'd like to thank you for commenting out what was happen

Link to comment
Share on other sites

So im looking at this, and it seems this:

for k,v in pairs(entities) do

if IsValidFollower(v) then
 
-- Insert a new behaviour into the brain
local behaviours = v.brain.bt.root.children
table.insert(behaviours, math.min(3, #behaviours), GLOBAL.Follow(v, GetLeader, MIN_FOLLOW_LEADER, TARGET_FOLLOW_LEADER, MAX_FOLLOW_LEADER, true))
 
-- Add follower component if it doesn't already have one.
if not v.components.follower then
v:AddComponent("follower")
end
 
-- Tell entity to stop combat just in case it was trying to fight us.
if v.components.combat then
v.components.combat:GiveUp()
end
 
-- Tell the entity to follow us.
if v.components.follower.leader ~= player then
player.components.leader:AddFollower(v)
end
 
-- Tag this entity so we don't try and convert it again.
v:AddTag(FOLLOW_THE_LEADER_TAG)
end
end

end

Seems to be the portion in which the entity is converted into a follower, what im a bit confused about in this is how the game determines what the leader is, putting that aside, if i found a way to make this apply to the things that are hit, it would make it follow me until death? or am i looking at this wrong.

 

Link to comment
Share on other sites

So im looking at this, and it seems this:

for k,v in pairs(entities) do

if IsValidFollower(v) then
 
-- Insert a new behaviour into the brain
local behaviours = v.brain.bt.root.children
table.insert(behaviours, math.min(3, #behaviours), GLOBAL.Follow(v, GetLeader, MIN_FOLLOW_LEADER, TARGET_FOLLOW_LEADER, MAX_FOLLOW_LEADER, true))
 
-- Add follower component if it doesn't already have one.
if not v.components.follower then
v:AddComponent("follower")
end
 
-- Tell entity to stop combat just in case it was trying to fight us.
if v.components.combat then
v.components.combat:GiveUp()
end
 
-- Tell the entity to follow us.
if v.components.follower.leader ~= player then
player.components.leader:AddFollower(v)
end
 
-- Tag this entity so we don't try and convert it again.
v:AddTag(FOLLOW_THE_LEADER_TAG)
end
end

end

Seems to be the portion in which the entity is converted into a follower, what im a bit confused about in this is how the game determines what the leader is, putting that aside, if i found a way to make this apply to the things that are hit, it would make it follow me until death? or am i looking at this wrong.

 

Link to comment
Share on other sites

  • Developer

So im looking at this, and it seems this:

for k,v in pairs(entities) do

if IsValidFollower(v) then
 
-- Insert a new behaviour into the brain
local behaviours = v.brain.bt.root.children
table.insert(behaviours, math.min(3, #behaviours), GLOBAL.Follow(v, GetLeader, MIN_FOLLOW_LEADER, TARGET_FOLLOW_LEADER, MAX_FOLLOW_LEADER, true))
 
-- Add follower component if it doesn't already have one.
if not v.components.follower then
v:AddComponent("follower")
end
 
-- Tell entity to stop combat just in case it was trying to fight us.
if v.components.combat then
v.components.combat:GiveUp()
end
 
-- Tell the entity to follow us.
if v.components.follower.leader ~= player then
player.components.leader:AddFollower(v)
end
 
-- Tag this entity so we don't try and convert it again.
v:AddTag(FOLLOW_THE_LEADER_TAG)
end
end

end

Seems to be the portion in which the entity is converted into a follower, what im a bit confused about in this is how the game determines what the leader is, putting that aside, if i found a way to make this apply to the things that are hit, it would make it follow me until death? or am i looking at this wrong.

A lot of the other stuff is just setup.  This line tells the player to add a follower.

player.components.leader:AddFollower(v)
Link to comment
Share on other sites

  • Developer

So im looking at this, and it seems this:

for k,v in pairs(entities) do

if IsValidFollower(v) then
 
-- Insert a new behaviour into the brain
local behaviours = v.brain.bt.root.children
table.insert(behaviours, math.min(3, #behaviours), GLOBAL.Follow(v, GetLeader, MIN_FOLLOW_LEADER, TARGET_FOLLOW_LEADER, MAX_FOLLOW_LEADER, true))
 
-- Add follower component if it doesn't already have one.
if not v.components.follower then
v:AddComponent("follower")
end
 
-- Tell entity to stop combat just in case it was trying to fight us.
if v.components.combat then
v.components.combat:GiveUp()
end
 
-- Tell the entity to follow us.
if v.components.follower.leader ~= player then
player.components.leader:AddFollower(v)
end
 
-- Tag this entity so we don't try and convert it again.
v:AddTag(FOLLOW_THE_LEADER_TAG)
end
end

end

Seems to be the portion in which the entity is converted into a follower, what im a bit confused about in this is how the game determines what the leader is, putting that aside, if i found a way to make this apply to the things that are hit, it would make it follow me until death? or am i looking at this wrong.

And yes, right now they would follow you until death or till you ran out of range or their brains found something more interesting to do :). You should be able to make them stop following you by setting their leader to nil.

Link to comment
Share on other sites

 

A lot of the other stuff is just setup.  This line tells the player to add a follower.

player.components.leader:AddFollower(v)

Alright, so, this seems like the essential things that change it to a follower

-- Tell entity to stop combat just in case it was trying to fight us.
if v.components.combat then
v.components.combat:GiveUp()
end
 
-- Tell the entity to follow us.
if v.components.follower.leader ~= player then
player.components.leader:AddFollower(v)
 
And if you were to remove the
-- Insert a new behaviour into the brain
local behaviours = v.brain.bt.root.children
table.insert(behaviours, math.min(3, #behaviours), GLOBAL.Follow(v, GetLeader, MIN_FOLLOW_LEADER, TARGET_FOLLOW_LEADER, MAX_FOLLOW_LEADER, true))
 
-- Add follower component if it doesn't already have one.
if not v.components.follower then
v:AddComponent("follower")
end

It would only work on things that already have the follower component? or would it cause a crash

Edit - tested it, caused a crash, anyway to make it only work on things with a follower component, or only make it work on certain animals with certain tags, e.g nothing will follow you unless they have that tag

Link to comment
Share on other sites

  • Developer

Alright, so, this seems like the essential things that change it to a follower

-- Tell entity to stop combat just in case it was trying to fight us.
if v.components.combat then
v.components.combat:GiveUp()
end
 
-- Tell the entity to follow us.
if v.components.follower.leader ~= player then
player.components.leader:AddFollower(v)
 
And if you were to remove the
-- Insert a new behaviour into the brain
local behaviours = v.brain.bt.root.children
table.insert(behaviours, math.min(3, #behaviours), GLOBAL.Follow(v, GetLeader, MIN_FOLLOW_LEADER, TARGET_FOLLOW_LEADER, MAX_FOLLOW_LEADER, true))
 
-- Add follower component if it doesn't already have one.
if not v.components.follower then
v:AddComponent("follower")
end

It would only work on things that already have the follower component? or would it cause a crash

Edit - tested it, caused a crash, anyway to make it only work on things with a follower component, or only make it work on certain animals with certain tags, e.g nothing will follow you unless they have that tag

If you remove what you're suggesting you just need to add a check in the 'IsValidFollower' part to make sure there's already a follow component.  I didn't check for that later because I knew I was going to add the component if it was missing.

Link to comment
Share on other sites

If you remove what you're suggesting you just need to add a check in the 'IsValidFollower' part to make sure there's already a follow component.  I didn't check for that later because I knew I was going to add the component if it was missing.

So in english, what your trying to do is, If this prefab has the follower component then follow through with the script, if not then do nothing?

 

On a side note- i just read the part about "we don't want any trees following us"

I've half a mind to see what happens if i do remove that... xD

Link to comment
Share on other sites

Well, i looked at the code from the horn and added a little bit to the part so it says this: 

 
local function IsValidFollower(entity)
    if leader.components.leader
    and follower.components.follower
then return entity.components and entity.components.locomotor and entity.brain and entity.brain.bt and entity.brain.bt.root and entity ~= GLOBAL.GetPlayer()
end
 
But then i get a error saying "modmain,lua:65: 'end' expected (to close 'function' at line 12) near '<eof>'
 
I figured this 
    if leader.components.leader
    and follower.components.follower
checked to see whether or not the prefab had the follower component
Link to comment
Share on other sites

  • Developer

Try this:

local function IsValidFollower(entity)    return entity.components and entity.components.locomotor and entity.brain and entity.brain.bt and entity.brain.bt.root and entity ~= GLOBAL.GetPlayer() and entity.components.followerend
Link to comment
Share on other sites

 

Try this:

local function IsValidFollower(entity)    return entity.components and entity.components.locomotor and entity.brain and entity.brain.bt and entity.brain.bt.root and entity ~= GLOBAL.GetPlayer() and entity.components.followerend

Oh, so those components listed after return are the components it checks for to determine whether its a valid follower or not?

Edit- Sweet it works perfectly

Link to comment
Share on other sites

So, to determine which ones would be affected by the staff i could create a component that does nothing, and attach it to what entities i want the staff to work with and make that component a requirement for it to be a valid follower?

 

Right now im trying to do this - 

Make a component that does nothing (named followertag.lua)

Add that component to a creature e.g beefalo

Make that component a requirement for the isValidFollower check, making whatever i give followertag.lua able to follow me.

Link to comment
Share on other sites

  • Developer

So, to determine which ones would be affected by the staff i could create a component that does nothing, and attach it to what entities i want the staff to work with and make that component a requirement for it to be a valid follower?

 

Right now im trying to do this - 

Make a component that does nothing (named followertag.lua)

Add that component to a creature e.g beefalo

Make that component a requirement for the isValidFollower check, making whatever i give followertag.lua able to follow me.

That would work but there's a simpler and more efficient way which is the tags.  You can just use these functions to do the same thing:

 

entity:AddTag("my_tag")entity:HasTag("my_tag")entity:RemoveTag("my_tag")
Link to comment
Share on other sites

 

That would work but there's a simpler and more efficient way which is the tags.  You can just use these functions to do the same thing:

entity:AddTag("my_tag")entity:HasTag("my_tag")entity:RemoveTag("my_tag")

So entity:AddTag ("my_tag") makes a tag

     entity:HasTag("my_tag" checks for said tag

     entity:RemoveTag("my_tag")

I must ask, is there any particular reason for using this instead of the way i mentioned? or is it just a matter of preference

Link to comment
Share on other sites

Here is the version of follow_the_leader that makes use of the method i suggested earlier to make it where anything with the follower and followertag component will follow you, and nothing else Follow_The_Leader(Mediafire) I Guess the next step would be to make something that shoots a projectile, then have said projectile run that script for the entity it hits

Link to comment
Share on other sites

  • Developer

So entity:AddTag ("my_tag") makes a tag

     entity:HasTag("my_tag" checks for said tag

     entity:RemoveTag("my_tag")

I must ask, is there any particular reason for using this instead of the way i mentioned? or is it just a matter of preference

You don't have to create a new file and adding and checking tags is much more efficient than adding components.  Both should work though.

Link to comment
Share on other sites

You don't have to create a new file and adding and checking tags is much more efficient than adding components.  Both should work though.

Alright, well ill just keep using the method, and if i notice any fatal flaws (e.g terrible game slowdown and stuff like that) ill switch over to the tag system, but this should work for now, now i have to find a way to make the staff/wand/whatever and make it shoot a projectile, and then that projectile would run the script in the modmain.lua of follow_the_leader

Link to comment
Share on other sites

Tags are better in the way that you don't need to have a seperate file for them. Think of tags as post-its you stick on your prefabs whereas components are more like little books with instructions on how the prefab works and what you can do with it. In your case its enough to just stick that post-it on ther which says "I am special"

Link to comment
Share on other sites

Alright, so now here's everything i've compiled together into a modfile (the modified script from follow_the_leader is in the scripts folder named makefollower.lua) Friendship Wand(MediafireRight now, i need to find a way to make the wand fire a projectile, and make it so whatever gets hit by that projectile gets turned into a follower via makefollower.lua

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

Please be aware that the content of this thread may be outdated and no longer applicable.

×
  • Create New...