Page 1 of 1

[Resolved] Creating Multiple Entities

Posted: Sat Jul 08, 2017 5:35 pm
by TheSAguy
Hi,

I want to create 100 new enemy entities.
I was wondering if there was a easy way to do this, instead of me physically creating the 100 entities.

If I just want to call the newly created enemies: Unit1 to Unit100.
Is there a way, maybe with deep-copy or something I can use to do this? Then I can just use a reference table for their health and damage or something.

Thanks.

Re: Creating Multiple Entities

Posted: Sun Jul 09, 2017 8:20 am
by prg
You mean create lots of prototypes? Something like

Code: Select all

health = { 5, 10, 20 }
damage = { 7, 15, 25 }

for i = 1, #health do
    new_biter = table.deepcopy(data.raw.unit["small-biter"])
    new_biter.name = "new-biter-" .. i
    new_biter.max_health = health[i]
    new_biter.attack_parameters.ammo_type.action.action_delivery.target_effects.damage.amount = damage[i]
    data:extend{new_biter}
end

Re: Creating Multiple Entities

Posted: Sun Jul 09, 2017 9:42 am
by darkfrei
I think

Code: Select all

local new_biter = ...

Re: Creating Multiple Entities

Posted: Sun Jul 09, 2017 10:01 am
by prg
That really won't make a difference there.

Re: Creating Multiple Entities

Posted: Sun Jul 09, 2017 10:32 pm
by TheSAguy
Thanks guys, I'll give it a try when I'm back from vacation :D

Re: Creating Multiple Entities

Posted: Mon Jul 10, 2017 9:34 am
by bobingabout
Going by this they'll all be the size and colour of a small biter, but it's a good way to start.

I'd do things differently, but then the way I do things wouldn't be designed for as many as 100.

And if you are working with as many as 100, I'd suggest replacing those input tables with a formula instead.

Re: Creating Multiple Entities

Posted: Mon Jul 17, 2017 5:36 pm
by TheSAguy
I have something weird happening when I'm trying to do a tint change. (Well, weird for me ;) )

For some reason, when I do a Random tint, it works, but when applying a specific tint, PER newly created Unit, it does not work.
So, what I'm saying is that:

The below code words, creating a random tint:

Code: Select all

alien_tint1 = { {r=math.random(255), g=math.random(255), b=math.random(255), a=255},	{r=math.random(255), g=math.random(255), b=math.random(255), a=255},	{r=math.random(255), g=math.random(255), b=math.random(255), a=255},	{r=math.random(255), g=math.random(255), b=math.random(255), a=255},	{r=math.random(255), g=math.random(255), b=math.random(255), a=255}}
but the below does not work:

Code: Select all

alien_tint1 = { {r=0, g=0, b=0, a=255},	 {r=3, g=0, b=0, a=255},	 {r=5, g=0, b=0, a=255},	 {r=8, g=0, b=0, a=255},	 {r=10, g=0, b=0, a=255},	 {r=13, g=0, b=0, a=255}}
The above is just an example, I actually have a 100 iterations. Full code below.

Here is a screenshot of the random tint, vs. the tint that goes from a=0 to a=255:
Images
I've tried to apply the tint in two ways:

Code: Select all

alien_tint1 = { {r=0, g=0, b=0, a=255},	 {r=3, g=0, b=0, a=255}, ..... to 100 }
and

Code: Select all

alien_tint1 = {
["alien-army-1"] ={r=0, g=0, b=0, a=255},
["alien-army-2"] = {r=3, g=0, b=0, a=255},
["alien-army-3"] = {r=5, g=0, b=0, a=255},
----
["alien-army-100"] = {r=255, g=0, b=0, a=255}
}
with the same result.
I think the same issue is happening with the collision/selection boxes.
All the other stuff seems to work, Health, Scale, Damage.

Code:

Code: Select all


for i = 1, 100 do
    alien_army = table.deepcopy(data.raw.unit["base-alien"])
    alien_army.name = "alien-army-" .. i
	alien_army.collision_box = v_collision_box[i]
	alien_army.selection_box = v_selection_box[i]
	alien_army.sticker_box = v_collision_box[i]
    alien_army.max_health = health[i]
	alien_army.corpse = "alien-corpse-" .. i
	alien_army.attack_parameters.ammo_type.action.action_delivery.target_effects.damage = damage_amount[i]
	
	--Option 1:
	alien_army.attack_parameters.animation = biterattackanimation(alien_scale[i], alien_tint1[i], alien_tint2[i])
	alien_army.run_animation = biterrunanimation(alien_scale[i], alien_tint1[i], alien_tint2[i])
	
	--Option2:
	--alien_army.attack_parameters.animation = biterattackanimation(alien_scale[i], alien_tint1["alien-army-" .. i], alien_tint2["alien-army-" .. i])
	--alien_army.run_animation = biterrunanimation(alien_scale[i], alien_tint1["alien-army-" .. i], alien_tint2["alien-army-" .. i])
	
	
    data:extend{alien_army}
end

Code attached.
Thanks.

Re: Creating Multiple Entities

Posted: Mon Jul 17, 2017 5:48 pm
by orzelek
I have an idea - I think I seen something similar with tables in tables.
Try using deepcopy to give actual table copy with tint to data structure.

This would also match your list of things that work and those that don't work. All those that you listed contain tables.

Re: Creating Multiple Entities

Posted: Mon Jul 17, 2017 6:39 pm
by TheSAguy
orzelek wrote:I have an idea - I think I seen something similar with tables in tables.
Try using deepcopy to give actual table copy with tint to data structure.

This would also match your list of things that work and those that don't work. All those that you listed contain tables.
I do agree it's something to do with tables, in tables...

Is this what you mean:

Code: Select all

	alien_army.attack_parameters.animation = biterattackanimation(alien_scale[i], table.deepcopy(alien_tint1[i]), table.deepcopy(alien_tint2[i]))
	alien_army.run_animation = biterrunanimation(alien_scale[i], table.deepcopy(alien_tint1[i]), table.deepcopy(alien_tint2[i]))
Is that syntax correct?

Still got this result:
Image

I think the reason the random one works, is because only the first value in the value/table is hit each time. (when dealing with a table in a table) and since the first value is random, it creates a random tint.

Re: Creating Multiple Entities

Posted: Mon Jul 17, 2017 6:57 pm
by orzelek
Can you post the whole mod to make it easier to test stuff?

Re: Creating Multiple Entities

Posted: Mon Jul 17, 2017 7:28 pm
by TheSAguy
Here is the mod, though I swear it might be working now after not working once the whole weekend...
The Selection and Collision boxes still don't seem to work.

Re: Creating Multiple Entities

Posted: Mon Jul 17, 2017 8:20 pm
by TheSAguy
There must have been a space or something, but is seems like it's working now...
Thanks for checking though.

Re: Creating Multiple Entities

Posted: Mon Jul 17, 2017 8:35 pm
by orzelek
Thats even more interesting.
Since you have rgba in 0-255 range and game seems to like 0-1 range :D