Advertisement
Guest User

Safezones

a guest
Jan 18th, 2014
559
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.83 KB | None | 0 0
  1. diag_log ( "[IG] Starting Trader City Safezones!" );
  2.  
  3. if ( isDedicated || isServer ) exitWith {diag_log ( "Error: Attempting to start AGN products on a server where it should not be!" );};
  4.  
  5. Private ["_EH_Fired", "_ehID", "_fix","_inVehicle","_inVehicleLast","_EH_Fired_Vehicle",
  6. "_inVehicleDamage","_antiBackpackThread","_antiBackpackThread2"];
  7.  
  8. //SCRIPT SETTINGS
  9. AGN_safeZoneDebug = false; //Debug notes on screen.
  10. AGN_safeZoneGodmode = true; //Should safezone Godmode be enabled?
  11. AGN_safeZoneMessages = true; //Should players get messages when entering and exiting the safe zone?
  12. AGN_safeZone_Backpack_EnableAntiBackpack = true; //Should players not be able to take from peoples bags?
  13. AGN_safeZone_Backpack_AllowGearFromLootPiles = true; //Should players be able to loot from loot piles?
  14. AGN_safeZone_Backpack_AllowGearFromVehicles = true; //Should players be able to loot from a vehicles gear?
  15. AGN_safeZone_Backpack_AllowGearFromDeadPlayers = true; //Should players be able to loot from a dead players corpse?
  16. AGN_safeZone_Backpack_AllowFriendlyTaggedAccess = true; //Should players who are tagged friendly be able to access eachothers bags?
  17. AGN_safeZone_Vehicles_DisableMountedGuns = true; //Should players not be able to shoot bullets/projectiles from mounted guns?
  18. AGN_safeZone_DisableZombies = true; //Should safezones disable zombie spawning?
  19. AGN_safeZone_Vehicles_AllowGearFromWithinVehicles = true; //Should players be able to open the gear screen while they are inside a vehicle?
  20. AGN_safeZone_Players_DisableWeaponFiring = true; //Should players not be able to shoot bullets/projectiles from their weapon(s)?
  21.  
  22. //Probs not needed, but meh :)
  23. disableSerialization;
  24.  
  25. waitUntil {!isNil "dayz_animalCheck"};
  26. if ( AGN_safeZoneMessages ) then { systemChat ( "[IG] Trader Zones Loaded!" ); };
  27.  
  28. _inVehicle = objNull;
  29. _inVehicleLast = objNull;
  30.  
  31. while {true} do {
  32.  
  33. waitUntil { !canBuild };
  34.  
  35. _inSafezoneFinished = false;
  36. if ( AGN_safeZoneMessages ) then { systemChat ("[IG] Entering Trader Area - God Mode Enabled"); };
  37. _thePlayer = player;
  38.  
  39. if ( AGN_safeZoneGodmode ) then
  40. {
  41. player_zombieCheck = {};
  42. fnc_usec_damageHandler = {};
  43. _thePlayer removeAllEventHandlers "handleDamage";
  44. _thePlayer addEventHandler ["handleDamage", {false}];
  45. _thePlayer allowDamage false;
  46. };
  47.  
  48. if ( AGN_safeZone_Players_DisableWeaponFiring ) then
  49. {
  50. _EH_Fired = _thePlayer addEventHandler ["Fired", {
  51. systemChat ("[IG] You can not fire your weapon in a Trader City Area");
  52. NearestObject [_this select 0,_this select 4] setPos[0,0,0];
  53. }];
  54. };
  55.  
  56. if ( AGN_safeZone_Backpack_EnableAntiBackpack ) then
  57. {
  58. AGN_LastPlayerLookedAt = objNull;
  59. AGN_LastPlayerLookedAtCountDown = 5;
  60. _antiBackpackThread = [] spawn {
  61. private [ "_ct","_ip","_ia","_dis"] ;
  62. while {!canBuild} do
  63. {
  64. if ( isNull AGN_LastPlayerLookedAt ) then
  65. {
  66. waitUntil {!isNull cursorTarget};
  67. _ct = cursorTarget;
  68. _ip = isPlayer _ct;
  69. if ( _ip ) then { _ia = alive _ct; _dis = _ct distance player; } else { _ia = false; _dis = 1000; };
  70.  
  71. if ( (_ip && _ia) && (_dis < 6.5) ) then
  72. {
  73. AGN_LastPlayerLookedAt = _ct;
  74. };
  75. } else {
  76. AGN_LastPlayerLookedAtCountDown = AGN_LastPlayerLookedAtCountDown - 1;
  77. if ( AGN_LastPlayerLookedAtCountDown < 0 ) then { AGN_LastPlayerLookedAtCountDown = 5; AGN_LastPlayerLookedAt = objNull; };
  78. sleep 1;
  79. };
  80. };
  81. };
  82.  
  83. _antiBackpackThread2 = [] spawn {
  84. private ["_to","_dis","_inchk","_ip","_ia","_skip","_ct","_iv","_lp","_inv","_ctOwnerID","_friendlies","_if"];
  85. _ctOwnerID = 0;
  86. while {!canBuild} do
  87. {
  88. _ct = cursorTarget;
  89. _skip = false;
  90.  
  91. if ( !isNull (_ct) ) then
  92. {
  93. _to = typeOf _ct;
  94. _dis = _ct distance player;
  95. _inchk = ["WeaponHolder","ReammoBox"];
  96.  
  97. _lp = false;
  98. {
  99. if ( (_to isKindOf _x) && (_dis < 10) && AGN_safeZone_Backpack_AllowGearFromLootPiles ) then
  100. {
  101. _lp = true;
  102. };
  103. } forEach ( _inchk );
  104.  
  105. _ip = isPlayer _ct;
  106. _ia = alive _ct;
  107. _iv = _ct isKindOf "AllVehicles";
  108. _inv = (vehicle player != player);
  109.  
  110. _if = false;
  111. if ( _ip ) then {
  112. _ctOwnerID = _ct getVariable["CharacterID","0"];
  113. _friendlies = player getVariable ["friendlyTo",[]];
  114. if(_ctOwnerID in _friendlies) then {
  115. if ( AGN_safeZone_Backpack_AllowFriendlyTaggedAccess ) then
  116. {
  117. _if = true;
  118. };
  119. };
  120. };
  121. if ( AGN_safeZoneDebug ) then {
  122. 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",
  123. _ct, _dis, _lp, _ip, _ia, _iv, _inv, _if, AGN_safeZone_Backpack_AllowGearFromLootPiles, AGN_safeZone_Backpack_AllowFriendlyTaggedAccess, _skip, _ctOwnerID] );
  124. };
  125.  
  126.  
  127. //Lootpile check
  128. if ( _lp ) then {_skip = true;};
  129.  
  130. //Dead body check
  131. if ( !(_ia) && AGN_safeZone_Backpack_AllowGearFromDeadPlayers ) then {_skip = true;};
  132.  
  133. //Vehicle check
  134. if ( _iv && (_dis < 10) && !(_ip) && AGN_safeZone_Backpack_AllowGearFromVehicles ) then {_skip = true;};
  135.  
  136. //In a vehicle check
  137. if ( _inv && AGN_safeZone_Vehicles_AllowGearFromWithinVehicles ) then { _skip = true; };
  138.  
  139. //Is player friendly?
  140. if ( _if ) then { _skip = true; };
  141. };
  142.  
  143. if( !isNull (FindDisplay 106) && !_skip ) then
  144. {
  145. if ( isNull AGN_LastPlayerLookedAt ) then
  146. {
  147. (findDisplay 106) closeDisplay 1;
  148. waitUntil { isNull (FindDisplay 106) };
  149. createGearDialog [(player), 'RscDisplayGear'];
  150. if ( AGN_safeZoneMessages ) then { systemChat ("[IG] Anti Backpack Stealing - Redirecting you to your own gear!"); };
  151. waitUntil { isNull (FindDisplay 106) };
  152. } else {
  153. if ( AGN_safeZoneMessages ) then { systemChat (format["[IG] You cannot open your gear at this time as you have looked at a player in the last 5 seconds."]); };
  154. (findDisplay 106) closeDisplay 1;
  155. waitUntil { isNull (FindDisplay 106) };
  156. };
  157. };
  158. if ( _skip && _if ) then {
  159. if ( AGN_safeZoneMessages ) then { systemChat ("[IG] This player is tagged friendly, you have access to this players bag") };
  160. };
  161. };
  162. };
  163. };
  164.  
  165. if ( AGN_safeZone_Vehicles_DisableMountedGuns ) then
  166. {
  167. while { !canBuild } do
  168. {
  169. sleep 0.1;
  170. if ( !(isNull _inVehicle) && (vehicle player == player) ) then
  171. {
  172. _inVehicle removeEventHandler ["Fired", _EH_Fired_Vehicle];
  173. _inVehicleLast = _inVehicle;
  174. _inVehicleLast removeEventHandler ["Fired", _EH_Fired_Vehicle];
  175. _inVehicle = objNull;
  176. };
  177.  
  178. if ( AGN_safeZone_DisableZombies ) then
  179. {
  180. _pos = getMarkerPos "MarkerOne";
  181. _zombies = _pos nearEntities ["zZombie_Base",50];
  182. _count = count _zombies;
  183. for "_i" from 0 to (_count -1) do
  184. {
  185. _zombie = _zombies select _i;
  186. deleteVehicle _zombie;
  187. };
  188. sleep 0.5;
  189. };
  190.  
  191. if ( vehicle player != player && isNull _inVehicle ) then
  192. {
  193. if (AGN_safeZoneMessages) then { systemChat ( "[IG] No Firing Vehicle Guns Enabled" ); };
  194. _inVehicle = vehicle player;
  195. _inVehicleDamage = getDammage _inVehicle;
  196. _EH_Fired_Vehicle = _inVehicle addEventHandler ["Fired", {
  197. systemChat ("[IG] You can not fire your vehicles weapon in a Trader City Area");
  198. NearestObject [_this select 0,_this select 4] setPos[0,0,0];
  199. }];
  200. };
  201. };
  202. } else {
  203. waitUntil { canBuild };
  204. };
  205.  
  206. AGN_LastPlayerLookedAt = objNull;
  207. AGN_LastPlayerLookedAtCountDown = 5;
  208. terminate _antiBackpackThread;
  209. terminate _antiBackpackThread2;
  210. if ( AGN_safeZoneMessages ) then { systemChat ("[IG] Exiting Trader Area - God Mode Disabled"); };
  211.  
  212. if ( AGN_safeZone_Vehicles_DisableMountedGuns ) then
  213. {
  214. if ( !(isNull _inVehicle) ) then
  215. {
  216. if ( AGN_safeZoneMessages ) then { systemChat ( "[IG] No Firing Vehicle Guns Disabled" ); };
  217. _inVehicle removeEventHandler ["Fired", _EH_Fired_Vehicle];
  218. };
  219.  
  220. if ( !(isNull _inVehicleLast) ) then
  221. {
  222. if ( AGN_safeZoneMessages ) then { systemChat ( "[IG] No Firing Vehicle Guns Disabled" ); };
  223. _inVehicleLast removeEventHandler ["Fired", _EH_Fired_Vehicle];
  224. };
  225. };
  226.  
  227. if ( AGN_safeZone_Players_DisableWeaponFiring ) then
  228. {
  229. _thePlayer removeEventHandler ["Fired", _EH_Fired];
  230. };
  231.  
  232. if ( AGN_safeZoneGodmode ) then
  233. {
  234. player_zombieCheck = compile preprocessFileLineNumbers "\z\addons\dayz_code\compile\player_zombieCheck.sqf";
  235. fnc_usec_damageHandler = compile preprocessFileLineNumbers "\z\addons\dayz_code\compile\fn_damageHandler.sqf";
  236. _thePlayer addEventHandler ["handleDamage", {true}];
  237. _thePlayer removeAllEventHandlers "handleDamage";
  238. _thePlayer allowDamage true;
  239. };
  240. _inSafezoneFinished = true;
  241. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement