Jump to content
Sign in to follow this  
pcgamers123

Simple Suicide & Dead Man's Switch script

Recommended Posts

<<FIXED IT!>>

 

Hello! So I just started to try out some scripting in Arma 3, and it's been fun so far. But I have stumbled upon a little issue that I can't get by.

To test, I'm running two versions of Arma 3 on my PC, where one of them is hosting a local server. When I enable Dead Man's Switch (further abbreviated as 'DMS') on the host player game, it removes both of the actions as it should, but when I enable DMS on the player that is connected to the local server, it only removes the DMS action, and not my "blow up" action. I also added debug hints in the init.sqf file, but the connected local client didn't see those hints, only the host player.
In the end, I will use this on my dedicated server.
I have other classes too, but I reckon those won't be necessary.

Dead Man's Switch Class:

//the suicide bomber
_bomber = _this select 0;

if((_bomber getVariable "is_dead_man") == "false") then {
	_bomber setVariable["is_dead_man", "true"];
	
	//Check if player dies
	//[player] execVM "scripts\suicide_bomber\explode.sqf";
	//[[[player], "scripts\suicide_bomber\explode.sqf"], "BIS_fnc_execVM", false, true] call BIS_fnc_MP; 
	_bomber addEventHandler ["Killed", {
		_pl = _this select 0;
		_pl execVM "scripts\suicide_bomber\allahu_akbar.sqf";
		}];
	
	//Remove Dead Man's Switch
	_id = _bomber getVariable "DeadMansSwitch";
	_bomber removeAction (_id);
	
	_id2 = _bomber getVariable "AllahuAkbar";
	_bomber removeAction (_id2);
	
	hint "Dead Man's Switch has been enabled!";
	sleep 4;
	hint "";
}

Explode Class:

//if (!hasInterface || isServer) exitWith {};

//the suicide _bomber
_bomber = _this select 0; //player;

if ((!isServer) && (_bomber != player)) then
{
  waitUntil {_bomber == player};
};

explodeFunc = {
	_ammoType = "Bo_GBU12_LGB_MI10";

	_bombLoc = GetPos _bomber;
	_bombLocX = _bombLoc select 0;
	_bombLocY = _bombLoc select 1;
	_bombLocZ = _bombLoc select 2;

	//suicide action
	_ammoType createVehicle[_bombLocX, _bombLocY, _bombLocZ];

	_bomber setdammage 1;
};

explode = {
	_bomber say "allahu"; //playSound "allahu";
	sleep 1.7;
	call explodeFunc;
};

immediate_explode = {
	call explodeFunc;
};

if("SatchelCharge_Remote_Mag" in (items _bomber + assignedItems _bomber + backpackitems _bomber + vestItems _bomber) || "ATMine_Range_Mag" in (items _bomber + assignedItems _bomber + backpackitems _bomber + vestItems _bomber) || "APERSMine_Range_Mag" in (items _bomber + assignedItems _bomber + backpackitems _bomber + vestItems _bomber) || "APERSBoundingMine_Range_Mag" in (items _bomber + assignedItems _bomber + backpackitems _bomber + vestItems _bomber) || "SLAMDirectionalMine_Wire_Mag" in (items _bomber + assignedItems _bomber + backpackitems _bomber + vestItems _bomber) || "APERSTripMine_Wire_Mag" in (items _bomber + assignedItems _bomber + backpackitems _bomber + vestItems _bomber) || "ClaymoreDirectionalMine_Remote_Mag" in (items _bomber + assignedItems _bomber + backpackitems _bomber + vestItems _bomber) || "DemoCharge_Remote_Mag" in (items _bomber + assignedItems _bomber + backpackitems _bomber + vestItems _bomber) || "IEDUrbanBig_Remote_Mag" in (items _bomber + assignedItems _bomber + backpackitems _bomber + vestItems _bomber) || "IEDLandBig_Remote_Mag" in (items _bomber + assignedItems _bomber + backpackitems _bomber + vestItems _bomber) || "IEDUrbanSmall_Remote_Mag" in (items _bomber + assignedItems _bomber + backpackitems _bomber + vestItems _bomber) || "IEDLandSmall_Remote_Mag" in (items _bomber + assignedItems _bomber + backpackitems _bomber + vestItems _bomber) || "HandGrenade" in (items _bomber + assignedItems _bomber + backpackitems _bomber + vestItems _bomber) || "MiniGrenade" in (items _bomber + assignedItems _bomber + backpackitems _bomber + vestItems _bomber) || "HandGrenade_Stone" in (items _bomber + assignedItems _bomber + backpackitems _bomber + vestItems _bomber)) then {
	
        if((_bomber getVariable "is_dead_man") == "true") then {
		call immediate_explode;
		//Remove EventHandler from player
		_bomber removeEventHandler["Killed", 0];
		_bomber setVariable["is_dead_man", "false"];
		_bomber setVariable["DeadMansSwitch", _bomber addAction["<t color='#FF0000'>Dead Man's Switch</t>", "scripts\suicide_bomber\dead_mans_switch_exec.sqf"]];
	}
	else {
		call explode;
	}
}
else {
	hint "You don't have any explosives on you!";
	_bomber addItem "DemoCharge_Remote_Mag";
	sleep 4;
	hint "";
}
  • Like 1

Share this post


Link to post
Share on other sites

This:

 

   _ammoType = "Bo_GBU12_LGB_MI10";

    _bombLoc = GetPos _bomber;
    _bombLocX = _bombLoc select 0;
    _bombLocY = _bombLoc select 1;
    _bombLocZ = _bombLoc select 2;

    //suicide action
    _ammoType createVehicle[_bombLocX, _bombLocY, _bombLocZ];

is the same as this:

    "Bo_GBU12_LGB_MI10" createVehicle getPos _bomber;

Every line of code saves a puppy out there.

 

 

 

A rather important suggestion:

You could simplify that humongous nightmare inducing if statement (this can't be good, right?).

The entire

items _bomber + assignedItems _bomber + backpackItems _bomber + vestItems _bomber bleh bleh bleh

sausage isn't necessary at all since you can check for explosives with magazines player.

Explosives will NEVER be returned by 'items' or 'assignedItems' commands, so these checks are not valid.

Just checking for your huge condition takes 0.058 ms on my machine (~700% slower than my following suggestion).

 

A simple

_bomber = player;
_explosives =["SatchelCharge_Remote_Mag","ATMine_Range_Mag","APERSMine_Range_Mag","APERSBoundingMine_Range_Mag","SLAMDirectionalMine_Wire_Mag","APERSTripMine_Wire_Mag","ClaymoreDirectionalMine_Remote_Mag","DemoCharge_Remote_Mag","IEDUrbanBig_Remote_Mag","IEDLandBig_Remote_Mag","IEDUrbanSmall_Remote_Mag","IEDLandSmall_Remote_Mag","HandGrenade","MiniGrenade","HandGrenade_Stone"];
_hasExplosive = false;
if (count (_explosives arrayIntersect magazines _bomber) > 0) then {_hasExplosive = true};

is a bit better to read/modify and executes at an average time of 0.007 ms on my machine.

You can also easily add mod explosives to the array.

 

If you have to check the same stuff twice in the same condition put it in a variable beforehand to get a, most likely, significant performance increase.

 

Cheers

  • Like 2

Share this post


Link to post
Share on other sites

This:

   _ammoType = "Bo_GBU12_LGB_MI10";

    _bombLoc = GetPos _bomber;
    _bombLocX = _bombLoc select 0;
    _bombLocY = _bombLoc select 1;
    _bombLocZ = _bombLoc select 2;

    //suicide action
    _ammoType createVehicle[_bombLocX, _bombLocY, _bombLocZ];

is the same as this:

    "Bo_GBU12_LGB_MI10" createVehicle getPos _bomber;

Every line of code saves a puppy out there.

 

 

 

A rather important suggestion:

You could simplify that humongous nightmare inducing if statement (this can't be good, right?).

The entire

items _bomber + assignedItems _bomber + backpackItems _bomber + vestItems _bomber bleh bleh bleh

sausage isn't necessary at all since you can check for explosives with magazines player.

Explosives will NEVER be returned by 'items' or 'assignedItems' commands, so these checks are not valid.

Just checking for your huge condition takes 0.058 ms on my machine (~700% slower than my following suggestion).

 

A simple

_bomber = player;
_explosives =["SatchelCharge_Remote_Mag","ATMine_Range_Mag","APERSMine_Range_Mag","APERSBoundingMine_Range_Mag","SLAMDirectionalMine_Wire_Mag","APERSTripMine_Wire_Mag","ClaymoreDirectionalMine_Remote_Mag","DemoCharge_Remote_Mag","IEDUrbanBig_Remote_Mag","IEDLandBig_Remote_Mag","IEDUrbanSmall_Remote_Mag","IEDLandSmall_Remote_Mag","HandGrenade","MiniGrenade","HandGrenade_Stone"];
_hasExplosive = false;
if (count (_explosives arrayIntersect magazines _bomber) > 0) then {_hasExplosive = true};

is a bit better to read/modify and executes at an average time of 0.007 ms on my machine.

You can also easily add mod explosives to the array.

 

If you have to check the same stuff twice in the same condition put it in a variable beforehand to get a, most likely, significant performance increase.

 

Cheers

Thank you! I guess I'll go and save some puppies then ;)

  • Like 1

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  

×