[2.0.60] Event "on_player_placed_equipment" Firing Twice

Place to get help with not working mods / modding interface.
NovaDrox
Manual Inserter
Manual Inserter
Posts: 2
Joined: Mon Jul 21, 2025 2:06 am
Contact:

[2.0.60] Event "on_player_placed_equipment" Firing Twice

Post by NovaDrox »

I am trying to develop a mod that adds custom equipment, which I am needing to detect upon it being placed in the grid for logic and such. The code I have below is just the bare basic of just detecting what equipment I put into a grid (armor, vehicle, etc), and for some reason it fires off once and displays everything correctly, but then it fires off the event again with just the first game.print statement only and not the other 2 print statements (see below code). I also saw that if I shift + click the equipment in, it fired the event once (perfect), but if I do it manually by click and placing it in the grid, it either fires the event 2 times or just once if spammed clicked a few times.

Code: Select all

local placed_event_counter = 0

script.on_event(defines.events.on_player_placed_equipment, function(event)
  local equipment = event.equipment
  placed_event_counter = placed_event_counter + 1 -- Always increment, as the event always fires.

  if equipment and equipment.valid then
    game.print("[Drone Companion] --- on_player_placed_equipment FIRED (" .. placed_event_counter .. " total fires) at tick " .. game.tick .. " ---")
    game.print("Name:" .. equipment.name)
    game.print(equipment)
  else 
    game.print("Is not valid or is nil")
  end
end)
In game chat/console:
[Drone Companion] --- on_player_placed_equipment FIRED (1 total fires) at tick 102872 ---
Name:fission-reactor-equipment
[LuaEquipment: fission-reactor-equipment (normal) at [0,0] in power-armor-mk2 (normal) itemNumber=1]
[Drone Companion] --- on_player_placed_equipment FIRED (2 total fires) at tick 102872 ---


Does anyone know what is happening with this double firing event? As this wasn't an issue before, but now it suddenly is in 2.0.60
User avatar
yaim904
Fast Inserter
Fast Inserter
Posts: 129
Joined: Wed Nov 17, 2021 11:26 pm
Contact:

Re: [2.0.60] Event "on_player_placed_equipment" Firing Twice

Post by yaim904 »

I tested your code and you're right.
Perhaps you should use another event.

Code: Select all

defines.events.on_equipment_inserted
on_equipment_inserted

Try it and let me know if it works for you. I'll be waiting to hear from you.
Solo entiendo español, pero si tu también lo entiendes, escríbeme
:D
Everything i write in English is translated by Deepl.
:D
NovaDrox
Manual Inserter
Manual Inserter
Posts: 2
Joined: Mon Jul 21, 2025 2:06 am
Contact:

Re: [2.0.60] Event "on_player_placed_equipment" Firing Twice

Post by NovaDrox »

So I switched out the on_player_placed_equipment event for the one you suggested and that works! :o

I kind of feel dumb for how easy of a fix that was, but I appreciate the extra help!


Thank you!!! :D
Post Reply

Return to “Modding help”