Sign in to follow this  
Followers 0
AimRabbit

Stealthstick's Explosive-To-Vehicle Script

22 posts in this topic

I need someone who can check the script. I think there is a misstake in a variable. It would be kind if someone can help me.

 

EtVinit.sqf:

waitUntil {time > 0};
[] execVM "addons\EtV.sqf";
waitUntil {!isNil "EtVInitialized"};
[player] call EtV_Actions;

 

EtV.sqf:

/*
	Stealthstick's "Explosive-To-Vehicle" Script
	-Allows players to attach their explosive charges to any vehicle.
*/

EtV_ChargeCheck =
{
	_charge = _this select 0;
	_unit = _this select 1;
	_hasIt = _charge in (magazines _unit);
	_nearVehs = nearestObjects [_unit,["Air","Ship","LandVehicle"],5];
	
	_return = (_hasIt && count _nearVehs > 0 && alive _unit);
	_return
};

EtV_TouchOff =
{
	_array = _this select 3;
	_unit = _array select 0;
	_explosives = _unit getVariable ["charges",[]];
	{
		if(alive _x) then
		{
			"HelicopterExploSmall" createVehicle (position _x);
			deleteVehicle _x;
		};
	} forEach _explosives;
	_unit setVariable ["charges",[]];
};

EtV_UnitCheck =
{
	private "_return";
	_unit = _this select 0;
	_explosives = _unit getVariable ["charges",[]];
	if(count _explosives > 0) then
	{
		_return = true;
	}
	else
	{
		_return = false;
	};
	
	_return
};

EtV_TimedCharge =
{
	_explosive = _this select 0;
	_unit = _this select 1;
	_illogic = group server createUnit ["logic", Position _explosive, [], 0, "FORM"];
	_illogic attachTo [_explosive];
	while {alive _explosive} do
	{
		waitUntil {!isNil {_illogic getVariable "timer"};};
		if(_illogic getVariable "timer" == 0) exitWith 
		{
			_charges = _unit getVariable ["charges",[]];
			_unit setVariable ["charges",_charges - [_explosive]];
			"HelicopterExploSmall" createVehicle (position _explosive);
			deleteVehicle _explosive;
		};
		sleep 1;
		_oldTime = _illogic getVariable "timer";
		_illogic setVariable ["timer",_oldTime - 1];
	};
};

EtV_AttachCharge =
{
	_array = _this select 3;
	_charge = _array select 0;
	_unit = _array select 1;
	private "_class";
	
	_unit removeMagazine _charge;
	_unit playMove "AinvPercMstpSnonWnonDnon_Putdown_AmovPercMstpSnonWnonDnon";
	
	switch _charge do
	{
		case "DemoCharge_Remote_Mag":
		{
			_class = "DemoCharge_Remote_Ammo";
		};
	};
	
	_nearVehicle = (nearestObjects [_unit,["Air","Ship","LandVehicle"],5]) select 0;
	_explosive = _class createVehicle [0,0,0];
	_explosive attachTo [_unit,[0,0,0],"leftHand"];
	_random0 = random 180;
	_random1 = random 180;
	[_explosive,_random0,_random1] call BIS_fnc_SetPitchBank;
	[_explosive,_nearVehicle,_unit,_random0,_random1] spawn
	{		
		_explosive = _this select 0;
		_nearVehicle = _this select 1;
		_unit = _this select 2;
		_random0 = _this select 3;
		_random1 = _this select 4;
		
		sleep 1.5;
		_explosive attachTo [_nearVehicle];
		[_explosive,_random0,_random1] call BIS_fnc_SetPitchBank;
		_unit setVariable ["charges",(_unit getVariable ["charges",[]]) + [_explosive]];
		[_explosive,_unit] spawn EtV_TimedCharge;
	};
};

EtV_ClosestExplosive =
{
	_unit = _this select 0;
	_charges = _unit getVariable ["charges",[]];
	_newArray = [];
	{_newArray = _newArray + [player distance _x];} forEach _charges;
	_closest = _newArray call BIS_fnc_lowestNum;
	_selection = _newArray find _closest;
	_charge = _charges select _selection;
	_charge
};

EtV_Timer =
{
	private "_explosive";
	_array = _this select 3;
	_unit = _array select 0;
	_explosive = [_unit] call EtV_ClosestExplosive;
	_illogic = (nearestObjects [_explosive,["Logic"],50]) select 0;
	if(!isNil "_illogic") then
	{
		_oldTime = _illogic getVariable ["timer",0];
		_illogic setVariable ["timer",_oldTime + 30];
		_newTime = _illogic getVariable "timer";
		hint format ["Explosive timer set to %1 seconds.",_newTime];
	};
};

EtV_UnitCheckTimer =
{
	private "_return";
	_unit = _this select 0;
	_explosives = _unit getVariable ["charges",[]];
	_return = false;
	{if(_unit distance _x <= 5) exitWith {_return = true;};} forEach _explosives;
	_return
};

//[unit] spawn EtV_Actions;
EtV_Actions =
{
	private ["_unit"];
	_unit = _this select 0;
	_unit addAction ["<t color=""#FFE496"">" +"Attach Explosive Charge", EtV_AttachCharge, ["DemoCharge_Remote_Mag",_unit], 1, true, true, "","['DemoCharge_Remote_Mag',_target] call EtV_ChargeCheck"];
	_unit addAction ["<t color=""#FFE496"">" +"Touch-Off Explosives", EtV_TouchOff, [_unit], 1, true, true, "","[_target] call EtV_UnitCheck"];
	_unit addAction ["<t color=""#FFE496"">" +"+30Secs to Timer", EtV_Timer, [_unit], 1, true, true, "","[_target] call EtV_UnitCheckTimer"];
};
//=======================
EtVInitialized = true;

 

Thanks a lot!

Edited by AimRabbit

Share this post


Link to post
Share on other sites

Try making the init look like this:

[] execVM "addons\EtV.sqf";
waitUntil {!isNil "EtVInitialized"};
[player] call EtV_Actions;

And then make the main file look like this:

 

/*
	Stealthstick's "Explosive-To-Vehicle" Script
	-Allows players to attach their explosive charges to any vehicle.
*/

EtV_ChargeCheck =
{
	_charge = _this select 0;
	_unit = _this select 1;
	_hasIt = _charge in (magazines _unit);
	_nearVehs = nearestObjects [_unit,["Air","Ship","LandVehicle"],5];
	
	_return = (_hasIt && count _nearVehs > 0 && alive _unit);
	_return
};

EtV_TouchOff =
{
	_array = _this select 3;
	_unit = _array select 0;
	_explosives = _unit getVariable ["charges",[]];
	{
		if(alive _x) then
		{
			"HelicopterExploSmall" createVehicle (position _x);
			deleteVehicle _x;
		};
	} forEach _explosives;
	_unit setVariable ["charges",[]];
};

EtV_UnitCheck =
{
	private "_return";
	_unit = _this select 0;
	_explosives = _unit getVariable ["charges",[]];
	if(count _explosives > 0) then
	{
		_return = true;
	}
	else
	{
		_return = false;
	};
	
	_return
};

EtV_TimedCharge =
{
	_explosive = _this select 0;
	_unit = _this select 1;
	_illogic = group server createUnit ["logic", Position _explosive, [], 0, "FORM"];
	_illogic attachTo [_explosive];
	while {alive _explosive} do
	{
		waitUntil {!isNil {_illogic getVariable "timer"};};
		if(_illogic getVariable "timer" == 0) exitWith 
		{
			_charges = _unit getVariable ["charges",[]];
			_unit setVariable ["charges",_charges - [_explosive]];
			"HelicopterExploSmall" createVehicle (position _explosive);
			deleteVehicle _explosive;
		};
		sleep 1;
		_oldTime = _illogic getVariable "timer";
		_illogic setVariable ["timer",_oldTime - 1];
	};
};

EtV_AttachCharge =
{
	_array = _this select 3;
	_charge = _array select 0;
	_unit = _array select 1;
	private "_class";
	
	_unit removeMagazine _charge;
	_unit playMove "AinvPercMstpSnonWnonDnon_Putdown_AmovPercMstpSnonWnonDnon";
	
	switch _charge do
	{
		case "DemoCharge_Remote_Mag":
		{
			_class = "DemoCharge_Remote_Ammo";
		};
	};
	
	_nearVehicle = (nearestObjects [_unit,["Air","Ship","LandVehicle"],5]) select 0;
	_explosive = _class createVehicle [0,0,0];
	_explosive attachTo [_unit,[0,0,0],"leftHand"];
	_random0 = random 180;
	_random1 = random 180;
	[_explosive,_random0,_random1] call BIS_fnc_SetPitchBank;
	[_explosive,_nearVehicle,_unit,_random0,_random1] spawn
	{		
		_explosive = _this select 0;
		_nearVehicle = _this select 1;
		_unit = _this select 2;
		_random0 = _this select 3;
		_random1 = _this select 4;
		
		sleep 1.5;
		_explosive attachTo [_nearVehicle];
		[_explosive,_random0,_random1] call BIS_fnc_SetPitchBank;
		_unit setVariable ["charges",(_unit getVariable ["charges",[]]) + [_explosive]];
		[_explosive,_unit] spawn EtV_TimedCharge;
	};
};

EtV_ClosestExplosive =
{
	_unit = _this select 0;
	_charges = _unit getVariable ["charges",[]];
	_newArray = [];
	{_newArray = _newArray + [player distance _x];} forEach _charges;
	_closest = _newArray call BIS_fnc_lowestNum;
	_selection = _newArray find _closest;
	_charge = _charges select _selection;
	_charge
};

EtV_Timer =
{
	private "_explosive";
	_array = _this select 3;
	_unit = _array select 0;
	_explosive = [_unit] call EtV_ClosestExplosive;
	_illogic = (nearestObjects [_explosive,["Logic"],50]) select 0;
	if(!isNil "_illogic") then
	{
		_oldTime = _illogic getVariable ["timer",0];
		_illogic setVariable ["timer",_oldTime + 30];
		_newTime = _illogic getVariable "timer";
		hint format ["Explosive timer set to %1 seconds.",_newTime];
	};
};

EtV_UnitCheckTimer =
{
	private "_return";
	_unit = _this select 0;
	_explosives = _unit getVariable ["charges",[]];
	_return = false;
	{if(_unit distance _x <= 5) exitWith {_return = true;};} forEach _explosives;
	_return
};

//[unit] spawn EtV_Actions;
EtV_Actions =
{
	private ["_unit"];
	_unit = _this select 0;
	_unit addAction ["<t color=""#FFE496"">" +"Attach Explosive Charge", EtV_AttachCharge, ["DemoCharge_Remote_Mag",_unit], 1, true, true, "","['DemoCharge_Remote_Mag',_target] call EtV_ChargeCheck"];
	_unit addAction ["<t color=""#FFE496"">" +"Touch-Off Explosives", EtV_TouchOff, [_unit], 1, true, true, "","[_target] call EtV_UnitCheck"];
	_unit addAction ["<t color=""#FFE496"">" +"+30Secs to Timer", EtV_Timer, [_unit], 1, true, true, "","[_target] call EtV_UnitCheckTimer"];
};
//=======================
EtVInitialized = true;
[player] call EtV_Actions;

 

Edited by Darth_Rogue

Share this post


Link to post
Share on other sites
Advertisement

I'll try it in the evening together and give feedback !  thank a lot for helping :)

Awesome fill us all in would love to throw this in our server

Share this post


Link to post
Share on other sites

I'm actually working on making a functional version of this as we speak. It is probably 90% done just need to figure out a few more small things. So far I have made it so..

-Explosives attach to vehicles and wooden gates and wooden doors (done!)

-When wood gates/doors are destroyed they are deleted from the DB (done!)

-Explosives cannot be attached or detonated by a player in safe zone (done!)

-30 sec timer disabled so players cant attach explosive to vehicle and drive in safe zone (done!)

-(WIP) deleting the explosive if someone tries to detonate in safe zone with "You are a MUPPET!" message

Might be a few days out still. I'm learning as I go but so far everything I've outlined above works, aside from the last part. Also hoping to add future functionality of attaching explosive to yourself so you can be a suicide bomber. I might release a version early that only works on wood doors and gates. Theres more to think about when you add vehicles to the script.

Edited by READTHESCROLL
3 people like this

Share this post


Link to post
Share on other sites

Any chance of doing an optional "alternate" version for the purpose of attaching lightsticks and IR strobes to vehicles?

I have found many times where this is useful. For example, party members could throw a lightstick to the rear of their vehicle for easier IFF and convoy night ops. Players could even use different colors of sticks to help distinguish themselves from other groups, or to even allow each vehicle in a group to use a different color for easier identification at distance.

On the other hand, players can use something like this effectively in PvP situations, such as marking target vehicles. You could sneak up to an enemy vehicle, stick an IR strobe to it, and if the driver doesn't notice you may be able to follow them back to their base or ambush them on a mission.

 

Not saying everyone would want to use this feature, but on some servers that ban the use of explosives, such an option would allow them the use your script in another way. If it's possible, would be great to see it.

1 person likes this

Share this post


Link to post
Share on other sites

That is an awesome idea. I'm sure it is possible to do that. I just ripped the important parts of EtV to modify them to see if I can do it.

10 mins later..

Quick and dirty. Very dirty. And completely untested.

http://pastebin.com/samfy1gf

1 person likes this

Share this post


Link to post
Share on other sites

That is an awesome idea. I'm sure it is possible to do that. I just ripped the important parts of EtV to modify them to see if I can do it.

10 mins later..

Quick and dirty. Very dirty. And completely untested.

http://pastebin.com/samfy1gf

Awesome gunna test this out!

*EDIT* Action menu not showing up as far as I call tell.

Edited by Nakama

Share this post


Link to post
Share on other sites
Advertisement

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0

  • Recently Browsing   0 members

    No registered users viewing this page.