Forum Jump :

Author Message


Posts: 106
Rank:


Level: Member

Country: us
Location: Pennsylvania
Occupation:
Age:
In-game name: Xian

 
#1 Posted at 2017-09-13 15:50        
     
So the following code works exactly the way I need it to. My issue is, I don't understand why. In a nutshell, I added a few Opfor slots to a mission to add a small PvP element to it. I wanted to Opfor to be underpowered/undergeared but have a tech to be able to "recon" blufor player's position in a "not quite cheating" way. so I came up with the following:

openMap true;
{
	if ((side _x) == West) then {
		_pos = getPos _x;
		_posMarker = [_pos,20,150] call BIS_fnc_findSafePos;
		_marker = createMarkerLocal ["pvp_opformarker" + str _x,_posMarker];
		_marker setMarkerColorLocal "ColorBlue";
		_marker setMarkerShapeLocal "ELLIPSE";
		_marker setMarkerBrushLocal "Solid";
		_marker setMarkerSizeLocal [200, 200];
	};
	
} forEach allUnits;
sleep 10;

{
  private "_pvpMarker";
  _pvpMarker = toArray _x;
  _pvpMarker resize 15;
  if (toString _pvpMarker == "pvp_opformarker") then {
    deleteMarker _x;
  }
} forEach allMapMarkers;
hint format ["%1",allMapMarkers];

And it works perfectly, just the way I wanted. My issue is that the section:
{
  private "_pvpMarker";
  _pvpMarker = toArray _x;
  _pvpMarker resize 15;
  if (toString _pvpMarker == "pvp_opformarker") then {
    deleteMarker _x;
  }
} forEach allMapMarkers;

is what I don't quite understand. I grabbed it while looking through the examples of allMapMarkers on the wiki. I was curious to what it did exactly and lucky me, it did what I had been struggling to do! Can anyone explain in layman's terms what that part of the code is doing for me? Specfically the "toArray" and "toString" parts are what is confusing me the most.


Author Message


Posts: 1484
Rank:


Level: Member

Country: uk
Location:
Occupation:
Age:
In-game name:

 
#2 Posted at 2017-09-14 01:21        
     
I take a stab at it.

toArray converts the marker name which is a string into an array
resize 15 reduces the array to the fist fifteen characters characters
tostring is used to change the result back to a string and then compare it to "pvp_opformarker" if they equal each other _x is deleted


Advertisement


Author Message


Posts: 106
Rank:


Level: Member

Country: us
Location: Pennsylvania
Occupation:
Age:
In-game name: Xian

 
#3 Posted at 2017-09-15 11:45        
     
Ah ha! That makes perfect sense now! Thanks alot!