Advertisement
Guest User

111

a guest
Nov 20th, 2013
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.48 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 ( "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"];
  13.  
  14. private ["_safeZoneGodmode","_safeZoneMessages","_safeZone_Backpack_AllowGearFromLootPiles",
  15. "_safeZone_Backpack_AllowGearFromVehicles","_safeZone_Backpack_AllowGearFromDeadPlayers",
  16. "_safeZone_Vehicles_DisableMountedGuns","_safeZone_Players_DisableWeaponFiring",
  17. "_safeZone_Backpack_EnableAntiBackpack","_safeZone_Vehicles_AllowGearFromWithinVehicles"];
  18.  
  19.  
  20. //SCRIPT SETTINGS
  21. _safeZoneGodmode = true; //Should safezone Godmode be enabled?
  22. _safeZoneMessages = true; //Should players get messages when entering and exiting the safe zone?
  23. _safeZone_Backpack_EnableAntiBackpack = true; //Should players not be able to take from peoples bags?
  24. _safeZone_Backpack_AllowGearFromLootPiles = true; //Should players be able to loot from loot piles?
  25. _safeZone_Backpack_AllowGearFromVehicles = true; //Should players be able to loot from a vehicles gear?
  26. _safeZone_Backpack_AllowGearFromDeadPlayers = true; //Should players be able to loot from a dead players corpse?
  27. _safeZone_Vehicles_DisableMountedGuns = true; //Should players not be able to shoot bullets/projectiles from mounted guns?
  28. _safeZone_Vehicles_AllowGearFromWithinVehicles = true; //Should players be able to open the gear screen while they are inside a vehicle?
  29. _safeZone_Players_DisableWeaponFiring = true; //Should players not be able to shoot bullets/projectiles from their weapon(s)?
  30.  
  31. waitUntil {!isNil "dayz_animalCheck"};
  32. if ( _safeZoneMessages ) then { systemChat ( " Trader Safe Zones Loaded!" ); };
  33.  
  34. _inVehicle = objNull;
  35. _inVehicleLast = objNull;
  36.  
  37. while {true} do {
  38.  
  39. waitUntil { !canBuild };
  40.  
  41. _inSafezoneFinished = false;
  42. if ( _safeZoneMessages ) then { systemChat ("Entering Trader Area - God Mode Enabled"); };
  43. _thePlayer = player;
  44.  
  45. if ( _safeZoneGodmode ) then
  46. {
  47. player_zombieCheck = {};
  48. fnc_usec_damageHandler = {};
  49. _thePlayer removeAllEventHandlers "handleDamage";
  50. _thePlayer addEventHandler ["handleDamage", {false}];
  51. _thePlayer allowDamage false;
  52. };
  53.  
  54. if ( _safeZone_Players_DisableWeaponFiring ) then
  55. {
  56. _EH_Fired = _thePlayer addEventHandler ["Fired", {
  57. systemChat ("You can not fire your weapon in a Trader City Area");
  58. NearestObject [_this select 0,_this select 4] setPos[0,0,0];
  59. }];
  60. };
  61.  
  62. if ( _safeZone_Backpack_EnableAntiBackpack ) then
  63. {
  64. AGN_LastPlayerLookedAt = objNull;
  65. AGN_LastPlayerLookedAtCountDown = 5;
  66. _antiBackpackThread = [] spawn {
  67. private [ "_ct","_ip","_ia","_dis"] ;
  68. while {!canBuild} do
  69. {
  70. if ( isNull AGN_LastPlayerLookedAt ) then
  71. {
  72. waitUntil {!isNull cursorTarget};
  73. _ct = cursorTarget;
  74. _ip = isPlayer _ct;
  75. if ( _ip ) then { _ia = alive _ct; _dis = _ct distance player; } else { _ia = false; _dis = 1000; };
  76.  
  77. if ( (_ip && _ia) && (_dis < 6.5) ) then
  78. {
  79. AGN_LastPlayerLookedAt = _ct;
  80. };
  81. } else {
  82. AGN_LastPlayerLookedAtCountDown = AGN_LastPlayerLookedAtCountDown - 1;
  83. if ( AGN_LastPlayerLookedAtCountDown < 0 ) then { AGN_LastPlayerLookedAtCountDown = 5; AGN_LastPlayerLookedAt = objNull; };
  84. sleep 1;
  85. };
  86. };
  87. };
  88.  
  89. _antiBackpackThread2 = [] spawn {
  90. private ["_to","_dis","_inchk","_ip","_ia","_skip","_ct","_iv","_lp","_inv"];
  91. while {!canBuild} do
  92. {
  93. _ct = cursorTarget;
  94. _skip = false;
  95.  
  96. if ( !isNull (_ct) ) then
  97. {
  98. _to = typeOf _ct;
  99. _dis = _ct distance player;
  100. _inchk = ["WeaponHolder","ReammoBox"];
  101. _lp = ((_to in _inchk) && (_dis < 10) && _safeZone_Backpack_AllowGearFromLootPiles);
  102. _ip = isPlayer _ct;
  103. if ( _ip ) then { _ia = alive _ct; } else { _ia = true; };
  104. _iv = _ct isKindOf "AllVehicles";
  105. _inv = (vehicle player != player);
  106.  
  107. //Lootpile check
  108. if ( _lp ) then {_skip = true;};
  109.  
  110. //Dead body check
  111. if ( !_ia && _safeZone_Backpack_AllowGearFromDeadPlayers ) then {_skip = true;};
  112.  
  113. //Vehicle check
  114. if ( _iv && (_dis < 10) && !_ip && _safeZone_Backpack_AllowGearFromVehicles ) then {_skip = true;};
  115.  
  116. //In a vehicle check
  117. if ( _inv && _safeZone_Vehicles_AllowGearFromWithinVehicles ) then { _skip = true; };
  118. };
  119.  
  120. if( !isNull (FindDisplay 106) && !_skip ) then
  121. {
  122. if ( isNull AGN_LastPlayerLookedAt ) then
  123. {
  124. (findDisplay 106) closeDisplay 1;
  125. waitUntil { isNull (FindDisplay 106) };
  126. createGearDialog [(player), 'RscDisplayGear'];
  127. if ( _safeZoneMessages ) then { systemChat ("Anti Backpack Stealing - Redirecting you to your own gear!"); };
  128. waitUntil { isNull (FindDisplay 106) };
  129. } else {
  130. if ( _safeZoneMessages ) then { systemChat (format["You cannot open your gear at this time as you have looked at a player in the last 5 seconds."]); };
  131. (findDisplay 106) closeDisplay 1;
  132. waitUntil { isNull (FindDisplay 106) };
  133. };
  134. };
  135. };
  136. };
  137. };
  138.  
  139. if ( _safeZone_Vehicles_DisableMountedGuns ) then
  140. {
  141. while { !canBuild } do
  142. {
  143. sleep 0.1;
  144. if ( !(isNull _inVehicle) && (vehicle player == player) ) then
  145. {
  146. _inVehicle removeEventHandler ["Fired", _EH_Fired_Vehicle];
  147. _inVehicleLast = _inVehicle;
  148. _inVehicleLast removeEventHandler ["Fired", _EH_Fired_Vehicle];
  149. _inVehicle = objNull;
  150. };
  151.  
  152. if ( vehicle player != player && isNull _inVehicle ) then
  153. {
  154. if (_safeZoneMessages) then { systemChat ( "No Firing! Vehicle Guns Enabled" ); };
  155. _inVehicle = vehicle player;
  156. _inVehicleDamage = getDammage _inVehicle;
  157. _EH_Fired_Vehicle = _inVehicle addEventHandler ["Fired", {
  158. systemChat ("You can not fire your vehicles weapon in a Trader City Area");
  159. NearestObject [_this select 0,_this select 4] setPos[0,0,0];
  160. }];
  161. };
  162. };
  163. } else {
  164. waitUntil { canBuild };
  165. };
  166.  
  167. AGN_LastPlayerLookedAt = objNull;
  168. AGN_LastPlayerLookedAtCountDown = 5;
  169. terminate _antiBackpackThread;
  170. terminate _antiBackpackThread2;
  171. if ( _safeZoneMessages ) then { systemChat ("Exiting Trader Area - God Mode Disabled"); };
  172.  
  173. if ( _safeZone_Vehicles_DisableMountedGuns ) then
  174. {
  175. if ( !(isNull _inVehicle) ) then
  176. {
  177. if ( _safeZoneMessages ) then { systemChat ( "No Firing! Vehicle Guns Disabled" ); };
  178. _inVehicle removeEventHandler ["Fired", _EH_Fired_Vehicle];
  179. };
  180.  
  181. if ( !(isNull _inVehicleLast) ) then
  182. {
  183. if ( _safeZoneMessages ) then { systemChat ( "No Firing! Vehicle Guns Disabled" ); };
  184. _inVehicleLast removeEventHandler ["Fired", _EH_Fired_Vehicle];
  185. };
  186. };
  187.  
  188. if ( _safeZone_Players_DisableWeaponFiring ) then
  189. {
  190. _thePlayer removeEventHandler ["Fired", _EH_Fired];
  191. };
  192.  
  193. if ( _safeZoneGodmode ) then
  194. {
  195. player_zombieCheck = compile preprocessFileLineNumbers "\z\addons\dayz_code\compile\player_zombieCheck.sqf";
  196. fnc_usec_damageHandler = compile preprocessFileLineNumbers "\z\addons\dayz_code\compile\fn_damageHandler.sqf";
  197. _thePlayer addEventHandler ["handleDamage", {true}];
  198. _thePlayer removeAllEventHandlers "handleDamage";
  199. _thePlayer allowDamage true;
  200. };
  201. _inSafezoneFinished = true;
  202. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement