Help adding multiple map markers at once for carepackages!

DangerRuss

OpenDayZ Rockstar!
So again I run a battle royale event server from time to time. One of the features is that carepackages are frequently dropped. I was able to go in and edit the file to add a marker on the map for the carepackage when it's dropped, and it is removed when a player gets close to the carepackage.

The problem is as follows. The first carepackage is dropped and a marker is placed on the map. A second carepackage is dropped and no new marker is added to the map. If a player captures the first carepackage, the marker is removed from the map. The very next carepackage that drops, following the capture of the first carepackage, updates the map marker to it's location. Therefore, any carepackages dropped after the first, and before it's captured, will not have a map marker.
spawn_carepackages.sqf
Code:
//_chutetype, _boxtype, _helistart, _crashwreck
private ["_chutetype","_boxtype","_helistart","_crashwreck","_randomizedLoot","_guaranteedLoot","_chute","_box","_num","_weights","_index","_itemType","_lootRadius","_lootPos","_pos","_bam","_i","_nearby","_smoke","_itemTypes","_cntWeights","_lootTable","_playerName","_null","_message2"];

_chutetype = _this select 0;
_boxtype = _this select 1;
_helistart    = _this select 2;
_crashwreck    = _this select 3;
_randomizedLoot = _this select 4;
_guaranteedLoot = _this select 5;

_lootRadius = 1;
_lootTable = ["HeliCrash","MilitarySpecial","Military"] call BIS_fnc_selectRandom;

    _chute = createVehicle [_chutetype,_helistart,[],0,"CAN_COLLIDE"];
    _chute setVariable["Sarge",1];
    _chute setPos [(getpos _crashwreck select 0), (getPos _crashwreck select 1), (getPos _crashwreck select 2)-10];
   
    _box = createVehicle [_boxtype,_helistart,[],0,"CAN_COLLIDE"];
    _box setVariable["Sarge",1];
    _box setPos [(getpos _crashwreck  select 0), (getPos _crashwreck select 1), (getPos _crashwreck select 2)-10];
   
    _box attachto [_chute, [0, 0, 0]];
   
    _i = 0;


    while {_i < 45} do {
    scopeName "loop1";
    if (((getPos _box) select 2) < 1) then {breakOut "loop1"};

    sleep 1;
    _i=_i+1;
    };  


    switch (true) do {
     case not (alive _box): {detach _box;_box setpos [(getpos _box select 0), (getpos _box select 1), 0];};
     case alive _box: {detach _box;_box setpos [(getpos _box select 0), (getpos _box select 1), 0];_bam = _boxtype createVehicle [(getpos _box select 0),(getpos _box select 1),(getpos _box select 2)+0];deletevehicle _box;};
    };
    _bam setVariable["Sarge",1];
    deletevehicle _chute;
   
    sleep 2;
   
    _pos = [getpos _bam select 0, getpos _bam select 1,0];
   
    //Map Marker
    _null  = createMarker ["MarkerDrop",_pos];
    "MarkerDrop"  setMarkerText "Air Drop";
    "MarkerDrop"  setMarkerType "mil_dot";
    "MarkerDrop"  setMarkerColor "ColorRed";
    //Map Marker
   
    _smoke = createVehicle ["SmokeShellred",_pos,[],0,"CAN_COLLIDE"];
    _smoke setVariable["Sarge",1];

   
   
    //Wait until player is near, wait 90 seconds and delete marker/box.
    waitUntil{
    sleep 1;
    (({isPlayer _x && _x distance _pos <= 5} count playableUnits > 0));
    };


    //_message2 = format[" %1 is at the carepackage!",_playerName];
    _message2 = format[" A player is looting the carepackage!",_playerName];
    [nil,nil,rTitleText,_message2, "PLAIN",6] call RE;

    sleep 5;
    deleteMarker "MarkerDrop";
   
    _num        = (round(random _randomizedLoot)) + _guaranteedLoot;

       
        _itemTypes =    [] + getArray (configFile >> "CfgBuildingLoot" >> _lootTable >> "lootType");   
        _index =        dayz_CBLBase  find _lootTable;
        _weights =        dayz_CBLChances select _index;
        _cntWeights = count _weights;  

        //Creating the Lootpiles outside of the _crashModel
        for "_x" from 1 to _num do {
            //Create loot
            _index = floor(random _cntWeights);
            _index = _weights select _index;
            _itemType = _itemTypes select _index;
       
           
            //Let the Loot spawn in a non-perfect circle around _crashModel
            _lootPos = [_pos, ((random 2) + (sizeOf(_boxtype) * _lootRadius)), random 360] call BIS_fnc_relPos;
            [_itemType select 0, _itemType select 1, _lootPos, 0] call spawn_loot;

            diag_log(format["CAREPACKAGE: Loot spawn at '%1' with loot %2", _lootPos, _itemType]); 

            // ReammoBox is preferred parent class here, as WeaponHolder wouldn't match MedBox0 and other such items.
            _nearby = _pos nearObjects ["ReammoBox", (sizeOf(_boxtype)+3)];
            {
                _x setVariable ["permaLoot",true];
            } forEach _nearBy;
        };
 
ok problem is the script will always create a marker called "MarkerDrop", if this marker already exists the the script cant make it again

so a quick dirty method to avoid this is to have the script check if the marker already exists and if it does make a second one called "MarkerDrop2"

heres the code :) marker check taken from
https://forums.bistudio.com/topic/118355-how-to-check-if-a-marker-exist/

the below code will allow 2 markers if you need more im sure you can dissect the below code and add multiple checks for markers

as with all code i supply i take no responsibility for the launch of nuclear weapons at third world country, destruction of property or loss of life :)

ALWAYS BACKUP AND TEST!!! :p

Code:
if (getMarkerColor "MarkerDrop" == "")then {
    //Map Marker2
    _null  = createMarker ["MarkerDrop2",_pos];
    "MarkerDrop2"  setMarkerText "Air Drop";
    "MarkerDrop2"  setMarkerType "mil_dot";
    "MarkerDrop2"  setMarkerColor "ColorRed";
    //Map Marker2
} else{
    //Map Marker
    _null  = createMarker ["MarkerDrop",_pos];
    "MarkerDrop"  setMarkerText "Air Drop";
    "MarkerDrop"  setMarkerType "mil_dot";
    "MarkerDrop"  setMarkerColor "ColorRed";
    //Map Marker
};

dont forget to add
Code:
deleteMarker "MarkerDrop2";
under
Code:
deleteMarker "MarkerDrop";
 
awesome Sheep thanks bud. I wish there was an easier/cleaner way because this is going to make the script huge. The carepackage drop runs every couple of minutes so there could be a dozen or more after a little bit.
 
awesome Sheep thanks bud. I wish there was an easier/cleaner way because this is going to make the script huge. The carepackage drop runs every couple of minutes so there could be a dozen or more after a little bit.

I can't remember how I did it exactly but I believe it was something like this:

Code:
// add _check and _markername to private at top
_check = true;
while {_check} do {
_random = round(random 1000);
_markername = format["MarkerDrop%1",_random]; //creates random marker name
if (getMarkerColor _markername == "")then {
    _null  = createMarker [_markername,_pos];
    _markername  setMarkerText "Air Drop";
    _markername  setMarkerType "mil_dot";
    _markername  setMarkerColor "ColorRed";
    _check = false;
    //Map Marker2
};
};

could be wrong but I remember it being something like this that I had done to have a script create multiple markers and clean them up afterwards.
 
Back
Top