Accessing the prototype data that the unit was created with?

Place to get help with not working mods / modding interface.
blah900
Burner Inserter
Burner Inserter
Posts: 7
Joined: Sat May 31, 2014 12:42 am
Contact:

Accessing the prototype data that the unit was created with?

Post by blah900 »

So, I've been trying to access the prototype programmatically but I've been running into the problem of "luaEntityPrototype doesn't have readable property X"

To be more specific, I wanted to access the max_health parameter of the entity (because I am trying to create different entities dynamically through createentity, for example creating a biter with random amount of max health). Is there currently a way to do this?

If not, I can always create a table that keeps a mapping of the entity to its max hp on creation but i would like to avoid that if possible.

Thanks in advance!

EDIT: To be clearer, I am setting up a point system where the point is a function of the max_health of the unit killed. So I would like to know the hp of the unit being killed when onentitdied event pops up.

EDIT2: Well it seems I can't dynamically generate new type of enemies, but I could still use a loop to create multiple different types.
drs9999
Filter Inserter
Filter Inserter
Posts: 831
Joined: Wed Mar 06, 2013 11:16 pm
Contact:

Re: Accessing the prototype data that the unit was created w

Post by drs9999 »

Just guessing, you try to create a td-like scenario?! That would be awesome.

Anyway back to topic:
There is a typo on the wiki. You can access the maximum health of the prototype with "maxhealth" instead of max_health...
But it is read only, so not really what you wanted I guess.
You could create different entities (or use a function that does the work for you) which share the same sprite but have different maxhealth-values (but not random-values, though)

Hope that helps
blah900
Burner Inserter
Burner Inserter
Posts: 7
Joined: Sat May 31, 2014 12:42 am
Contact:

Re: Accessing the prototype data that the unit was created w

Post by blah900 »

Yup, you got it! I was trying to make a td like scenario! And thanks, that is actually good enough for now!
Post Reply

Return to “Modding help”