Jump to content
Phantom Aspect

Trying to find and mark locations on map.

Recommended Posts

I'm a complete beginner at Arma scripting and am having trouble wrapping my head around it entirely to be honest.

 

I've been searching the Arma SQF Wiki for a way to find town locations and place markers on them for a CTI mission I'm attempting to make.

Frankly the info on how commands are supposed to work on the SQF wiki have not been helpful at figuring out how to use them 90% of the time for me.

 

My latest attempt so far is these lines in PACTI_FindTowns.sqf with a Game Logic inserted into the map with the name PACTI and ExecVM "PACTI_FindTowns.sqf"; in the Init field.

 

_PACTI_Capital = nearestLocation [PACTI, "NameCityCapital"];
_PACTI_City = nearestLocation [PACTI, "NameCity"];
_PACTI_Town = nearestLocation [PACTI, "Name"];
_PACTI_Village = nearestLocation [PACTI, "NameVillage"];

createMarker ["hd_dot", _PACTI_Capital];
createMarker ["hd_dot", _PACTI_City];
createMarker ["hd_dot", _PACTI_Town];
createMarker ["hd_dot", _PACTI_Village];

 

What I expected from this was _PACTI_Capital would hold the names of all NameCityCapital values found on the entire map and createMarker would place a hd_dot marker on each one so I could see it working, unfortunately no such luck. I'm hoping to use this to have City Capitals with high capture values and make them lower for each smaller location.

I want it to eventually become an automated system to find and value towns based on type to make CTI mission creation a breeze for future maps, right now this is all just proof of concept and I'm just trying to find what works.

 

Could any SQF programming gods offer guidance? My keyboard has suffered enough stressed headbutting today 😂

Share this post


Link to post
Share on other sites

I don't know what PACTI is , but you are using it as a position!.

 

If you place something in an init field (no matter the object) thing about:

- don't use local variable in main scope (directly as you did). But you can call or spawn the code with local variables, like:   call {_blabla = "hello"; hint _blabla};

- anyway, the code will run in all PCs (in MP) and it's totally useless to create marker globally from everywhere! .

So start with a code like: if (isServer) then {<code>  };  // this way is OK also for local variables because you are in an inner scope.

 

Now your code itself:

nearestLocation returns... location , which is not a position. Always read BIKI for all syntax and returned value(s)

So here, in your code, PACTI should be a position.... of what you want (getPos player, car, trigger, logic, even marker with markerPos) Probably not in your case.

Then you need to use locationPosition for a position of a location using nearestLocation.


createMarker has also some requirements for syntax. You can't use "hd_dot" which is a marker type (In fact you can for one marker, but that doesn't mean you created this type of marker). Read the orange warning in BIKI

So you code should look like:
 

if (isServer) then {
  private _positionRef = [worldSize/2,worldSize/2];
  private _PACTI_Capital = nearestLocation [_positionRef, "NameCityCapital"];
  private _PACTI_City = nearestLocation [_positionRef, "NameCity"];
  private _PACTI_Town = nearestLocation [_positionRef, "Name"];
  private _PACTI_Village = nearestLocation [_positionRef, "NameVillage"];
  private "_mk";
  {
    _mk = createMarker [str random1, locationPosition _x];
    _mk setMarkerType "mil_dot";
    _mk setmarkerText str _x;
  } forEach [_PACTI_Capital,_PACTI_City,_PACTI_Town,_PACTI_Village];
};

Note:

I took [worldSize/2,worldSize]  (center of the map) as position for finding locations. You can use any existing position.

str random 1 is a string (so OK for marker names if you don't care about names). It's a quick mean for multiple names, statistically "never" the same (markers can't have the same name). You can fill the map full of markers with that.

some maps (modded) have no location or very few ones. Check for that in config viewer at:  configfile >> "CfgWorlds" >>your map  >> "Names"

You can find all you need also here! example: configfile >> "CfgWorlds" >> "Stratis" >> "Names" >> "AirStation"

  • Like 1

Share this post


Link to post
Share on other sites

That does clear a couple of things up, "PACTI" was the name used for a Game Logic I had placed on the map, I assumed it would work as the name of a position to search from.

 

I don't see any reference to "worldSize" as an option when searching the BIKI on how to use these commands? Example https://community.bistudio.com/wiki/nearestLocation

That is an issue I'm having, it gives you the bare minimum in how it works and the info on what you can use in commands and how to use them is minimal for a beginner.

 

The info for worldSize itself on the BIKI also doesn't explain anything at all https://community.bistudio.com/wiki/worldSize

 

Basically every command in BIKI says something along these lines

 

"1 is a thing and it can do this"

Syntax: _YourThing = 1  [2, 3] ;

 

However finding everything that can be used for "2" and "3" can't be done by following links on a BIKI page for a command...

Share this post


Link to post
Share on other sites

You just can't be a beginner and know the whole thing at the same time.

Its (like) learning a language. To have the vocabularies and the grammar rules is not enough. You just need to practice it and you have to do it step by step. Mostly very small steps in the beginning...

 

First thing most people learn is to say: "Hello (world)" in that language.

  • Like 3

Share this post


Link to post
Share on other sites
1 hour ago, Phantom Aspect said:

The info for worldSize itself on the BIKI also doesn't explain anything at all

 

It explains it very well and without unnecessary exposition.

 

The command worldSize returns the length in meters of one side of the current terrain. 

 

Quote

 

Example 1:

private _size = worldSize;

 

 

The first example shows the local variable _size being defined as the current worldSize.

 

To tag onto @sarogahtyp's excellent advice, you need to learn to walk before you can run.

 

Start at the beginning: https://community.bistudio.com/wiki/SQF_Syntax

 

 

  • Like 1

Share this post


Link to post
Share on other sites

worldSize

Returns the engine calculated size (terrain side length) of the current world (BIS_fnc_mapSize may return the same value, but is just a simple look up in config).

i.e. in config viewer (from console, and for Stratis) configfile >> "CfgWorlds" >> "Stratis" >> "mapSize"  // 8192

If PACTI is the name of a game logic placed in editor, just use getPos PACTI as position.

  • Like 1

Share this post


Link to post
Share on other sites
18 hours ago, Phantom Aspect said:

I've been searching the Arma SQF Wiki for a way to find town locations and place markers on them

 

You might try using BIS_fnc_locations

 

Example, to find locations of type "NameCity":

["NameCity",[[0,0,0],1000000],true] Call BIS_fnc_locations;

Classname types you might check for:

"NameCityCapital"
"NameCity"
"NameLocal"
"NameVillage"
"NameMarine"
"Hill"

 

  • Like 1

Share this post


Link to post
Share on other sites

I understand it makes sense to you guys and I have a lot to learn, it'd just be nice to have a simple list of known things that work in a command to make the learning process less painful.

 

Compare what I put down earlier.

    1 is a thing and it can do this"

    Syntax: _YourThing = 1  [2, 3] ;

 

To this.

    Syntax: nearestLocation [position, locationClass]

 

There is nothing on the "nearestLocation" BIKI page, no links etc for that function that leads me directly to "worldSiz", the only reason I found out about it is because I had to ask here... The BIKI is extremely vague in its explanations.

Share this post


Link to post
Share on other sites

There is nothing hard to understand.

The commands have always a syntax (at least one) which can be:

- as simple as:  worldSize (no parameter), returning the value for the size of the (square) map. worldsize was my choice for grabbing the position of the center of the map;

- Some of them are a little bit more complex like nearestLocation working with a position (as reference you choose) and a type of location. BIKI gives you the location types (mind for arma3) if you click on the link.

The result is a location. You need to know what a location is. It's not a position (see above). So, nothing hard so far.

- You have also some elaborated commands like addAction which needs a little skill to make them work, especially in multiplayer context.

What's a position? (follow the link)

Then you have functions which are scripts. Same principle as command: some parameters, or not, and returned values. Here you can say that some functions are elaborated and not really documented (not all!)

 

Some links to read for beginning with simple script in single player.

https://community.bistudio.com/wiki/Introduction_to_Arma_Scripting

https://community.bistudio.com/wiki/Variables

https://community.bistudio.com/wiki/Magic_Variables

https://community.bistudio.com/wiki/Category:Data_Types

https://community.bistudio.com/wiki/Code_Best_Practices

 

https://community.bistudio.com/wiki/Code_Optimisation

https://community.bistudio.com/wiki/Mission_Optimisation

 

Have fun!

  • Like 2

Share this post


Link to post
Share on other sites
1 hour ago, Phantom Aspect said:

There is nothing on the "nearestLocation" BIKI page, no links etc for that function that leads me directly to "worldSiz"

 

There is no reason for there to be, as there is no direct relationship between the two.

 

1 hour ago, Phantom Aspect said:

a simple list of known things that work in a command

 

Would be enormous to the point of being entirely useless.

 

I know it's a lot less fun initially, but you really need to sit down and learn this stuff from the beginning as the others have said. Otherwise, it will simply be a frustrating experience.

  • Like 4

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

×