Home   Help Search Login Register  

Author Topic: FindClosestTown (ACCEPTED)  (Read 5309 times)

0 Members and 2 Guests are viewing this topic.

Offline hoz

  • OFPEC Site
  • Administrator
  • *****
FindClosestTown (ACCEPTED)
« on: 06 Jul 2007, 05:18:03 »
I built this script which was based on the idea from Taurus over at the BI forums. His script was called ShowSarahaniTowns, mine goes a step further and finds all the town names based on the few town types. It does exclude the vegetation and other things that pop up which aren't really towns IMO. It 'should' work on other islands as long as the config includes the town type.

Updated to include a function, original script didn't change, but I did add to the mission to include a demo for the function. Many thanks to Mandoble for being patient.  :clap:

OFPEC DOWNLOAD
« Last Edit: 22 Jan 2009, 18:42:06 by hoz »
Xbox Rocks

Offline Taurus

  • Members
  • *
  • Yepp, I'm a llama!
Re: FindClosestTown
« Reply #1 on: 06 Jul 2007, 05:53:29 »
 :cool2:

I've checked it out, and it works perfectly!  :good:
I crashed a few times with the chopper whilst using the radio and or the action, but thats just me beeing a bad pilot :D

And yes, not all areas are towns(from my script),  :scratch:!

[edit]
Heres my script (and mission) which Hoz were talking about
http://files.filefront.com//;7974452;;/



« Last Edit: 06 Jul 2007, 09:19:37 by Taurus »

Offline Mandoble

  • Former Staff
  • ****
    • Grunt ONE and MandoMissile suite
Re: FindClosestTown
« Reply #2 on: 06 Jul 2007, 12:12:03 »
Interesting script, may you convert it to a function so it returns the closest town or nothing when called?

Offline hoz

  • OFPEC Site
  • Administrator
  • *****
Re: FindClosestTown
« Reply #3 on: 10 Jul 2007, 04:44:05 »
I updated the first post with a new demo mission to include the function. If no towns are found then it will return "No Towns Found" not sure if this is ideal but the someone using the function they could alter the return msg.
Xbox Rocks

Offline Mandoble

  • Former Staff
  • ****
    • Grunt ONE and MandoMissile suite
Re: FindClosestTown
« Reply #4 on: 10 Jul 2007, 12:02:28 »
First, the function is quite usefull and may be used many times along a mission, so you dont want to keep compiling it every time. You may set the following line to be executed in the init.sqs or init.sqf of any mission:
Code: [Select]
ClosestTown = compile loadfile "FuncfindClosestTown.sqf";

You may still do the following inside the function:
change:
_return = "No Towns Found!";
by:
_return = "";

So the calling function may easily check for "", and if so, display any wanted text there in any language.

This way:
Code: [Select]
_closesttown = [player] call ClosestTown;
if (_closesttown != "") then
{
   hint format["You are near %1",  _closesttown];
}
else
{
   hint "No towns nearby";
};

You may also add another argument: minimum distance to detect a town. So, only towns closer than that will be returned.

Offline hoz

  • OFPEC Site
  • Administrator
  • *****
Re: FindClosestTown
« Reply #5 on: 11 Jul 2007, 05:42:40 »
Updated the zip file. Now it contains only a function to return the nearest town. Hopefully this is the last revision. :)
Xbox Rocks

Offline Mandoble

  • Former Staff
  • ****
    • Grunt ONE and MandoMissile suite
Re: FindClosestTown
« Reply #6 on: 11 Jul 2007, 15:43:42 »
I agreen, it may be considered final and ready to send to ED, right?

BUT

I think it may be also the baseline of a FindNearestFriendlyTown function or script. It would return the nearest town or city where enemy forces are not present or where friendly forces have numerical advantage over enemy ones.

Offline Mr.Peanut

  • Former Staff
  • ****
  • urp!
Re: FindClosestTown
« Reply #7 on: 12 Jul 2007, 15:43:51 »
Mandoble, you could combine it with your power balance script. The question is how to properly get the area that a town covers.  Perhaps allow the user to define an array of trigger radii for each town type, and then for each town return a threat array for each radius. Let the user decide  whether he wants a threat to be represented by control of the town core, or of a area surrounding the entire town.  If the user does not provide values, then a single default radius could be set for each type.
« Last Edit: 12 Jul 2007, 15:49:52 by Mr.Peanut »
urp!

Offline Mandoble

  • Former Staff
  • ****
    • Grunt ONE and MandoMissile suite
Re: FindClosestTown
« Reply #8 on: 12 Jul 2007, 17:33:37 »
mmm the problem here is different. The closesttown is a function, but to detect enemies you would like to use a trigger placed over each town to check balance of forces, BUT, that trigger would require 1 sec to update its list of units, so you would need to Sleep 1 sec before checking. So it is actualy tricky to solve the problem. It may be switched back to a script, updating a global var array so the caller just execute it with execVM, get the returning handler of the script and waits till the script terminates before checking the results in that global array. Lets see how Hoz decides to solve the "problem" ...  :whistle:  :P

Offline Mandoble

  • Former Staff
  • ****
    • Grunt ONE and MandoMissile suite
Re: FindClosestTown (ACEPTED)
« Reply #9 on: 01 Sep 2007, 15:04:42 »
The function has been accepted and moved to ED Depot ArmA functions

Offline Trexian

  • Members
  • *
Re: FindClosestTown (ACCEPTED)
« Reply #10 on: 22 Sep 2008, 17:30:26 »
First, great thanks to Hoz (and everyone) for this script.  VERY cool.

Second, sorry for the thread-necromancy. :)

Anyway, I've been using it to familiarize myself with several things - getting arrays from configs and creating functions.

In working through this function/script, I am confused by something.  This part doesn't seem to work quite properly when I run it.

Code: [Select]
_cfgTowns=(configFile >> "cfgWorlds" >> WorldName >> "Names");
...
_cfgPath = _cfgTowns select _i;
_typecity =  getText (_cfgPath >> "type");
if ((_typecity == "NAMECITY") || (_typecity == "NAMEVILLAGE") || (_typecity == "NAMECITYCAPITAL")) then
{
 _towns Set [_i,[getText (_cfgPath >> "name"),getArray (_cfgPath >> "position")]]; 

};
_ntowns = count _towns;

When run on Sarahni, the initial _ntowns array brings back ~250 entries.  Some of which throw errors.  I narrowed it down, for example, to element 13 (base 0, the 14th item in the config entry).  That element is:

Code: [Select]
class Forest_SelvaDeCresta {
name = "Selva De Cresta";
position[] = {7475, 16815};
type = "VegetationFir";
radiusA = 100;
radiusB = 100;

Clearly, that isn't a "city" type. :)

The errors don't stop the script, but are annoying.

Any help would be greatly appreciated. :)
Sic semper tyrannosauro.

Offline Spooner

  • Members
  • *
  • Mostly useless
    • Community Base Addons
Re: FindClosestTown (ACCEPTED)
« Reply #11 on: 22 Sep 2008, 17:54:42 »
Code: (funcFindClosestTown.sqf Line 21) [Select]
_towns Set [_i,[getText (_cfgPath >> "name"),getArray (_cfgPath >> "position"), _typecity]];
Should be:
Code: (funcFindClosestTown.sqf Line 21) [Select]
_towns = _towns + [[getText (_cfgPath >> "name"),getArray (_cfgPath >> "position"), _typecity]];
This will now give the correct _ntowns = 41 and the array will not have "empty" values in it (the function, as is, just ignores these empty values, but I'm assuming you wanted to use the list of towns for another purpose).

The reason: If you use set beyond the size of an array, then it will expand the array to the right size before setting that value, which means any missing values will be left undefined.
Code: [Select]
_frog = [1, 2, 3];
_fish = _frog set [5, 6]; // Set a index that isn't in the array.
hint str _fish;
// => [1, 2, 3, <null>, <null>, 6];

Incidentally, SPON_directionName could be used to get the direction to the town in other formats.
« Last Edit: 22 Sep 2008, 18:01:27 by Spooner »
[Arma 2] CBA: Community Base Addons
[Arma 1] SPON Core (including links to my other scripts)

Offline hoz

  • OFPEC Site
  • Administrator
  • *****
Re: FindClosestTown (ACCEPTED)
« Reply #12 on: 22 Sep 2008, 17:56:04 »
some of the valleys and forests have names.
Xbox Rocks

Offline Trexian

  • Members
  • *
Re: FindClosestTown (ACCEPTED)
« Reply #13 on: 22 Sep 2008, 18:15:05 »
Ah!  That makes sense, then!  Of course, using the "set" with the iterator meant in each instance where the conditional filtered out the non-cities, it left a null entry.  That's why I couldn't even get it to hint the "name."

Thanks!

(And thanks hoz, too!) :D
Sic semper tyrannosauro.

Offline Trexian

  • Members
  • *
Re: FindClosestTown
« Reply #14 on: 25 Sep 2008, 19:59:51 »
... but to detect enemies you would like to use a trigger placed over each town to check balance of forces, BUT, that trigger would require 1 sec to update its list of units, so you would need to Sleep 1 sec before checking....

Did you guys ever resolve this issue?   :cool2:
Sic semper tyrannosauro.