Jump to content

How to properly get player craft in turrets system scripts?


Treexter

Recommended Posts

Hi,

 

I'm trying to experiment with turrets systems.

But every attempt to get player craft leads to this

a5f0a607a4.jpg

 

Spent couple of hours playing with the code with no luck.

The current code is (Avorion\data\scripts\systems\militarytcs.lua):

function getNumTurrets(seed, rarity)
local numTurrets = math.max(1, rarity.value + 1)

local player = Player().craft

return numTurrets
end

 

What's the problem? Is this a bug?

How to obtain player craft properly here?

Link to comment
Share on other sites

system (modules) are attached to the entity not the player, so you want to use:

 

local craft = Entity()

 

there are a few places inside an entity where you can call Player() particularly on client side functions like onPreRender and onInstalled to name a few

 

In which case if you want the players craft you need to do this

 

local craftIndex = Player().craftIndex

 

    local ship = Entity()
    local player = Player()
    if not player.craftIndex == ship.index then return end

 

Link to comment
Share on other sites

Thanks!

 

I get it.

 

The final correct code without errors looks like this

This is the starting point for my further experiments.

function getNumTurrets(seed, rarity)
local numTurrets = math.max(1, rarity.value + 1)
local ship = Entity()

if ship == nil then return numTurrets end

        <... some stuff here with ship properties ...>

        return numTurrets
end

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