Jump to content

How to get ship Entity from turret Entity?


Rinart73

Recommended Posts

I need to know which ship fired the shot. So, I register a callback:

function MyMod.initialize()
    Sector():registerCallback("onStartFiring", "onSomeoneFired")
end

function MyMod.onSomeoneFired(turretId)
    local turret = Entity(turretId)
end

 

And now what? There is no way to get "parent entity" of other entity.

Link to comment
Share on other sites

I'm also interested.

There is a "ParentEntity"- Component (Enums -> ComponentType -> ParentEntity), but it's not surfaced to the LUA API.

There is also the possibility of going through the ships of the same faction and search for that specific turret:

function MyMod.onSomeoneFired(turretId)
    local turret = Entity(turretId)
    local parent
    local possibleParents = {getEntitiesByFaction(turret.factionIndex)}
    for _,p in pairs(possibleParents) do
        if (p.isShip or p.isStation) then
            local pTurrets = {p:getTurrets()}
            for _,t in pairs(pTurrets) do
                if t.index.number == turret.index.number then
                    parent = p
            end
        end
    end
    if parent then print("parent found", parent.name) else print("no parent found, weird!") end
end

I didn't try the code but it should work ;D

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...