Jump to content
Sign in to follow this  
Spatsiba

Get damage state of building

Recommended Posts

Hey!

 

I'm trying to make a little "side mission" where you destroy an IED factory.

So far it's *mostly* working fine. My biggest issue is sometimes the script decides to pick a previously destroyed building twice. I'm assuming this is because the classname remains the same even after the building is "destroyed".

It's worth mentioning I'm using CUP core buildings. 

 

Here's my code: 

Spoiler

//Pick random building from whitelist.
_buildings = [
	"Land_Ind_Coltan_Main_EP1",
	"Land_Shed_Ind02",
	"Land_Ind_Workshop01_01",
	"Land_Ind_Workshop01_02",
	"Land_Ind_Workshop01_03",
	"Land_Ind_Workshop01_04"
];
_buildingList = [];
{
	_list = [worldSize / 2, worldSize / 2, 0] nearObjects [_x, worldSize];
	_buildingList append _list;
} foreach _buildings;
_building = selectRandom _buildingList;

//My 342324th terrible attempt at fixing this issue.
_buildingChosen = false;

while {!alive _building} do {
	sleep 0.1;
	_building = selectRandom _buildingList;
	if (alive _building) then {
		_buildingChosen = true;
	};
};

waitUntil {
	sleep 0.1; 
	_buildingChosen;
};

//Spawn a bunch of IED factory looking shit in the building (currently spawns flying barrels here and there).
_iedList = [
	"CUP_ammobednaX",
	"Land_Barrel_sand",
	"Barrels",
	"Barrel3",
	"Barrel1",
	"Barrel6",
	"Barrel5",
	"Barrel4"
];
_iedSpots = [_building] call BIS_fnc_buildingPositions;
{
	_ied = createVehicle [selectRandom _iedList, _x];
	_ied setPosAsl _x;
} count _iedSpots;

//Add "task".
_pos = getPos _building;
[west,["Side Mission"],["Recent intel has revealed the location of a nearby IED factory. Destroy it by any means necessary.","Destroy IED Factory",_pos],_pos,true,2,true,"destroy",false] call BIS_fnc_taskCreate;

//When building destroyed, end task and doesn't even delete the _IED because my coding is 5/7. 
//I tried setting _building setDamage 1; to destroy the building completely but this doesn't fix anything neither. 
waitUntil {
	sleep 10;
	damage _building > 0.7;
};
_building setDamage 1;
deleteVehicle _ied;
["Side Mission",true] call BIS_fnc_deleteTask;
systemChat "Side mission COMPLETED!";

 

If you ignore the terrible code and butcheredness due to me trying to fix this problem. You can see it very simply just choose a building on the map, marks it out and waits for you to destroy it. BUT! If I run the code again after completing my last mission it might pick the same building twice. This will mean my team will drive out to destroy an already wrecked building. 

 

My question is: Is there any way to figure out if the building has previously been destroyed?

I've tried checking if the building is damaged after being destroyed, which it apparently is not. I'm assuming this is because after being destroyed a building keeps its classname but changes state. When the state is changed the "Damage", etc is reset. That's all speculation however. 

Share this post


Link to post
Share on other sites

The event handler is added only once and from that time it will fire every time a building anywhere on the map is damaged or destroyed. It's up to you how to handle the event.

  • Like 2

Share this post


Link to post
Share on other sites
Just now, Jezuro said:

The event handler is added only once and from that time it will fire every time a building anywhere on the map is damaged or destroyed. It's up to you how to handle the event.

I didn't see it under mission event handlers (heh).

 

Thanks! 

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
Sign in to follow this  

×