Guest User

Untitled

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