Jump to content

[MOD] Complex Craft Orders


Rinart73

Recommended Posts

[0.17.1-0.18.3] [mod in beta]

 

GitHub

 

First of all, I want to ask devs to give us Turrets API. Let us turn them on/off, give and set their targets. That API with this mod (and other possible mods too) could open endless possibilities: mining ships that switch to battle turrets to protect themselves, supporter-type ships that heal allies with repair turrets while attacking enemies at the same time etc.

 

Has ever thought "I pay my captains too much for such simple tasks" crossed your mind? Do you want them to be smarter and to act to the situation accordingly? Now you can get what you want - with this mod you can specify various conditions and outcomes that your captains will follow.

And if you're a modder you can write a module for this mod, expanding it's possibilities.

 

screenshot_0_1_1.jpg

 

Installation

  • Install Ship Script Loader
  • Unpack mod archive into "Avorion" folder
  • Open "mods\ShipScriptLoader\config\ShipScriptLoader.lua" and add following line before "return config":

Config.Add("mods/ComplexCraftOrders/scripts/entity/complexcraftorders.lua")


 

Uninstallation

  • Remove line that you previously added from file "mods\ShipScriptLoader\config\ShipScriptLoader.lua"
  • Replace contents of the file "mods\ComplexCraftOrders\scripts\entity\complexcraftorders.lua" with "terminate()". Don't delete file itself

 

Changelog

 

 

0.1.1

  • Fixed: 'basic' module - Now can remove custom ai scrips that were added by other mods (as longs as they're placed in "mods/ModName/scripts/entity/ai" folder)
  • Fixed: 'basic' module - No more reapplying already executed commands (this caused problems with Mining)
  • Fixed: 'basic' module - Temporal fix to distinguish escort/follow actions
  • Improved: 'basic' module - Now you can use space, ", " or ";" to separate coordinates for "At Coordinates" condition and "Jump To" action

0.1.0

  • First version

 

 

Compatibility

Should be perfectly compatible with any other mod, unless that mod completely messes up "data\scripts\entity\craftorders.lua"

 

Bugs

  • Scrolling dropdown lists is not possible when they're in a scrollable container (game bug (1)). This doesn't cause problems when you only have basic module installed, because all lists currently have less than 16 entries.  I'm waiting for the fix, otherwise will find a workaround.

 

Notes

  • Extra-space that causes scroll to appear even with small amount of rows is a workaround to treat other game bug (2)

 

To server owners

I tried to optimize this mod as much as possible. If player uses "Nearest Enemy, Ship" few times, first result is cached for current server update. The same happens with Conditions. In the config file ("mods\ComplexCraftOrders\config\Config.lua") you can play with "updateInterval" variable  (default 10 seconds). You can also set "logLevel" to 3 and mod will write in logs how much time every update takes.

 

How to use

 

Mod operates several concepts:

  • Target (who) - it may be current ship, closest enemy station e.t.c
  • Condition (when) - 'distance less than', 'with chance' and other
  • Action (what to do) - what will be executed if conditions were or weren't matched - patrol, jump, follow entity..
  • Argument - certain parameter that will help to specify Target, execute Action or will be used to compare something in Condition
  • Inverter - simply allows to invert the result of Condition - turn your 'health less than' into 'health not less than'
  • Operator - allows to connect Conditions ('and', 'or'), Actions ('and', 'else') or go from Conditions to Actions ('action')
  • Row - is either Target+Condition + arguments - Condition Row or Action + arguments - Action Row
  • Group / Condition Group - conditons that are connected with 'and' operator. 'or' operator starts a new group

tutorial_better_smaller.jpg

 

A few key moments:

  • You need to own the ship or have an Alliance "Manage Ships" permission to interact with menu
  • Each block is executed independently. You're limited by your fantasy and the amount of rows that is set on server.
  • Most conditions require Target and will be not processed if Target was not found.
  • You can divide your conditions in Condition Groups with 'or' operator. This means that actions will be executed if at least one Condition group was met.
  • Actions that go after Action Row with 'else' operator will be executed only if all condition groups are failed. They even will be executed if no Targets were found at all.
  • Actions always receive last successful target (even if it's 'else' Actions)

 

Here you can see the list of Targets, Conditions and Actions of 'basic' module:

Targets

  • Self - current ship
  • Any Ally - first found ally in the sector. Accepts argument: ''(any), 'Ship', 'Station'. It's advised to use this Target if you just need to check if there any allies.
  • Any Enemy - first found enemy in the sector. Accepts argument: ''(any), 'Ship', 'Station'. It's advised to use this Target if you just need to check if there any enemies.
  • Nearest Ally - Accepts argument: ''(any), 'Ship', 'Station'
  • Nearest Enemy - Accepts argument: ''(any), 'Ship', 'Station'
  • Most Hurt Ally - ally with smalles percentage of health (not shield). Accepts argument: ''(any), 'Ship', 'Station'
  • Most Hurt Enemy - enemy with smalles percentage of health (not shield). Accepts argument: ''(any), 'Ship', 'Station'
  • Least Hurt Ally - ally with biggest percentage of health (not shield). Accepts argument: ''(any), 'Ship', 'Station'
  • Least Hurt Enemy - enemy with biggest percentage of health (not shield). Accepts argument: ''(any), 'Ship', 'Station'
  • Random Ally - Accepts argument: ''(any), 'Ship', 'Station'
  • Random Enemy - Accepts argument: ''(any), 'Ship', 'Station'

Conditions

  • In Sector - checks if target was found (not nil). Accepts Target than can be nil
  • Health Less Than - checks if Target health percentage is less than Argument (should be number)
  • Shield Less Than - checks if Target shield percentage is less than Argument (should be number)
  • With Chance - works with a certain chance, that is specified in Argument (should be number)
  • Distance Less Than - compares distance to target with an Argument (should be number). 1000 means 1km
  • At Coordinates - check if sector coordinates are matching Argument coordinates (should be 2 numbers divided with a comma - "15,-300")

Actions

  • Idle - same as vanilla order. Doesn't care about Target
  • Passive - same as vanilla order. Doesn't care about Target
  • Guard Position - same as vanilla order. Doesn't care about Target
  • Follow Target - follows Target (without jumping)
  • Escort Target - escorts Target (including jumping)
  • Attack Target - attack Target
  • Patrol - same as vanilla order. Doesn't care about Target
  • Mine - same as vanilla order. Doesn't care about Target
  • Salvage - same as vanilla order. Doesn't care about Target
  • Toggle Passive Shooting - toggles passive shooting on/off. Doesn't care about Target
  • Jump To - Accepts sector coordinates as two number divided with a comma ("-114,26") and tries to jump to them. Doesn't care about Target

 

 

 

For modders - ready

 

 

You can active module by adding it's name into 'config.modules' table in "mods\ComplexCraftOrders\config" folder.

 

Modules are stored in "mods\ComplexCraftOrders\modules" folder.

Inside module folder you should create a file named 'module.lua'.

This file should return a table that may or may not have following items:

  • initialize(modAPI) - function that will be called by the mod. It will pass API for this module as first argument.
  • Target - table of target items
  • Condition - table of condition items
  • Action - table of action items

 

Current API:

Variables

  • modAPI.Level - table with log levels: Error, Warn, Info and Debug

Functions

  • function modAPI:log(int logLevel, string message [, arguments ]) - Writes a message to the log. It also works as 'string.format', so you can use

modAPI:log(modAPI.Level.Debug, "number is %u", yournumber)


 

Target item should have a key that will be shown in UI. It's value is a table that contains these parameters:

  • func(sector [, arg ]) - function that will be called when mod will try to get this target. Should return Entity or nil
  • argument - (optional) if your functions accepts argument, you can specify which type of argument do you want: 'true' - TextBox, table with items - ComboBox
  • cache - (optional, default = true) if set to false, the result of your function will not be cached. Use with caution as it affects performance

 

Condition item follows the same rules as target item but has some differences:

  • func(target [,arg ]) - function that will be called to check some condition. Should return true of false/nil
  • acceptsNil - (optional, default = false) If true, your function can be called if target is nil. Use only when you absolutely understand what're you doing. If you don't use a target, it doesn't mean that this should be 'true'

 

Action item is the same as condition item except:

  • It doesn't have 'cache' and 'acceptsNil' params
  • func(target [,arg ]) - shouldn't return anything

 

 

 

This mod is currently in Beta as I'm trying to find and fix possible errors. While it won't corrupt your sectors, it may stop working at any time.

Current version 0.1.1 works for Avorion 0.17.1 - 0.18.2

ComplexCraftOrders-0.1.0.zip

ComplexCraftOrders-0.1.1_0.17.1-0.18.2.zip

Link to comment
Share on other sites

0.1.1

  • Fixed: 'basic' module - Now can remove custom ai scrips that were added by other mods (as longs as they're placed in "mods/ModName/scripts/entity/ai" folder)
  • Fixed: 'basic' module - No more reapplying already executed commands (this caused problems with Mining)
  • Fixed: 'basic' module - Temporal fix to distinguish escort/follow actions
  • Improved: 'basic' module - Now you can use space, ", " or ";" to separate coordinates for "At Coordinates" condition and "Jump To" action

Link to comment
Share on other sites

  • 2 weeks later...

Awesome mod, most stuff works without issue, however I can't set a jump patrol.

In order to have a jump jump around two or more sectors and engage enemies, I used:

Any Enemy In Sector/At Coords And

Self In Sector/At Coords Action

Engage Else

Jump to

And several variations of this for at least two sectors. The ship starts engaging enemies in the current sector and jumps after the sector is cleared, but then stops doing anything. What I am doing wrong?

Link to comment
Share on other sites

Hi Exspes, thanks for posting.

This ruleset should do the trick.

 

hint.jpg

 

The thing is: currently if ship jumped into another sector, it will NOT jump again unless any other action was made. I'm working on this issue. Other than that, everything should work fine after the jump

Link to comment
Share on other sites

  • 2 months later...

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
×
×
  • Create New...