Jump to content

Why Does the Player Ship not Have AI?


Shrooblord

Recommended Posts

Hi forum,

 

I'm currently modding in an AutoDocker script that allows for easier docking at Stations, and I ran into a bit of a conundrum. Now, for the mod itself it doesn't matter, since I've found a work-around, but it left me curious: has anyone figured out why the player's ship can't perform AI commands while the player is flying it? With AI commands, I mean executing the Orders that you can give to Captained ships, or how the tradership.lua ships are ordered to flyaround and dock at Stations. Essentially, I'm talking about ShipAI()'s control over the ship.

 

Certainly, AI control is disabled while the player flies it, and for a good reason: can you imagine the frustration of trying to wrestle AI commands for control when you're trying to do one thing, but the AI is trying to do something else? Still though: I scoured through all the relevant code and documentation I could think of, but never found a conclusive answer: where and how does the ship get inactivated while the player flies the craft?

 

Good examples of the AI trying to wrestle back control from the player are mods where an AI command is given to the craft but isn't removed after the player enters the ship. One such example is Goods Hauler, and I found the same behaviour when trying to implement ShipAI() on the player's ship for my mod. The way you can tell the AI is trying to take control of the ship is that, when you exit into your Drone, the ship instantly starts heading to the location the commands are telling it to. But as soon as you get back into the ship, it stops flying and you can control it again.

 

I'd love to be able to programmatically take control of a player's ship, for example for the following use cases:

  • Auto-piloting ships to locations in the Sector, for example by using Tactical Mode (F9).
  • Auto-Docking (which I aim to implement, but more specifically:) by flying towards the Station in question first.
  • Enemies with immobilising Tractor Beams.
  • Cinematic cutscenes.

 

So finding out how to wrestle control from the player craft would be excellent.

 

But I fear that this is one more of those cases where the code to do so simply isn't exposed to us from source.

 

Anyway, please tell me what you know. I'm eager to find out.

Link to comment
Share on other sites

I had such a situation that I added additional comments for the miner, and made a mistake when the miner is terminate on the player enters the ship. It turns out I was getting on the ship, the script gave an error and the AI ​​continued to work, it drives my ship and at the same time it also controlled my guns, it was a specifically controlling the machine, I can fly, but AI try to fly at same time and it was pushing the gun trigger, like players left mouse button.

So it comes out theoretically possible to make it possible for AI to control the ship, in whole or in part, while player onboard.

It may be necessary to do so that he took the place of the co-pilot, and pass it a couple of turrets or disassembly fighters, so that it control fighters work.

Link to comment
Share on other sites

Oh, really? That's quite awesome. Can you reproduce your bug so we can turn it into a feature?  ;D

 

Looking forward to that mod! Are you able to use the docking tractor beams for it? I think those look cool.
Yup it does and yes they do. x)

It's pretty much done now. I'm currently debugging (there are some instances where it chooses one dock to show the player to dock to, but then proceeds to shoot tractor beams from a different dock, which is stupid), and want to add just a tiny bit more QoL updates to the current code. Then I'm ready to release!

Link to comment
Share on other sites

Oh, really? That's quite awesome. Can you reproduce your bug so we can turn it into a feature?  ;D

 

I tried to comment out the pilot check in the mine.lua

 

 

function AIMine.updateServer(timeStep)
    local ship = Entity()

    if --[[ship.hasPilot or ]]ship:getCrewMembers(CrewProfessionType.Captain) == 0 then
	print("(%s) Stops mine work!"%_T, ship.name)
        terminate()
        return
    end

    -- find an asteroid that can be harvested
    AIMine.updateMining(timeStep)
end

 

But when I climbed aboard the ship, the AI did not continue to move :(, and only steal shooting from the lasers.

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