Jump to content
LoseBummer

Hide map objects Junk, Garbage and Wrecks with Script [Done]

Recommended Posts

[FIX version in the post #3. thanks to Kylania]

 

Looking for a way to remove objectmaps like junk, garbage and scrap cars within a range I come across with nearestTerrainObjects. The types name "hide" appears to be the one. There are different ones.

 

I´ve been searching this for a while now, thanks to the help of R3vo and das attorney i adapt a script from Brun (link to the reference post). 

 

Gamelogic>init

null = ["MARKERNAME"] execVM "SCRIPTNAME.sqf";

The radious is taken from the size of area marker.

 

Script.sqf

_marker = _this param [0,"CENTER",[""]];
_Size = markerSize _marker;
_markerSize = _Size select 1;
{
    hideObjectGlobal  _x;
} foreach (nearestTerrainObjects [markerpos _marker, ["HIDE"],_markerSize]);
  • Like 2

Share this post


Link to post
Share on other sites

Turns out "HIDE" captures a lot more than just wrecks and garbage unfortunately.  Here's 100m worth of "HIDE" standing on the hospital in Kavala capturing things like sidewalks, lampposts, ATMs, traffic signs, benches, phonebooths, garbage bins and more.

 

http://imgur.com/a/lQvq1

 

You can delete just the wrecks with this tweak to the above:

{
	if ((toUpper(str _x) find "WRECK") >= 0) then {
		hideObjectGlobal  _x;
	};
} foreach (nearestTerrainObjects [markerpos _marker, ["HIDE"], _markerSize]);
  • Like 2

Share this post


Link to post
Share on other sites

Nice! Thanks Kylania. With Wreck, Toilet and Garbage in my case is enough.

_marker = _this param [0,"CENTER",[""]];
_Size = markerSize _marker;
_markerSize = _Size select 1;
{
	if ((toUpper(str _x) find "WRECK") >= 0) then {
		hideObjectGlobal  _x;
	};
} foreach (nearestTerrainObjects [markerpos _marker, ["HIDE"], _markerSize]);
{
	if ((toUpper(str _x) find "GARBAGE") >= 0) then {
		hideObjectGlobal  _x;
	};
} foreach (nearestTerrainObjects [markerpos _marker, ["HIDE"], _markerSize]);
{
	if ((toUpper(str _x) find "TOILET") >= 0) then {
		hideObjectGlobal  _x;
	};
} foreach (nearestTerrainObjects [markerpos _marker, ["HIDE"], _markerSize]);

Share this post


Link to post
Share on other sites

Ack! Duplicate code detected! Nobody panic!  :P

 

I'm sure there's a better way of doing this, but I wasn't finding anything definite so try this maybe?

_marker = _this param [0,"CENTER",[""]];
_markerSize = (markerSize _marker) select 1;
_junk = ["GARBAGE", "WRECK", "TOILET", "TYRES", "JUNKPILE"];

{
	_item = _x;
	if ({(toUpper(str _item) find _x >=0)} count _junk > 0) then {
		hideObjectGlobal  _item;
	};
} foreach nearestTerrainObjects [markerpos _marker, ["HIDE"], _markerSize];
  • Like 1

Share this post


Link to post
Share on other sites

Great (I knew it that was wrong, but i was too shy to ask).

Share this post


Link to post
Share on other sites

Nothing you wrote was wrong at all!  Just not as elegant as it could be. :)

Share this post


Link to post
Share on other sites

it's weird.The codes not working for me.can you share a sample mission here, please?

Share this post


Link to post
Share on other sites

Here's a demo mission.

 

The demo mission has an info stand with three actions on it.  First is default using the 50x70 area "center" marker which will miss the wreck to the left and the washing machine even though they within 70m of the center of the marker they are on the 50m side so out of range of the area of the marker.  Second action is using a custom non-area marker and default radius of 50m.  So it'll pick up the washing machine but not the wreck on the left.  Third action is that same custom marker but with a specified 70m range which will clear the washing machine and the wreck (and more!).

 

The code has been changed to take into account marker area even if it's not symmetrical.  The marker name is optional (defaults to "center") and the area is optional as well (defaults to 50m or the area of a marker).

 

Here's the improved code:

/*
Ex: null = [] execVM "clean.sqf // Defaults to marker named "center" and 50m radius (unless it's an area marker).
	null = ["myOtherMarker"] execVM "clean.sqf // Cleans around a marker named "myOtherMarker" with 50m radius (unless it's an area marker).
	null = ["myUglyBackyard", 200] execVM "clean.sqf // Cleans 200m around a marker named "myUglyBackyard" (unless it's an area marker).
*/ 

// Defaults
params [["_marker", "center"], ["_area", 50]];

// Types of junk to clean.
_junk = ["GARBAGE", "WRECK", "TOILET", "TYRES", "JUNKPILE"];

// Area marker flag
_markerArea = false;

// If we're an area marker sort sizes to get the largest size and set the area flag for later.
if (markerShape _marker in ["ELLIPSE", "RECTANGLE"]) then {
	_shape = markerSize _marker; // Returns the size, ie [50, 70]
	_shape sort false; // Sort the area array, ie now [70, 50]
	_area = _shape select 0;  // Set area to the largest size
	_markerArea = true;  // Set flag for later
};

{
	_item = _x;  // Current item in search area list

	// If we're an area marker check that the object is actually within the marker.  Ie, 65m away from the 50m side for example.
	if (_markerArea && !(getPosWorld _item inArea _marker)) exitWith {};

	// If we're in the area compare the object name to the _junk list.  If we match hide the object.
	if ({(toUpper(str _item) find _x >=0)} count _junk > 0) then {
		hideObjectGlobal _item;
	};
} foreach nearestTerrainObjects [markerpos _marker, ["HIDE"], _area];
  • Like 3

Share this post


Link to post
Share on other sites

Hi If you set the marker size to the full size of Altis will it help with performance a bit.

Share this post


Link to post
Share on other sites

thanks alot for sample mission.

 

_junk = ["GARBAGE", "WRECK", "TOILET", "TYRES", "JUNKPILE"];

about _junk, have i need to put all objects class names or its a something like cfgpatch classnames?

Share this post


Link to post
Share on other sites

Here's what the return of nearestTerrainObjects looks like:

[
1571177: garbagewashingmachine_f.p3d,
1571174: garbage_square3_f.p3d,
1571206: wreck_offroad_f.p3d,
1571179: lampshabby_off_f.p3d,
1571178: garbagepallet_f.p3d,
1571207: wreck_offroad2_f.p3d,
1571172: junkpile_f.p3d,
1570414: powerpolewooden_small_f.p3d,
51195: signt_dangerbendsr.p3d
]

So you'd place it _junk capitalized unique parts of what you'd want to remote from that list.  So like putting "GARBAGE" would clean up the garbagewashingmachine, garbage square and garbagepallet.  If you added in "POWERPOLE" you'd also remove the small wooden power pole that's nearby.  If you changed "GARBAGE" to "GARBAGE_" you'd only remove the square of garbage but leave behind the washing machine and pallet.

 

So in the editor you might play around with it to get a list of objects first to see what to filter from.

 

Here's my debug console from while I'd been testing the mission.

 

TOj8GdW.jpg

 

You'll see I was able to test the script in the top execute field on demand.  I had the list of objects around me in the first watch field.  I had a gamelogic near the left wreck I used to create the bob object which I could then check the distance from the custom marker I had and check if it was in the area of my area marker too.  Debug console is pretty useful.  You can bring it up in the editor by pressing ESC.

 

Make sense?

  • Like 2

Share this post


Link to post
Share on other sites

You can aslo type in your debug console "hint str cursorObject;" to get the name of a specific object you're directly looking at.

 

Perfect to identify those uglys FISHINGGEAR and CRABCAGES.

  • Like 2

Share this post


Link to post
Share on other sites

I added "CARGO" to try and get rid of those horrible cargo houses on the Stratis airbase and they are still there.

Share this post


Link to post
Share on other sites

I added "CARGO" to try and get rid of those horrible cargo houses on the Stratis airbase and they are still there.

 

If you mean the rusty ones that's because those are considered "HOUSE" rather than "HIDE".

 

So to capture things like that change the last line of the script to read:

} foreach nearestTerrainObjects [markerpos _marker, ["HIDE", "HOUSE"], _area];

Share this post


Link to post
Share on other sites

Thanks. I thought HIDE was the command to make it invisible, So if I want to get rid of walls/ fences will either of those work or do i need another bit of text?

Share this post


Link to post
Share on other sites

 

If you mean the rusty ones that's because those are considered "HOUSE" rather than "HIDE".

 

So to capture things like that change the last line of the script to read:

} foreach nearestTerrainObjects [markerpos _marker, ["HIDE", "HOUSE"]

They still show up in mission after making changes.

Share this post


Link to post
Share on other sites

I added all types on that link you sent so that I have options later on.

Share this post


Link to post
Share on other sites

You can change the first line to:

params [["_marker", "center"], ["_area", 50], ["_types", ["HIDE"]]];

and the last line to:

} foreach nearestTerrainObjects [markerpos _marker, _types, _area];

Then if you need the extra types you can call it with:

null = ["myMarker", 30, ["HIDE", "HOUSE"]] execVM "clean.sqf";

or just this if you're happy with just HIDE  objects and a 50 meter range:

null = ["myMarker"] execVM "clean.sqf";

Share this post


Link to post
Share on other sites

Oh that improved code its beautiful.

I´m triyng to find a way to replace the p3d off lamps with the on version without results.

It´s possible?

Share this post


Link to post
Share on other sites

Got an idea how, but do you have a sample of where one of these lamps are?  All the ones I can find turn on at night automatically.

Share this post


Link to post
Share on other sites

Yeah, I´m working in a template in this sector to build a compound.

Link part mission;

 

With a previous version o the script with command nearestobject what i do is search for the object (that version can´t find map objects). Searchs Off or ON lamps and change it for the counterpart.

Radio Alpha is ON, Radio Bravo is Off. (In my case I manually find the off lamps and create one by one a on version above hidding the old one)

 

Triyng to adapt with the neastestTerrainObject goes above my little knowlegde. With your script i can find it but not create the new object.

Share this post


Link to post
Share on other sites

You can use createSimpleObject to make a new one but I wasn't able to detect the lampposts with nearestTerrainObjects.  I think they are still actual objects so you'd need to use nearestObjects to find them.  However in my tests I think it was creating them underground since I couldn't see them.  It wasn't till I added in the vectorAdd stuff from the example before I could see the objects however they were like 10m in the air!

Share this post


Link to post
Share on other sites

Ok, progress.

I remix the two scripts. One issue, if createsimpleobject is use the lights are on but without the light effect (i can explain better, the model of lamp is white but has no light effect on object).

And with createvehicle, the light effect and model are created and can be destroyed.

 

Sample Mission with the example. LINK

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

×