Jump to content
Sign in to follow this  
guyfawkestom

Checking if engine has been destroyed

Recommended Posts

Good Morning to all of you,

After a year without touching Arma2 I decided to come back to mission making. I surprised myself by being able to understand and write little pieces of script...

Anyway, I wanted to recreate objectives of the mission PMC05 elimination where you have to destroy engine block of armoured vehicle.

--------------------------------------------------------------------------EDIT--------------------------------------------------------------------------------

But after searching all over the forums, I did not find an answer.

Thanks to this topic : http://forums.bistudio.com/showthread.php?111384-fired-eventhandler-count-how-many-rounds-fired and [FRL]Myke, I managed to write a completely functional script for as mush vehicle as needed

In the init line of the vehicle :

0 = [this] execVM "scripts\chkmotEH.sqf" // adapt the path that you want

chkmotEH.sqf

private ["_unitsht"];
_unitsht = _this select 0; // Target vehicle - init line : 0 = [this] execVM "scripts\chkmotEH.sqf";
_unitsht setVariable ["ShotsTaken", 0]; // unit (vehicle) variablespace to store the required variables
if (isnil "gf_dmgcnt") then {
	gf_dmgcnt = { // stting up of the fonction related to handle damage, that will handle the number of hits.
private ["_unitsht","_loc","_dmgval","_shooter","_ammun"];
_unitsht = _this select 0;
_loc = _this select 1;
_dmgval = _this select 2;
_shooter = _this select 3;
_ammun = _this select 4;
if ((_loc == "motor") and // required target selection
	(_dmgval > 0.02) and  // damage value for direct hit
	(_ammun == "B_127x99_Ball_noTracer" )) // type of ammo to damage
										then { 
_unitsht setVariable ["ShotsTaken", (_unitsht getVariable "ShotsTaken") + 1];
//hint format ["%1", (_unitsht getVariable "ShotsTaken")];// hint the value of the hit stored in Shotstaken
												 if ((_unitsht getVariable "ShotsTaken") == 6) // 3 or 4 shots to call the script fx
																then 	{
		0=[_unitsht] execVM "[b]scripts\chkmotfx.sqf[/b]"; // script fx in an external script for allowing sleep, adapt the path that you want of course
																		};
												 };
				};
						};
gf_chkmotEH = _unitsht addEventHandler ["handledamage", {_this call gf_dmgcnt}]; // finally the EH setup
exit

chkmotfx.sqf

private ["_unitsht2"];
_unitsht2 = _this select 0;
hint "motor has been destroyed";
_unitsht2 setFuel 0;
_unitsht2 lock true;
_gfLogic = "logic" createvehiclelocal (getposASL _unitsht2);
_gfLogic attachTo [_unitsht2, [0,-2,0], "motor"]; 
0 = [_gfLogic,0.75,750,false,false] spawn BIS_Effects_Burn;
sleep 2;
{unassignVehicle _x} foreach crew _unitsht2;
crew _unitsht2 allowGetIn false;
{_x action ["eject", _unitsht2]} foreach crew _unitsht2;
{_x allowfleeing 1} foreach crew _unitsht2;
{_x setdamage 0.5} foreach crew _unitsht2;
{removeallweapons _x} foreach crew _unitsht2;
//{[_x,(getPos _unitsht2),100] call gf_fnc_flee} foreach crew _unitsht2;// to do
exit

With these scripts, once the M107 ammo has hit 3 or 4 times the engine block (selection name : "motor" in brdm-2), chkmotfx.sqf is triggered, smoke starts on the engine block, crew is disembarking, injured, and should flee.

Works at least in SP, I don't play MP. But feel free to tell me.

The problem of Handledamage EH is that it returns two events, for indirect and direct hit, if I caught well. So the trick was to segregate each of them. Fortunately it is more easy than segregating protain from yeast extract, so I asked also for damage value condition, making sure that only the direct Hit was used to increase the hitcount.

I'm sure there is a better way to to that, but it seem to fulfill my requirements. However, if some of you knows how to do a clean script, I'll be very eager to learn proper coding.

Thank you for your help, :)

GFt

Edited by guyfawkestom

Share this post


Link to post
Share on other sites

The script has been updated, but I'd like to have any comments that could optimize the code....

Thanks,

GFt

Share this post


Link to post
Share on other sites

Sounds interesting, I will try this next week after my holidays :)

Share this post


Link to post
Share on other sites

Hello,

I'll be glad to here any advice on that. This script is SP oriented, so I'm not sure that it will work for MP. But I'm happy to obtain such a result. Let me know if you like it.

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  

×