Jump to content
gc8

Hiding vegetation problem

Recommended Posts

Hi

I was trying to hide some trees via script but ran in to a problem. 

Here's my code:

 

_vegs = nearestTerrainObjects [_pos, ["Tree","Bush"], 50];
{
 _x hideobjectglobal true;
 _x setDamage 1;
} foreach _vegs;

 

The problem is that some trees don't seem to take damage and when I hide them you can still hit them with vehicle!

So I'm thinking I need either a better way of doing this than hideObject or a way to detect trees that cannot be damaged so that I wont hide them.

 

Any ideas?

 

thx!

Share this post


Link to post
Share on other sites

Does it have to be a scripted solution?  There's the option of the "Hide Terrain Objects" module.

Share this post


Link to post
Share on other sites
2 minutes ago, EO said:

Does it have to be a scripted solution?  There's the option of the "Hide Terrain Objects" module.

 

I assume that relies on the same hideobject command

Share this post


Link to post
Share on other sites

I'm guessing so, not really my field, i'm just suggesting an alternative. 

If it helps here is the init.sqf for the "Hide Terrain Object" module...

Spoiler

/*--------------------------------------------------------------------------------------------------

	3DEN MOD: Hiddes closest terrain object.

--------------------------------------------------------------------------------------------------*/
#define MAP_TYPES_BUILDING			["BUILDING","HOUSE","CHURCH","CHAPEL","FUELSTATION","HOSPITAL","RUIN","BUNKER"]
#define MAP_TYPES_VEGETATION		["TREE","SMALL TREE","BUSH"]
#define MAP_TYPES_WALL				["WALL","FENCE"]
#define MAP_TYPES_MISC				["ROCK","ROCKS","FOREST BORDER","FOREST TRIANGLE","FOREST SQUARE","CROSS","FORTRESS","FOUNTAIN","VIEW-TOWER","LIGHTHOUSE","QUAY","HIDE","BUSSTOP","ROAD","FOREST","TRANSMITTER","STACK","TOURISM","WATERTOWER","TRACK","MAIN ROAD","POWER LINES","RAILWAY","POWERSOLAR","POWERWAVE","POWERWIND","SHIPWRECK","TRAIL"]

#define CATEGORY_COMP				[MAP_TYPES_BUILDING,MAP_TYPES_WALL,MAP_TYPES_VEGETATION,MAP_TYPES_MISC]

//["[ ] %1",_this] call bis_fnc_logFormat;

private _mode = param [0,"",[""]];
private _input = param [1,[],[[]]];
private _module = _input param [0,objNull,[objNull]];

switch _mode do
{
	// Default object init
	case "init":
	{
		if (is3DEN) exitWith {};

		//local hiding is applicable only in MP where checkbox is ticked
		private _hideLocaly = (_module getVariable ["#hideLocally",false]) && isMultiplayer;

		//filter flags
		private _value = _module getVariable ["#filter",0];

		if (_hideLocaly) then
		{
			//hide locally on each client; cannot delete the module
			["hide",[_module,_hideLocaly,_value]] remoteExecCall ["bis_fnc_moduleHideTerrainObjects",0,true];
		}
		else
		{
			//hide globally on server
			["hide",[_module,_hideLocaly,_value]] call bis_fnc_moduleHideTerrainObjects;

			//delete module
			deleteVehicle _module;
		};
	};
	//[_mode,[_module,_hideLocaly]] call bis_fnc_moduleHideTerrainObjects;
	case "hide":
	{
		//local hiding is applicable only in MP where checkbox is ticked
		private _hideLocaly = _input param [1,false,[true]];
		private _value = _input param [2,0,[123]];

		//get the data
		private _area = [getPos _module];
		_area append (_module getVariable ["objectarea",[]]);
		_area params ["_pivot","_a","_b"];

		private _radius = (_a max _b) * 1.42;
		private _objects = [];

		//get objects to hide
		private _flags = _value call bis_fnc_decodeFlags2;

		//prepare hiding code
		private _hidingCode = switch (true) do
		{
			case (_hideLocaly && isServer):
			{
				{_x hideObject true;_x allowDamage false;};
			};
			case (_hideLocaly && !isServer):
			{
				{_x hideObject true;};
			};
			default
			{
				{_x hideObjectGlobal true;_x allowDamage false;};
			};
		};

		{
			if (_x == 1) then
			{
				private _found = nearestTerrainObjects [_module,CATEGORY_COMP select _forEachIndex,_radius,false,true];

				_hidingCode forEach (_found inAreaArray _area);
			};
		}
		forEach _flags;
	};

	// When some attributes were changed (including position and rotation)
	case "attributesChanged3DEN":
	{
		//get module info
		private _size = (_module get3DENAttribute "Size3") select 0;
		private _isRectangle = (_module get3DENAttribute "isRectangle") select 0;

		//exit if module is deleted during dragging; _size & _isRectangle become nil at that point
		if (isNil{_size} || {isNil{_isRectangle}}) exitWith {};

		_size params ["_a","_b"];

		private _radius = (_a max _b) * 1.42;
		private _objects = [];
		private _area = [getPos _module, _a, _b, getDir _module, _isRectangle, -1];

		private _value = (_module get3DENAttribute "#filter") select 0;

		private _flags = _value call bis_fnc_decodeFlags2;

		//get counts per category
		private _counts = _module getVariable ["#counts",[]];

		for "_i" from 0 to 3 do
		{
			private _state = _flags param [_i,0];

			//get objects in the area and category
			private _found = nearestTerrainObjects [_module,CATEGORY_COMP select _i,_radius,false,true];
			_found = _found inAreaArray _area;

			//update count for given category
			_counts set [_i,count _found];

			//collect the objects
			if (_state == 1) then {_objects append _found};
		};

		//unhide previously hidden object
		{_x hideObject false;} forEach (_module getVariable ["#objects",[]]);

		//store objects that will be hidden and hide them
		_module setVariable ["#objects",_objects];
		_module setVariable ["#counts",_counts];

		//hide all objects on map
		{
			private _objects = _x getVariable ["#objects",[]];

			{_x hideObject true} forEach _objects;
		}
		forEach ((all3DENEntities select 3) select {typeOf _x == "ModuleHideTerrainObjects_F"});
	};
	// When added to the world (e.g., after undoing and redoing creation)
	case "registeredToWorld3DEN":
	{


	};
	// When removed from the world (i.e., by deletion or undoing creation)
	case "unregisteredFromWorld3DEN":
	{
		//module is removed, show all hidden objects
		{_x hideObject false} forEach (_module getVariable ["#objects",[]]);
	};
	// When connection to object changes (i.e., new one is added or existing one removed)
	case "connectionChanged3DEN":
	{


	};

	case "objectTypeFilter_attributeLoad":
	{
		private _ctrlAttribute = _input param [1,controlNull,[controlNull]];
		private _value = _input param [2,1,[123]];

		private _ctrlCheckboxes = _ctrlAttribute controlsGroupCtrl 100;
		private _flags = _value call bis_fnc_decodeFlags2;

		for "_i" from 0 to 3 do
		{
			private _state= _flags param [_i,0];

			if (_state == 1) then
			{
				private _ctrlCheckbox = _ctrlCheckboxes controlsGroupCtrl (101+_i);
				_ctrlCheckbox cbSetChecked true;
			};

			private _count = (_module getVariable ["#counts",0]) select _i;

			if (_count > 0) then
			{
				private _ctrlText = _ctrlCheckboxes controlsGroupCtrl (121+_i);
				_ctrlText ctrlSetText str _count;
				_ctrlText ctrlSetTextColor [1, 0.56, 0, 1];
				_ctrlText ctrlSetTooltip format[localize "STR_a3_to_hideTerrainObjects5",_count];
			};
		};
	};
	case "objectTypeFilter_attributeSave":
	{
		private _ctrlAttribute = _input param [1,controlNull,[controlNull]];
		private _ctrlCheckboxes = _ctrlAttribute controlsGroupCtrl 100;
		private _flags = [];
		private _value = 0;

		for "_idc" from 101 to 104 do
		{
			if (cbChecked(_ctrlCheckboxes controlsGroupCtrl _idc)) then
			{
				_flags pushBack 1;
			}
			else
			{
				_flags pushBack 0;
			};
		};

		_value = _flags call bis_fnc_encodeFlags2;

		_value
	};
};

 

:rthumb: 

  • Like 3
  • Thanks 1

Share this post


Link to post
Share on other sites

Thx @EO

It certainly seems to be using the hideObject command

Share this post


Link to post
Share on other sites

Well, open the editor, drop the module on the relevant trees, and see what happens. I've never had collision problems with objects hidden with the module.

  • Like 2

Share this post


Link to post
Share on other sites
5 hours ago, gc8 said:

Hi

I was trying to hide some trees via script but ran in to a problem. 

Here's my code:

 


_vegs = nearestTerrainObjects [_pos, ["Tree","Bush"], 50];
{
 _x hideobjectglobal true;
 _x setDamage 1;
} foreach _vegs;

 

The problem is that some trees don't seem to take damage and when I hide them you can still hit them with vehicle!

So I'm thinking I need either a better way of doing this than hideObject or a way to detect trees that cannot be damaged so that I wont hide them.

 

Any ideas?

 

thx!

 

 

this could be simple as: Where do you run this script?

Should be on server only.

  • Like 2

Share this post


Link to post
Share on other sites
9 hours ago, pierremgi said:

 

 

this could be simple as: Where do you run this script?

Should be on server only.

 

Running it in init.sqf SP just for testing

 

In tanoa it can fall down most trees and make them invisible but there's this big tree that doesn't seem to take damage and if I hide it my vehicle still collides to it.

Share this post


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

Well, open the editor, drop the module on the relevant trees, and see what happens. I've never had collision problems with objects hidden with the module.

 

Actually it seems to work, no collision problem with module. Now I just have to figure what the module does to make it work. Or place the module dynamically via createunit which I'm not sure is even possible (because of the parameters)...

Share this post


Link to post
Share on other sites
41 minutes ago, gc8 said:

 

Actually it seems to work, no collision problem with module. Now I just have to figure what the module does to make it work. Or place the module dynamically via createunit which I'm not sure is even possible (because of the parameters)...

Check the config which script the module runs on and use that, unPBO it if you need more details.

  • Like 1

Share this post


Link to post
Share on other sites
5 minutes ago, mrcurry said:

Check the config which script the module runs on and use that, unPBO it if you need more details.

 

EO already posted the script in this thread but I can't find where the code is different from mine

Share this post


Link to post
Share on other sites
14 minutes ago, gc8 said:

 

EO already posted the script in this thread but I can't find where the code is different from mine

Ah yes sorry... reading helps. :)

If you got an example (position) of the trees in question and I can try giving it a replicate tonight.

 

  • Like 1

Share this post


Link to post
Share on other sites

@mrcurry I placed bobcat in editor at [6226.17,9742.87,-0.000793457] . Player is the driver

  • Like 1

Share this post


Link to post
Share on other sites

So anyone know why the code in the module successfully hides stuff but my code doesn't? Can't figure it out...

 

Share this post


Link to post
Share on other sites

As already mentioned:

- (by EO) the module  acts on:

    * ["TREE","SMALL TREE","BUSH"] for vegetation

    * ["ROCK","ROCKS","FOREST BORDER","FOREST TRIANGLE","FOREST SQUARE","CROSS","FORTRESS","FOUNTAIN","VIEW-TOWER","LIGHTHOUSE","QUAY","HIDE","BUSSTOP","ROAD","FOREST","TRANSMITTER","STACK","TOURISM","WATERTOWER","TRACK","MAIN ROAD","POWER LINES","RAILWAY","POWERSOLAR","POWERWAVE","POWERWIND","SHIPWRECK","TRAIL"] for miscellaneous;

    NB: usually "HIDE" is a weird but efficient tool

- any global command should run on server only.

 

 

 

Share this post


Link to post
Share on other sites

@pierremgi Yes but I made this script from the module's code:

 

while { true } do
{

#define MAP_TYPES_BUILDING			["BUILDING","HOUSE","CHURCH","CHAPEL","FUELSTATION","HOSPITAL","RUIN","BUNKER"]
#define MAP_TYPES_VEGETATION		["TREE","SMALL TREE","BUSH"]
#define MAP_TYPES_WALL				["WALL","FENCE"]
#define MAP_TYPES_MISC				["ROCK","ROCKS","FOREST BORDER","FOREST TRIANGLE","FOREST SQUARE","CROSS","FORTRESS","FOUNTAIN","VIEW-TOWER","LIGHTHOUSE","QUAY","HIDE","BUSSTOP","ROAD","FOREST","TRANSMITTER","STACK","TOURISM","WATERTOWER","TRACK","MAIN ROAD","POWER LINES","RAILWAY","POWERSOLAR","POWERWAVE","POWERWIND","SHIPWRECK","TRAIL"]

#define CATEGORY_COMP				[MAP_TYPES_BUILDING,MAP_TYPES_WALL,MAP_TYPES_VEGETATION,MAP_TYPES_MISC]

{
_objs = nearestTerrainObjects [player, _x, 20, false, true];
hintsilent format["%1", _objs ];

{
 _x hideObjectGlobal true;_x allowDamage false;

} foreach _objs;

} foreach CATEGORY_COMP;

sleep 0.1;
};

 

It hides everything on your path but the vehicles still hit on invisible obstacles

 

 

Edited by gc8
not function, script

Share this post


Link to post
Share on other sites

Your script works without loop, for a specific area (a trigger for example, not an updated player's position)!

It's the same as the BI module function. You just have to wait for the initialization order. So, if your vehicle is already inside a bunch of rocks, with a waypoint, you will see the vehicle stuck or it'll climb on hidden rock. But if you pass through these rocks after mission start, that will work (like the module). Simple as that.

Share this post


Link to post
Share on other sites

@pierremgi Thanks for the explanation but I haven't got it working yet. I tried running the object hid code in the console after mission has started but that didn't work (still hitting invisible things).I have also tried calling the code in init.sqf but that didn't work. Where I am supposed to call the object hide code?

Share this post


Link to post
Share on other sites
16 minutes ago, pierremgi said:

The sooner as possible. Try a trigger set to true. But frankly, use the module instead!

 

I tried calling code via preInit = 1; in description.ext but then nearestTerrainObjects returns empty array.

 

Wish I could just use the module but I need to dynamically clear some areas for FOBs.

Share this post


Link to post
Share on other sites

Ok somehow I got the code working and stuff hidden when calling the code from init.sqf. But the problem seems to be I can't hide the trees during the mission but only on start?

 

Edit: It seems to work randomly... sometimes invisible trees block some times not

 

 

Share this post


Link to post
Share on other sites

Well I did some hacking and found out that if I call runInitScript after the object hide code then the invisible geometry is removed!

Problem is the function isn't really meant for that and it causes brief black screen when called.

 

Anyone know other functions that might do the trick?

Share this post


Link to post
Share on other sites

Ok I figured something new again. When I am in vehicle and first call the hide code the invisible geometry remains. But when I exit the vehicle and reenter then it does not collide anymore. very strange, quite buggy it seems, but at least it seems to work to a point

Share this post


Link to post
Share on other sites

It's because you have to use that command on the server via the hideObjectGlobal command in the Preinit phase of the scheduler.

  • Like 1

Share this post


Link to post
Share on other sites
32 minutes ago, nerexis said:

It's because you have to use that command on the server via the hideObjectGlobal command in the Preinit phase of the scheduler.

 

preinit? I don't remember anymore what solution I had for this but it appears to be working in my mission. I will keep that preinit in mind if there's problems again. thx!

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

×