Jump to content
Sign in to follow this  
Spudgunner

Where am I?

Recommended Posts

Is there a way to determine which city or village an AI unit is located. So in psuedocode I can do things like...

IF unit is in Novy Sabor THEN 
   "do stuff"
ELSE
   IF unit is in Berezino THEN 
  "do stuff"
   ELSE go to Novy Sabor or Berezino

Share this post


Link to post
Share on other sites
Is there a way to determine which city or village an AI unit is located. So in psuedocode I can do things like...

IF unit is in Novy Sabor THEN 
   "do stuff"
ELSE
   IF unit is in Berezino THEN 
  "do stuff"
   ELSE go to Novy Sabor or Berezino

You can always use triggers over those towns you want them to be in, can't you?

Share this post


Link to post
Share on other sites
The best is to make some triggers.
You can always use triggers over those towns you want them to be in, can't you?

Not really because, where these AI end up is totally random. So I need to get the location or location name. I heard that cities and towns are like glorified markers. I've useed commands like nearestLocations or LocationLogicCityCenter, but the return is bunch of numbers like you get with grouped AI.

Share this post


Link to post
Share on other sites
There are also the BIS location functions, which can allow you to get the distance of a unit from those locations. Depending on how far away they are, do the stuff.

Edit - just saw your post (we posted at the same time). Try something from this thread:

http://www.ofpec.com/forum/index.php?topic=33978.0

I'll have a look at that thread & the function. The name of towns, villages and cities seem to be in CfgLocationTypes, but I don't know how to access it.

I also found Location and Command Group: Locations. I tried Text Location in conjunction with

_locCtr = nearestObjects [_pasRnd, ["LocationLogicCityCenter"], 500]

but no name appears when using hint.

EDIT: I looked at the code for BIS location functions and noticed a command that's not in the wiki: GetText. I wonder if there's a mix up between text and text location, as the same syntax is used.

Edited by Spudgunner
add a link + function

Share this post


Link to post
Share on other sites

You can retrieve towns via

_names = configfile >> "cfgWorlds" >> worldname >> "Names";

_name = _names Select 0; //--- First town of the array.
_position = GetArray (_name >> "position"); //--- Position of the town.
_townName = GetText (_name >> "name"); //--- Name of the town.

Then you just have to check which town is in range of the player.

Share this post


Link to post
Share on other sites

Yeah, it is a bit more complicated - but not much. :) You need to go into the Game Modules and add the location thing like this:

locationFunction01.jpg

Once you have that setup, you can do something like:

_list = ["CityCenter",[position player,500],true] call bis_fnc_locations;

That will compile a list of the city centers. Then you need to get the names of anything in the list (may have to hint the name, to make sure you have the spelling and such correct):


if ((count _list) > 0) then
{
 {
_name = _x getVariable "name";
hint format ["name == %1", _name];
sleep 1;
if (_name == "Novy Sobor") then {hint "dude is near New Church";};
if (_name == "Berezino") then {hint "dude is near Birchville";};

 } forEach _list;
};

Obviously, the conditionals would just allow you to run whatever code you wanted. You could also play with the distance, if 500m is too far distant for you. I've found that ~200m is a good rule-of-thumb for the city borders in most of Chernarus (the big cities are exceptions, of course).

Share this post


Link to post
Share on other sites

Sorry to butt in, but why are triggers unworthy of simply figuring out where a certain unit spawns/is?

You could just create a trigger over each town you need and create a switch statement to discover which he is in... no?

Share this post


Link to post
Share on other sites

Thanks Benny, I'll try that code and see if I can work it in to what I'm trying to do. Basically it just determining which city (town, village) the AI is in and get a name rather than some strange numbers.

Up until now, I tried this code, but nothing happens, although the script is not interrupted.

//_pasRnd: Random AI

_locCtr = nearestLocations [getPos _pasRnd, ["NameCityCapital","NameCity", "NameVillage"], 500];
_townName = name(_locCtr select 0);
hint _townName;

EDIT: Sorry guys missed your post.

Thanks TRexian, I'll give that a go too. Thanks for the example.

Your probably right Jdog but I'll give everything a try. I'm not checking for spawning units, just existing ones that travel from one random town to another random town.

Edited by Spudgunner

Share this post


Link to post
Share on other sites

So if the unit moves... you could create a simple script that runs every minute or something, re-executing the script that checks which trigger list the unit is in (since you won't need it running constantly, unless he's able to teleport). And if you have it execute something once based on where he is... set it so it only executes if currentPos != lastPos (make those variables).

Anyway, good luck with this :)

Share this post


Link to post
Share on other sites
How are you generating the destination? :)

Just by sending a vehicle to markers along the road using scripted WP's. A trigger would cause a random civiilian to disembark at each bus stop. Because its so random, the AI needs to know where it is. Then the AI will walk to a random location. Depending on time of day, it could be a home object, workplace or recreational place like the pub. For instance a Worker civ will go to an industrial building, a functionary or secretary would go to a civil or office building. Once there, they would be removed from the game to conserve resources - unless there's a way for ALICE to take over :bounce3:

The only other problem is finding a easy way to choose a location since the "House" includes thing other than houses, such as pipes and walls :eek:

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  

×