Advertisement
Guest User

Untitled

a guest
May 19th, 2014
202
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 15.17 KB | None | 0 0
  1. /*
  2.  * Safezone Commander Script by AlienX
  3.  * www.opendayz.net
  4.  * Thanks to everyone who has provided other scripts of the same format, without you I would not have been able to make this.
  5.  */
  6.  
  7. diag_log ( "[AGN] Starting Trader City Safezone Commander!" );
  8.  
  9. if ( isDedicated || isServer ) exitWith {diag_log ( "Error: Attempting to start AGN products on a server where it should not be!" );};
  10.  
  11. Private ["_EH_Fired", "_ehID", "_fix","_inVehicle","_inVehicleLast","_EH_Fired_Vehicle",
  12.                 "_inVehicleDamage","_antiBackpackThread","_antiBackpackThread2","_anti_zombie",
  13.                 "_vehicle","_veh_array","_y","_veh_total","_entity_array_dzai"];
  14.  
  15. //SCRIPT SETTINGS
  16. AGN_safeZoneDebug = false;                                                      //Debug notes on screen.
  17. AGN_safeZoneGodmode = true;                                                     //Should safezone Godmode be enabled?
  18. AGN_safeZoneMessages = true;                                                    //Should players get messages when entering and exiting the safe zone?
  19. AGN_safeZone_Backpack_EnableAntiBackpack = true;                        //Should players not be able to take from peoples bags?
  20. AGN_safeZone_Backpack_AllowGearFromLootPiles = true;            //Should players be able to loot from loot piles?
  21. AGN_safeZone_Backpack_AllowGearFromVehicles = false;            //Should players be able to loot from a vehicles gear?
  22. AGN_safeZone_Backpack_AllowGearFromDeadPlayers = true;          //Should players be able to loot from a dead players corpse?
  23. AGN_safeZone_Backpack_AllowFriendlyTaggedAccess = true; //Should players who are tagged friendly be able to access each others bags?
  24. AGN_safeZone_Vehicles_DisableMountedGuns = true;                        //Should players not be able to shoot bullets/projectiles from mounted guns?
  25. AGN_safeZone_Vehicles_AllowGearFromWithinVehicles = true;       //Should players be able to open the gear screen while they are inside a vehicle?
  26. AGN_safeZone_Players_DisableWeaponFiring = true;                        //Should players not be able to shoot bullets/projectiles from their weapon(s)?
  27. AGN_safeZone_Players_RemoveZombies= true;                               //Players allowed to delete zombies while in safe zone?
  28. AGN_safeZone_Players_DZAI= true;                                //Players allowed to delete AI while in safe zone?
  29.  
  30. //Probs not needed, but meh :)
  31. disableSerialization;
  32.  
  33. waitUntil {!isNil "dayz_animalCheck"};
  34.  
  35. _inVehicle = objNull;
  36. _inVehicleLast = objNull;
  37.  
  38. while {true} do {
  39.        
  40.         waitUntil { !canBuild };
  41.  
  42.         _inSafezoneFinished = false;
  43.         if ( AGN_safeZoneMessages ) then { systemChat (" Entering Trader Area - God Mode Enabled"); };
  44.         _thePlayer = player;
  45.  
  46.         if ( AGN_safeZoneGodmode ) then
  47.         {
  48.                 player_zombieCheck = {};
  49.                 fnc_usec_damageHandler = {};
  50.                 _thePlayer removeAllEventHandlers "handleDamage";
  51.                 _thePlayer addEventHandler ["handleDamage", {false}];
  52.                 _thePlayer allowDamage false;
  53.                 _inVehicle allowDamage false;
  54.         };
  55.        
  56.         if ( AGN_safeZone_Players_RemoveZombies ) then
  57.         {
  58.                 _anti_zombie = [] spawn {
  59.                 private ["_entity_array"];
  60.                         while {!canBuild} do
  61.                         {
  62.                                 _entity_array = (getPos player) nearEntities ["CAManBase",110];
  63.                                 {
  64.                                         if (_x isKindof "zZombie_Base") then {
  65.                                                 deletevehicle _x;
  66.                                         };
  67.                                         if (!isNil {_x getVariable "unithealth"}) then {
  68.                                             deletevehicle _x;
  69.                                         };
  70.                                 } forEach _entity_array;
  71.                                 sleep 4;
  72.                         };
  73.                 };
  74.         };
  75.        
  76. if ( AGN_safeZone_Players_DZAI ) then
  77.         {
  78.             _remove_ai = [] spawn {
  79.                 while {!canBuild} do
  80.                 {
  81.                         _entity_array_dzai = (getPos player) nearEntities ["CAManBase",110];
  82.                         {
  83.                                 // this is just the variable I saw in that cleanup... no idea if its correct...tried this several different ways none worked
  84.                                 if (!isNil {_unit getVariable "HSO_Identifier"}) then {
  85.                                         deletevehicle _x;
  86.                                 };
  87.                         } forEach _entity_array_dzai;
  88.                         sleep 4;
  89.                 };
  90.             };
  91.         };
  92.         if ( AGN_safeZone_Players_DisableWeaponFiring ) then
  93.         {
  94.                 _EH_Fired = _thePlayer addEventHandler ["Fired", {
  95.                         systemChat (" You can not fire your weapon in a Trader City Area");
  96.                         NearestObject [_this select 0,_this select 4] setPos[0,0,0];
  97.                 }];
  98.         };
  99.        
  100.         if ( AGN_safeZone_Backpack_EnableAntiBackpack ) then
  101.         {
  102.                 AGN_LastPlayerLookedAt = objNull;
  103.                 AGN_LastPlayerLookedAtCountDown = 5;
  104.                 _antiBackpackThread = [] spawn {
  105.                         private [ "_ct","_ip","_ia","_dis"] ;
  106.                         while {!canBuild} do
  107.                         {
  108.                                 if ( isNull AGN_LastPlayerLookedAt ) then
  109.                                 {
  110.                                         waitUntil {!isNull cursorTarget};
  111.                                         _ct = cursorTarget;
  112.                                         _ip = isPlayer _ct;
  113.                                         if ( _ip ) then { _ia = alive _ct; _dis = _ct distance player; } else { _ia = false; _dis = 1000; };
  114.                                        
  115.                                         if ( (_ip && _ia) && (_dis < 6.5) ) then
  116.                                         {
  117.                                                 AGN_LastPlayerLookedAt = _ct;
  118.                                         };
  119.                                 } else {
  120.                                         AGN_LastPlayerLookedAtCountDown = AGN_LastPlayerLookedAtCountDown - 1;
  121.                                         if ( AGN_LastPlayerLookedAtCountDown < 0 ) then { AGN_LastPlayerLookedAtCountDown = 5; AGN_LastPlayerLookedAt = objNull; };
  122.                                         sleep 1;
  123.                                 };
  124.                         };
  125.                 };
  126.                        
  127.                 _antiBackpackThread2 = [] spawn {
  128.                         private ["_to","_dis","_inchk","_ip","_ia","_skip","_ct","_iv","_lp","_inv","_ctOwnerID","_friendlies","_if"];
  129.                         _ctOwnerID = 0;
  130.                         while {!canBuild} do
  131.                         {
  132.                                 _ct = cursorTarget;
  133.                                 _skip = false;
  134.                                
  135.                                 if ( !isNull (_ct) ) then
  136.                                 {
  137.                                         _to = typeOf _ct;
  138.                                         _dis = _ct distance player;
  139.                                         _inchk = ["WeaponHolder","ReammoBox"];
  140.                                        
  141.                                         _lp = false;
  142.                                         {
  143.                                                 if ( (_to isKindOf _x) && (_dis < 10) && AGN_safeZone_Backpack_AllowGearFromLootPiles ) then
  144.                                                 {
  145.                                                         _lp = true;
  146.                                                 };
  147.                                         } forEach ( _inchk );
  148.  
  149.                                         _ip = isPlayer _ct;
  150.                                         _ia = alive _ct;
  151.                                         _iv = _ct isKindOf "AllVehicles";
  152.                                         _inv = (vehicle player != player);
  153.                                        
  154.                                         _if = false;
  155.                                         if ( _ip ) then {
  156.                                                 _ctOwnerID = _ct getVariable["CharacterID","0"];
  157.                                                 _friendlies     = player getVariable ["friendlyTo",[]];
  158.                                                 if(_ctOwnerID in _friendlies) then {  
  159.                                                         if ( AGN_safeZone_Backpack_AllowFriendlyTaggedAccess ) then
  160.                                                         {
  161.                                                                 _if = true;
  162.                                                         };
  163.                                                 };
  164.                                         };
  165.                                         if ( AGN_safeZoneDebug ) then {
  166.                                         hintSilent ( format["AGN Safezone Commander\n\nCursorTarget\n%1\n\nDistance\n%2\n\nLootpile\n%3 [%9]\n\nisPlayer\n%4\n\nAlive\n%5\n\nisVehicle\n%6\n\ninVehicle\n%7\n\nisFriendly\n%8 (%12) [%10]\n\nSkip: %11\n",
  167.                                                 _ct, _dis, _lp, _ip, _ia, _iv, _inv, _if, AGN_safeZone_Backpack_AllowGearFromLootPiles, AGN_safeZone_Backpack_AllowFriendlyTaggedAccess, _skip, _ctOwnerID] );
  168. };
  169.                                        
  170.                                         //Lootpile check
  171.                                         if ( _lp ) then {_skip = true;};
  172.                                        
  173.                                         //Dead body check
  174.                                         if ( !(_ia) && AGN_safeZone_Backpack_AllowGearFromDeadPlayers ) then {_skip = true;};
  175.                                        
  176.                                         //Vehicle check
  177.                                         if ( _iv && (_dis < 10) && !(_ip) && AGN_safeZone_Backpack_AllowGearFromVehicles ) then {_skip = true;};
  178.                                        
  179.                                         //In a vehicle check
  180.                                         if ( _inv && AGN_safeZone_Vehicles_AllowGearFromWithinVehicles ) then { _skip = true; };
  181.                                        
  182.                                         //Is player friendly?
  183.                                         if ( _if ) then { _skip = true; };
  184.                                 };
  185.                                
  186.                                 if( !isNull (FindDisplay 106) && !_skip ) then
  187.                                 {
  188.                                         if ( isNull AGN_LastPlayerLookedAt ) then
  189.                                         {
  190.                                                 (findDisplay 106) closeDisplay 1;
  191.                                                 waitUntil { isNull (FindDisplay 106) };
  192.                                                 createGearDialog [(player), 'RscDisplayGear'];
  193.                                                 if ( AGN_safeZoneMessages ) then { systemChat (" Anti Backpack Stealing - Redirecting you to your own gear!"); };
  194.                                                 waitUntil { isNull (FindDisplay 106) };
  195.                                         } else {
  196.                                                 if ( AGN_safeZoneMessages ) then { systemChat (format[" You cannot open your gear at this time as you have looked at a player in the last 5 seconds."]); };
  197.                                                 (findDisplay 106) closeDisplay 1;
  198.                                                 waitUntil { isNull (FindDisplay 106) };
  199.                                         };
  200.                                 };
  201.                                 if ( _skip && _if ) then {
  202.                                         if ( AGN_safeZoneMessages ) then { systemChat (" This player is tagged friendly, you have access to this players bag") };
  203.                                 };
  204.                         };
  205.                 };
  206.         };
  207.        
  208.         if ( AGN_safeZone_Vehicles_DisableMountedGuns ) then
  209.         {
  210.                 while { !canBuild } do
  211.                 {
  212.                         sleep 0.1;
  213.                         if ( !(isNull _inVehicle) && (vehicle player == player) ) then
  214.                         {
  215.                                 _inVehicle removeEventHandler ["Fired", _EH_Fired_Vehicle];
  216.                                 _inVehicleLast = _inVehicle;
  217.                                 _inVehicleLast removeEventHandler ["Fired", _EH_Fired_Vehicle];
  218.                                 _inVehicle = objNull;
  219.                         };
  220.                        
  221.                         if ( vehicle player != player && isNull _inVehicle ) then
  222.                         {
  223.                                 if (AGN_safeZoneMessages) then { systemChat ( " No Firing Vehicle Guns Enabled" ); };
  224.                                 _inVehicle = vehicle player;
  225.                                 _inVehicleDamage = getDammage _inVehicle;
  226.                                 _EH_Fired_Vehicle = _inVehicle addEventHandler ["Fired", {
  227.                                         systemChat (" You can not fire your vehicles weapon in a Trader City Area");
  228.                                         NearestObject [_this select 0,_this select 4] setPos[0,0,0];
  229.                                 }];
  230.                         };
  231.                 };
  232.         } else {
  233.                 waitUntil { canBuild };
  234.         };
  235.        
  236.         AGN_LastPlayerLookedAt = objNull;
  237.         AGN_LastPlayerLookedAtCountDown = 5;
  238.         terminate _antiBackpackThread;
  239.         terminate _antiBackpackThread2;
  240.         if ( AGN_safeZoneMessages ) then { systemChat (" Exiting Trader Area - God Mode Disabled"); };
  241.        
  242.         if ( AGN_safeZone_Vehicles_DisableMountedGuns ) then
  243.         {
  244.                 if ( !(isNull _inVehicle) ) then
  245.                 {
  246.                         if ( AGN_safeZoneMessages ) then { systemChat ( " No Firing Vehicle Guns Disabled" ); };
  247.                         _inVehicle removeEventHandler ["Fired", _EH_Fired_Vehicle];
  248.                 };
  249.                
  250.                 if ( !(isNull _inVehicleLast) ) then
  251.                 {
  252.                         if ( AGN_safeZoneMessages ) then { systemChat ( " No Firing Vehicle Guns Disabled" ); };
  253.                         _inVehicleLast removeEventHandler ["Fired", _EH_Fired_Vehicle];
  254.                 };
  255.         };
  256.  
  257.         if ( AGN_safeZone_Players_DisableWeaponFiring ) then
  258.         {
  259.                 _thePlayer removeEventHandler ["Fired", _EH_Fired];
  260.         };
  261.        
  262.         if ( AGN_safeZoneGodmode ) then
  263.         {
  264.                 player_zombieCheck = compile preprocessFileLineNumbers "\z\addons\dayz_code\compile\player_zombieCheck.sqf";
  265.                 fnc_usec_damageHandler = compile preprocessFileLineNumbers "\z\addons\dayz_code\compile\fn_damageHandler.sqf";
  266.                 _thePlayer addEventHandler ["handleDamage", {true}];
  267.                 _thePlayer removeAllEventHandlers "handleDamage";
  268.                 _thePlayer allowDamage true;
  269.                 _inVehicle allowDamage true;
  270.         };
  271.         _inSafezoneFinished = true;
  272. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement