Addon: Town/Location Information

Addon: Town/Location Information

« posted: Jul 14, 2016, 06:13 PM »
As players moved around the map I wanted to display their closest location.  Looking online I found a few scripts to pull location information so I mashed up a few things and made this little add-on.  I'm sure it can be optimized a bit but figured I would share what I had so far.. for anyone that is interested.

There is sometimes a delay when displaying the location information. I know there is another script out there for displaying text with additional delay on the screen so I may add that custom code in.  Also the location information appears in the lower right. This is sometimes a problem when you're in a vehicle with players showing on the right and the text is blocked by player names.   I believe this can be changed by creating an overlay to move the text to another location (using custom text display)

I did have some issues using nearestlocation vs nearestlocations.  I wasn't receiving the correct location information. Not sure if it was a bug or not.  Also played around with the location types but I ran into issues with information not coming back correctly.  The radius check is pretty large but feel free to play around with the settings.  When I lowered it I ran into weird results.

If you make some changes and get better performance/results let me know and post it here.

Onto the script:

Place the TownLocation.sqf into addons\scripts\

Modify your init.sqf

Code: [Select]
[] execVM "addons\scripts\TownLocation.sqf";


Code: [Select]
//Spawn this
[] spawn {

//Grab a listing of town types that we will search through (bistudio nearestlocations example)
// allLocationTypes = [];
// "allLocationTypes pushBack configName _x" configClasses (configFile >> "CfgLocationTypes");

_closestlocation = text ((nearestLocations [position player, ["Airport", "NameLocal", "NameVillage", "NameCity", "NameCityCapital", "NameMarine"], 20000]) select 0);
_location_old = _closestlocation;

//Loop this shit forever
while {true} do
_closestlocation = text ((nearestLocations [position player, ["Airport", "NameLocal", "NameVillage", "NameCity", "NameCityCapital", "NameMarine"], 20000]) select 0);
//_closestlocation = text ((nearestLocations [position player, allLocationTypes, 20000]) select 0);
_location_new = _closestlocation;
//systemChat format["Location 3: %1", _closestlocation];

if (_location_new == _location_old) then {
//you can debug some shit here if you like
} else {

//update the _town_nameold variable with the new town name
_location_old = _location_new;

//Time calculation
_hour = date select 3;
_mins = date select 4;

//Display our location on the screen
["LOCATION", _location_new, format ["%1:%3%2", _hour, _mins, if (_mins < 10) then {"0"} else {""}]] spawn BIS_fnc_infoText;

//Check for a new town every x seconds
sleep 10;

}; //end: while
}; //spawn

Re: Addon: Town/Location Information

« Reply #1 posted: Jul 14, 2016, 06:15 PM »

This displays the location information in the lower right.. the same as if you just join the game. It shows you the town along with the current game time.


If anyone can get allLocationTypes working per the BIStudio Nearestlocations example let me know. When I tried to pull from the config the locations I would not return the results expected.