Forum Jump :

Author Message


Posts: 2
Rank:


Level: Member

Country: us
Location:
Occupation:
Age:
In-game name:

 
#1 Posted at 2015-01-12 04:03        
     
I am trying to find all Land_tank_rust_f objects in a town named Neochori on Altis. I thought I would be able to
nearestObjects [[12502,14337], ['Land_tank_rust_f'], 500]
But that didn't find anything. So I looked up the path configfile >> "CfgVehicles" >> "Land_Tank_rust_F" and found that the parents are ["House_Small_F","House_F","House","HouseBase","NonStrategic","Building","Static","All"].

I am able to find one individually by using
nearestObject [12465.5,14373.3,2.68724]
Which then returns:
702284: tank_rust_f.p3d
I can't get the land tank with nearestObjects when using any of the parents "house_small_f" or even "All".

What am I missing?


Author Message


Posts: 635
Rank:


Level: Member

Country: uk
Location: N.W.
Occupation:
Age: 30
In-game name: big_wilk

 
#2 Posted at 2015-01-12 13:26        
     
Is this an object thats on the map from the start? If so, some just don't seem to exist and return something.p3d, I had a similar problem with some of the fences that are on the map, I never found a way round the problem. You can spawn these objects in and then get them using nearest object, but thats not very useful for influencing one thats on the map already.


Advertisement


Author Message

Crix  



Posts: 122
Rank:


Level: Member

Country: de
Location:
Occupation:
Age:
In-game name:

 
#3 Posted at 2015-01-12 20:16        
     
Hey,

I actually wrote a function for that matter a while ago.

Documentation:
/*
	Author: Crix
	Description:
	Search for nearby pre-built objects like trees, brushes, stone in a nearestObjects-like manner. 
	Use this function carefully as it is extremely slow.  

	Parameter(s):
	0: ARRAY - Position of search center
	1: ARRAY of STRINGS - Array of .p3d names
	2: SCALAR - Search range
	
	
	Returns:
	ARRAY - Array of objects. [] if no objects were found. 

	Example
	//--- Find nearby brushes & trees
	_flora = [position player, ["b_ficusc1s_f", "b_ficusc2d_f", "b_neriumo2d_f", "b_aroundod3s_f", "b_aroundod2s_f"], 250] call CRX_fnc_nearestP3Ds; 
	
*/


Function:
CRX_fnc_nearestP3Ds =
{
	_pos	= [_this, 0, [0,0,0], [[]], [2,3]] call BIS_fnc_param;
	_types	= [_this, 1, ["All"], [[]]] call BIS_fnc_param;
	_range 	= [_this, 2, 50, [0]] call BIS_fnc_param;

	_objs 	= nearestObjects [_pos, [], _range]; 
	_colon 	= 58; 
	_dot 	= 46; 


	_allOfType	= []; 
	{
		_obj = _x; 
		if (typeOf _obj isEqualTo "") then 
		{
			_arr 	= toArray str(_obj); 
			_start 	= _arr find 58; 
			if !(_start < 0) then 
			{
				_name = []; 
				_end = _arr find 46;
				for "_k" from (_start + 2) to (_end - 1) do 
				{
					_name set [count _name, _arr select _k]; 
				}; 
				if (toString _name in _types) then
				{
					_allOfType set [count _allOfType, _obj]; 
				}; 
			}; 
		}; 
	}
	count _objs; 

	_allOfType
};

There might be a simpler and faster way but this worked for me. Be careful with bigger range-values as the function is very slow.

Your case:
_rustyTanks = [[12502,14337], ["tank_rust_f"], 500] call CRX_fnc_nearestP3Ds;

Crix

This post was edited by Crix (2015-01-12 20:31, 1070 days ago)


Author Message


Posts: 2
Rank:


Level: Member

Country: us
Location:
Occupation:
Age:
In-game name:

 
#4 Posted at 2015-01-13 07:47        
     
# big_wilk : Is this an object thats on the map from the start?
Yes.
If so, some just don't seem to exist and return something.p3d, I had a similar problem with some of the fences that are on the map, I never found a way round the problem.
It does exist. I find it using nearestObjects [player, [], 10] if I stand right next to it. It comes in as:
702284: tank_rust_f.p3d
along with footsteps, bees, mosquitos, flys, telephone poles.
You can spawn these objects in and then get them using nearest object, but thats not very useful for influencing one thats on the map already.
Yes, you are correct. If I spawn a rusty land tank myself I can find it easily using:
nearestObjects [[12502,14337], ['Land_tank_rust_f'], 500]
Then it works great and it comes in as:
5de3d600# 1779945: tank_rust_f.p3d

Added 11 hours 9 minutes later:

# Crix : Hey,

I actually wrote a function for that matter a while ago.
Thanks Crix. That function worked well and fast enough. I put this at the top inside of the function so none of my variables would get stomped.
private ["_pos", "_types", "_range", "_objs", "_colon", "_dot", "_allOfType", "_obj", "_arr", "_start", "_name", "_end"];

This post was edited by Zectbumo (2015-01-13 18:57, 1069 days ago)


Author Message


Posts: 1
Rank:


Level: Member

Country: de
Location:
Occupation:
Age:
In-game name:

 
#5 Posted at 2015-07-23 16:02        
     
Hey guys,

I adjusted the script somewhat so it works with all names from CfgVehicles. This way you don't have to mind the tying case and names of the items.

private ["_pos", "_types", "_range", "_objs", "_colon", "_dot", "_allOfType", "_obj", "_arr", "_start", "_name", "_end"];

_pos = [_this, 0, [0,0,0], [[]], [2,3]] call BIS_fnc_param;
_types = [_this, 1, ["All"], [[]]] call BIS_fnc_param;
_range = [_this, 2, 50, [0]] call BIS_fnc_param;

_objs = nearestObjects [_pos, [], _range];
_allOfType = nearestObjects [_pos, _types, _range];
_colon = 58; 
_dot = 46; 

for '_i' from 0 to ((count _types) - 1) do {
	_types set [_i, toLower (_types select _i)];
};

{
	_obj = _x; 
	if (typeOf _obj isEqualTo "") then 
	{
		_arr 	= toArray str(_obj); 
		_start 	= _arr find 58; 
		if !(_start < 0) then 
		{
			_name = []; 
			_end = _arr find 46;
			for "_k" from (_start + 2) to (_end - 1) do 
			{
				_name set [count _name, _arr select _k]; 
			};
			if (((toLower (toString _name)) in _types) or ((toLower('Land_' + (toString _name))) in _types) and (!(_obj in _allOfType))) then
			{
				_allOfType set [count _allOfType, _obj]; 
			}; 
		}; 
	}; 
} forEach _objs;

_allOfType

This post was edited by ViciousViper79 (2015-07-23 16:51, 878 days ago)