Requires .13.14 or higher
if (ev.created_entity.name == "entity-ghost" or ev.created_entity.name == "tile-ghost") and game.players[ev.player_index].cheat_mode then
local _, entity = ev.created_entity.revive() --revive returns new entity as second argument
if entity and entity.valid then game.raise_event(defines.events.on_built_entity, {player_index=ev.player_index, created_entity=entity}) end
end