Advertisement
infiSTAR23

infiSTAR SafeZone

May 22nd, 2014
18,670
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 10.36 KB | None | 0 0
  1. /*
  2.    by: http://infiSTAR.de || http://DayzAntiHack.com
  3.    *updated on 24.12.2014
  4.    
  5.     Instructions:
  6.     1. Copy paste this pastebin code into a file called SafeZone.sqf - save the file.
  7.     2. Now extract your mpmission pbo and put the SafeZone.sqf into the extracted folder.
  8.     3. Open the init.sqf of the mpmission.
  9.     4. At the bottom of the file add
  10.     [] execVM 'SafeZone.sqf';
  11.     5. Save the init.sqf, repack your mpmission, upload it to your gameserver and restart your server
  12. */
  13. USE_CANBUILD = false;       // if you don't want to define your own positions
  14. USE_TraderCity = false; //  if you don't want to define your own positions (Epoch 1.0.5)
  15. USE_POSITIONS = true;   // to use own positions and radius
  16. USE_AI_REMOVER = false; // use this to remove Missionbots (AI) within 100m of a player if the player is in a SafeZone
  17. USE_AntiSteal = true;   // use this to block opening gear if another player is within 3m!
  18. USE_SPEEDLIMIT = true;  // very secret function, nobody is supposed to find out what it does.
  19.     SPEEDLIMIT = 20;        // Only used if USE_SPEEDLIMIT is true.
  20. USE_SIGNS = true;       // use this to build signs around the SafeZone
  21. LOG_EnterLeave = true;  // This will log to your .rpt when a player enters or leaves a SafeZone! (only works with infiSTAR.de Admintools / AntiHack)
  22. /* You can use USE_CANBUILD or/and (works together) the custom positions below (USE_POSITIONS) [position or zone,radius] */
  23. _infiSZ =
  24. [
  25.     [[6325.6772,7807.7412,0],150,true],
  26.     [[4063.4226,11664.19,0],150,true],
  27.     [[11447.472,11364.504,0],150,true],
  28.     [[1606.6443,7803.5156,0],150,true],
  29.     [[12944.227,12766.889,0],150,true],
  30.     [[5068.6636,9723.4248,0],100,true],
  31.     [[12060,12640,0],200,true]
  32. ];
  33. if (isServer) exitWith
  34. {
  35.     if (USE_SIGNS) then
  36.     {
  37.         {
  38.             _center = _x select 0;
  39.             _radius = _x select 1;
  40.             _lSign = _x select 2;
  41.             if (_lSign) then
  42.             {
  43.                 for '_i' from 0 to 360 step (270 / _radius)*2 do
  44.                 {
  45.                     _location = [(_center select 0) + ((cos _i) * _radius), (_center select 1) + ((sin _i) * _radius),0];
  46.                     _dir = ((_center select 0) - (_location select 0)) atan2 ((_center select 1) - (_location select 1));
  47.                     _object = createVehicle ['Sign_sphere100cm_EP1', _location, [], 0, 'CAN_COLLIDE'];
  48.                     //  _object = createVehicle ['SignM_FARP_Winchester_EP1', _location, [], 0, 'CAN_COLLIDE'];
  49.                     //  _object setVehicleInit 'this setObjectTexture [0,''Addons\SafeZones\sign.paa''];';
  50.                     _object setDir _dir;
  51.                 };
  52.             };
  53.         } forEach _infiSZ;
  54.     };
  55. };
  56. waitUntil {((!isNil 'dayz_animalCheck') || (!isNil 'dayz_medicalH') || (!isNil 'dayz_slowCheck') || (!isNil 'dayz_gui'))};
  57. if (isNil 'inSafeZone') then { inSafeZone = false; } else { if (typename inSafeZone != 'BOOL') then { inSafeZone = false; }; };
  58. [_infiSZ] spawn {
  59.     _infiSZ = _this select 0;
  60.     _startSafeZone =
  61.     {
  62.         if (isNil 'outNow') then
  63.         {
  64.             _msg = 'You entered a Safe Zone!';
  65.             hint _msg;
  66.             taskHint [_msg, [0,1,0,1], 'taskDone'];
  67.             inNow = nil;
  68.             outNow = true;
  69.            
  70.             if (LOG_EnterLeave) then
  71.             {
  72.                 PVDZE_send = [player,'SafeZoneState',[1]];
  73.                 publicVariableServer 'PVDZE_send';
  74.             };
  75.         };
  76.         player_fired = {
  77.             deleteVehicle (nearestObject [_this select 0,_this select 4]);
  78.             cutText ['You can not fire in a SafeZone!','WHITE IN'];
  79.         };
  80.         wild_spawnZombies = {};
  81.         zombie_generate = {};
  82.        
  83.         fnc_usec_damageHandler = {};
  84.         player removeAllEventHandlers 'handleDamage';
  85.         player addEventHandler ['handleDamage', {false}];
  86.         player allowDamage false;
  87.         _veh = vehicle player;
  88.         _szs = _veh getVariable ['inSafeZone',0];
  89.         if (_szs == 0) then
  90.         {
  91.             _veh setVariable ['inSafeZone',1,true];
  92.             if (player != _veh) then
  93.             {
  94.                 _veh removeAllEventHandlers 'Fired';
  95.                 _veh addEventHandler ['Fired', {_this call player_fired;}];
  96.                 {
  97.                     _x removeAllEventHandlers 'Fired';
  98.                     _x addEventHandler ['Fired', {_this call player_fired;}];
  99.                 } forEach (crew _veh);
  100.                 vehicle_handleDamage = {false};
  101.                 _veh removeAllEventHandlers 'HandleDamage';
  102.                 _veh addeventhandler ['HandleDamage',{ _this call vehicle_handleDamage } ];
  103.                 _veh allowDamage false;
  104.             };
  105.         };
  106.         _notInSafeZone =
  107.         [
  108.             'MAAWS','RPG7V','M136','RPG18','STINGER',
  109.             'MeleeHatchet_DZE','MeleeHatchet','MeleeCrowbar','MeleeMachete','MeleeFishingPole','MeleeSledge',
  110.             'MeleeBaseBallBatNails','MeleeBaseBallBatBarbed','MeleeBaseBallBat'
  111.         ];
  112.         _cwep = currentWeapon player;
  113.         if (_cwep in _notInSafeZone) then
  114.         {
  115.             _swep = '';
  116.             {
  117.                 if ((getNumber (configFile >> 'CfgWeapons' >> _x >> 'Type')) == 2) exitWith
  118.                 {
  119.                     _swep = _x;
  120.                 };
  121.             } forEach (weapons player);
  122.             if (_swep == '') then
  123.             {
  124.                 player playActionNow 'PutDown';
  125.                 _iPos = getPosATL player;
  126.                 _radius = 1;
  127.                 _removed = ([player,_cwep,1] call BIS_fnc_invRemove);
  128.                 if (_removed == 1) then
  129.                 {
  130.                     _item = createVehicle ['WeaponHolder', _iPos, [], _radius, 'CAN_COLLIDE'];
  131.                     _item addWeaponCargoGlobal [_cwep,1];
  132.                 };
  133.             }
  134.             else
  135.             {
  136.                 player selectweapon _swep;
  137.             };
  138.         };
  139.     };
  140.     _endSafeZone =
  141.     {
  142.         if (isNil 'inNow') then
  143.         {
  144.             if (str fnc_usec_damageHandler == '{}') then
  145.             {
  146.                 _msg = 'You left the Safe Zone!';
  147.                 hint _msg;
  148.                 taskHint [_msg, [1,0,0.1,1], 'taskFailed'];
  149.             };
  150.             inNow = true;
  151.             outNow = nil;
  152.            
  153.             if (LOG_EnterLeave) then
  154.             {
  155.                 PVDZE_send = [player,'SafeZoneState',[0]];
  156.                 publicVariableServer 'PVDZE_send';
  157.             };
  158.         };
  159.         wild_spawnZombies = compile preprocessFileLineNumbers '\z\addons\dayz_code\compile\wild_spawnZombies.sqf';
  160.         zombie_generate = compile preprocessFileLineNumbers '\z\addons\dayz_code\compile\zombie_generate.sqf';
  161.        
  162.        
  163.         player_fired = {
  164.             _this call compile preprocessFileLineNumbers '\z\addons\dayz_code\compile\player_fired.sqf';
  165.             _unit = _this select 0;
  166.             _weapon = _this select 1;
  167.             _muzzle = _this select 2;
  168.             _mode = _this select 3;
  169.             _ammo = _this select 4;
  170.             _magazine = _this select 5;
  171.             _projectile = _this select 6;
  172.             _screenToWorld = screenToWorld [0.5,0.5];
  173.             _near = _screenToWorld nearEntities ['AllVehicles',100];
  174.             {
  175.                 if (isPlayer _x) then
  176.                 {
  177.                     _szs = _x getVariable ['inSafeZone',0];
  178.                     if (_szs == 1) then
  179.                     {
  180.                         deleteVehicle (nearestObject [_unit,_ammo]);
  181.                     };
  182.                 };
  183.             } forEach _near;
  184.         };
  185.        
  186.         fnc_usec_unconscious = compile preprocessFileLineNumbers '\z\addons\dayz_code\compile\fn_unconscious.sqf';
  187.         object_monitorGear = compile preprocessFileLineNumbers '\z\addons\dayz_code\compile\object_monitorGear.sqf';
  188.         vehicle_handleDamage = compile preprocessFileLineNumbers '\z\addons\dayz_code\compile\vehicle_handleDamage.sqf';
  189.        
  190.         _veh = vehicle player;
  191.         _szs = _veh getVariable ['inSafeZone',0];
  192.         if (_szs == 1) then
  193.         {
  194.             _veh setVariable ['inSafeZone',0,true];
  195.             if (player != _veh) then
  196.             {
  197.                 _veh removeAllEventHandlers 'HandleDamage';
  198.                 _veh addeventhandler ['HandleDamage',{ _this call vehicle_handleDamage } ];
  199.                 _veh allowDamage true;
  200.             };
  201.         };
  202.        
  203.         _end = false;
  204.         if (isNil 'gmadmin') then
  205.         {
  206.             _end = true;
  207.         }
  208.         else
  209.         {
  210.             if (gmadmin == 0) then
  211.             {
  212.                 _end = true;
  213.             };
  214.         };
  215.         if (_end) then
  216.         {
  217.             player allowDamage true;
  218.             fnc_usec_damageHandler = compile preprocessFileLineNumbers '\z\addons\dayz_code\compile\fn_damageHandler.sqf';
  219.             player removeAllEventHandlers 'HandleDamage';
  220.             player addeventhandler ['HandleDamage',{_this call fnc_usec_damageHandler;} ];
  221.         };
  222.     };
  223.     while {1 == 1} do
  224.     {
  225.         if (isNil 'inSafeZone') then { inSafeZone = false; } else { if (typename inSafeZone != 'BOOL') then { inSafeZone = false; }; };
  226.         _state = false;
  227.         if (isNil 'USE_POSITIONS') then { USE_POSITIONS = false; } else { if (typename USE_POSITIONS != 'BOOL') then { USE_POSITIONS = false; }; };
  228.         if (USE_POSITIONS) then
  229.         {
  230.             {
  231.                 _z = _x select 0;
  232.                 _r = _x select 1;
  233.                 if ((vehicle player) distance _z < _r) then {_state = true;};
  234.             } forEach _infiSZ;
  235.         };
  236.         if (isNil 'USE_CANBUILD') then { USE_CANBUILD = true; } else { if (typename USE_CANBUILD != 'BOOL') then { USE_CANBUILD = true; }; };
  237.         if (USE_CANBUILD) then
  238.         {
  239.             if (isNil 'canbuild') then { canbuild = true; } else { if (typename canbuild != 'BOOL') then { canbuild = true; }; };
  240.             if (!canbuild) then {_state = true;};
  241.         };
  242.         if (isNil 'USE_TraderCity') then { USE_TraderCity = true; } else { if (typename USE_TraderCity != 'BOOL') then { USE_TraderCity = true; }; };
  243.         if (USE_TraderCity) then
  244.         {
  245.             if (isNil 'isInTraderCity') then { isInTraderCity = false; } else { if (typename isInTraderCity != 'BOOL') then { isInTraderCity = false; }; };
  246.             if (isInTraderCity) then {_state = true;};
  247.         };
  248.         if (_state) then
  249.         {
  250.             inSafeZone = true;
  251.             call _startSafeZone;
  252.             {
  253.                 if (!isNull _x) then
  254.                 {
  255.                     if !(isPlayer _x) then
  256.                     {
  257.                         deletevehicle _x;
  258.                     };
  259.                 };
  260.             } forEach ((vehicle player) nearEntities ['zZombie_Base',50]);
  261.            
  262.             if (isNil 'USE_AI_REMOVER') then { USE_AI_REMOVER = false; } else { if (typename USE_AI_REMOVER != 'BOOL') then { USE_AI_REMOVER = false; }; };
  263.             if (USE_AI_REMOVER) then
  264.             {
  265.                 {
  266.                     if ((!isNull group _x) && (getPlayerUID _x == '')) then
  267.                     {
  268.                         deleteVehicle _x;
  269.                     };
  270.                 } forEach (player nearEntities ['Man',100]);
  271.             };
  272.         }
  273.         else
  274.         {
  275.             inSafeZone = false;
  276.         };
  277.         uiSleep 2;
  278.         if (!inSafeZone) then
  279.         {
  280.             call _endSafeZone;
  281.         };
  282.     };
  283. };
  284. if ((USE_AntiSteal) || (USE_SPEEDLIMIT)) then
  285. {
  286.     [] spawn {
  287.         _USE_AntiSteal = USE_AntiSteal;
  288.         _USE_SPEEDLIMIT = USE_SPEEDLIMIT;
  289.         _speedlimit = SPEEDLIMIT;
  290.         while {1 == 1} do
  291.         {
  292.             if (inSafezone) then
  293.             {
  294.                 if (_USE_AntiSteal) then
  295.                 {
  296.                     _cnt = {isPlayer _x && _x != player} count (player nearEntities [['CAManBase'],4]);
  297.                     if ((_cnt > 0) && (!isNull (findDisplay 106))) then
  298.                     {
  299.                         (findDisplay 106) closedisplay 0;
  300.                         closeDialog 0;closeDialog 0;closeDialog 0;
  301.                         _log = format['%1 You are not allowed to open Gear while near another player!',name player];
  302.                         cutText [_log,'PLAIN'];
  303.                         hint _log;
  304.                     };
  305.                 };
  306.                 if (_USE_SPEEDLIMIT) then
  307.                 {
  308.                     _obj = vehicle player;
  309.                     if !(_obj isKindOf 'Plane') then
  310.                     {
  311.                         _speed = abs speed _obj;
  312.                         if ((_obj != player) && (_speed > _speedlimit)) then
  313.                         {
  314.                             _vel = velocity _obj;
  315.                             _x = 0.8;
  316.                             if (_speed > 50) then {_x = 0.1;};
  317.                             _velNew = [(_vel select 0) * _x, (_vel select 1) * _x,(_vel select 2) * _x];
  318.                             _obj SetVelocity _velNew;
  319.                         };
  320.                     };
  321.                 };
  322.             }
  323.             else
  324.             {
  325.                 uiSleep 2;
  326.             };
  327.             uiSleep .01;
  328.         };
  329.     };
  330. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement