Jump to content
Sign in to follow this  
champ-1

Check if IED already activated

Recommended Posts

I have vehicle with this init:

this addAction ["Activate IED", "scripts\activate_ied.sqf"]

Which runs this script:

_veh = _this select 0;
_unit = _this select 1;
_id = _this select 2;
_not_used = 1;

_unit playmove "AinvPknlMstpSlayWrflDnon_medic";
sleep 3;
_veh removeAction _id;

_unit addAction ["Touch Off IED","
sleep (random 2);
""Bo_GBU12_LGB"" createVehicle (getPos ied_truck);
(_this select 0) removeAction (_this select 2);
_not_used = 0;
"];

if (((_not_used) == 1) and (!alive _unit)) then {
while {true} do {
	"Bo_GBU12_LGB" createVehicle (getPos ied_truck);
	_not_used = 0;
	sleep 5;
};
}

The idea is to make IED blow up on distant activation or player death. But I need to check if bomb already explode so it doesn't detonate twice.

This doesn't seems to work no matter what I try. IED either explode twice or doesn't explode on unit death at all.

Please help.

Share this post


Link to post
Share on other sites

That loop at the bottom of your code. Once that is true it will keep exploding no matter what.

if(!alive _unit) then 
{
 while{true}
do
{
       if(_not_used == 1) exitWith 
       { 
           Bo_GBU12_LGB" createVehicle (getPos ied_truck);
           _not_used = 0;
       }
       else
       {
          sleep 5;
       }
}

Share this post


Link to post
Share on other sites
That loop at the bottom of your code. Once that is true it will keep exploding no matter what.
This doesn't work:

if (!alive _unit) then {
while {true} do {
	if (_not_used == 1) exitWith {
		"Bo_GBU12_LGB" createVehicle (getPos ied_truck);
		_not_used = 0;
	} else {	
		sleep 5;
	};
};
};

And this doesn't work too:

if (!alive _unit) then {
while {true} do {
	if (_not_used == 1) exitWith {
		"Bo_GBU12_LGB" createVehicle (getPos ied_truck);
		_not_used = 0;
	};
sleep 5;
};
};

:(

Share this post


Link to post
Share on other sites

It didn't explode on player death.

Share this post


Link to post
Share on other sites
 while{true}
do
{
       if(!alive _unit) exitWith 
       { 
           Bo_GBU12_LGB" createVehicle (getPos ied_truck);
       }
       else
       {
          sleep 5;
       };
};

Okay now that I know what you want this should work.

Share this post


Link to post
Share on other sites
Okay now that I know what you want this should work.
Not execly what I wanted. My script adds action to touch off IED. So if I blow up IED first and then die it will explode twice. Which is what I'm trying to avoid here.

Share this post


Link to post
Share on other sites
Question what is the purpose of _not_used?
To check if IED is already exploded or not.

When I touch off IED manually it will set _not_used variable to false (0), so it wouldn't explode on player death.

But it doesn't work as I wanted.

Share this post


Link to post
Share on other sites
	while {true} do 
{
       if(!alive _unit && _not_used == 1) then 
	{
		"Bo_GBU12_LGB" createVehicle (getPos ied_truck);
		_not_used = 0;
	}
	else
	{
		if(!alive _unit && _not_used == 0 ) exitWith {}
		else
		{
			if(_unit distance _veh < 5 && _not_used == 1) exitWith
			{
				"Bo_GBU12_LGB" createVehicle (getPos ied_truck);
				_not_used = 0;
			};

		};
	};
       sleep 5;
   };

will this work? I think I checked for every condition. You may have to fix some syntax errors that I'm unaware of.

Share this post


Link to post
Share on other sites

The problem is your use of _not_used, As it is a local variable it is out of scope when setting in the second addAction and the first script will no nothing about its new value.

_veh = _this select 0;
_unit = _this select 1;
_id = _this select 2;
_veh setVariable ["IED_used", false];

_unit playMove "AinvPknlMstpSlayWrflDnon_medic";
sleep 3;
_veh removeAction _id;

_unit addAction ["Touch Off IED","
   sleep (random 2);
   ""Bo_GBU12_LGB"" createVehicle (getPos (_this select 3));
   (_this select 0) removeAction (_this select 2);
   (_this select 3) setVariable ['IED_used', true];
",_veh];

waitUntil { ( (_veh getVariable "IED_used") || !(alive _unit))};
if ( !(_veh getVariable "IED_used")) then {
"Bo_GBU12_LGB" createVehicle (getPos _veh);
}; 

Here i have set a value on the actual vehicle itself IED_used as false, i then pass a reference to the vehicle into the second addAction (_this select 3). If you use the second addAction to explode the IED then the variable on the vehicle is set to true.

Mean while the first action is waiting for either the variable on the vehicle to become true or the player with the action to die. On either becoming true then it will finish the script , if the IED_used variable is still false then it will explode the bomb.

Think that looks about right untested though

Share this post


Link to post
Share on other sites
The problem is your use of _not_used, As it is a local variable it is out of scope when setting in the second addAction and the first script will no nothing about its new value.

Here i have set a value on the actual vehicle itself IED_used as false, i then pass a reference to the vehicle into the second addAction (_this select 3). If you use the second addAction to explode the IED then the variable on the vehicle is set to true.

Mean while the first action is waiting for either the variable on the vehicle to become true or the player with the action to die. On either becoming true then it will finish the script , if the IED_used variable is still false then it will explode the bomb.

Think that looks about right untested though

Oh yeah, works like a charm.

Though can you explain me these two strings please, so I don't make dumb threads in the future.

waitUntil { ( (_veh getVariable "IED_used") || !(alive _unit))};
if ( !(_veh getVariable "IED_used")) then {

Why there is no check for true or false value? How it works?

Share this post


Link to post
Share on other sites

The variable itself is either true or false ( the return from _veh getVariable "IED_used" ) so there is no need to compare it against anything.

You could say

if ( (_veh getVariable "IED_used") == false ) then {  

but

if ( !(_veh getVariable "IED_used")) then { 

If _veh getVariable "IED_used" is false then !false is true

Mmm hope that makes sense :/

Share this post


Link to post
Share on other sites
Mmm hope that makes sense :/
Yeah, thanks. Now I understand it more or less. :D

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  

×