This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
behaviortree [2016/12/01 15:41] – fxfire | behaviortree [2022/07/18 09:27] (current) – fxfire | ||
---|---|---|---|
Line 1: | Line 1: | ||
=====Behavior Tree Framwork===== | =====Behavior Tree Framwork===== | ||
- | Behavior Trees are a wonderful thing when it comes to writing any kind of AI logic. It is currently in its "first working version" | + | Behavior Trees are a wonderful thing when it comes to writing any kind of AI logic. It is currently in its "first working version" |
- | GW2Minion is completely written with this framework. | + | |
+ | **FFXIVMinion** is not making use of this, but it *could* be used as well. Instead, it uses the ' | ||
**BT Basics, How they work:** [[http:// | **BT Basics, How they work:** [[http:// | ||
Line 41: | Line 42: | ||
-- Load all our local " | -- Load all our local " | ||
- | BehaviorManager: | + | BehaviorManager: |
end | end | ||
Line 69: | Line 70: | ||
{{youtube> | {{youtube> | ||
+ | EDIT: Above the lines where you add the Checkbox, you need to make sure the used variable is NOT nil, so put this above: | ||
+ | <code lua> | ||
+ | if (not Settings.sillyjumper.jump ) then Settings.sillyjumper.jump = false end | ||
+ | </ | ||
\\ | \\ | ||
Line 112: | Line 116: | ||
Reload = function() sillyjumper.LoadBehaviorFiles() end, | Reload = function() sillyjumper.LoadBehaviorFiles() end, | ||
-- if set, it will be treated as a private addon, loadable from the addon store | -- if set, it will be treated as a private addon, loadable from the addon store | ||
- | private = true, | + | private = false, |
} | } | ||
Line 201: | Line 205: | ||
Reload = function() sillyjumper.LoadBehaviorFiles() end, | Reload = function() sillyjumper.LoadBehaviorFiles() end, | ||
-- if set, it will be treated as a private addon, loadable from the addon store | -- if set, it will be treated as a private addon, loadable from the addon store | ||
- | private = true, | + | private = false, |
| | ||
-- (optional) Callback function, is called by the BTree Framework when the BTree is started. Allows us to supply a custom " | -- (optional) Callback function, is called by the BTree Framework when the BTree is started. Allows us to supply a custom " | ||
LoadContext = function() return sillyjumper.GetContext() end, | LoadContext = function() return sillyjumper.GetContext() end, | ||
+ | |||
+ | -- (optional) Function to draw the menu elements that always appears on the "Main menu" interface. | ||
+ | DrawMenuCode = function(btree) end, | ||
+ | |||
+ | -- (optional) Function to draw the menu elements that appears on the "Main menu" interface when the btree is selected. | ||
+ | -- This locks the edit field inside the btree editor. | ||
+ | DrawMainMenuCode = function(btree) end, | ||
+ | | ||
+ | -- (optional) Function to draw the menu elements that appears on the subtree node. This is also used for drawing custom properties in the taskmanager. | ||
+ | -- This locks the edit field inside the btree editor. | ||
+ | DrawSubMenuCode = function(btree) end | ||
} | } | ||
</ | </ | ||
Line 226: | Line 241: | ||
</ | </ | ||
- | - | + | * And now you can access this function in any node in your BTree with // |
+ | {{:: | ||
\\ | \\ | ||
- | \\ | ||
- | \\ | ||
- | Dont mind the stuff below...just things I dont want to forget when finising this tutorial ;) | ||
- | ======== | ||
- | Please be aware that this GUI | ||
- | -- The "variables" | + | === 8. Creating Private SubTrees === |
- | -- The "settings" | + | In order to create and use a private subtree, you will need to extend the loading code again by a new function: |
+ | <code lua> | ||
+ | function sillyjumper.LoadBehaviorFiles() | ||
+ | |||
+ | -- The BehaviorTree Framework requires specific information in order to use an "external | ||
+ | local btreeinfo = { | ||
+ | -- Our Main Behaviortree filename: | ||
+ | filename = "sillyjumper.bt", | ||
+ | -- Our Foldername and a mandatory subfolder where our "sillyjumper.bt" | ||
+ | filepath = GetLuaModsPath() | ||
+ | -- Callback function, when the BTree was changed and saved in the BT-Editor. Reload all addon bt files here, including private subtrees. | ||
+ | Reload = function() sillyjumper.LoadBehaviorFiles() end, | ||
+ | -- if set, it will be treated as a private addon, loadable from the addon store | ||
+ | private = false, | ||
+ | -- (optional) Callback function, is called by the BTree Framework when the BTree is started. Allows us to supply a custom " | ||
+ | LoadContext = function() return sillyjumper.GetContext() end, | ||
+ | |||
+ | -- Required for private addons with additional private sub-behavior trees | ||
+ | LoadSubTree = function(filename) return sillyjumper.LoadSubtreeData(filename) end, | ||
+ | } | ||
+ | </ | ||
+ | * And then define this new Callback function (in my case, sillyjumper.LoadSubtreeData(filename)). This will load the requested file from your private addon folder. | ||
- | + | <code lua> | |
- | --- | + | -- Required for private addons with additional private sub-behavior trees |
- | common errors | + | function sillyjumper.LoadSubtreeData(filename) |
- | if ( Player.alive ) then | + | if ( FileExists(GetLuaModsPath() |
- | | + | return FileLoad(GetLuaModsPath() |
- | | + | |
+ | else | ||
+ | |||
+ | local files = sillyjumper.modulefunctions.GetModuleFiles() | ||
+ | if(table.valid(files)) then | ||
+ | for _, | ||
+ | if( btreeinfo.filename == filedata.f) then | ||
+ | local fileString = sillyjumper.modulefunctions.ReadModuleFile(filedata) | ||
+ | if(fileString) then | ||
+ | local fileFunction, | ||
+ | if (fileFunction) then | ||
+ | return fileFunction() | ||
+ | end | ||
+ | end | ||
+ | break | ||
+ | end | ||
+ | end | ||
+ | end | ||
+ | end | ||
end | end | ||
- | self:fail() | + | </ |
- | must be : | + | * You should now be all setup for creating and loading private SubTrees and building your own Addon. |
- | if ( Player.alive ) then | + | |
- | Inventory: | + | |
- | self: | + | |
- | else | + | |
- | self: | + | |
- | end | + | |
+ | \\ | ||
+ | === 9. Creating a private Subtree === | ||
- | To start an external btree that takes control of the bot | + | * Todo ...it works, but this is a larger time consuming part I'll do when I have time :D |
- | | + | |
- | ml_bt_mgr.paused = true | + | |
- | my_btree: | + | |
- | end | + | |
- | + | ||
- | | + | |
- | + | ||
- | The bot main pulse will continue to run, but the main btree will not. | + | |
- | + | ||
- | When your task is completed remember to set ml_bt_mgr.paused to false | + | |
+ | === 10. Common Errors and Infos === | ||
+ | * You ALWAYS need to be aware that if you save for example a " | ||
+ | * You ALWAYS need to return a self: | ||
+ | * You can access each node's data by using self.settings, | ||
+ | * There are additional BehaviorManager functions that might be helpful to you: | ||
+ | |||
+ | === 11. BTreeinfo === | ||
+ | <code lua> | ||
+ | local btreeinfo = { | ||
+ | -- Our Main Behaviortree filename: | ||
+ | filename = string, | ||
+ | |||
+ | -- Our Foldername and a mandatory subfolder where our btree will be loaded from: | ||
+ | filepath = string, | ||
+ | |||
+ | -- Callback function, when the BTree was changed and saved in the BT-Editor. Reload all addon bt files here, including private subtrees. | ||
+ | Reload = function() end, | ||
+ | |||
+ | -- if set, it will be treated as a private addon, loadable from the addon store | ||
+ | private = false, | ||
+ | |||
+ | -- if set, the btree will not appear in the botmode dropdown | ||
+ | internal = false, | ||
+ | | ||
+ | -- Preloaded task data. Important when using a private addon. | ||
+ | data = table, | ||
+ | | ||
+ | -- (optional) Callback function, is called by the BTree Framework when the BTree is started. Allows us to supply a custom " | ||
+ | LoadContext = function() end, | ||
+ | |||
+ | -- (optional) Function to draw the menu elements that always appears on the "Main menu" interface. (Requires internal) | ||
+ | DrawMenuCode = function(btree) end, | ||
+ | | ||
+ | -- (optional) Function to draw the menu elements that appears on the "Main menu" interface when the btree is selected. | ||
+ | -- This locks the edit field inside the btree editor. | ||
+ | DrawMainMenuCode = function(btree) end, | ||
+ | |||
+ | -- (optional) Function to draw the menu elements that appears on the subtree node. This is also used for drawing custom properties in the taskmanager. | ||
+ | -- This locks the edit field inside the btree editor. | ||
+ | DrawSubMenuCode = function(btree) end, | ||
+ | |||
+ | -- Required for private addons with additional private sub-behavior trees | ||
+ | LoadSubTree = function(filename) end, | ||
+ | |||
+ | } | ||
+ | </ | ||
+ | |||
+ | === 12. BehaviorManager functions === | ||
+ | <code lua> | ||
+ | BehaviorManager: | ||
+ | BehaviorManager: | ||
+ | BehaviorManager: | ||
+ | BehaviorManager: | ||
+ | BehaviorManager: | ||
+ | BehaviorManager: | ||
+ | BehaviorManager: | ||
+ | BehaviorManager: | ||
+ | BehaviorManager: | ||
+ | BehaviorManager: | ||
+ | BehaviorManager: | ||
+ | BehaviorManager: | ||
+ | BehaviorManager: | ||
+ | BehaviorManager: | ||
+ | BehaviorManager: | ||
+ | </ |