Guest User

Untitled

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