sizraide 4 Posted September 16, 2021 (edited) I'm creating a COOP mission. And I made a little script that spawns IED around a bunch of markers. Hardest part is how do I make it so when the player is very near to the IED it explodes? Here is my script, it is incomplete. Quote _markerArray = ["l_1", "l_2", "l_3", "l_4", "l_5", "l_6", "l_7", "l_8", "l_9", "l_10"]; _IEDarray = ["IEDUrbanSmall_Remote_Ammo","IEDLandSmall_Remote_Ammo","IEDUrbanBig_Remote_Ammo","IEDLandBig_Remote_Ammo"]; for "_i" from 0 to 200 do { _chosenIED = selectRandom _IEDarray; _chosenMarker = selectRandom _markerArray; _posIED = [[[getMarkerPos _chosenMarker, 250]],[]] call BIS_fnc_randomPos; _isEmpty = !(_posIED isFlatEmpty [15, -1, -1, -1, -1, false, player] isEqualTo []); if(_isEmpty) then { createIED = _chosenIED createVehicle _posIED; }; sleep 0.01; }; while {true} do { { _nearIED = _x nearestObject ["IEDUrbanSmall_Remote_Ammo","IEDLandSmall_Remote_Ammo","IEDUrbanBig_Remote_Ammo","IEDLandBig_Remote_Ammo"]; if(_nearIED < 1) then { //Don't know if what I'm typing is even correct here }; } forEach allPlayers; sleep 1; }; EDIT: IEDs only explode when a player shoots at them. Edited September 16, 2021 by sizraide Share this post Link to post Share on other sites
Joe98 92 Posted September 17, 2021 Place the explosives on the map in an out of the way place. Place a series of triggers on the map. When soldier enters any trigger, the explosive is transported to the centre of the trigger (it can be placed at a random location within the trigger) then the explosive is detonated. . Share this post Link to post Share on other sites
domcho 20 Posted September 17, 2021 I'm not sure the code in your while loop is correct. Try removing the forEach allPlayers block.The nearestObject syntax also seems wrong - I don't think you can pass an array of object types, only single object type. Try something like this: _nearIED1 = nearestObject [player, "IEDUrbanSmall_Remote_Ammo"]; _nearIED2 = nearestObject [player, "IEDLandSmall_Remote_Ammo"]; _nearIED3 = nearestObject [player, "IEDUrbanBig_Remote_Ammo"]; _nearIED4 = nearestObject [player, "IEDLandBig_Remote_Ammo"]; if (alive _nearIED1 AND player distance _nearIED1 < 5) then { *code to detonate _nearIED1* }; if (alive _nearIED2 AND player distance _nearIED2 < 5) then { *code to detonate _nearIED2* }; if (alive _nearIED3 AND player distance _nearIED3 < 5) then { *code to detonate _nearIED3* }; if (alive _nearIED4 AND player distance _nearIED4 < 5) then { *code to detonate _nearIED4* }; I haven't tested this, nor do I know how it will behave in multiplayer. Share this post Link to post Share on other sites
wogz187 1086 Posted September 17, 2021 (edited) @sizraide, _markerArray = ["l_1", "l_2", "l_3", "l_4", "l_5", "l_6", "l_7", "l_8", "l_9", "l_10"]; _IEDarray = ["IEDUrbanSmall_Remote_Ammo","IEDLandSmall_Remote_Ammo","IEDUrbanBig_Remote_Ammo","IEDLandBig_Remote_Ammo"]; _markerArray apply { private _veh= (selectRandom _iedArray) createVehicle (getMarkerPos _x); _veh spawn { waitUntil { sleep 1; if !((_this nearEntities ["Man", 20]) select {_x in allPlayers} isEqualTo []) then {_this setDamage 1}; !alive _this } }; _veh }; Create an IED at each marker position. Detonation radius is set to 20 which you may change as you please. Have fun! Edited September 17, 2021 by wogz187 simplified 1 Share this post Link to post Share on other sites
pierremgi 4905 Posted September 17, 2021 You can give an area to markers and making them invisible, so they are like triggers with a looped code. Personally I'd place triggers because that doesn't hurt. You can set an interval cooling down them and even delete them (which should be always the case for non-repeatable ones, especially with complex conditions). Spoiler I recently tested the enableSimulation on them, playing on EL Alamein map (CUP) with more than 12,000 wired fences! Just for fun, I created a trigger on each fence! As is, the FPS drop is just unplayable. If stated as enabled sim false , then enabling the closer ones with players move, that works flawless. But, it's not the best solution. The best one is to create them on the fly (then delete them). You can also make them local, for local treatment, so you don't have to broadcast them. To conclude, there are many way to make things work. The demand on resource is the way you are scripting. Share this post Link to post Share on other sites
sizraide 4 Posted September 18, 2021 8 hours ago, pierremgi said: You can give an area to markers and making them invisible, so they are like triggers with a looped code. Personally I'd place triggers because that doesn't hurt. You can set an interval cooling down them and even delete them (which should be always the case for non-repeatable ones, especially with complex conditions). Reveal hidden contents I recently tested the enableSimulation on them, playing on EL Alamein map (CUP) with more than 12,000 wired fences! Just for fun, I created a trigger on each fence! As is, the FPS drop is just unplayable. If stated as enabled sim false , then enabling the closer ones with players move, that works flawless. But, it's not the best solution. The best one is to create them on the fly (then delete them). You can also make them local, for local treatment, so you don't have to broadcast them. To conclude, there are many way to make things work. The demand on resource is the way you are scripting. Quote for "_i" from 0 to 300 do { _chosenIED = selectRandom _IEDarray; _chosenMarker = selectRandom _markerArray; _posIED = [[[getMarkerPos _chosenMarker, 200]],[]] call BIS_fnc_randomPos; _isEmpty = !(_posIED isFlatEmpty [20, -1, -1, -1, -1, false, player] isEqualTo []); if(_isEmpty) then { createIED = _chosenIED createVehicle _posIED; iedTrg = createTrigger ["EmptyDetector", _posIED, true]; iedTrg setTriggerStatements ["this", "createIED setDamage 1; deleteVehicle iedTrg;"]; iedTrg setTriggerArea [3, 3, 45, false, 5]; iedTrg setTriggerActivation ["ANYPLAYER", "PRESENT", false]; }; sleep 0.01; }; I'm very inexperienced with scripting, would this work? I assume it wouldn't because all of the IED's have the same variable name so if one trigger is set off all IED's will explode wouldn't it? Is there a way I can convert strings to use them as variable names so I could have a different name for every IED created, including the trigger? Like createIED1, createIED2, createIED3 and iedTrg1, iedTrg2, eidTrg3... and so on.EDIT: I've looked into toArray but that's all I can find. Share this post Link to post Share on other sites
sizraide 4 Posted September 18, 2021 8 hours ago, wogz187 said: @sizraide, _markerArray = ["l_1", "l_2", "l_3", "l_4", "l_5", "l_6", "l_7", "l_8", "l_9", "l_10"]; _IEDarray = ["IEDUrbanSmall_Remote_Ammo","IEDLandSmall_Remote_Ammo","IEDUrbanBig_Remote_Ammo","IEDLandBig_Remote_Ammo"]; _markerArray apply { private _veh= (selectRandom _iedArray) createVehicle (getMarkerPos _x); _veh spawn { waitUntil { sleep 1; if !((_this nearEntities ["Man", 20]) select {_x in allPlayers} isEqualTo []) then {_this setDamage 1}; !alive _this } }; _veh }; Create an IED at each marker position. Detonation radius is set to 20 which you may change as you please. Have fun! Works awesome, except I would like it to spawn multiple IED's around the marker in 200m radius in random position and have the nearEntities applied to all of them. Is that possible? As seen here. Quote _posIED = [[[getMarkerPos _chosenMarker, 200]],[]] call BIS_fnc_randomPos; _isEmpty = !(_posIED isFlatEmpty [20, -1, -1, -1, -1, false, player] isEqualTo []); Share this post Link to post Share on other sites
pierremgi 4905 Posted September 18, 2021 Units in multiple areas: inAreaArray is made for that. If markers have an area (invisible or not): In a (unique) trigger or in a loop, let's say plyers only are concerned: for the trigger, none, none repeatable, condition (if you are not familiar with trigger interval and rearm it: see also) : thisTrigger setTriggerInterval 2; isNil "test" on activation: test = true; [] spawn { private _result = []; private _mkrs = ["l_1", "l_2", "l_3", "l_4", "l_5", "l_6", "l_7", "l_8", "l_9", "l_10"]; private _units = allPlayers; { if ((_units inAreaArray _x) isNotEqualTo []) then { private _mkrVisitors = _units inAreaArray _x; _result pushBackUnique _mkrVisitors; for "_i" from 0 to count _result -1 do { hint format ["units %1 are in %2", _mkrVisitors,_x] }; sleep 1; _result = []; } } forEach _mkrs }; on deact: test = nil; If all units of all played groups are concerned: [] spawn { private _result = []; private _mkrs = ["l_1", "l_2", "l_3", "l_4", "l_5", "l_6", "l_7", "l_8", "l_9", "l_10"]; private _units = flatten (allPlayers apply {units _x}); { if ((_units inAreaArray _x) isNotEqualTo []) then { _mkrVisitors = _units inAreaArray _x; _result pushBackUnique _mkrVisitors; for "_i" from 0 to count _result -1 do { hint format ["units %1 are in %2", _mkrVisitors,_x] }; sleep 1; _result = []; } } forEach _mkrs }; See BIKI for command details. If you place/spawn multiple IED, you can add a scripted marker on it (with area) and push the(se) marker(s) in markers' array. (this array must be known in trigger's code, make it global. There is no problem adding markers. Or You can try to check for any distance from units/IEDs less than the limit of active radius. You need to check updated arrays of units (alive) and IEDs. 1 Share this post Link to post Share on other sites