Last active
September 1, 2015 23:57
-
-
Save GeorgeDettmer/9234d96d12f7ef60451a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| moveToGroupMarker = { | |
| if (typeName _this != "OBJECT") then { | |
| _this = player | |
| }; | |
| _pos = getMarkerPos format["#RESPAWN#%1",group _this]; //get respawn marker position | |
| if (_pos isEqualTo [0,0,0]) exitWith {}; //if pos == [0,0,0] no marker exists, exit | |
| _this setVehiclePosition [_pos,[],5]; //set player position to within 5 meter radius at marker pos | |
| _this setDir random 360; //set ranom player direction | |
| }; | |
| if isServer then { | |
| _groupRespawnMarkers = profileNamespace getVariable ["groupRespawnMarkers",[]]; //read saved markers, if none default to [] | |
| if !(_groupRespawnMarkers isEqualTo []) then { //if there are some markers | |
| { | |
| _marker = createMarker [_x select 0,_x select 1]; //create the marker with the saved name and at save position | |
| _marker setMarkerShape "ICON"; | |
| _marker setMarkerType "DOT"; | |
| _marker setMarkerText (_x select 2); //set text from saved data | |
| _thingsToMove = []; | |
| { | |
| _x setDir random 360; | |
| _x setVehiclePosition [_pos,[],10]; | |
| } forEach _thingsToMove; //move items to new marker (ammoboxes etc) | |
| } forEach _groupRespawnMarkers; | |
| }; | |
| groupRespawnMarkerSaveLoop = 10 spawn { | |
| while {TRUE} do { | |
| uiSleep _this; //delay loop | |
| _groupRespawnMarkers = []; | |
| { | |
| if (_x find "#RESPAWN#" != -1) then { | |
| _groupRespawnMarkers pushBack [_x,getMarkerPos _x,markerText _x] //add respawn marker data [marker name,marker position,marker text] | |
| }; | |
| } forEach allMapMarkers; | |
| if !(profileNamespace getVariable ["groupRespawnMarkers",[]] isEqualTo _groupRespawnMarkers) then { //if there are some respawn markers to save | |
| diag_log format["RESPAWN: Saving group respawn markers: %1",_groupRespawnMarkers]; | |
| profileNamespace setVariable ["groupRespawnMarkers",_groupRespawnMarkers]; //set variable ready for saving | |
| saveProfileNamespace; //save all profile namespace variables to file | |
| }; | |
| }; | |
| }; | |
| }; | |
| if !hasInterface exitWith {}; | |
| if (rankId player > 2) then { //if rank is above Sergeant | |
| ["groupRespawnMarker","onMapSingleClick",{ //add on map single click handler | |
| if !_shift exitWith {}; //if shift is not pressed, EXIT | |
| _respawnMarker = format["#RESPAWN#%1",group player]; //create marker name e.g: "#RESPAWN#B Alpha 1-1" | |
| _respawnMarkers = []; | |
| if ( | |
| { | |
| if (_x == _respawnMarker) exitWith { //if respawn marker already exists, delete it and exit | |
| deleteMarker _respawnMarker; | |
| true | |
| }; | |
| if (_x find "#RESPAWN#" != -1) then { //if any other marker with #RESPAWN# is found, add its distance from the new position to array | |
| _respawnMarkers pushBack [_x,_pos distance (markerPos _x)] | |
| }; | |
| false | |
| } forEach allMapMarkers | |
| ) exitWith { | |
| systemChat "RESPAWN: Marker already exists for this group, removing it." | |
| }; | |
| _respawnMarkers sort false; //sort the distances in decending order | |
| if (_respawnMarkers select 0 select 1 < 25) exitWith { //first element in nearest marker, if its less than 25m away, exit | |
| systemChat "RESPAWN: Marker is too near another group respawn position. It must be over 25m away!" | |
| }; | |
| _thingsToMove = []; | |
| { | |
| _x setDir random 360; | |
| _x setVehiclePosition [_pos,[],10]; | |
| } forEach _thingsToMove; //move items to new marker (ammoboxes etc) | |
| _marker = createMarker [_respawnMarker,_pos]; //create the new marker | |
| _marker setMarkerShape "ICON"; | |
| _marker setMarkerType "DOT"; | |
| _marker setMarkerText format["RESPAWN: %1",group player]; | |
| }] call BIS_fnc_addStackedEventHandler; | |
| }; | |
| player addEventHandler ["Respawn",{player call moveToGroupMarker}]; //add event to make player spawn at marker |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment