Author Topic: [REQUEST] [MOD] The AI  (Read 1803 times)

T4Ken

  • Newbie
  • *
  • Status:
    Offline
    Posts:
    18
    • View Profile
on: February 24, 2018, 12:04:53 PM
Hello ,
I wanna set some Minions for The Ai when it becomes 50% Damage of Shield or Hull. I got allready a The_ai_Minion.xml , but no clue how to get it done  ;D



Hammelpilaw

  • Hero Member
  • *****
  • Status:
    Offline
    Posts:
    542
    • View Profile
    • Scrap Yard - Avofactory
on: February 27, 2018, 07:00:14 PM
The xml file is only the ship plan. Put it in your local ship folder (C:\users\USERNAME\AppData\Roaming\Avorion\ships) and you can load it on your ship in build menu.

Try to take a look into /data/scripts/entity/story/aibehaviour.lua and /data/scripts/lib/story/ai.lua. If you have further questions ask again.
Scrap Yard Galaxy
My mods and tools
My Workshop

If you find a bug in my mods please contact me.



T4Ken

  • Newbie
  • *
  • Status:
    Offline
    Posts:
    18
    • View Profile
on: February 28, 2018, 12:52:51 AM
I know... did this allready but know i need a command or Mod to make them spawn when "The Ai" drops below 50% .

this also usable for other mods/mission :)



Hammelpilaw

  • Hero Member
  • *****
  • Status:
    Offline
    Posts:
    542
    • View Profile
    • Scrap Yard - Avofactory
on: March 04, 2018, 08:44:08 AM
I know... did this allready but know i need a command or Mod to make them spawn when "The Ai" drops below 50% .

this also usable for other mods/mission :)

Add some code to the file aibehaviour.lua.


Before line 14 if onClient() then add:
Code: [Select]
local spawnedShips = false
In function updateServer() add this:
Code: [Select]
health = 0
    shield = 0

    local maxHealthSum = 0
    local maxShieldSum = 0

    local entities = {Sector():getEntitiesByType(EntityType.Ship)}
    for _, entity in pairs(entities) do
        if entity:hasScript("aibehaviour.lua") then

            health = health + entity.durability
            shield = shield + entity.shieldDurability

            maxHealthSum = maxHealthSum + entity.maxDurability
            maxShieldSum = maxShieldSum + entity.shieldMaxDurability
        end
    end

    maxHealth = math.max(maxHealth, maxHealthSum)
    maxShield = math.max(maxShield, maxShieldSum)

if not spawnedShips and health < maxHealth / 2 then
  -- Insert your custom code here. This will be executed once when health drops below 50%
end

I did no test it, it may be buggy.

To spawn the ships you may copy paste code from the file xsotan.lua, asyncpirategenerator.lua or any other script file where ships get spawned.
Scrap Yard Galaxy
My mods and tools
My Workshop

If you find a bug in my mods please contact me.