Jump to content

world.searchObjects function example


eekz

Recommended Posts

Could you please give and example of using this function

function array of Airbase world.searchObjects([array of enum Object.Category] or [Object.Category] objectCategory, Volume volume, ObjectSearchHandler handler, any data)

if we have volume:

 

VolumeSphere = {

id = world.VolumeType.SPHERE,

params = {

point = Vec3,

radius = Distance

}

}

 

and we need to get STATIC objects from this volume.

Куплю B-17, можно B-24. B-29 не предлагать!

Burning Skies

=Burning Skies= @ Facebook

Link to comment
Share on other sites

	 local sphere = trigger.misc.getZone('town')
 local volS = {
 id = world.VolumeType.SPHERE,
	params = {
	 point = sphere.point,
	 radius = sphere.radius
	}
	
 }
 local ifFound = function(foundItem, val)
		if foundItem:getTypeName() == val then
			env.info('Tech static object found')
		end
		return true
end

world.searchObjects(Object.Category.STATIC, volS, ifFound, 'TECH')

 

world.searchObjects checks volS as defined by a trigger zone placed in the editor for a static object called "TECH" using the function 'ifFound'.

  • Like 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

With your help, I've done that thingy:

local sphere = trigger.misc.getZone('kobuleti')
 local volS = {
 id = world.VolumeType.SPHERE,
 params = {
  point = sphere.point,
  radius = sphere.radius
 }
}
 
 local ifFound = function(foundItem, val)
 val = foundItem:getTypeName()
 env.info(val .. 'Scenery object found')
  
 return true
end
world.searchObjects(Object.Category.SCENERY, volS, ifFound, val);

:)

Going to add userflag increase by 1 on every found object and make this check periodically, if userflag = 0 then all scenery objects in zone destroyed. Seems nice perspectives of making ground targets with not need to painfully putting every single static in ME.


Edited by eekz

Куплю B-17, можно B-24. B-29 не предлагать!

Burning Skies

=Burning Skies= @ Facebook

Link to comment
Share on other sites

  • 1 year later...
UP

Is it possible to search in trigger zone but not in volume?

 

You can search in a sphere, and then use land.getHeight to filter out anything not on the ground.

 

FYI, in 1.5 I've found searchObjects is a bit fragile when the callback has any sort of error. It doesn't report the error, and it breaks searchObjects until you restart the game entirely. So I've taken to use pcall like this this:

 

local searchCallback = function (object, data)
	local status, err = pcall(function () self:storeBuilding(object, data) end)
	if err then
		env.error("Something went wrong searching " .. err)
	end
	return true
end
local vol = {
	id = world.VolumeType.BOX,
	params = {
		min = self:getMin(),
		max = self:getMax(),
	}
}
world.searchObjects(Object.Category.SCENERY, vol, searchCallback, store)

Link to comment
Share on other sites

You can search in a sphere, and then use land.getHeight to filter out anything not on the ground.

 

FYI, in 1.5 I've found searchObjects is a bit fragile when the callback has any sort of error. It doesn't report the error, and it breaks searchObjects until you restart the game entirely. So I've taken to use pcall like this this:

 

Yep, I know, but I need a cylinder with unlimited heigh but not a sphere :)

Currently it seems that it's impossible to create with current volume types. Probably it's possible to hack using found object coordinates projection to the ground and if projected point in the sphere then return true...

Need to work on that :)


Edited by eekz

Куплю B-17, можно B-24. B-29 не предлагать!

Burning Skies

=Burning Skies= @ Facebook

Link to comment
Share on other sites

Yep, I know, but I need a cylinder with unlimited heigh but not a sphere :)

Then it might be easiest to use a box volume:

 

local vol = {
	id = world.VolumeType.BOX,
	params = {
		min = {x=center.x-radius, z=center.y-radius, y=0},
		max = {x=center.x+radius, z=center.y+radius, y=math.huge}, -- Or a high altitude if math.huge doesn't work
	}
}

 

And in the search callback you can calculate the 2D distance between the center and the object and filter on that.

Link to comment
Share on other sites

  • Recently Browsing   0 members

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