Page 1 of 1

How to detect what kill biters

Posted: Tue Jun 10, 2014 3:14 pm
by darius456
One fast question. On entity died event I can check what type of entity died... Biter, building etc. but how I can determine what was the cause of death. How to determine that I shoot biter or laser tower did?

Re: How to detect what kill biters

Posted: Tue Jun 10, 2014 3:18 pm
by drs9999
I am afraid that this is not possible.

Re: How to detect what kill biters

Posted: Tue Jun 10, 2014 3:19 pm
by FreeER
I'm fairly sure that's not directly supported... You could check the distance of the player (util.distance) from the biter but that's obviously not foolproof... As far as I (and the wiki) know onentitydied only contains the Lua/Entity that died not what killed it, and as far as I know there's no way to tell what damaged it...

edit for completeness: you'd compare the distance to the range of the weapons that the player has equipped, not sure if you can tell which weapon is active though... or if there is an easy way to tell the range of any weapon (maybe game.itemprototypes would have that? but there doesn't seem to be a listing anywhere of exactly which parts of the prototypes are provided in the runtime prototypes...)

Re: How to detect what kill biters

Posted: Tue Jun 10, 2014 5:01 pm
by darius456
Thank you for your answers, I thought so. But I have 2 another small questions:
1. Have you ever tried to use this command:

Code: Select all

game.findentitiesfiltered{area = {{-10, -10}, {10, 10}}, type="resource"} -- gets all resources in the rectangle
game.findentitiesfiltered{area = {{-10, -10}, {10, 10}}, name="iron-ore"} -- gets all iron ores in the rectangle
but try to filter by force not type/name?

2.Help me with command:
This doesn't work:

Code: Select all

glob.dog[1].setcommand({type=defines.command.attackarea, destination = {pos_x, pos_y}, Radius=8 ,distraction=defines.distraction.none })
-attackarea - requires Destination=Types/position, Radius=Types/double, and Distraction=Types/Distraction

This doesn't too:

Code: Select all

glob.dog[1].setcommand({type=defines.command.attack, target = uwilldie, distraction=defines.distraction.none })
-attack - requires Target=entity and Types/Distraction

This work:

Code: Select all

glob.dog[i].setcommand({type=defines.command.gotolocation, destination = {pos_x, pos_y}, Radius=20 ,distraction=defines.distraction.none })
-gotolocation - requires Destination=Types/position or entity, Radius=Types/double, and Distraction=Types/Distraction

I got error that i'm trying to put nil value instead of table. How to use attack or attackarea commands? Please give me an example.

I'm trying to create PSI technology with PSI Tower that capture bitters, then friendly bitters will fallow player and player will have ability to order them to attack or move somewhere.
May be bitters will be upgradable... if you kill enough bitters of one kind or DNA modify or even implant exoskeleton :)

Re: How to detect what kill biters

Posted: Tue Jun 10, 2014 5:17 pm
by drs9999
darius456 wrote:1. Have you ever tried to use this command: [...]
You can only use type or name, but not force.

I cannot answer the rest, because I had not used it, though...

Re: How to detect what kill biters

Posted: Tue Jun 10, 2014 5:38 pm
by FreeER
darius456 wrote:but try to filter by force not type/name?
Nope ;) as drs9999 said it only filters based on type or name, there is a game.findenemyunits command (which I assume checks the force as well as type), but it won't find unit-spawners, to do so you'd need to use findentities and check each entity yourself. Or findenemyunits and findentitiesfiltered{type="unit-spawner"}.
darius456 wrote: glob.dog[1].setcommand({type=defines.command.attackarea, destination = {pos_x, pos_y}, Radius=8 ,distraction=defines.distraction.none })
Radius should be lowercase 'radius', then it works (just tested with destination=game.player.position), I'll update the wiki to show it properly ;) not sure why it's different than gotolocation however :lol:
darius456 wrote: glob.dog[1].setcommand({type=defines.command.attack, target = uwilldie, distraction=defines.distraction.none })
This worked for me as written, assuming 'uwilldie' was a valid lua/entity (I used game.player.selected over a biter-spawner, they were the same force so that's not a problem)

Re: How to detect what kill biters

Posted: Tue Jun 10, 2014 5:52 pm
by darius456
Thank you... fuc!@#$ R...