Jump to content

remove Map Objects by Type Name scipt


Veteran66

Recommended Posts

world.searchObjects

 

Search for scenery, use getTypeName() on the object, if its the right string, then use destroy() on the object. Easy way to do it is to make a reference table and list all the object types you want to remove. You might need to first output a list of the object names or make mark panels over an object just so you can get an idea what is what.

 

if searchInclude[obj:getTypeName()] then
  obj:destroy()
end

 

Note. It might not be synced correctly in MP.

The right man in the wrong place makes all the difference in the world.

Current Projects:  Grayflag ServerScripting Wiki

Useful Links: Mission Scripting Tools MIST-(GitHub) MIST-(Thread)

 SLMOD, Wiki wishlist, Mission Editing Wiki!, Mission Building Forum

Link to comment
Share on other sites

  • 3 weeks later...

Use :destroy() within the search function. 

if obj:getTypeName() == 'GREENHOUSE2' then

    obj:destroy()

end 

The right man in the wrong place makes all the difference in the world.

Current Projects:  Grayflag ServerScripting Wiki

Useful Links: Mission Scripting Tools MIST-(GitHub) MIST-(Thread)

 SLMOD, Wiki wishlist, Mission Editing Wiki!, Mission Building Forum

Link to comment
Share on other sites

18 hours ago, Grimes said:

Use :destroy() within the search function. 

if obj:getTypeName() == 'GREENHOUSE2' then

    obj:destroy()

end 

 

 

thx Grimes but your scrip will not work

local foundUnits = {}

 local sphere = trigger.misc.getZone('greenhouse')

 local volS = {

   id = world.VolumeType.SPHERE,

   params = {

     point = sphere.point,

     radius = sphere.radius

   }

 }

 if obj:getTypeName() == 'GREENHOUSE2' then

    obj:destroy()

end


Edited by Veteran66
Link to comment
Share on other sites

Try something like this:

local destroyObject = function(obj, val)
	if obj:getTypeName() == "GREENHOUSE2" then
		obj:destroy()
	end
	return true
end
local zone = trigger.misc.getZone("greenhouse")
local volume = {
	id = world.VolumeType.SPHERE,
	params = {
		point = zone.point,
		radius = zone.radius
	}
}
world.searchObjects(Object.Category.STATIC, volume, destroyObject)

 

Link to comment
Share on other sites

13 minutes ago, Chump said:

Try something like this:


local destroyObject = function(obj, val)
	if obj:getTypeName() == "GREENHOUSE2" then
		obj:destroy()
	end
	return true
end
local zone = trigger.misc.getZone("greenhouse")
local volume = {
	id = world.VolumeType.SPHERE,
	params = {
		point = zone.point,
		radius = zone.radius
	}
}
world.searchObjects(Object.Category.STATIC, volume, destroyObject)

 

don`t work, the Greenhouses in the Trigger greenhouse still there, don`t know what is wrong GREENHOUSE2 maybe?

when i find a working script i can remove all unnecessary objects. This will more comfortable like many Triggers and object remove actions.

Link to comment
Share on other sites

Try it with some debug logic to see what's going on:

local destroyObject = function(obj, val)
	local name = obj:getName()
	local typeName = obj:getTypeName()
	env.info(string.format("** Object: %s (%s)", name, typeName))
	if typeName == "GREENHOUSE2" then
		obj:destroy()
	end
	return true
end
local zone = trigger.misc.getZone("greenhouse")
if not zone then
	env.info("** Zone not found!")
end
local volume = {
	id = world.VolumeType.SPHERE,
	params = {
		point = zone.point,
		radius = zone.radius
	}
}
local num = world.searchObjects(Object.Category.STATIC, volume, destroyObject)
env.info(string.format("** Found %i objects", num))

 

  • Thanks 1
Link to comment
Share on other sites

This is the script used in the attached mission. 

 

 local foundUnits = {}
 local deleteThis = {['GREENHOUSE1'] = true, ['GREENHOUSE2'] = true,}
 local sphere = trigger.misc.getZone('zone')
 local volS = {
   id = world.VolumeType.SPHERE,
   params = {
     point = sphere.point,
     radius = sphere.radius
   }
 }
 
 local ifFound = function(foundItem, val)
   local tName = foundItem:getTypeName()
   if deleteThis[tName] then 
       if not foundUnits[tName] then
            foundUnits[tName] = 0
       end
       foundUnits[tName] = foundUnits[tName] + 1
      foundItem:destroy()
    end
 end

 world.searchObjects(Object.Category.SCENERY, volS, ifFound)

local msg = {'Removed: \n'}
for tName, val in pairs(foundUnits) do
  env.info(tName .. ' : ' .. val)
  msg[#msg+1] = tName .. ' : ' .. val .. '\n'
end

trigger.action.outText(table.concat(msg), 20)

 

Screen_201203_164842.jpg

Screen_201203_164837.jpg

remove_hippy_farmers.miz


Edited by Grimes
  • Thanks 1

The right man in the wrong place makes all the difference in the world.

Current Projects:  Grayflag ServerScripting Wiki

Useful Links: Mission Scripting Tools MIST-(GitHub) MIST-(Thread)

 SLMOD, Wiki wishlist, Mission Editing Wiki!, Mission Building Forum

Link to comment
Share on other sites

wauu yes it work fine, i just test Grimes Mission work very well.

 

Thx Chump and Grimes.

This script is a powerful tool.

Now you can desable not needed Objects like Greenhouse, Road Path limitation and Electricity pylons in the Mission environment, so you get (i hope so) better fps.

Or you can switch off the Runway lighting 🙂

 

(sorry for my bad english)

Link to comment
Share on other sites

Trees are not accessible to the scripting engine unfortunately. Its one of those highly desirable features requests. 

The right man in the wrong place makes all the difference in the world.

Current Projects:  Grayflag ServerScripting Wiki

Useful Links: Mission Scripting Tools MIST-(GitHub) MIST-(Thread)

 SLMOD, Wiki wishlist, Mission Editing Wiki!, Mission Building Forum

Link to comment
Share on other sites

i make a Test Mission with a MapObject_Detection_in_Zone.lua and MapObject_remove.lua script

 

the MapObject_Detection_in_Zone.lua script show the Map Object Type Name in the "zone" Trigger so you have the Object Name 

 

The MapObject_remove.lua script remove the Object you wride in the script and it is in the "zone" Trigger

 

Thx for all who help 🙂

 

MapObject_remove_by_TypeName.miz MapObject_Detection_in_Zone.lua MapObject_remove.lua

Link to comment
Share on other sites

  • Veteran66 changed the title to remove Map Objects by Type Name scipt
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...