Jump to content
kaleb c0d3

SOLVED: Serialize/unserialize map markers, including Polylines

Recommended Posts

Sup all!
I've made a modification of BIS_fnc_markerToString and BIS_fnc_stringToMarker to allow Polylines (map drawings) to be serialized/unserialized, because native scripted functions does not allows it. I'm currently using this because my players sometimes participate in a pre-mission recon and this allows them to save important map intel data, that will be re-renderized on their maps on the official mission day.

Use/modify them as you see fit. Enjoy!

 

GLMRK_fnc_markerToString:

Spoiler

/*
	Authors: 
		Killzone_Kid (original, BIS_fnc_markerToString)
		Kaleb (added marker polyline support)
	
	Description:
		Serializes marker to string for storage (supports polylines).
	
	Parameter(s):
		0: STRING - existing marker name
		1: STRING (Optional) - a single data delimiter character. Default "|"
	
	Returns:
		STRING - serialized marker to be used with GLMRK_fnc_stringToMarker or GLMRK_fnc_stringToMarkerLocal 
		or 
		"" on error
	
	Example:
		["marker_0"] call GLMRK_fnc_markerToString;
		["marker_1", ":"] call GLMRK_fnc_markerToString;
*/

params [["_markerName", "", [""]], ["_delimiter", "|", [""]]];

private _markerShape = markerShape _markerName;
private _markerType = [configName (configFile >> "CfgMarkers" >> markerType _markerName), ""] select ((markerType _markerName) == "");

if ( (_markerShape != "POLYLINE") && (_markerType isEqualTo "") ) exitWith { [["Invalid marker type for `%1`", "Marker `%1` does not exist"] select (allMapMarkers findIf { _x == _markerName } < 0), _markerName] call BIS_fnc_error; "" };

toFixed 4;
private _markerPosition = str markerPos [_markerName, true];
private _markerPolyline = str markerPolyline _markerName;
toFixed -1; 

[
	"",
	_markerName,
	_markerPosition,
	["polyline", _markerType] select (_markerShape != "POLYLINE"), 
	_markerShape, 
	_markerPolyline,
	markerSize _markerName, 
	markerDir _markerName,
	markerBrush _markerName, 
	markerColor _markerName, 
	markerAlpha _markerName, 
	markerText _markerName
]	
joinString _delimiter

 


GLMRK_fnc_stringToMarker:

Spoiler

/*
	Authors: 
		Killzone_Kid (original, BIS_fnc_stringToMarker)
		Kaleb (added marker polyline support)
	
	Description:
		Creates marker from serialized data (supports polylines).
	
	Parameter(s):
		0: STRING - marker data from BIS_fnc_markerToString
	
	Returns:
		STRING - created marker 
		or 
		"" on error or if marker exists
	
	Example:
		["|marker_0|[4359.1,4093.51,0]|mil_objective|ICON|[1,1]|0|[]|Solid|Default|1|An objective"] call GLMRK_fnc_stringToMarker;
*/

params [["_markerData","",[""]]];

if (_markerData isEqualTo "") exitWith 
{
	["Marker data is empty"] call BIS_fnc_error;
	""
};

_markerData splitString (_markerData select [0,1]) params
[
	"_markerName", 
	"_markerPos", 
	"_markerType",
	"_markerShape",
	"_markerPolyline",
	"_markerSize",
	"_markerDir",
	"_markerBrush",
	"_markerColor",
	"_markerAlpha",
	["_markerText",""]
];

private _marker = createMarker [_markerName, parseSimpleArray _markerPos];

if (_markerShape == "POLYLINE") then {
	_marker setMarkerPolyline parseSimpleArray _markerPolyline;
} else {
	_marker setMarkerType _markerType;
	_marker setMarkerShape _markerShape;
	_marker setMarkerSize parseSimpleArray _markerSize;
	_marker setMarkerDir parseNumber _markerDir;
	_marker setMarkerBrush _markerBrush;
	_marker setMarkerText _markerText;
};

_marker setMarkerAlpha parseNumber _markerAlpha;
_marker setMarkerColor _markerColor;

_marker 

 

 

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

×