Jump to content

Setting a map object to dead


Recommended Posts

Hi,

 

I know that using MIST I can know when a certain map object is dead. But if I want to set dead some object at mission start, is there a function that could allow that to me?

 

PS given that I know the object ID.

 

Thanks in advance.

ChromiumDis.png

Author of DSMC, mod to enable scenario persistency and save updated miz file

Stable version & site: https://dsmcfordcs.wordpress.com/

Openbeta: https://github.com/Chromium18/DSMC

 

The thing is, helicopters are different from planes. An airplane by it's nature wants to fly, and if not interfered with too strongly by unusual events or by a deliberately incompetent pilot, it will fly. A helicopter does not want to fly. It is maintained in the air by a variety of forces in opposition to each other, and if there is any disturbance in this delicate balance the helicopter stops flying; immediately and disastrously.

Link to comment
Share on other sites

No sorry, i mean by script, whitout desteoying it at missione stare

T.. Cause if i will have hundreds of objects... :(

ChromiumDis.png

Author of DSMC, mod to enable scenario persistency and save updated miz file

Stable version & site: https://dsmcfordcs.wordpress.com/

Openbeta: https://github.com/Chromium18/DSMC

 

The thing is, helicopters are different from planes. An airplane by it's nature wants to fly, and if not interfered with too strongly by unusual events or by a deliberately incompetent pilot, it will fly. A helicopter does not want to fly. It is maintained in the air by a variety of forces in opposition to each other, and if there is any disturbance in this delicate balance the helicopter stops flying; immediately and disastrously.

Link to comment
Share on other sites

Yes you're right:

 

To obtain some sort of "persistence" of map objects destroyed in a sequential mission campaign, I'm going to use MIST to retrieve a table of destroyed map object for every mission. Then I print out a csv file with objects' IDs.

 

At the start of the next mission, this file is read and parsed into a table of destroyed objects' IDs, which I would like to use to set those objects "dead".

 

As dooom suggested, My first thought was to set up an explosion trigger for every map objects position, but this way I'm going to have three potential issues:

 

- Object producing smoke every time (even it has been destroyed some mission ago)

- Some performance concern regarding multiple explosions and smoke drawing at mission start.

- Possibity of unwanted collateral damage to sorrounding map object due to explosion power).

 

Given those limitation, which could leave me with the idea of a potential "no go" issues, I'm trying to avoid the explosion by setting the objects dead at mission start.

 

Thanks in advance for your suggestions :)

 

 

PS:

I obviously have sanitize module disabled for this purposes.

ChromiumDis.png

Author of DSMC, mod to enable scenario persistency and save updated miz file

Stable version & site: https://dsmcfordcs.wordpress.com/

Openbeta: https://github.com/Chromium18/DSMC

 

The thing is, helicopters are different from planes. An airplane by it's nature wants to fly, and if not interfered with too strongly by unusual events or by a deliberately incompetent pilot, it will fly. A helicopter does not want to fly. It is maintained in the air by a variety of forces in opposition to each other, and if there is any disturbance in this delicate balance the helicopter stops flying; immediately and disastrously.

Link to comment
Share on other sites

For sure it is something that has been request as a feature, for precisely the reason you want to do it. But I am not sure there is a practical way to do it quite yet.

 

The only plausible method, which is completely untested on my part, is to remove the world object and spawn in a static object replacing it in a "dead" state. There are a few problems with this, for instance not every world object has a static object equivalent. Also I'm not 100% sure the objectIDs are constant from mission to mission or if they are changed if the map changes.

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

Current Projects: Scripting Wiki, Something...

Useful Links: Mission Scripting Tools MIST-(GitHub) MIST-(Thread), SLMOD, IADScript, Mission Editing Wiki!, Mission Building Forum

Link to comment
Share on other sites

So, for the moment, there isn't a way to set a map object dead by script during a mission. Understood :).

ChromiumDis.png

Author of DSMC, mod to enable scenario persistency and save updated miz file

Stable version & site: https://dsmcfordcs.wordpress.com/

Openbeta: https://github.com/Chromium18/DSMC

 

The thing is, helicopters are different from planes. An airplane by it's nature wants to fly, and if not interfered with too strongly by unusual events or by a deliberately incompetent pilot, it will fly. A helicopter does not want to fly. It is maintained in the air by a variety of forces in opposition to each other, and if there is any disturbance in this delicate balance the helicopter stops flying; immediately and disastrously.

Link to comment
Share on other sites

If you have the information of the dead unit and are able to spawn it, you could possible do this by getting the location of the destroyed units.

 

For example -

1. Get position of destroyed units by event handler.

2. Write a table to a file of the unit category + position.

3. Create a script that would respawn a dead unit object (Same category if possible) and position it on the same position in the file.

Link to comment
Share on other sites

Yes, but it's not about units but scenery map objects. Do you think it's possible anyway?

 

Destroyed obj position (and heading, if i'm right) can be retrieved by MIST DB.

 

By Grimes way, insted (after I figured out how I could remove a map object in mission environment), I may replace a obj map... but I have to decide what "destroyed building" model using: if I destroy a bridge or a Factory it would be needed to be replaced with something correct.

ChromiumDis.png

Author of DSMC, mod to enable scenario persistency and save updated miz file

Stable version & site: https://dsmcfordcs.wordpress.com/

Openbeta: https://github.com/Chromium18/DSMC

 

The thing is, helicopters are different from planes. An airplane by it's nature wants to fly, and if not interfered with too strongly by unusual events or by a deliberately incompetent pilot, it will fly. A helicopter does not want to fly. It is maintained in the air by a variety of forces in opposition to each other, and if there is any disturbance in this delicate balance the helicopter stops flying; immediately and disastrously.

Link to comment
Share on other sites

  • 3 months later...

Well, finally I found a way to destroy any map objects that was destroyed last mission at mission start, using those two functions: (the first is scheduled every "n" minutes, the second is launched some seconds after mission start)

 

	-- this function store in a file the destroyed map objects table
DGWS.deadMapObjCollect = function() 
	
	local deadOBJ = ""	

	-- add to the previous data stored in "deadOBJ" string the new data
	for deadId,deadData in pairs(mist.DBs.deadObjects) do
		if deadData.objectType == "building" then -- filter map Objects
			local Id = deadId
			local Pos = deadData.objectPos

			deadOBJ = deadOBJ .. Id .. tss .. Pos.x .. tss  .. Pos.y .. tss  .. Pos.z .. tss .. OPdate .. "\n"
		end
	end	
	
	-- now overwrite the old file (erase previous data)
	local o = io.open(lfs.writedir() .. tabledirectory .. "deadobjects" .. exportfiletype, "w")	
	o:write(deadOBJ)
	o:close()
	
end

 

	-- this function will destroy objects indicated in the 
DGWS.deadMapObjDestroy = function()
	local destroyMethod = 1 -- 0 means by destroy, 1 by explosion
	local u = io.open(lfs.writedir() .. tabledirectory  .. "deadobjects" .. exportfiletype, "r")		
	
	for line in io.lines(u) do
		local rdeadID, rdeadPosX, rdeadPosY, rdeadPosZ, rdeadDate = line:match("(%d-)"..tss.."(.-)"..tss.."(.-)"..tss.."(.-)"..tss.."(.-)$")
			if (rdeadID) then 
			DeadMapObjects[#DeadMapObjects + 1] = { deadID = rdeadID, deadPosX = rdeadPosX, deadPosY = rdeadPosY, deadPosZ = rdeadPosZ, deadDate = rdeadDate}
		end
	end
	u:close()		
	
	for id, DeadData in pairs(DeadMapObjects) do
		local deadX = tonumber(DeadData.deadPosX)
		local deadY = tonumber(DeadData.deadPosY)
		local deadZ = tonumber(DeadData.deadPosZ)
	
		local ExpPos = {
						x = deadX,
						y = deadY,
						z = deadZ
						}
	
		[color="Red"]if destroyMethod == 0 then
			if id then
				SceneryObject.GetById(DeadData.deadID):destroy()
			end[/color]
[color="SeaGreen"]			elseif destroyMethod == 1 then
			if id then
				trigger.action.explosion(ExpPos, 3000)
			end[/color]
		end
	end
	
	
end

 

But I'm forced to use the green method (that will create an explosion to re-destroy the object), cause I'm clearly doing something wrong with the other method, which should make disappear the building (that may is my preffered solution actually...).

 

Can you give some advice? thanks :)

 

 

PS: if you want to try this scripts, you may need to modify some lines cause they are part of a bigger table of functions (DGWS), and it will be necessary to set the sanitize module off.

ChromiumDis.png

Author of DSMC, mod to enable scenario persistency and save updated miz file

Stable version & site: https://dsmcfordcs.wordpress.com/

Openbeta: https://github.com/Chromium18/DSMC

 

The thing is, helicopters are different from planes. An airplane by it's nature wants to fly, and if not interfered with too strongly by unusual events or by a deliberately incompetent pilot, it will fly. A helicopter does not want to fly. It is maintained in the air by a variety of forces in opposition to each other, and if there is any disturbance in this delicate balance the helicopter stops flying; immediately and disastrously.

Link to comment
Share on other sites

Ok given that this could seems crazy but... do you think it's possibile to disable smoke and fire effects in the first 30 minutes since mission start?

 

(This is a pure crazy brainstorming idea... :p )

ChromiumDis.png

Author of DSMC, mod to enable scenario persistency and save updated miz file

Stable version & site: https://dsmcfordcs.wordpress.com/

Openbeta: https://github.com/Chromium18/DSMC

 

The thing is, helicopters are different from planes. An airplane by it's nature wants to fly, and if not interfered with too strongly by unusual events or by a deliberately incompetent pilot, it will fly. A helicopter does not want to fly. It is maintained in the air by a variety of forces in opposition to each other, and if there is any disturbance in this delicate balance the helicopter stops flying; immediately and disastrously.

Link to comment
Share on other sites

I don't know for sure, but the IDs of map objects may be non-deterministic, i.e. the ID of a building might change between mission restarts.

 

If that is the case, the solution would be to enumerate all buildings within, say, five meters of the building position, find the one that matches the position exactly, and destroy() that.

 

I have working code for enumerating buildings lying around somewhere, I'll post it later when I have some time to dig it up (have to go to a lecture in a few minutes).

Link to comment
Share on other sites

That could be a good solution

...

ChromiumDis.png

Author of DSMC, mod to enable scenario persistency and save updated miz file

Stable version & site: https://dsmcfordcs.wordpress.com/

Openbeta: https://github.com/Chromium18/DSMC

 

The thing is, helicopters are different from planes. An airplane by it's nature wants to fly, and if not interfered with too strongly by unusual events or by a deliberately incompetent pilot, it will fly. A helicopter does not want to fly. It is maintained in the air by a variety of forces in opposition to each other, and if there is any disturbance in this delicate balance the helicopter stops flying; immediately and disastrously.

Link to comment
Share on other sites

The following function (untested) should destroy scenery objects around a point (x, y, z) within the given radius.

 

function destroySceneryObjects(x, y, z, radius)
local volume = {
	id = world.VolumeType.SPHERE,
	params = {
		point = {x = x, y = y, z = z},
		radius = radius
	}
}
local function handler(object, data)
	object:destroy()
end

world.searchObjects({Object.Category.SCENERY}, volume, handler, nil)
end

 

Try using something like destroySceneryObjects(deadX, deadY, deadZ, 0.2) to destroy the map object.

Link to comment
Share on other sites

Ian, I'll test it this evening or Tomorrow evening. Thanks so much :)

ChromiumDis.png

Author of DSMC, mod to enable scenario persistency and save updated miz file

Stable version & site: https://dsmcfordcs.wordpress.com/

Openbeta: https://github.com/Chromium18/DSMC

 

The thing is, helicopters are different from planes. An airplane by it's nature wants to fly, and if not interfered with too strongly by unusual events or by a deliberately incompetent pilot, it will fly. A helicopter does not want to fly. It is maintained in the air by a variety of forces in opposition to each other, and if there is any disturbance in this delicate balance the helicopter stops flying; immediately and disastrously.

Link to comment
Share on other sites

All(!) Map objects are available as a model and can be inserted! They hide in the depth of the bazar directory... if you can "deactivate" a map object aka make-it-disappear you could replace it with a destroyed building model of the same type.

If you just need to track strategic targets, e.g. a chemical plant that was destroyed, you could place it on the map. After destruction place a model of the same plant (destroyed).

I'll look for that script I ripped from mudspikes mission "General helicopter operations 1.1"

Shagrat

 

- Flying Sims since 1984 -:pilotfly:

Win 10 | i5 10600K@4.1GHz | 32GB | GeForce RTX 2080S - Acer XB280HK 28" 4k | TrackIR5 | Simshaker & Jetseat | VIRPIL CM 50 Stick & Throttle | MFG Crosswind Rudder Pedals | TM Cougar MFDs | a hand made UFC | AHCP | 2x Elgato StreamDeck (Buttons galore)

Link to comment
Share on other sites

Here we go:

 

the original mission that uses this as part of its Initialization Script is HERE

 

The script as I use it places a "Mosque" with stone Tower and a stone building at the position of Trigger Zone "towerMosque"...

 

It can be easily adapted, or just use the "coalition.addStaticObject" command with the correct objects.

 

So where are these nice Map objects? Have a look here:

"C:\Program Files\Eagle Dynamics\DCS World\Bazar\Terrain\Structures\"

 

...and to better find what you're looking for, have a look at the "Preview" folder! :thumbup:

 

EDIT If you need destroyed buildings look for the "_crash" or "_crush" .EDM files...

 

-- initialize everything

function initialize()

customItems()

 

end

 

-- initial script startup delay

timer.scheduleFunction(initialize, nil, timer.getTime() + 1)

 

--custom static items

function customItems()

local _trgZone1 = trigger.misc.getZone("towerMosque")

local staticBuilding1 = {

["shape_name"] = "bashnja-stena", -- "StoneTower"

["type"] = "bashnja-stena",

["unitId"] = math.random(999, 99999),

["rate"] = 100,

["y"] = _trgZone1.point.z - 10,

["x"] = _trgZone1.point.x + 13,

["name"] = "stonetoweritem",

["category"] = "Fortifications",

["canCargo"] = false,

["heading"] = 0.25,

}

coalition.addStaticObject(country.id.RUSSIA, staticBuilding1)

 

local _trgZone2 = trigger.misc.getZone("towerMosque")

local staticBuilding2 = {

["shape_name"] = "mechet", -- "Mosque"

["type"] = "mechet",

["unitId"] = math.random(999, 99999),

["rate"] = 100,

["y"] = _trgZone2.point.z,

["x"] = _trgZone2.point.x,

["name"] = "mosquebldg",

["category"] = "Fortifications",

["canCargo"] = false,

["heading"] = 0.20,

}

coalition.addStaticObject(country.id.RUSSIA, staticBuilding2)

 

local _trgZone3 = trigger.misc.getZone("towerMosque")

local staticBuilding3 = {

["shape_name"] = "s3", -- "Barrack",

["type"] = "s3",

["unitId"] = math.random(999, 99999),

["rate"] = 100,

["y"] = _trgZone3.point.z - 15,

["x"] = _trgZone3.point.x,

["name"] = "barrackMosqueitem",

["category"] = "Fortifications",

["canCargo"] = false,

["heading"] = 1.80,

}

coalition.addStaticObject(country.id.RUSSIA, staticBuilding3)

 

--local _trgZone4 = trigger.misc.getZone("rock")

--local staticBuilding4 = {

--["shape_name"] = "gold_gate",

--["type"] = "gold_gate",

--["unitId"] = <YOUR ID HERE>,

--["rate"] = 100,

--["y"] = _trgZone4.point.z,

--["x"] = _trgZone4.point.x,

--["name"] = "rockItem",

--["category"] = "Fortifications",

--["canCargo"] = false,

--["heading"] = 6.74,

--}

--coalition.addStaticObject(country.id.RUSSIA, staticBuilding4)

end

--trigger.action.outTextForCoalition(coalition.side.BLUE, string.format("###debug### "), 3)


Edited by shagrat

Shagrat

 

- Flying Sims since 1984 -:pilotfly:

Win 10 | i5 10600K@4.1GHz | 32GB | GeForce RTX 2080S - Acer XB280HK 28" 4k | TrackIR5 | Simshaker & Jetseat | VIRPIL CM 50 Stick & Throttle | MFG Crosswind Rudder Pedals | TM Cougar MFDs | a hand made UFC | AHCP | 2x Elgato StreamDeck (Buttons galore)

Link to comment
Share on other sites

Ian;2209792']The following function (untested) should destroy scenery objects around a point (x, y, z) within the given radius.

 

function destroySceneryObjects(x, y, z, radius)
local volume = {
	id = world.VolumeType.SPHERE,
	params = {
		point = {x = x, y = y, z = z},
		radius = radius
	}
}
local function handler(object, data)
	object:destroy()
end

world.searchObjects({Object.Category.SCENERY}, volume, handler, nil)
end

 

Try using something like destroySceneryObjects(deadX, deadY, deadZ, 0.2) to destroy the map object.

 

Doesn't work, while if I sobstitute the destroy command with a message, it works. There is something not working properly about the destroy() actions... :(

ChromiumDis.png

Author of DSMC, mod to enable scenario persistency and save updated miz file

Stable version & site: https://dsmcfordcs.wordpress.com/

Openbeta: https://github.com/Chromium18/DSMC

 

The thing is, helicopters are different from planes. An airplane by it's nature wants to fly, and if not interfered with too strongly by unusual events or by a deliberately incompetent pilot, it will fly. A helicopter does not want to fly. It is maintained in the air by a variety of forces in opposition to each other, and if there is any disturbance in this delicate balance the helicopter stops flying; immediately and disastrously.

Link to comment
Share on other sites

Object.destroy() is currently bugged for world objects, sadly its been like that for a few patches I think.

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

Current Projects: Scripting Wiki, Something...

Useful Links: Mission Scripting Tools MIST-(GitHub) MIST-(Thread), SLMOD, IADScript, Mission Editing Wiki!, Mission Building Forum

Link to comment
Share on other sites

Object.destroy() is currently bugged for world objects, sadly its been like that for a few patches I think.

 

Sad news.... Since I can get the "life" level using SceneryObject.getLife(object), is it possibile to set the life of the object <1.0 to get it dead? (or it will explode?)


Edited by chromium

ChromiumDis.png

Author of DSMC, mod to enable scenario persistency and save updated miz file

Stable version & site: https://dsmcfordcs.wordpress.com/

Openbeta: https://github.com/Chromium18/DSMC

 

The thing is, helicopters are different from planes. An airplane by it's nature wants to fly, and if not interfered with too strongly by unusual events or by a deliberately incompetent pilot, it will fly. A helicopter does not want to fly. It is maintained in the air by a variety of forces in opposition to each other, and if there is any disturbance in this delicate balance the helicopter stops flying; immediately and disastrously.

Link to comment
Share on other sites

Well, since destroy() bug isn't solved I guess I don't have any other solution...

ChromiumDis.png

Author of DSMC, mod to enable scenario persistency and save updated miz file

Stable version & site: https://dsmcfordcs.wordpress.com/

Openbeta: https://github.com/Chromium18/DSMC

 

The thing is, helicopters are different from planes. An airplane by it's nature wants to fly, and if not interfered with too strongly by unusual events or by a deliberately incompetent pilot, it will fly. A helicopter does not want to fly. It is maintained in the air by a variety of forces in opposition to each other, and if there is any disturbance in this delicate balance the helicopter stops flying; immediately and disastrously.

Link to comment
Share on other sites

Are you all interested in a standalone version of the script? It will work only with explosion and with sanitization module disable.

 

PS

I'm sure that everyone that helped me in this thread are more than able to do that... I'm asking for Others :)

ChromiumDis.png

Author of DSMC, mod to enable scenario persistency and save updated miz file

Stable version & site: https://dsmcfordcs.wordpress.com/

Openbeta: https://github.com/Chromium18/DSMC

 

The thing is, helicopters are different from planes. An airplane by it's nature wants to fly, and if not interfered with too strongly by unusual events or by a deliberately incompetent pilot, it will fly. A helicopter does not want to fly. It is maintained in the air by a variety of forces in opposition to each other, and if there is any disturbance in this delicate balance the helicopter stops flying; immediately and disastrously.

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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