Jump to content
Sign in to follow this  
schmoking

deleting player placed explosives and chemlight on server?

Recommended Posts

ive been trying to clean up all placed explosives and chemlights in a loop on my server, but i cant figure it out.

 

this is what i am using to clean up the craters and it works great

_list = nearestObjects [(getMarkerPos "base"), ["CraterLong"], 4000];
{deleteVehicle _x} foreach _list;

 

but when i try the same with explosives and chemlights, it doesnt work

_list = nearestObjects [(getMarkerPos "base"), ["Chemlight_green","Chemlight_red","Chemlight_yellow","Chemlight_blue","ATMine_Range_Mag","APERSMine_Range_Mag","APERSBoundingMine_Range_Mag","SLAMDirectionalMine_Wire_Mag","APERSTripMine_Wire_Mag","ClaymoreDirectionalMine_Remote_Mag","SatchelCharge_Remote_Mag","DemoCharge_Remote_Mag","IEDUrbanBig_Remote_Mag","IEDLandBig_Remote_Mag","IEDUrbanSmall_Remote_Mag","IEDLandSmall_Remote_Mag"], 4000];
{deleteVehicle _x} foreach _list;

 

i have tried both with the mag and ammo names

ATMine_Range_Mag	                        ATMine_Range_Ammo
APERSMine_Range_Mag	                  APERSMine_Range_Ammo
APERSBoundingMine_Range_Mag   	      APERSBoundingMine_Range_Ammo
SLAMDirectionalMine_Wire_Mag	       	SLAMDirectionalMine_Wire_Ammo
APERSTripMine_Wire_Mag	       	      APERSTripMine_Wire_Ammo
ClaymoreDirectionalMine_Remote_Mag		ClaymoreDirectionalMine_Remote_Ammo
SatchelCharge_Remote_Mag	      	SatchelCharge_Remote_Ammo
DemoCharge_Remote_Mag	            	DemoCharge_Remote_Ammo
IEDUrbanBig_Remote_Mag	            	IEDUrbanBig_Remote_Ammo
IEDLandBig_Remote_Mag	            	IEDLandBig_Remote_Ammo
IEDUrbanSmall_Remote_Mag	      	IEDUrbanSmall_Remote_Ammo
IEDLandSmall_Remote_Mag	             	IEDLandSmall_Remote_Ammo

 

i was pretty sure this would do it, but no...

anyone know whats wrong here? or if there is another way to do it?

if not, is it  possible to trigger them so they all blow up?

Share this post


Link to post
Share on other sites

Add a fired eventhandler to every player, check for distance to base and if the ammo is an explosive or chemlight, delete it.

No need for loops here.

 

Cheers

Share this post


Link to post
Share on other sites

i should say im not very good at this. i looked at eventhandlers, but thats a whole new can of worms...

would that delete them instantly when they are placed?

 

i allready have two loops running on the server, every 3 minutes vehicles and stuff is cleaned and every 35 minutes it resets to morning again.

i wanted to run explosives cleanup in the 35 min loop. since the loop is already there, running one more script from it wouldnt be an issue, would it?

 

i found this on wiki from Ceeeb:

In Arma 3, nearestObjects is partially broken and is unable to return nearby placed explosive charges or mines when searching by classnames. Use nearObjects, nearestObject or allMines instead.

 

so i tried changing nearestObjects to nearObjects, only difrense i could see is nearObjects doesnt necessarily list closest object first...

_list = nearObjects [(getMarkerPos "base"), ["ATMine_Range_Ammo","ATMine_Range_Ammo","APERSBoundingMine_Range_Ammo","SLAMDirectionalMine_Wire_Ammo","APERSTripMine_Wire_Ammo","ClaymoreDirectionalMine_Remote_Ammo","SatchelCharge_Remote_Ammo","DemoCharge_Remote_Ammo","IEDUrbanBig_Remote_Ammo","IEDLandBig_Remote_Ammo","IEDUrbanSmall_Remote_Ammo","IEDLandSmall_Remote_Ammo"], 4000];
{deleteVehicle _x} foreach _list;

but that gave me this rpt errors:

Spoiler

Error in expression <losivescleanup.sqf"
_list = nearObjects [(getMarkerPos "base"), ["ATMine_Range_A>
Error position: <[(getMarkerPos "base"), ["ATMine_Range_A>
Error Missing ;

Error in expression <\scripts\explosivescleanup.sqf"
_list = nearObjects [(getMarkerPos "base"), ["AT>
Error position: <nearObjects [(getMarkerPos "base"), ["AT>
Error Undefined variable in expression: nearobjects
 

 

Share this post


Link to post
Share on other sites
1 hour ago, schmoking said:

so i tried changing nearestObjects to nearObjects, only difrense i could see is nearObjects doesnt necessarily list closest object first...

but that gave me this rpt errors:

 

You may want to double-check your nearObjects syntax, because the one you're using is not in the wiki

  • Like 1

Share this post


Link to post
Share on other sites

Wouldn't it be better to remove all explosives from the mission in the beginning, so there are no explosives to place?

Share this post


Link to post
Share on other sites
1 hour ago, schmoking said:

i should say im not very good at this. i looked at eventhandlers, but thats a whole new can of worms...

would that delete them instantly when they are placed?

Eventhandlers are not so special. Think of it as code that gets executed when something happens.

 

Their code will be executed immediately, but that code can be delayed (using sleep inside a spawn).

Share this post


Link to post
Share on other sites
4 hours ago, Nikander said:

 

You may want to double-check your nearObjects syntax, because the one you're using is not in the wiki

i did try a few combinations from the 3 examples, but im pretty much just guessing.. 

 

4 hours ago, engima said:

Wouldn't it be better to remove all explosives from the mission in the beginning, so there are no explosives to place?

i want players to be able to use them, i just wanna clean the map of them every 35 minutes when time resets

 

4 hours ago, engima said:

Eventhandlers are not so special. Think of it as code that gets executed when something happens.

 

Their code will be executed immediately, but that code can be delayed (using sleep inside a spawn).

would that work so that every explosive placed would get its own timer for deleting?

and could you give me an example of how that would look?

 

_EHkilledIdx = player addEventHandler ["killed", {_this exec "playerKilled.sqs"}]

would it be like this example? to execute a script when explosives are placed?

or would the delete and sleep be done without a script?

 

 

Share this post


Link to post
Share on other sites

Ok, after reading more carefully I see you will run the code exactly every 35 minutes. I'd say forget about the event handler and go for your loop with a 35 minutes sleep. Best for performance. (However, learn event handlers anyway, because they are extremely handy, and you are on the right track. In your case you should not use the 'killed' event handler though, but the 'fired': https://community.bistudio.com/wiki/Arma_3:_Event_Handlers#Fired.)

 

I don't know about the error you get, but I believe that Nikander has a point above.

  • Like 1

Share this post


Link to post
Share on other sites
8 hours ago, Nikander said:

 

You may want to double-check your nearObjects syntax, because the one you're using is not in the wiki

yep.. youre right, i messed that up  :)

 

wiki example:

_list = [_xpos,_ypos] nearObjects ["House", 20];

 

when i do this it works:

_list = [2284,5458] nearObjects ["APERSTripMine_Wire_Ammo", 4000];
{deleteVehicle _x} foreach _list;

 

but this gives me the Error 3 elements provided, 2 expected

_list = [2284,5458] nearObjects ["APERSTripMine_Wire_Ammo","Chemlight_blue", 4000];
{deleteVehicle _x} foreach _list;

 

anyone got some fancy bracket magic or something that will let me name more objects to remove?

i guess i could make a script for each object, but that cant be a good way to do it  :dozingoff:

Share this post


Link to post
Share on other sites
12 hours ago, schmoking said:

anyone got some fancy bracket magic or something that will let me name more objects to remove?

 

Nothing fancy here, especially with the insane radius in using the nearestObjects command, but try this one

_list = nearestObjects [[2284,5458], [], 4000] select {typeOf _x in ["APERSTripMine_Wire_Ammo", "Chemlight_blue"]};

Here's equally senseless nearObjects variant to try

_list = []; {_list append ([2284,5458] nearObjects [_x, 4000])} forEach ["APERSTripMine_Wire_Ammo", "Chemlight_blue"];

 

  • Like 1

Share this post


Link to post
Share on other sites

well.. this looks pretty fancy to me :)

 

this works, wich i found abit confusing as the wiki entry by Ceeeb said nearestObjects was unable to return nearby placed explosive charges or mines.
however it gave quite a stutter when executed, redusing the radius reduced the stutter.


_list = nearestObjects [[2284,5458], [], 4000] select {typeOf _x in ["APERSTripMine_Wire_Ammo", "Chemlight_blue"]};

 

then there is this piece of magic, this works also... but with no stutter at all, even at 4000 radius.
i guess it works better because objects dont have to be sorted by distance? anyways i found that 1200 radius will do what i need it to.

_list = []; {_list append ([2284,5458] nearObjects [_x, 1200])} forEach ["APERSTripMine_Wire_Ammo", "Chemlight_blue"];

 

Thank you for this!

Share this post


Link to post
Share on other sites

Here's what I'd use (untested, but should work fine):

 


TAG_fnc_myExplosivesAutoDelete = {

	params ["_firer","_weapon","_muzzle","_mode","_ammo","_magazine","_projectile"];

	_debug = true;

	if ((getNumber (configfile >> "CfgAmmo" >> _ammo >> "explosive")) > 0) then {

		_timer = 5;

		if (_debug) then {

			systemchat format ["%1 placed by %2 will be deleted in %3 minutes.",_ammo,name _firer,_timer / 60];

		};

		sleep _timer;

		if (alive _projectile) then {

			if (_debug) then {

				systemchat format ["%1 placed by %2 has been deleted!",_ammo,name _firer];

			};

			deletevehicle _projectile;

		};

	};

};

player addEventHandler ["Fired",{_this spawn TAG_fnc_myExplosivesAutoDelete}];

No usage of nearestAnything which can be a performance hit, no loops, just an inexpensive sleep and alive check after n seconds.

Adjust the timer value and the debug and you're set.

 

Using a global array to delete all placed explosive every n minute can lead to a situation where you just placed an explosive, bad luck has it that the loop is just kicking in after n minutes and your explosive is gone.

My solution avoids this.

 

Cheers

  • Like 2

Share this post


Link to post
Share on other sites

just when i thought i was done, here comes another puzzle...  :)

this looks interesting, i will try to figure it out.  thank you!

Share this post


Link to post
Share on other sites

well... that was alot easier to figure out then i thought. this works great!! now i understand other scripts i use much better, and i have more use for this :)

 

so far i only tested in editor, so i have a few questions:

 

as i understand it systemchat is just for debugging and doesnt work for a dedicated server.

i like the idea that players would get this message on server, so if i change systemchat to hint, would this hint only be visible to the player that placed the explosives or to everyone?

 

i have a rearm script that runs every respawn, this is where i add this line. is it correct to add this on every respawn?

player addEventHandler ["Fired",{_this spawn TAG_fnc_myExplosivesAutoDelete}];

 

im thinking about how long i would like the explosives to stay before deleting them,  and im at 5, 10 or 15 minutes, i think id prefer 10 or 15.

does the time affect any performanse? and if a player leaves does the explosives still delete?

im also thinking about using the rearm script to give the players some mines at every spawn, would it affect performanse if alot of the players was to use these at the same time?

 

 

Share this post


Link to post
Share on other sites
19 hours ago, schmoking said:

as i understand it systemchat is just for debugging and doesnt work for a dedicated server

 

Evidently this holds true to the script snippet sent by GOM in particular since systemChat has local effect only. Notice locality with each command that you learn. In the wiki this is represented with these icons arguments_global.gif effects_local.gif

 

19 hours ago, schmoking said:

if i change systemchat to hint, would this hint only be visible to the player that placed the explosives or to everyone?

 

Hint command has local effect as well, so that would only be visible to the player that placed the explosives in this case

 

19 hours ago, schmoking said:

i have a rearm script that runs every respawn, this is where i add this line. is it correct to add this on every respawn?

 

 Eventhandler "Fired" is not listed as persistent on respawn according to Arma 3: Event Handlers, so you are correct to add on every respawn. While the wiki is perfect per se, in my experience it is always worthwhile to test when in doubt

 

19 hours ago, schmoking said:

does the time affect any performanse?

 

The script is scheduled by game engine anyway, so sleep doesn't affect performance but merely postpones execution

 

19 hours ago, schmoking said:

if a player leaves does the explosives still delete?

 

No, the process is lost with player leaving but they disappear still since they were local objects to the disconnecting player

 

19 hours ago, schmoking said:

im also thinking about using the rearm script to give the players some mines at every spawn, would it affect performanse if alot of the players was to use these at the same time?

 

No, because each player machine is using local eventhandler to delete their own mines individually

Edited by Nikander
  • Like 2

Share this post


Link to post
Share on other sites

that really clear things up, i appreciate everyone`s time...  thank you!

  • 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  

×