Advertisement
Guest User

agn safezone zed and ai delete attempt v1

a guest
May 19th, 2014
321
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.96 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. } forEach _entity_array;
  68. sleep 4;
  69. };
  70. };
  71. };
  72.  
  73. if ( AGN_safeZone_Players_DZAI ) then
  74. {
  75. _remove_ai = [] spawn {
  76. while {!canBuild} do
  77. {
  78. _entity_array_dzai = (getPos player) nearEntities ["CAManBase",110];
  79. {
  80. // this is just the variable I saw in that cleanup... no idea if its correct...tried this several different ways none worked
  81. if (!isNil {_unit getVariable "HSO_Identifier"}) then {
  82. deletevehicle _x;
  83. };
  84. } forEach _entity_array_dzai;
  85. sleep 4;
  86. };
  87. };
  88. };
  89. if ( AGN_safeZone_Players_DisableWeaponFiring ) then
  90. {
  91. _EH_Fired = _thePlayer addEventHandler ["Fired", {
  92. systemChat (" You can not fire your weapon in a Trader City Area");
  93. NearestObject [_this select 0,_this select 4] setPos[0,0,0];
  94. }];
  95. };
  96.  
  97. if ( AGN_safeZone_Backpack_EnableAntiBackpack ) then
  98. {
  99. AGN_LastPlayerLookedAt = objNull;
  100. AGN_LastPlayerLookedAtCountDown = 5;
  101. _antiBackpackThread = [] spawn {
  102. private [ "_ct","_ip","_ia","_dis"] ;
  103. while {!canBuild} do
  104. {
  105. if ( isNull AGN_LastPlayerLookedAt ) then
  106. {
  107. waitUntil {!isNull cursorTarget};
  108. _ct = cursorTarget;
  109. _ip = isPlayer _ct;
  110. if ( _ip ) then { _ia = alive _ct; _dis = _ct distance player; } else { _ia = false; _dis = 1000; };
  111.  
  112. if ( (_ip && _ia) && (_dis < 6.5) ) then
  113. {
  114. AGN_LastPlayerLookedAt = _ct;
  115. };
  116. } else {
  117. AGN_LastPlayerLookedAtCountDown = AGN_LastPlayerLookedAtCountDown - 1;
  118. if ( AGN_LastPlayerLookedAtCountDown < 0 ) then { AGN_LastPlayerLookedAtCountDown = 5; AGN_LastPlayerLookedAt = objNull; };
  119. sleep 1;
  120. };
  121. };
  122. };
  123.  
  124. _antiBackpackThread2 = [] spawn {
  125. private ["_to","_dis","_inchk","_ip","_ia","_skip","_ct","_iv","_lp","_inv","_ctOwnerID","_friendlies","_if"];
  126. _ctOwnerID = 0;
  127. while {!canBuild} do
  128. {
  129. _ct = cursorTarget;
  130. _skip = false;
  131.  
  132. if ( !isNull (_ct) ) then
  133. {
  134. _to = typeOf _ct;
  135. _dis = _ct distance player;
  136. _inchk = ["WeaponHolder","ReammoBox"];
  137.  
  138. _lp = false;
  139. {
  140. if ( (_to isKindOf _x) && (_dis < 10) && AGN_safeZone_Backpack_AllowGearFromLootPiles ) then
  141. {
  142. _lp = true;
  143. };
  144. } forEach ( _inchk );
  145.  
  146. _ip = isPlayer _ct;
  147. _ia = alive _ct;
  148. _iv = _ct isKindOf "AllVehicles";
  149. _inv = (vehicle player != player);
  150.  
  151. _if = false;
  152. if ( _ip ) then {
  153. _ctOwnerID = _ct getVariable["CharacterID","0"];
  154. _friendlies = player getVariable ["friendlyTo",[]];
  155. if(_ctOwnerID in _friendlies) then {
  156. if ( AGN_safeZone_Backpack_AllowFriendlyTaggedAccess ) then
  157. {
  158. _if = true;
  159. };
  160. };
  161. };
  162. if ( AGN_safeZoneDebug ) then {
  163. 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",
  164. _ct, _dis, _lp, _ip, _ia, _iv, _inv, _if, AGN_safeZone_Backpack_AllowGearFromLootPiles, AGN_safeZone_Backpack_AllowFriendlyTaggedAccess, _skip, _ctOwnerID] );
  165. };
  166.  
  167. //Lootpile check
  168. if ( _lp ) then {_skip = true;};
  169.  
  170. //Dead body check
  171. if ( !(_ia) && AGN_safeZone_Backpack_AllowGearFromDeadPlayers ) then {_skip = true;};
  172.  
  173. //Vehicle check
  174. if ( _iv && (_dis < 10) && !(_ip) && AGN_safeZone_Backpack_AllowGearFromVehicles ) then {_skip = true;};
  175.  
  176. //In a vehicle check
  177. if ( _inv && AGN_safeZone_Vehicles_AllowGearFromWithinVehicles ) then { _skip = true; };
  178.  
  179. //Is player friendly?
  180. if ( _if ) then { _skip = true; };
  181. };
  182.  
  183. if( !isNull (FindDisplay 106) && !_skip ) then
  184. {
  185. if ( isNull AGN_LastPlayerLookedAt ) then
  186. {
  187. (findDisplay 106) closeDisplay 1;
  188. waitUntil { isNull (FindDisplay 106) };
  189. createGearDialog [(player), 'RscDisplayGear'];
  190. if ( AGN_safeZoneMessages ) then { systemChat (" Anti Backpack Stealing - Redirecting you to your own gear!"); };
  191. waitUntil { isNull (FindDisplay 106) };
  192. } else {
  193. 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."]); };
  194. (findDisplay 106) closeDisplay 1;
  195. waitUntil { isNull (FindDisplay 106) };
  196. };
  197. };
  198. if ( _skip && _if ) then {
  199. if ( AGN_safeZoneMessages ) then { systemChat (" This player is tagged friendly, you have access to this players bag") };
  200. };
  201. };
  202. };
  203. };
  204.  
  205. if ( AGN_safeZone_Vehicles_DisableMountedGuns ) then
  206. {
  207. while { !canBuild } do
  208. {
  209. sleep 0.1;
  210. if ( !(isNull _inVehicle) && (vehicle player == player) ) then
  211. {
  212. _inVehicle removeEventHandler ["Fired", _EH_Fired_Vehicle];
  213. _inVehicleLast = _inVehicle;
  214. _inVehicleLast removeEventHandler ["Fired", _EH_Fired_Vehicle];
  215. _inVehicle = objNull;
  216. };
  217.  
  218. if ( vehicle player != player && isNull _inVehicle ) then
  219. {
  220. if (AGN_safeZoneMessages) then { systemChat ( " No Firing Vehicle Guns Enabled" ); };
  221. _inVehicle = vehicle player;
  222. _inVehicleDamage = getDammage _inVehicle;
  223. _EH_Fired_Vehicle = _inVehicle addEventHandler ["Fired", {
  224. systemChat (" You can not fire your vehicles weapon in a Trader City Area");
  225. NearestObject [_this select 0,_this select 4] setPos[0,0,0];
  226. }];
  227. };
  228. };
  229. } else {
  230. waitUntil { canBuild };
  231. };
  232.  
  233. AGN_LastPlayerLookedAt = objNull;
  234. AGN_LastPlayerLookedAtCountDown = 5;
  235. terminate _antiBackpackThread;
  236. terminate _antiBackpackThread2;
  237. if ( AGN_safeZoneMessages ) then { systemChat (" Exiting Trader Area - God Mode Disabled"); };
  238.  
  239. if ( AGN_safeZone_Vehicles_DisableMountedGuns ) then
  240. {
  241. if ( !(isNull _inVehicle) ) then
  242. {
  243. if ( AGN_safeZoneMessages ) then { systemChat ( " No Firing Vehicle Guns Disabled" ); };
  244. _inVehicle removeEventHandler ["Fired", _EH_Fired_Vehicle];
  245. };
  246.  
  247. if ( !(isNull _inVehicleLast) ) then
  248. {
  249. if ( AGN_safeZoneMessages ) then { systemChat ( " No Firing Vehicle Guns Disabled" ); };
  250. _inVehicleLast removeEventHandler ["Fired", _EH_Fired_Vehicle];
  251. };
  252. };
  253.  
  254. if ( AGN_safeZone_Players_DisableWeaponFiring ) then
  255. {
  256. _thePlayer removeEventHandler ["Fired", _EH_Fired];
  257. };
  258.  
  259. if ( AGN_safeZoneGodmode ) then
  260. {
  261. player_zombieCheck = compile preprocessFileLineNumbers "\z\addons\dayz_code\compile\player_zombieCheck.sqf";
  262. fnc_usec_damageHandler = compile preprocessFileLineNumbers "\z\addons\dayz_code\compile\fn_damageHandler.sqf";
  263. _thePlayer addEventHandler ["handleDamage", {true}];
  264. _thePlayer removeAllEventHandlers "handleDamage";
  265. _thePlayer allowDamage true;
  266. _inVehicle allowDamage true;
  267. };
  268. _inSafezoneFinished = true;
  269. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement