Jump to content
Sign in to follow this  
odyseus

HideObjects

Recommended Posts

Hello guys, I have a few question about hidebject, i was reading on the wiki but could not quite understand what it means. First let me know what i m trying to do . I m drying to hide few units to improve performance on game. It is a MP and i want units to hide when player is lets say 1000 x 1000 meters way. I found this line on wiki for multiplayer _nic = [nil, mantohide, "per", rHideObject, true] call RE; First question can someone brake it down for me? Second does it gonna help performance? and last how can I include more than one units I was trying this but cant quite figure it out how to make sure unit is really invisible! :D LOL _nic = [nil, [mantohide01,mantohide02], "per", rHideObject, true] call RE;

Share this post


Link to post
Share on other sites

You could just create the units when a distance condition is met.

Share this post


Link to post
Share on other sites

Well hideobject does what it says: hide an object. It will be unvisible on the machine where the command was run. But the object will be able to move and will further communicate with the server.

If you really want to cut down network expenses you should consider using enableSimulation and set it to false on every object after you made them invisible. As this command also requires you to run it on every machine to take effect for every player, you have to remotely run it on the other machines.

But be advised that using RE will hide the objects on ALL machines, which could contradict your game logic, let's say you have 5 players on your map and 4 of them are near your objects and one player is 1km far way, so all objects would be hidden and the other 4 players wouldn't be able to see them.

So what you want to do is check the distance between every player individually and the objects.

You have to constantly check the distance of the player(s) to the objects you want to hide and then execute the commands. I'm not a scripting guru so there could be another approach to your issue but you could add a loop which constantly looks for the distance between the current player and the objects (use the command "distance") and hides the objects if the conditions are met.

-----------------

Okay, I tried it out now and this code is working for me (at least in singleplayer):

Put this into your init.sqf (or in a seperate sqf and execvm it from your init.sqf)

// init.sqf

_hideAndSeek = {
while {true} do
{
	{
		if (!(isPlayer _x)) then
		{
			_object2Hide = _x getVariable["object2Hide", false];
			if (_object2Hide) then
			{
				if ((player distance _x) > 1000) then
				{
				   _x setVariable ["hidden", true];
				   _x hideObject true;
				   _x enableSimulation false;
				}
				else
				{
					_isHidden = _x getVariable ["hidden", false];
					if (_isHidden) then 
					{
						_x setVariable ["hidden", false];
						_x hideObject false;
						_x enableSimulation true;
					}
				};
			};
		};
	} forEach allUnits; 

	sleep 10;
} 
};

_hideAndSeekSpawn = [] spawn _hideAndSeek;
player setVariable ["hideAndSeekSpawn", _hideAndSeekSpawn];  

Now you have to insert the following code into the Init-Field of every unit you create:

this setVariable["object2Hide", true, true];

I tried this code out but it could still be buggy but it should hide every object (which you decorated with the line above) if the distance to the player is more than 1km and checks every 10 seconds for the distance (with that great distance you don't have to check it more frequently).

There are still some informations missing to really help you out though!

Like when are the objects you want to hide are created? In the init.sqf? In the missions.sqm or during the game?

If your objects are created during the game you have to synchronize your objects with the objectsArray (like using publicVariable) or hope that setVariable does the job. If your objects are created in the init.sqf or within your missions.sqf you don't have to do anythin more.

Well I'm sure there are more efficient ways of doing this (like with triggers or smth) and I'm sure someone with better knowledge will help you out ^^

Edited by XxAnimusxX
major edit with code change

Share this post


Link to post
Share on other sites

I'll hijack this thread for a very similar question.

I know that there is a script that makes it possible to hide units. I even think it was HideUnit. The problem is, I want the unit to appear when a trigger is fired, and I cannot remember the script for that. objectName hideObject false; does not work, neither was this the script I used before either..

Share this post


Link to post
Share on other sites

You can slightly modify animus code to work. Or, you could avoid this headache entirely, by simply spawning the units when the condition is met. Or, you could use one of the UPS scripts or DAC, they cache units.

Share this post


Link to post
Share on other sites

Thank you guys for the reply. @animus yes all the units i m trying to hide is placed on the editor, none of them are created outside script or anything like that. I will try your script and see how it goes. Thank you very much for the help.

Share this post


Link to post
Share on other sites

Let us know how it went. I still say it's better to spawn the units (not placed in the editor), and waypoints etc when a condition is met, instead of hiding units :cool:. There are advantages to doing it that way. Clean work space (editor),simple scripting and it's not a hassle, as this has shown to be a thorn in your side.Odds are, "hiding" units, you'll be back asking x or y about the script. Unless there's some reason why they have to be placed in the editor and then hidden afterwords, instead of doing it an easy way. My 2C

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  

×