Advertisement
aum7

Untitled

Nov 28th, 2024
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.54 KB | Source Code | 0 0
  1. -- Define the map boundaries for a 1024x1024 map
  2. local mapMinX, mapMinY = 0, 0
  3. local mapMaxX, mapMaxY = 1024, 1024
  4.  
  5. -- Function to check if an entity's position is outside the map area
  6. local function isOutsideMapArea(position)
  7.     local x, y = position[1], position[2]
  8.     return x < mapMinX or x > mapMaxX or y < mapMinY or y > mapMaxY
  9. end
  10.  
  11. -- Function to remove all nodes and entities outside the map area
  12. local function removeNodesOutsideMap()
  13.     -- Use a bounding box to get entities within a large area
  14.     local boundingBox = {
  15.         {mapMinX - 500, mapMinY - 500},  -- Add a buffer outside the map bounds
  16.         {mapMaxX + 500, mapMaxY + 500}
  17.     }
  18.     local entities = game.interface.getEntities(boundingBox, { })  -- Fetch entities within bounding box
  19.     print("Number of entities found: " .. #entities)  -- Debug print to check how many entities are found
  20.  
  21.     for _, entityId in ipairs(entities) do
  22.         local entity = game.interface.getEntity(entityId)  -- Get the entity data
  23.        
  24.         if entity then
  25.             print("Entity Type: " .. tostring(entity.type))  -- Debugging line to check entity types
  26.             if entity.position and isOutsideMapArea(entity.position) then
  27.                 -- Check if entity is a node or any type of object
  28.                 print("Removing entity with ID: " .. tostring(entityId))  -- Debugging line
  29.                 game.interface.removeEntity(entityId)  -- Remove the entity
  30.             end
  31.         end
  32.     end
  33. end
  34.  
  35. -- Run the node removal function
  36. removeNodesOutsideMap()
  37.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement