[2.0.69] on_player_placed_equipment gets cancelled if character is assigned
Posted: Sat Oct 04, 2025 1:03 am
What you expected:
1) Multiple equipment gets inserted into armor
2) Changing the character during on_player_placed_equipment does not "cancel" the rest of the events
What happens:
1) Multiple equipment gets inserted into armor
2) Changing the character during on_player_placed_equipment "cancels" the rest of the events
Start a new game, run command, open your armor and fast-transfer solar panels. if cancel_events_bug is true, only one event is raised. If false, all 10 get raised.
Why this matters:
Someone was making a mod where the character entity changes, if certain equipment is inserted into armor. This behavior is quite unexpected.
1) Multiple equipment gets inserted into armor
2) Changing the character during on_player_placed_equipment does not "cancel" the rest of the events
What happens:
1) Multiple equipment gets inserted into armor
2) Changing the character during on_player_placed_equipment "cancels" the rest of the events
Code: Select all
/c
local player = game.player
local surface = player.surface
local character = player.character
character.insert("power-armor-mk2")
character.insert({name = "solar-panel-equipment", count = 10})
local position = character.position
position.x = position.x + 1
character = surface.create_entity{
name = "character",
position = position,
force = player.force
}
local event_trigger_count = 0
script.on_event(defines.events.on_player_placed_equipment, function(event)
local player = game.get_player(event.player_index)
event_trigger_count = event_trigger_count + 1
game.print("event_trigger_count: "..event_trigger_count)
local cancel_events_bug = true
if cancel_events_bug then
player.character = character
end
end)
Why this matters:
Someone was making a mod where the character entity changes, if certain equipment is inserted into armor. This behavior is quite unexpected.