Jump to content
Sign in to follow this  
arjay

Building unique identifiers, I feel like I'm missing something fundamental..

Recommended Posts

Hello All,

Here's the situation

I'm generating some position data for each building object on the map, and I would like to be able to store this data and futher data against a unique identifier for the building in question. I feel like I'm missing some fundamental command, or otherwise ARMA does not work in the way I'm thinking..

I have a list of building objects for example that has been generated from nearObjects:

_buildings = _position nearObjects ["House_F", _radiusA];

So my script goes ahead and generates some costly clear parking position data using an expensive function findEmptyPosition for each building.

I would like to be able to output that data to the RPT file for example and then bring it back into my script as a hard coded set of position data for each building. I was hoping I could do something along these lines:

pseudocode:

dictionary[buildingID] = [[additionalData],[additionalData]]]

The problem I have is with the buildingID part.

I notice that when I dump the the building object it will show the id that can be seen in the editor:

40e66b00# 126682: i_stone_shed_v1_f.p3d

So how can I get that id out of a building object (without messing around with string split or something), I would have thought there would have been a getObjectId or similar method? Also is there a getObjectById method that could grab the object by passing the id - I saw nearestObject but that looks like its limited to a radius, or may be expensive?

Apologies if I'm missing something fundamental here, I'm new to ARMA scripting and this is how I would go about it in another language.

Much obliged for any assistance given!

  • Like 1

Share this post


Link to post
Share on other sites

Tell us a bit more about what you're trying to do there, maybe there's an alternate solution.

Why do you need those positions to be linked to specific buildings?

Anyway, you could give these two commands a try:

http://community.bistudio.com/wiki/netId

http://community.bistudio.com/wiki/objectFromNetId

I haven't tested them yet, so I don't know if they're constant. Let us know what you find out.

If nothing else works, you could always save the exact position of the buildings and use http://community.bistudio.com/wiki/nearestObject on that position. That shouldn't be so expensive.

Share this post


Link to post
Share on other sites

Thank you for your response Tajin.

The purpose of this script is to generate a set of known good parking positions for each building, Currently I'm using findEmptyPosition and then spawning the vehicle in the spot with a spawn to check if the vehicle takes damage, if not after 10 seconds I can assume thats a safe spot to spawn a vehicle. Because of the placement of other objects around buildings, I don't think I can have a set of position data that is related to a building class only, I end up with most spawned vehicles blowing up. This and other expensive data being calculated on init is causing a fair hit on FPS, which I would like to reduce if possible.

I did try the netID and objectFromNetId on each of the building objects, but I got a null back, not sure if thats because I'm running on local server / client, so that might be worth a go on a dedicated server. Also not sure if those IDs are persistent across game instances.

dump example of netID and objectFromNetId

"<NULL-object>" - netID
"40e96b00# 149675: cargo_house_v1_f.p3d"
"" - objectFromNetId

I can always store against the string version of the object I guess - As long as this string doesn't change..

dictionary["40e96b00# 149675: cargo_house_v1_f.p3d"] = []

But then I'm still left with the issue if I want to retrieve that object from the ID only.

Share this post


Link to post
Share on other sites

Thanks Lifted

I was hoping to avoid string manipulation, hoping there was a better way, but I'll save that reference for a last resort, good find.

Share this post


Link to post
Share on other sites

netId only works in MP games (so not in the editor for example).

I tried getting SP id's from objects aswell but apparently that's not supported.

Anyway I don't understand why you would need the object id specific. You could get all objects, store them by their formatted name (_name = format["%1, _object]) and then store their positions inside the array. (Or the positions of the "Space you need near the house").

Either way if you can:

A. Output the house positions and use nearObjects with a small radius and then do your magic on init (or whenever needed) or

B. Output them in a test setup and import those back

Would look something like:

_buildings = getMarkerPos "centermap" nearObjects ["House_F", 5000];  
_building_objects [];
{
  _building = _x;
  _name = format["%1",_building];
  _building_object = [_name , getPos _building];
  _building_objects set [count _building_objects, _building_object];
} foreach _buildings;

{
  _building_object = _x;
  diag_log format ["Name:%1--Pos:%1", _building_object select 0, _building_object select 1];
} forEach _building_objects;

If you'd want to retrieve the ID from the name you could use the string functions made by Kronzky:

_object_id = [_object_name] call GET_OBJECT_ID;

GET_OBJECT_ID =
{
  _object_name = _this select 0;
  _object_id = [_object_name , 10, 6] call KRON_StrMid;
};


KRON_StrToArray = {
private["_in","_i","_arr","_out"];
_in=_this select 0;
_arr = toArray(_in);
_out=[];
for "_i" from 0 to (count _arr)-1 do {
	_out=_out+[toString([_arr select _i])];
};
_out
};
KRON_StrMid = {
private["_in","_pos","_len","_arr","_i","_out"];
_in=_this select 0;
_pos=abs(_this select 1);
_arr=[_in] call KRON_StrToArray;
_len=count(_arr);
if ((count _this)>2) then {_len=(_this select 2)};
_out="";
if ((_pos+_len)>=(count _arr)) then {_len=(count _arr)-_pos};
if (_len>0) then {
	for "_i" from _pos to (_pos+_len-1) do {
		_out=_out + (_arr select _i);
	};
};
_out
};

Share this post


Link to post
Share on other sites

Yep thats what I'm thinking as well mindstorm.

It just seemed odd that ids for those objects aren't accessible in the same way the using vehicleVarName for instance when working with named editor created objects. It would be great if I could do format["%1","STRING_BUILDING_ID"] and get an object back directly as with named objects. Ah well thought I would double check.

Cheers everyone!

Share this post


Link to post
Share on other sites

Hmm but is it really necessary to have those parking-positions linked to certain buildings?

If you only need them as safe spots to spawn vehicles in, then why don't you save only the positions (and whatever other parameters you need for them)?

Well maybe your spawn is somehow related or triggerd from those buildings?

In that case you could also do the following:

When the map loads, use your saved coordinates to create invisible dummy-objects across the map, for example "Sign_Sphere25cm_F" (use the hideObject command on it).

Now when you want to spawn something next to a certain house you only need to use a command like this..:

getPos _this nearestObject "Sign_Sphere25cm_F"

.. to easily detect the nearest spawn-position.

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  

×