Page 1 of 1

Accessing the prototype data that the unit was created with?

Posted: Sat May 31, 2014 4:51 pm
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.

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

Posted: Sat May 31, 2014 5:33 pm
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

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

Posted: Sat May 31, 2014 6:33 pm
by blah900
Yup, you got it! I was trying to make a td like scenario! And thanks, that is actually good enough for now!