Jump to content

How to count the number of a specific asteroid in a sector?


Engine

Recommended Posts

Working on a script that reports how many of each type of asteroid are in a sector and how many units of resource are in those.  I can not for the life of me figure out how to pull the specific types.  I can get total mineable in sector without an issue, but for example: if I want to know "how many Trinium asteroids are in this sector and how many units of Trinium are in all of those" I just can't figure out the proper function to call.

 

I've played with the following

Enum: MaterialType.type (eg. Trinium).  Also, the "Iron" type seems to be broken as it returns an error no slot for slot type 0.  all the other types return the total number of astroids in the system (including non mineable).

Function: getMineableResources()

Function: getMineableResources()

Link to comment
Share on other sites

Gona chalk this up to being up for nearly 30 hours when I was scripting this, but the answer above was correct, I was thinking getMineableMaterial() would directly return the material type.  Oops :).  Thanks for the help Laserzwei.

Link to comment
Share on other sites

Yesterday I had a much more in-depth description -about how the resource System in Avorion is done from a scripting perspective- prepared, but the Auto-Log-Out deleted it, when I pressed preview  :-\

So I will deliver it as an appendum:

 

This will Touch the following Classes:

Resource information:

Entity

Material

Resource Manipultaion:

BlockPlan

BlockPlanBlock

Box

 

Context: Entity

 

function int... getMineableResources()

Returns all resources available for extraction from that Entity as Arguments. If you expect more than 1 resources on that Entity, you will want to put {} around it to catch them. This is not necessary for Vanilla Asteroids. However: Wreckages with different Materials will need it. It does not provide any clue of what Material these resources are.

 

function Material getMineableMaterial()

This returns exactly 1 Material. It is only suitable to get a single resource. I haven't tested what it returns in case of multiple resources, but I doubt it holds meaningful Information.

 

function double... getPlanResourceValue()

This is pretty much a combination of the above. It returns 7 double Values (One for each Material: Iron->Avorion). Each of them holds the amount of resources build into the Entity. Most of these Values will have 0 in them. They are always given in ascending order, starting with Iron. To catch them in a single Table again use {}.

Here is an example code snippet:

 

local resources = {Entity():getPlanResourceValue()}
for material, amount in ipairs(resources) do
    print(Material(material-1).name, amount)
end

2 things to metion:

1. I use ipairs to traverse the table. It requires the indices to start with 1 and the next following to be +1. If not, data might be lost! The big pro: It is in order. pairs might traverse randomly.

2. I use material-1 to map the table indices to Material indices. The Material indices start with 0, the LUA-table with 1.

 

This is basically all the information about the resources on an Entity you can get.

If you want to manipulate them you have to dig into BlockPlan

 

To get the Blockplan of entity use:

Entity:getPlan:get()

getPlan() returns a Plan Object, which is basically an extended BlockPlan. the following get() gives the actual BlockPlan.

Both have the same -already discussed- getPlanResourceValue() function

 

 

Context: BlockPlan

The resources in an Entity are defined by the Blocks which make it up. So to manipulate the resources on an Entity (mainly, but not limited to Asteroids or wreckages) you have to modify the underlaying BlockPlanBlocks.

 

You can get these blocks by traversing through the BlockPlan.

Either use the tree-like traversing starting with the given BlockPlanBlock attribute root and root:getChildren(). Followed with the BlockPlan function BlockPlanBlock getBlock(int index). Traversing it in this manner allows to get information about the structual properties (to destroy a root-Block you need to inflict enough damage to destroy all of its children as well)

Or use function int... getBlockIndices() with function BlockPlanBlock getBlock(int index).

Don't forget to get them into a table with {...}.

 

Context: BlockPlanBlock

 

To manipulate the material-type, you can modify it with the BlockPlanBlock attribute material. It requires to be a Material object.

To Manipulate the amount, you have to change the volume of the block. Much like it costs proportionally more to build a Block, you also gain more resources back from it. The Volume of a Block is defined by it's size. As every (building-)Block is actually a cuboid, you have to change its size. It is stored in the box property. You can test which sizes you want in the building mode (it also allows to add resource-stones)- the build-cost and the resource-amount are the same.

You will probaly have to fiddle around with the Box's attributes, to get the desired results.

 

This completes the information and manipulation of resources in Entities -  available for modding.

 

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