[Resolved] Creating Multiple Entities

Place to get help with not working mods / modding interface.
Post Reply
TheSAguy
Smart Inserter
Smart Inserter
Posts: 1449
Joined: Mon Jan 13, 2014 6:17 pm
Contact:

[Resolved] Creating Multiple Entities

Post 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.
Last edited by TheSAguy on Tue Jul 18, 2017 2:31 pm, edited 3 times in total.

User avatar
prg
Filter Inserter
Filter Inserter
Posts: 947
Joined: Mon Jan 19, 2015 12:39 am
Contact:

Re: Creating Multiple Entities

Post 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
Automatic Belt (and pipe) Planner—Automate yet another aspect of constructing your factory!

User avatar
darkfrei
Smart Inserter
Smart Inserter
Posts: 2904
Joined: Thu Nov 20, 2014 11:11 pm
Contact:

Re: Creating Multiple Entities

Post by darkfrei »

I think

Code: Select all

local new_biter = ...

User avatar
prg
Filter Inserter
Filter Inserter
Posts: 947
Joined: Mon Jan 19, 2015 12:39 am
Contact:

Re: Creating Multiple Entities

Post by prg »

That really won't make a difference there.
Automatic Belt (and pipe) Planner—Automate yet another aspect of constructing your factory!

TheSAguy
Smart Inserter
Smart Inserter
Posts: 1449
Joined: Mon Jan 13, 2014 6:17 pm
Contact:

Re: Creating Multiple Entities

Post by TheSAguy »

Thanks guys, I'll give it a try when I'm back from vacation :D

User avatar
bobingabout
Smart Inserter
Smart Inserter
Posts: 7352
Joined: Fri May 09, 2014 1:01 pm
Contact:

Re: Creating Multiple Entities

Post 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.
Creator of Bob's mods. Expanding your gameplay since version 0.9.8.
I also have a Patreon.

TheSAguy
Smart Inserter
Smart Inserter
Posts: 1449
Joined: Mon Jan 13, 2014 6:17 pm
Contact:

Re: Creating Multiple Entities

Post 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.
Attachments
alien-enemy.lua
Code
(43.52 KiB) Downloaded 94 times

orzelek
Smart Inserter
Smart Inserter
Posts: 3911
Joined: Fri Apr 03, 2015 10:20 am
Contact:

Re: Creating Multiple Entities

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

TheSAguy
Smart Inserter
Smart Inserter
Posts: 1449
Joined: Mon Jan 13, 2014 6:17 pm
Contact:

Re: Creating Multiple Entities

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

orzelek
Smart Inserter
Smart Inserter
Posts: 3911
Joined: Fri Apr 03, 2015 10:20 am
Contact:

Re: Creating Multiple Entities

Post by orzelek »

Can you post the whole mod to make it easier to test stuff?

TheSAguy
Smart Inserter
Smart Inserter
Posts: 1449
Joined: Mon Jan 13, 2014 6:17 pm
Contact:

Re: Creating Multiple Entities

Post 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.
Attachments
Alien_Biters_0.1.0.zip
Mod
(15.28 KiB) Downloaded 77 times

TheSAguy
Smart Inserter
Smart Inserter
Posts: 1449
Joined: Mon Jan 13, 2014 6:17 pm
Contact:

Re: Creating Multiple Entities

Post by TheSAguy »

There must have been a space or something, but is seems like it's working now...
Thanks for checking though.
Attachments
Alien_Biters_0.1.0.zip
Mod
(13.4 KiB) Downloaded 72 times

orzelek
Smart Inserter
Smart Inserter
Posts: 3911
Joined: Fri Apr 03, 2015 10:20 am
Contact:

Re: Creating Multiple Entities

Post by orzelek »

Thats even more interesting.
Since you have rgba in 0-255 range and game seems to like 0-1 range :D

Post Reply

Return to “Modding help”