Home   Help Search Login Register  

Author Topic: Count destroyed buildings in a zone  (Read 1072 times)

0 Members and 1 Guest are viewing this topic.

Offline Gnat

  • Addons Depot
  • Former Staff
  • ****
  • I Bite!
    • Gnats
Count destroyed buildings in a zone
« on: 20 Aug 2008, 12:29:58 »
Searched but not found something that matches.
Looking for a simple mission trigger where X% or >X buildings within a radius of a gamelogic or within the Trigger zone are destroyed.
I don't want to have to record the object ID for every object or building and script test every one, I just want to know the zone is very much been bombed back to the stone age!
The count including objects and vehicles etc is of no concern.

Thx  :D

Offline Planck

  • Honoured
  • Former Staff
  • ****
  • I'm never wrong ....I'm just not always right !
Re: Count destroyed buildings in a zone
« Reply #1 on: 20 Aug 2008, 12:39:23 »
Hmmmm, maybe check how many building models have been replaced by the Ruins class equivalent?

Just thinking aloud.


Planck
I know a little about a lot, and a lot about a little.

Offline Spooner

  • Members
  • *
  • Mostly useless
    • Community Base Addons
Re: Count destroyed buildings in a zone
« Reply #2 on: 20 Aug 2008, 13:26:33 »
Well, triggers only pick up vehicles, but you can still use a trigger for this. Name a trigger, "devastation". To check if there are greater than 5 ruined buildings within 200m of the trigger:
Code: (trigger condition) [Select]
(count nearestObjects [getPos devastation, ["Ruins"], 200]) > 5

Note that this will include any ruins that are already placed at the start of the mission, for example those in Corazol.

If you want lower cpu load (e.g. if you need to check a lot of buildings or a very large area), you could add KILLED handlers to all the buildings in a given area with each handler adding 1 to a count of destroyed buildings and if the count is too large at that point, it could run a handler function:
Code: (devastation.sqf) [Select]
// [getPos devastationLogic, 1000, 5, { player sideChat "Devastation!" }] execVM "devastation.sqf";
_centre = _this select 0;
_radius = _this select 1;
ruinsMax = _this select 2; // Buildings destroyed for handler to fire.
ruinsHandler = _this select 3; // Function to call when too many ruins.

_buildings = nearestObjects [_centre, ["House", "FuelStation", "Church"], _radius];

ruinsCount = 0;

{
_x addEventHandler ["KILLED", {
ruinsCount = ruinsCount + 1;
if (ruinsCount == ruinsMax) then
{
call ruinsHandler;
};
}];
} forEach _buildings;

EDIT: Probably best to add handler to just ["House", "FuelStation", "Church"] rather than to all ["Strategic"].
« Last Edit: 20 Aug 2008, 15:35:44 by Spooner »
[Arma 2] CBA: Community Base Addons
[Arma 1] SPON Core (including links to my other scripts)

Offline Gnat

  • Addons Depot
  • Former Staff
  • ****
  • I Bite!
    • Gnats
Re: Count destroyed buildings in a zone
« Reply #3 on: 20 Aug 2008, 14:32:09 »
Darn that was quick Spooner!
It worked perfectly ..... legend!  :good: