JackoJammie

Arma 3 script "unit_respawn.sqf"

May 8th, 2017
20
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*  Based on [EVO] Dan's vehicle respawn script modified by Steam-User immerfestedruv
  2.     In the Unit Init Field insert <0 = [this,5,"blackfish_1","Driver",helipad_2,15] execVM "unit_respawn.sqf";> for example.
  3.     Will run only on the server, as it only needs to run in one place,
  4.     but obviously can be used in both singleplayer and multiplayer */
  5.  
  6. _unit = _this select 0; // First Argument, get Unit's details
  7. _delay = _this select 1; // Second Argument,get the init set respawn time
  8. _vehCall = _this select 2; // Third Argument, the Variable-Name of the unit's vehicle(Call-Sign)
  9. _vehSeat = _this select 3; // Forth Argument, on which Seat shall the unit sit
  10. _parkPlace = _this select 4; // Fifth Argument, the place where the vehicle parks
  11. _parkRad = _this select 5; // Sixth Argument, possible park Radius from the center of the vehicle park
  12. _parkPos = getPos _parkPlace; // Fith Argument, get the Position of the supposed vehicle park
  13. _dirUnit = getDir _unit; // get original facing
  14. _posUnit = getPosATL _unit; // get original position
  15. _unitType = typeOf _unit; // get the unit type
  16. _unitgroup = group _unit; // get group of the original unit
  17. _unitName = vehicleVarName _unit; // get the Variable-Name of the unit
  18. _unitRank = rank _unit; // get the units orignal rank
  19. _unitSkill = skill _unit; // get the original skill of the unit
  20. _vehicle = nil; // the units vehicle will be determined in the code below
  21. _n = 1;
  22.  
  23.  
  24. if(isServer) then{
  25.     while{_n == 1} do{
  26.         sleep 20; // sleep for a bit in order to reduce processing calls
  27.         if((!alive _unit) || (!canMove _unit)) then { //true if unit is not alive or it cannot move
  28.             deleteVehicle _unit; // clear up old units
  29.             sleep _delay; // respawn time between deletion and respawn
  30.            
  31.             // create a new unit of same type at starting position
  32.             _unitType createUnit [_posUnit, _unitgroup,"_unit = this", _unitSkill, _unitRank];
  33.             _unit setPosATL _posUnit; // set correct position
  34.             _unit setVehicleVarName _unitName;
  35.             _unit setDir _dirUnit; // set correct facing of the unit
  36.  
  37.             /* Next Code-Line will be executed for the new Object by your CPU, but time of execution unkown.
  38.             This behaves similar to the code in the init-field of your object. */
  39.             [[[_unit,_delay,_vehCall,_vehSeat,_parkPlace,_parkRad],"unit_respawn.sqf"],"BIS_fnc_execVM",false,false] spawn BIS_fnc_MP;
  40.             _n = 0; // break out condition
  41.         } else {
  42.             /*The Vehicle shall be manned if its alive, therefore we have to search for the vehicle. We have
  43.             the Call-Sign and the place of the vehicle park where it should be.*/
  44.             _nearObjs = nearestObjects [_parkPos,[],_parkRad];
  45.             //hint format ["Liste aller Objekte %1",_nearObjs];
  46.             for "_i" from 0 to (count _nearObjs - 1) do {
  47.                 if ((vehicleVarName (_nearObjs select _i)) == _vehCall) then {
  48.                     if (!isNull (_nearObjs select _i)) then {
  49.                         if (alive (_nearObjs select _i)) then {
  50.                             _vehicle = _nearObjs select _i;
  51.                             switch (_vehSeat) do {
  52.                                 case "Driver": {_unit moveInDriver _vehicle};
  53.                                 case "Gunner": {_unit moveInGunner _vehicle};
  54.                                 case "Turret": {_unit moveInTurret _vehicle};
  55.                                 case "Commander": {_unit moveInCommander _vehicle};
  56.                                 default {_unit moveInCargo _vehicle};
  57.                             };
  58.                         };
  59.                     };
  60.                 };
  61.             };
  62.            
  63.         };
  64.     };
  65. };
RAW Paste Data