Jump to content

Remove objects


jsr9597

Recommended Posts

Anyone knows how to do this with Moose? Is there a handy "ZONE:RemoveScenery" function?

 

I've been at it for several hours and I'm starting to think that those helicopter objects can't be targeted by scripts atm (they seem to be "out of reach", just like cockpit arguments).

 

They don't seem to belong to any of the main DCS object categories (UNIT / WEAPON / STATIC / SCENERY / BASE / CARGO), so world.searchObjects() doesn't work on them (which means that I'm out of ideas :cry:).

 

Oddly enough, static Sea Shelf Objects can't be targeted either, since they no longer seem to use category 0, like they did last month (perhaps EDevs changed this in a recent update).

 

I've attached a modified version of Quadrafarian's demo mission (+script), which uses a standard DCS script to detect all objects within the zone (based on their DCS category).

 

As I said, the Mi-8s aren't detected (the crates and barrels aren't detected either), but the AAV7 and the nearby airbase truck are detected...

 

Here's the script I used:

 

 

local DetectionZone = trigger.misc.getZone('Detection_Zone')

 

local Loop = 1

 

local DCSCategoryTable = { 0, 1, 2, 3, 4, 5, 6 } -- 0 = VOID, 1 = UNIT, 2 = WEAPON, 3 = STATIC, 4 = BASE, 5 = SCENERY, 6 = CARGO. (Sea shelf objects were included in category 0 a month ago. Now they don't seem to have a category)

 

local LandSphere = {

id = world.VolumeType.SPHERE,

params = {

point = DetectionZone.point,

radius = DetectionZone.radius

}

}

 

local function ScheduledZoneDetection(Loop, time)

 

local function DetectLandZone( ZoneObject )

 

local Name = ZoneObject:getName()

local TypeName = ZoneObject:getTypeName()

local Category = ZoneObject:getCategory()

 

trigger.action.outText("Category "..Category.." object found!\nName = "..Name.."\nType = "..TypeName,5)

 

end

 

world.searchObjects(DCSCategoryTable, LandSphere, DetectLandZone )

 

if Loop == 1 then

return time + 10

end

end

 

timer.scheduleFunction(ScheduledZoneDetection, Loop, timer.getTime() + 1)

 

 

I've checked and tested several MOOSE classes and it does look like the standard world.searchObjects() DCS method is the best way to go.

Zone Object Detection by Category.miz

Object Detection in Zone Test.lua


Edited by Hardcard
Link to comment
Share on other sites

Yeah there are a lot of world objects that simply aren't returned at all via world.searchObjects. Usually smaller stuff and trees, but for instance on Persian Gulf a lot of the boats aren't returned. I filed a bug report on it. I think it might just be a master list of object types that it can or cannot return and that list is incomplete. Wonder if an event handler can see them if you damage the object. If so its runtime Id should be static so it might be possible to remove them.

 

Sea shelf objects should be seen as static objects, however they suffer from a bug that for some stupid reason FARP related objects aren't accessible to the scripting engine. StaticObject.getByName() on a FARP just returns nil. (Also reported)

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

Hi Grimes, I was just thinking about you! :D

 

I noticed something odd in the Hoggit documentation and some clarification would be appreciated.

 

Is this table discrepancy accurate or is it some sort of typo?

 

 

-- Object.Category table from the Hoggit Wiki

Object.Category

UNIT 1

WEAPON 2

STATIC 3

SCENERY 4

BASE 5

Cargo 6

 

-- StaticObject.Category table from the Hoggit Wiki

 

StaticObject.Category = {

"VOID": 0,

"UNIT": 1,

"WEAPON": 2,

"STATIC": 3,

"BASE": 4,

"SCENERY": 5,

"CARGO": 6

}

 

 

Shouldn't both Objects and StaticObjects use the same Category table?

 

Wonder if an event handler can see them if you damage the object. If so its runtime Id should be static so it might be possible to remove them.

 

Hey, you might be onto something here!

Last month I got the categories from those sea shelf objects by using an event handler for a DEAD event!

I'll add an event handler to the script, see if I get lucky!

 

Thanks!


Edited by Hardcard
Link to comment
Share on other sites

Typo.

 

Nice, thanks!

 

I'm assuming that this is the correct one, right?:

 

 

StaticObject.Category = {

"VOID": 0,

"UNIT": 1,

"WEAPON": 2,

"STATIC": 3,

"BASE": 4,

"SCENERY": 5,

"CARGO": 6

}

 

 

As for the event handler idea, I think it will work.

I made an AI Su-24 bomb those Mi-8s earlier this afternoon and the mission report did return their DEAD event initiator names (I believe they were using "monument" as name, isn't that weird?).


Edited by Hardcard
Link to comment
Share on other sites

If I do the following with Moose:

 

local zone = ZONE:New("TestZone")
env.info("zone data " .. zone:GetName() .. "," .. zone:GetVec2().x .. "," .. zone:GetVec2().y .. "," .. zone:GetRadius())
zone:Scan(Object.Category.SCENERY)
for scenType, scenObjects in pairs(zone:GetScannedScenery()) do
  for k,scenObject in pairs(scenObjects) do
      env.info("destroying scenery object")
      scenObject:GetDCSObject():destroy()
  end
end 

Then the log shows "destroying scenery object" several times, but it is not clear that any objects are actually removed. If I set the zone around a unit, like this:

local zone = ZONE_RADIUS:New("temp", unit:GetVec2(), 1000)

then nothing is removed (the unit is near some trees and a village) and the text "destroying scenery object" is not called. It is completely unclear to me what GetScannedScenery actually returns.

Link to comment
Share on other sites

It is completely unclear to me what GetScannedScenery actually returns.

 

According to the declaration, I think it returns a subtable called 'Scenery' (which is located inside the table 'ScanData') :

return self.ScanData.Scenery

 

Now, if I have to guess, 'Scenery' subtable might contain information about the SCENERY objects found in the zone radius.

 

For instance, if you do :GetScannedSceneryType(), this seems to return the object type by reading from the 'Scenery' subtable.

 

Here's the declaration of this method:

ZONE_RADIUS:GetScannedSceneryType( SceneryType )
 return self.ScanData.Scenery[sceneryType]
end

 

Anyway, it really bugs me that some static and scenery objects don't have a DCS category assigned. This makes Object.Category.x virtually useless :cry:

Link to comment
Share on other sites

Anyway, it really bugs me that some static and scenery objects don't have a DCS category assigned. This makes Object.Category.x virtually useless :cry:

I hear you. Do you know what Object.Category a tree would be? I'm just trying to clear the trees around group spawned within a zone (sometimes I have rocket artillery in the middle of a forest, doesn't stop them from firing, but it looks rather silly and it is hard to spot them).

Link to comment
Share on other sites

Ok , guys!

 

After many hours of trial and error, I've had some minor success in getting a few values from those elusive objects!

 

So far, I've been able to access their description tables in order to get displayName, typeName, category and life (initial life, that is).

 

However, I can only work with these elusive DCS objects when their DEAD events happen :cry:

 

Here's the script I've used (demo mission + script file attached):

 

 

local Event_Handler = {}

 

function Event_Handler:onEvent(Event)

 

if Event.id == 8 and Event.initiator ~= nil then -- If it's a DEAD Event and the initiator is reachable

 

local InitiatorObject = Event.initiator -- This successfully captures the elusive objects (as long as the event supports them)

 

--local InitiatorName = InitiatorObject:getName() -- Targets the "runway crater objects" created by the bomb explosions...not helpful!

 

--local InitiatorTypeName = InitiatorObject:getTypeName() -- Targets the "runway crater objects" created by the bomb explosions...not helpful!

 

--local InitiatorCategory = InitiatorObject:getCategory() -- Targets the "runway crater objects" created by the bomb explosions...not helpful!

 

local InitiatorDescTable = InitiatorObject:getDesc() -- In order get the values that we want from the elusive objects, we need to access their description tables!

 

local InitiatorDescTableDisplayName = InitiatorDescTable.displayName -- Returns the displayName of the elusive objects from their description tables. The returned value seems to be a blank string

 

local InitiatorDescTableTypeName = InitiatorDescTable.typeName -- Returns the typeName of the elusive objects from their description tables

 

local InitiatorDescTableCategory = InitiatorDescTable.category -- Returns the category of the elusive objects from their description tables (returned value is 4, but it doesn't seem to correspond to the Object.Category value)

 

local InitiatorDescTableLife = InitiatorDescTable.life -- Returns the initial hp of the elusive objects from their description tables

 

if InitiatorDescTableTypeName == "MI-8" or InitiatorDescTableTypeName == "AN-2M" then -- We'll only target the elusive MI-8s and AN-2Ms

 

trigger.action.outText("Elusive object has been destroyed!\nName = "..InitiatorDescTableDisplayName.."\nType = "..InitiatorDescTableTypeName.."\nCategory = "..InitiatorDescTableCategory.."\nInitial Life = "..InitiatorDescTableLife,5)

 

end

end

end

 

world.addEventHandler(Event_Handler)

 

 

Any ideas on why the methods marked in red target the runway craters instead of the elusive objects?

 

There's another interesting thing, you'll see the following errors in dcs.log when you run the mission:

 

2019-02-03 23:08:09.686 ERROR   wInfo: can't open Objects[MI-8] table
2019-02-03 23:08:09.694 ERROR   wInfo: can't open Objects[bARREL] table
2019-02-03 23:08:09.695 ERROR   wInfo: can't open Objects[WOOD_BOX_01] table
2019-02-03 23:08:09.697 ERROR   wInfo: can't open Objects[WOOD_BOX_02] table
2019-02-03 23:08:09.872 ERROR   wInfo: can't open Objects[uRAL_ATZ_P1] table
2019-02-03 23:09:01.032 ERROR   wInfo: can't open Objects[AN-2M] table

Elusive Objects Test.miz

Elusive objects.lua


Edited by Hardcard
  • Like 1
Link to comment
Share on other sites

  • Recently Browsing   0 members

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