Jump to content
Sign in to follow this  
madrussian

Detecting the roads via code

Recommended Posts

I'm attemting to create an escape style mission that starts just after breaking out from a prison bus. The starting location of the bus should be random, yet on a road somewhere.

I started out getting the types of each possible road segment from the editor and loading them into an array, like this:

_allRoads = [];
_allRoads = _allRoads + ["AAST112"];
_allRoads = _allRoads + ["AAST000"];
_allRoads = _allRoads + ["AAST092"];
_allRoads = _allRoads + ["AAST016"];
_allRoads = _allRoads + ["AAST101"];
_allRoads = _allRoads + ["AAST017"];
_allRoads = _allRoads + ["AAST010"];
_allRoads = _allRoads + ["AAST011"];
_allRoads = _allRoads + ["AAST001"];
_allRoads = _allRoads + ["AAST093"];
_allRoads = _allRoads + ["AAST102"];
_allRoads = _allRoads + ["AAST103"];
_allRoads = _allRoads + ["AAST104"];
_allRoads = _allRoads + ["AAST117"];
_allRoads = _allRoads + ["AAST115"];
_allRoads = _allRoads + ["AAST118"];
_allRoads = _allRoads + ["AAST119"];
_allRoads = _allRoads + ["AAST122"];
_allRoads = _allRoads + ["AAST123"];
_allRoads = _allRoads + ["AAST002"];
_allRoads = _allRoads + ["AAST094"];
_allRoads = _allRoads + ["AAST003"];
_allRoads = _allRoads + ["AAST095"];
_allRoads = _allRoads + ["AAST004"];
_allRoads = _allRoads + ["AAST012"];
_allRoads = _allRoads + ["AAST096"];
_allRoads = _allRoads + ["AAST035"];
_allRoads = _allRoads + ["AAST036"];
_allRoads = _allRoads + ["AAST013"];
_allRoads = _allRoads + ["AAST014"];
_allRoads = _allRoads + ["AAST015"];
_allRoads = _allRoads + ["AAST108"];
_allRoads = _allRoads + ["AAST006"];
_allRoads = _allRoads + ["AAST097"];
_allRoads = _allRoads + ["AAST105"];
_allRoads = _allRoads + ["AAST106"];
_allRoads = _allRoads + ["AAST091"];
_allRoads = _allRoads + ["AAST107"];
_allRoads = _allRoads + ["AAST113"];
_allRoads = _allRoads + ["AAST116"];
_allRoads = _allRoads + ["AAST109"];
_allRoads = _allRoads + ["AAST111"];
_allRoads = _allRoads + ["AAST110"];
_allRoads = _allRoads + ["AAST124"];
_allRoads = _allRoads + ["AAST126"];
_allRoads = _allRoads + ["AAST127"];
_allRoads = _allRoads + ["AAST007"];
_allRoads = _allRoads + ["AAST009"];
_allRoads = _allRoads + ["AAST008"];
_allRoads = _allRoads + ["AAST100"];
_allRoads = _allRoads + ["AAST099"];
_allRoads = _allRoads + ["AAST098"];
_allRoads = _allRoads + ["AAST005"];
_allRoads = _allRoads + ["AAST048"];
_allRoads = _allRoads + ["AAST061"];
_allRoads = _allRoads + ["AAST053"];
_allRoads = _allRoads + ["AAST050"];
_allRoads = _allRoads + ["AAST062"];
_allRoads = _allRoads + ["AAST051"];
_allRoads = _allRoads + ["AAST066"];
_allRoads = _allRoads + ["AAST064"];
_allRoads = _allRoads + ["AAST063"];
_allRoads = _allRoads + ["AAST057"];
_allRoads = _allRoads + ["AAST058"];
_allRoads = _allRoads + ["AAST060"];
_allRoads = _allRoads + ["AAST049"];
_allRoads = _allRoads + ["AAST059"];
_allRoads = _allRoads + ["AAST052"];
_allRoads = _allRoads + ["AAST065"];
_allRoads = _allRoads + ["AAST040"];
_allRoads = _allRoads + ["AAST041"];
_allRoads = _allRoads + ["AAST042"];
_allRoads = _allRoads + ["AAST043"];
_allRoads = _allRoads + ["AAST044"];
_allRoads = _allRoads + ["AAST045"];
_allRoads = _allRoads + ["AAST046"];
_allRoads = _allRoads + ["AAST047"];
_allRoads = _allRoads + ["AAST054"];
_allRoads = _allRoads + ["AAST055"];
_allRoads = _allRoads + ["AAST056"];
_allRoads = _allRoads + ["AAST027"];
_allRoads = _allRoads + ["AAST028"];
_allRoads = _allRoads + ["AAST029"];
_allRoads = _allRoads + ["AAST030"];
_allRoads = _allRoads + ["AAST031"];
_allRoads = _allRoads + ["AAST073"];
_allRoads = _allRoads + ["AAST032"];
_allRoads = _allRoads + ["AAST033"];
_allRoads = _allRoads + ["AAST034"];
_allRoads = _allRoads + ["AAST019"];
_allRoads = _allRoads + ["AAST020"];
_allRoads = _allRoads + ["AAST021"];
_allRoads = _allRoads + ["AAST022"];
_allRoads = _allRoads + ["AAST023"];
_allRoads = _allRoads + ["AAST024"];
_allRoads = _allRoads + ["AAST025"];
_allRoads = _allRoads + ["AAST026"];

Next I obtain a random position on the island, _checkPos.

Then I attempt to locate and use the closest road segment, like this:

_closeRoadSegs = nearestObjects [_checkPos, _allRoads, 1000];
_roadSeg = _closeRoadSegs select 0; // first element is the closest road segment
PrisonBus setPos position _roadSeg;

Unfortunately, when I do a hint, no road segments are detected:

hint format ["_closeRoadSegs: %1", _closeRoadSegs];

Now, if I place a road segment directly into the editor and try again, my code finds it and places the prison bus directly on top.

So are certain map items not really objects (like roads)?

Anyone have any idea on how to detect roads within the map, without resorting to crude techniques, such as tediously placing invisible markers on all the roads?

Share this post


Link to post
Share on other sites

I believe if something has no ID (when switching IDs on in the editor) then it cannot be dealt with scriptwise... But here comes a queston... How the sneaky AI manges to drive roads? AI is a script and it finds any road on the map... Pity we can't ask the AI how he does the trick)

Anyway, there's still hope for you MadRussian.

Share this post


Link to post
Share on other sites

G'day, I have tried to do this for trees (no luck), but in my searches I found this topic which may help you

Edited by =Odin=
bad link

Share this post


Link to post
Share on other sites

@zvukoper

That is the question indeed! How do those little sneaky SOBs know! :)

@=Odin=

Thanks for that topic. Originally I thought briefly about using the model names but I couldn't seem to figure out how to make it work. Looks like Worldeater figured it out though.

@raedor

Thank the makers! Oooh all the handy new ArmA2 commands are making me drool. :D Another week or so and I'll have my copy. For now I'm working on an escape from North Sarhani.

So I actually did eventually come up with my own solution. An script creating an army of HMMWVs starting in Bagango and spreading out across the map like a cancer. Worked like a charm though and now I've got the road data (points at 50 meter intervals with corresponding directional data) for all of North Sarhani. When in doubt, enlist the AI as your minnions!

Although it took the greater part of a day to write the code and get complete coverage, the method is fairly quick now to apply and could easily be used on a variety of maps. Probably obsolete though as far as ArmA2 is concerned given that new nearRoads command Raedor mentioned, but my method works great for ArmA1 (given the absence of such a command).

If anyone is interested, I'll paste the North Sarhani road data for use in any of your missions (and a screenshot for kicks). :)

Share this post


Link to post
Share on other sites
@raedor

Thank the makers! Oooh all the handy new ArmA2 commands are making me drool. :D Another week or so and I'll h

Oh sorry, I didn't realise we're in the A1 subforum. :confused:

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  

×