Jump to content

Recommended Posts

Posted

I'm guessing you want to remove an object (ie Greenhouse). Have you tried the action 'Scenery Remove Objects Zone' in ME?

Here is a quick video on how it works:

I would create a small trigger zone for each building you want to remove.

Posted

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

  • 3 weeks later...
Posted (edited)
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
Posted

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)

 

Posted
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.

Posted

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
Posted (edited)

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

Posted

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)

Posted

Can this script be used to remove the trees in the plantations that ground vehicles have such trouble driving through in the Syria map?

 

 

Posted
12 hours ago, Grimes said:

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

That’s a damn shame.

Posted

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

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

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