How to obtain name of equipment being taken from grid?

Place to get help with not working mods / modding interface.
Post Reply
Schallfalke
Fast Inserter
Fast Inserter
Posts: 162
Joined: Sun Oct 28, 2018 7:57 am
Contact:

How to obtain name of equipment being taken from grid?

Post by Schallfalke »

Hi,

I am trying to make an active defense equipment (like personal laser defense) but using ammo. I am using the battery level as the "ammo count".
Now I want to write a script to get back some ammo if the equipment is partially used (like 50% battery gives back half an ammo stack).

I looked around the API, I find on_player_removed_equipment and try to use that:

Code: Select all

local function remove_gunpod_equipment(e)
  local player = game.players[e.player_index]
  local eqp = e.equipment
  local gp = e.grid
  local count = e.count
  player.print("Count : " .. count);
  player.print("Item name : " .. eqp.name);
end
The "Count" always gives "1", while accessing "Item name" gives a crash, since e.equipment seems giving "nil" all the time.

So my questions are:
1. Is event on_player_removed_equipment executed AFTER the equipment is removed?
2. Is there any way to get the name of equipment being removed? (Either with this event or any other event.)
3. Is it possible to get the battery level of the equipment being removed?
4. Are there any alternate way for such ammo-consuming defense equipment? (Like ammo inventory to equipment, or alternate way of counter within equipment.)

Thanks for your attention,
Schall

Post Reply

Return to “Modding help”