Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Define the map boundaries for a 1024x1024 map
- local mapMinX, mapMinY = 0, 0
- local mapMaxX, mapMaxY = 1024, 1024
- -- Function to check if an entity's position is outside the map area
- local function isOutsideMapArea(position)
- local x, y = position[1], position[2]
- return x < mapMinX or x > mapMaxX or y < mapMinY or y > mapMaxY
- end
- -- Function to remove all nodes and entities outside the map area
- local function removeNodesOutsideMap()
- -- Use a bounding box to get entities within a large area
- local boundingBox = {
- {mapMinX - 500, mapMinY - 500}, -- Add a buffer outside the map bounds
- {mapMaxX + 500, mapMaxY + 500}
- }
- local entities = game.interface.getEntities(boundingBox, { }) -- Fetch entities within bounding box
- print("Number of entities found: " .. #entities) -- Debug print to check how many entities are found
- for _, entityId in ipairs(entities) do
- local entity = game.interface.getEntity(entityId) -- Get the entity data
- if entity then
- print("Entity Type: " .. tostring(entity.type)) -- Debugging line to check entity types
- if entity.position and isOutsideMapArea(entity.position) then
- -- Check if entity is a node or any type of object
- print("Removing entity with ID: " .. tostring(entityId)) -- Debugging line
- game.interface.removeEntity(entityId) -- Remove the entity
- end
- end
- end
- end
- -- Run the node removal function
- removeNodesOutsideMap()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement