Jump to content
Sign in to follow this  
Kieran

Placed Mines and Explosives Respawn

Recommended Posts

Hey all :)

I've been trying to figure this out but its really got me stumped.

How is it do i go about making Placed mines via the editor re-spawn upon detonating?

any help would be greatly appreciated

Share this post


Link to post
Share on other sites

Can you give us more context? Why do they need to respawn?

Share this post


Link to post
Share on other sites
Can you give us more context? Why do they need to respawn?

I am working on a section of a training mission where teams will have to maneuver past a a minefield and over booby trapped buildings without triggering a single explosion.

If one team managed to trip of the mines it would re spawn within a certain time for the next team to try.

Share this post


Link to post
Share on other sites

How are you placing the minefield in the first place? Set that up as a script and then just clear and run the script again.

Share this post


Link to post
Share on other sites
How are you placing the minefield in the first place? Set that up as a script and then just clear and run the script again.

The mines are placed via the Editor

Share this post


Link to post
Share on other sites

Tophe's Simple Vehicle Respawn script (with all of the edits) can be purposed to do that. I have vehicles and OPFOR on my training map that respawn after being destroyed/killed. I don't see why it wouldn't apply to mines (plus if you disarm them it'll either activate the 'destroyed' timer or the 'abandoned' timer.

Share this post


Link to post
Share on other sites

You wouldn't want a respawn script running for each and every mine.

Just spawn the mines via script in the first place and recreate them via the same method.

Share this post


Link to post
Share on other sites

private ["_hasname","_delay","_deserted","_respawns","_noend","_dead","_nodelay","_timeout","_position","_dir","_effect","_rounds","_run","_unit","_explode","_dynamic","_unitinit","_haveinit","_unitname","_type"];
if (!isServer) exitWith {};

// Define variables
_unit = _this select 1;
_delay = if (count _this > 1) then {_this select 1} else {30};
_deserted = if (count _this > 2) then {_this select 2} else {120};
_respawns = if (count _this > 3) then {_this select 3} else {0};
_explode = if (count _this > 4) then {_this select 4} else {false};
_dynamic = if (count _this > 5) then {_this select 5} else {false};
_unitinit = if (count _this > 6) then {_this select 6} else {};
_haveinit = if (count _this > 6) then {true} else {false};

_hasname = true;
_unitname = APERSBoundingMine_Range_Mag;
if (isNil _unitname) then {_hasname = false;} else {_hasname = true;};
_noend = true;
_run = true;
_rounds = 0;

if (_delay < 0) then {_delay = 0};
if (_deserted < 0) then {_deserted = 0};
if (_respawns <= 0) then {_respawns= 0; _noend = true;};
if (_respawns > 0) then {_noend = false};

_dir = getDir _unit;
_position = getPosASL _unit;
_type = typeOf _unit;
_dead = false;
_nodelay = false;


// Start monitoring the vehicle
while {_run} do 
{	
 sleep (5 + (random 20));
 if ((getDammage _unit > 0.8) and ({alive _x} count crew _unit == 0)) then {_dead = true};

// Check if the vehicle is deserted.
if (_deserted > 0) then
{
   _nearPlayers = false;
   {
     if ((_x distance _unit) < PARAMS_VehicleRespawnDistance) exitWith { _nearPlayers = true; };
   } forEach playableUnits;
	if ((getPosASL _unit distance _position > 10) and ({alive _x} count crew _unit == 0) and (getDammage _unit < 0.8) and !_nearPlayers) then 
	{
		_timeout = time + _deserted;
		sleep 0.1;
	 	waitUntil {_timeout < time or !alive _unit or {alive _x} count crew _unit > 0};
		if ({alive _x} count crew _unit > 0) then {_dead = false}; 
		if ({alive _x} count crew _unit == 0) then {_dead = true; _nodelay =true}; 
		if !(alive _unit) then {_dead = true; _nodelay = false}; 
	};
};

// Respawn vehicle
 if (_dead) then 
{	
	if (_nodelay) then {sleep 0.1; _nodelay = false;} else {sleep _delay;};
	if (_dynamic) then {_position = getPosASL _unit; _dir = getDir _unit;};
	if (_explode) then {_effect = "M_AT" createVehicle getPosASL _unit; _effect setPosASL getPosASL _unit;};
	sleep 0.1;

	deleteVehicle _unit;
	sleep 2;
	_unit = _type createVehicle _position;
	_unit setPosASL _position;
	_unit setDir _dir;

	_dead = false;

	// Check respawn amount
	if !(_noend) then {_rounds = _rounds + 1};
	if ((_rounds == _respawns) and !(_noend)) then {_run = false;};
};
};

Here is the code i am trying to use but with no luck.

Share this post


Link to post
Share on other sites

Can't really help but where and how are you trying to run the script.

It won't work if you place it in the mines init box.

Never mind I took a look and it works ok.

You need to put the script back to original and call it from another object other than a mine init. name your mines and place them in an array.

{null=[_x] execvm "respawn.sqf"} foreach [m_1,m_2,m_3,m_4];

save as respawn.sqf

private ["_hasname","_delay","_deserted","_respawns","_noend","_dead","_nodelay","_timeout","_position","_dir","_effect","_rounds","_run","_unit","_explode","_dynamic","_unitinit","_haveinit","_unitname","_type"];
if (!isServer) exitWith {};

// Define variables
_unit = _this select 0;
_delay = if (count _this > 1) then {_this select 1} else {30};
_deserted = if (count _this > 2) then {_this select 2} else {120};
_respawns = if (count _this > 3) then {_this select 3} else {0};
_explode = if (count _this > 4) then {_this select 4} else {false};
_dynamic = if (count _this > 5) then {_this select 5} else {false};
_unitinit = if (count _this > 6) then {_this select 6} else {};
_haveinit = if (count _this > 6) then {true} else {false};

_hasname = true;
_unitname = vehicleVarName _unit;
if (isNil _unitname) then {_hasname = false;} else {_hasname = true;};
_noend = true;
_run = true;
_rounds = 0;

if (_delay < 0) then {_delay = 0};
if (_deserted < 0) then {_deserted = 0};
if (_respawns <= 0) then {_respawns= 0; _noend = true;};
if (_respawns > 0) then {_noend = false};

_dir = getDir _unit;
_position = getPosASL _unit;
_type = typeOf _unit;
_dead = false;
_nodelay = false;


// Start monitoring the vehicle
while {_run} do 
{	
 sleep (5 + (random 20));
 if ((getDammage _unit > 0.8) and ({alive _x} count crew _unit == 0)) then {_dead = true};

// Check if the vehicle is deserted.
if (_deserted > 0) then
{
   _nearPlayers = false;
   {
     if ((_x distance _unit) < PARAMS_VehicleRespawnDistance) exitWith { _nearPlayers = true; };
   } forEach playableUnits;
	if ((getPosASL _unit distance _position > 10) and ({alive _x} count crew _unit == 0) and (getDammage _unit < 0.8) and !_nearPlayers) then 
	{
		_timeout = time + _deserted;
		sleep 0.1;
	 	waitUntil {_timeout < time or !alive _unit or {alive _x} count crew _unit > 0};
		if ({alive _x} count crew _unit > 0) then {_dead = false}; 
		if ({alive _x} count crew _unit == 0) then {_dead = true; _nodelay =true}; 
		if !(alive _unit) then {_dead = true; _nodelay = false}; 
	};
};

// Respawn vehicle
 if (_dead) then 
{	
	if (_nodelay) then {sleep 0.1; _nodelay = false;} else {sleep _delay;};
	if (_dynamic) then {_position = getPosASL _unit; _dir = getDir _unit;};
	if (_explode) then {_effect = "M_AT" createVehicle getPosASL _unit; _effect setPosASL getPosASL _unit;};
	sleep 0.1;

	deleteVehicle _unit;
	sleep 2;
	_unit = _type createVehicle _position;
	_unit setPosASL _position;
	_unit setDir _dir;

	_dead = false;

	// Check respawn amount
	if !(_noend) then {_rounds = _rounds + 1};
	if ((_rounds == _respawns) and !(_noend)) then {_run = false;};
};
};

Edited by F2k Sel

Share this post


Link to post
Share on other sites

C'mon, edited respawn scripts for every mine? Checking for crew count of the mine and that they are x distance away from players? Really??

Spawn dynamically and clean up when you're done:

Put down a marker called "minefield" then a radio trigger or whatever:

{deletevehicle _x} forEach currentField; null = ["minefield", 10, 10, "APERSBoundingMine_Range_Ammo"] execVM "refreshMines.sqf";

refreshMines.sqf:

_field = _this select 0; // "minefield"
_range = _this select 1; // 10 (meters)
_count = _this select 2; // 10 (count)
_type = _this select 3; // "APERSBoundingMine_Range_Ammo"

currentField = [];

for "_i" from 1 to _count do {
_mine = createvehicle [_type, getMarkerPos _field, [], _range, ""];
currentField = currentField + [_mine];
};

No waitUntils, no checking crew of a mine since you're using a vehicle respawn. Just random fresh minefields everytime you click a button. :)

Share this post


Link to post
Share on other sites

Awsome this is helping alot! the reason for the respawn script for each mine is because i don't want it to spawn randomly

it has to be in the exact position it was in before it was exploded.

For example I placed a Trip wire inside the building just at the door.

I don't want it after it explodes to re spawn in the middle or outside the building.

Share this post


Link to post
Share on other sites

That's fine. For static ones place one in the editor where you want it, name it bob then put this in a radio trigger:

copyToClipboard format["_mine = createVehicle [""%1"", %2, [], 0, """"];", typeOf bob, getPosATL bob];player sidechat str(getDir bob);

Then simply paste into the refreshMines.sqf file and add in the setDir using the number you said in sidechat:

_mine = createVehicle ["APERSTripMine_Wire_Ammo", [1911.02,5705.39,-0.0912566], [], 0, ""]; // this line is copy/pasted
_mine setDir 20;  // this number you said in game
_mine setPosATL getPosATL _mine;  // This is because servers suck.
currentField = currentField + [_mine];  // This resets it with the rest.

There is absolutely no reason to use a fully featured vehicle respawn script to replace a single mine on demand.

Share this post


Link to post
Share on other sites

The mine gets deleted immediately upon detonation.

create a script like this.

//whateverTheFileNameHasToBe.sqf///////////////////////////////

_vehicle = _this;

_vehicleClass = typeOf _vehicle;

_vehiclePos = getPos _vehicle;

waitUntil {isNull _vehicle};

_newVeh = _vehicleClass createVehicle _vehiclePos;

_newVeh execVM "whateverTheFileNameHasToBe.sqf";

/////////////////////////////////////////////////////////////////

and in the editor in your mine init put the following:

this execVM "whateverTheFileNameHasToBe.sqf";

Didn't test it but it should work.

Maybe it will cause a chain of explosions in the time frame that the vehicle is in detonation distance from the mine position. But it will blow the car into infinity anyways.

Else just put a sleep where you feel it's needed.

Share this post


Link to post
Share on other sites

and in the editor in your mine init put the following:

this execVM "whateverTheFileNameHasToBe.sqf";

I don't think that will work, if I remember correctly mine init doesn't work. You would have to name the mine and run the code from another init.

Share this post


Link to post
Share on other sites

the init must have a variable assigned to the script.

null = this execVM "asdfasdfasdf.sqf";

Share this post


Link to post
Share on other sites

Yes but unless they changed it even A hint won't work in then mines init.

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  

×