Advertisement
Guest User

Untitled

a guest
May 10th, 2014
394
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.62 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","_entity_array",
  13. "_vehicle","_veh_array","_y","_veh_total"];
  14. /* Global not needed to be declared
  15. private ["AGN_safeZoneGodmode","AGN_safeZoneMessages","AGN_safeZone_Backpack_AllowGearFromLootPiles",
  16. "AGN_safeZone_Backpack_AllowGearFromVehicles","AGN_safeZone_Backpack_AllowGearFromDeadPlayers",
  17. "AGN_safeZone_Vehicles_DisableMountedGuns","AGN_safeZone_Players_DisableWeaponFiring",
  18. "AGN_safeZone_Backpack_EnableAntiBackpack","AGN_safeZone_Vehicles_AllowGearFromWithinVehicles",
  19. "AGN_safeZone_Players_RemoveZombies","AGN_safeZone_VehicleGod"];
  20. */
  21.  
  22. //SCRIPT SETTINGS
  23. AGN_safeZoneDebug = false; //Debug notes on screen.
  24. AGN_safeZoneGodmode = true; //Should safezone Godmode be enabled?
  25. AGN_safeZoneMessages = true; //Should players get messages when entering and exiting the safe zone?
  26. AGN_safeZone_Backpack_EnableAntiBackpack = true; //Should players not be able to take from peoples bags?
  27. AGN_safeZone_Backpack_AllowGearFromLootPiles = true; //Should players be able to loot from loot piles?
  28. AGN_safeZone_Backpack_AllowGearFromVehicles = true; //Should players be able to loot from a vehicles gear?
  29. AGN_safeZone_Backpack_AllowGearFromDeadPlayers = true; //Should players be able to loot from a dead players corpse?
  30. AGN_safeZone_Backpack_AllowFriendlyTaggedAccess = true; //Should players who are tagged friendly be able to access each others bags?
  31. AGN_safeZone_Vehicles_DisableMountedGuns = true; //Should players not be able to shoot bullets/projectiles from mounted guns?
  32. AGN_safeZone_Vehicles_AllowGearFromWithinVehicles = true; //Should players be able to open the gear screen while they are inside a vehicle?
  33. AGN_safeZone_Players_DisableWeaponFiring = true; //Should players not be able to shoot bullets/projectiles from their weapon(s)?
  34. AGN_safeZone_Players_RemoveZombies= true; //Players allowed to delete zombies while in safe zone?
  35. //AGN_safeZone_VehicleGod= false; //Should players remove vehicle damage handlers nearby while in safe zones??
  36.  
  37. //Probs not needed, but meh :)
  38. disableSerialization;
  39.  
  40. waitUntil {!isNil "dayz_animalCheck"};
  41. if ( AGN_safeZoneMessages ) then { systemChat ( "[AGN] Trader Zone Commander Loaded!" ); };
  42.  
  43. _inVehicle = objNull;
  44. _inVehicleLast = objNull;
  45.  
  46. while {true} do {
  47.  
  48. waitUntil { !canBuild };
  49.  
  50. _inSafezoneFinished = false;
  51. if ( AGN_safeZoneMessages ) then { systemChat ("[AGN] Entering Trader Area - God Mode Enabled"); };
  52. _thePlayer = player;
  53.  
  54. if ( AGN_safeZoneGodmode ) then
  55. {
  56. player_zombieCheck = {};
  57. fnc_usec_damageHandler = {};
  58. _thePlayer removeAllEventHandlers "handleDamage";
  59. _thePlayer addEventHandler ["handleDamage", {false}];
  60. _thePlayer allowDamage false;
  61. _inVehicle allowDamage false;
  62. _zombies = _basis nearEntities ["zZombie_Base",50];
  63. _count = count _zombies;
  64. for "_i" from 0 to (_count -1) do
  65. {
  66. _zombie = _zombies select _i;
  67. deletevehicle _zombie;
  68. };
  69.  
  70. };
  71.  
  72. if ( AGN_safeZone_Players_DisableWeaponFiring ) then
  73. {
  74. _EH_Fired = _thePlayer addEventHandler ["Fired", {
  75. systemChat ("[AGN] You can not fire your weapon in a Trader City Area");
  76. NearestObject [_this select 0,_this select 4] setPos[0,0,0];
  77. }];
  78. };
  79.  
  80. if ( AGN_safeZone_Players_RemoveZombies ) then
  81. {
  82. while {!canBuild} do
  83. {
  84. _entity_array = (getPos player) nearEntities ["CAManBase",110];
  85. {
  86. if (_x isKindof "zZombie_Base") then {
  87. deletevehicle _x;
  88. };
  89. } forEach _entity_array;
  90. sleep 4;
  91. };
  92. };
  93.  
  94. /* WIP
  95. if ( AGN_safeZone_VehicleGod ) then
  96. {
  97. _y = 0;
  98. while {!canbuild} do {
  99. _veh_array = (getPos player) nearEntities [["Car","Tank","Helicopter","Plane","StaticWeapon","Ship"],110];
  100. while {(_y < (count _veh_array)) and (!canbuild)} do {
  101. _vehicle = (_veh_array select _y);
  102. _veh_total = _veh_total + _vehicle;
  103. _y = _y + 1;
  104. while {!canbuild} do { // loop for canbuild check
  105. {
  106. _x allowDamage false;
  107. _x enableSimulation false;
  108. } forEach _veh_total;
  109. } else {
  110. {
  111. _x allowDamage true;
  112. _x enableSimulation true;
  113. } forEach _veh_total;
  114. };
  115. };
  116. };
  117. };*/
  118.  
  119. if ( AGN_safeZone_Backpack_EnableAntiBackpack ) then
  120. {
  121. AGN_LastPlayerLookedAt = objNull;
  122. AGN_LastPlayerLookedAtCountDown = 5;
  123. _antiBackpackThread = [] spawn {
  124. private [ "_ct","_ip","_ia","_dis"] ;
  125. while {!canBuild} do
  126. {
  127. if ( isNull AGN_LastPlayerLookedAt ) then
  128. {
  129. waitUntil {!isNull cursorTarget};
  130. _ct = cursorTarget;
  131. _ip = isPlayer _ct;
  132. if ( _ip ) then { _ia = alive _ct; _dis = _ct distance player; } else { _ia = false; _dis = 1000; };
  133.  
  134. if ( (_ip && _ia) && (_dis < 6.5) ) then
  135. {
  136. AGN_LastPlayerLookedAt = _ct;
  137. };
  138. } else {
  139. AGN_LastPlayerLookedAtCountDown = AGN_LastPlayerLookedAtCountDown - 1;
  140. if ( AGN_LastPlayerLookedAtCountDown < 0 ) then { AGN_LastPlayerLookedAtCountDown = 5; AGN_LastPlayerLookedAt = objNull; };
  141. sleep 1;
  142. };
  143. };
  144. };
  145.  
  146. _antiBackpackThread2 = [] spawn {
  147. private ["_to","_dis","_inchk","_ip","_ia","_skip","_ct","_iv","_lp","_inv","_ctOwnerID","_friendlies","_if"];
  148. _ctOwnerID = 0;
  149. while {!canBuild} do
  150. {
  151. _ct = cursorTarget;
  152. _skip = false;
  153.  
  154. if ( !isNull (_ct) ) then
  155. {
  156. _to = typeOf _ct;
  157. _dis = _ct distance player;
  158. _inchk = ["WeaponHolder","ReammoBox"];
  159.  
  160. _lp = false;
  161. {
  162. if ( (_to isKindOf _x) && (_dis < 10) && AGN_safeZone_Backpack_AllowGearFromLootPiles ) then
  163. {
  164. _lp = true;
  165. };
  166. } forEach ( _inchk );
  167.  
  168. _ip = isPlayer _ct;
  169. _ia = alive _ct;
  170. _iv = _ct isKindOf "AllVehicles";
  171. _inv = (vehicle player != player);
  172.  
  173. _if = false;
  174. if ( _ip ) then {
  175. _ctOwnerID = _ct getVariable["CharacterID","0"];
  176. _friendlies = player getVariable ["friendlyTo",[]];
  177. if(_ctOwnerID in _friendlies) then {
  178. if ( AGN_safeZone_Backpack_AllowFriendlyTaggedAccess ) then
  179. {
  180. _if = true;
  181. };
  182. };
  183. };
  184. if ( AGN_safeZoneDebug ) then {
  185. 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",
  186. _ct, _dis, _lp, _ip, _ia, _iv, _inv, _if, AGN_safeZone_Backpack_AllowGearFromLootPiles, AGN_safeZone_Backpack_AllowFriendlyTaggedAccess, _skip, _ctOwnerID] );
  187. };
  188.  
  189.  
  190. //Lootpile check
  191. if ( _lp ) then {_skip = true;};
  192.  
  193. //Dead body check
  194. if ( !(_ia) && AGN_safeZone_Backpack_AllowGearFromDeadPlayers ) then {_skip = true;};
  195.  
  196. //Vehicle check
  197. if ( _iv && (_dis < 10) && !(_ip) && AGN_safeZone_Backpack_AllowGearFromVehicles ) then {_skip = true;};
  198.  
  199. //In a vehicle check
  200. if ( _inv && AGN_safeZone_Vehicles_AllowGearFromWithinVehicles ) then { _skip = true; };
  201.  
  202. //Is player friendly?
  203. if ( _if ) then { _skip = true; };
  204. };
  205.  
  206. if( !isNull (FindDisplay 106) && !_skip ) then
  207. {
  208. if ( isNull AGN_LastPlayerLookedAt ) then
  209. {
  210. (findDisplay 106) closeDisplay 1;
  211. waitUntil { isNull (FindDisplay 106) };
  212. createGearDialog [(player), 'RscDisplayGear'];
  213. if ( AGN_safeZoneMessages ) then { systemChat ("[AGN] Anti Backpack Stealing - Redirecting you to your own gear!"); };
  214. waitUntil { isNull (FindDisplay 106) };
  215. } else {
  216. 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."]); };
  217. (findDisplay 106) closeDisplay 1;
  218. waitUntil { isNull (FindDisplay 106) };
  219. };
  220. };
  221. if ( _skip && _if ) then {
  222. if ( AGN_safeZoneMessages ) then { systemChat ("[AGN] This player is tagged friendly, you have access to this players bag") };
  223. };
  224. };
  225. };
  226. };
  227.  
  228. if ( AGN_safeZone_Vehicles_DisableMountedGuns ) then
  229. {
  230. while { !canBuild } do
  231. {
  232. sleep 0.1;
  233. if ( !(isNull _inVehicle) && (vehicle player == player) ) then
  234. {
  235. _inVehicle removeEventHandler ["Fired", _EH_Fired_Vehicle];
  236. _inVehicleLast = _inVehicle;
  237. _inVehicleLast removeEventHandler ["Fired", _EH_Fired_Vehicle];
  238. _inVehicle = objNull;
  239. };
  240.  
  241. if ( vehicle player != player && isNull _inVehicle ) then
  242. {
  243. if (AGN_safeZoneMessages) then { systemChat ( "[AGN] No Firing Vehicle Guns Enabled" ); };
  244. _inVehicle = vehicle player;
  245. _inVehicleDamage = getDammage _inVehicle;
  246. _EH_Fired_Vehicle = _inVehicle addEventHandler ["Fired", {
  247. systemChat ("[AGN] You can not fire your vehicles weapon in a Trader City Area");
  248. NearestObject [_this select 0,_this select 4] setPos[0,0,0];
  249. }];
  250. };
  251. };
  252. } else {
  253. waitUntil { canBuild };
  254. };
  255.  
  256. AGN_LastPlayerLookedAt = objNull;
  257. AGN_LastPlayerLookedAtCountDown = 5;
  258. terminate _antiBackpackThread;
  259. terminate _antiBackpackThread2;
  260. if ( AGN_safeZoneMessages ) then { systemChat ("[AGN] Exiting Trader Area - God Mode Disabled"); };
  261.  
  262. if ( AGN_safeZone_Vehicles_DisableMountedGuns ) then
  263. {
  264. if ( !(isNull _inVehicle) ) then
  265. {
  266. if ( AGN_safeZoneMessages ) then { systemChat ( "[AGN] No Firing Vehicle Guns Disabled" ); };
  267. _inVehicle removeEventHandler ["Fired", _EH_Fired_Vehicle];
  268. };
  269.  
  270. if ( !(isNull _inVehicleLast) ) then
  271. {
  272. if ( AGN_safeZoneMessages ) then { systemChat ( "[AGN] No Firing Vehicle Guns Disabled" ); };
  273. _inVehicleLast removeEventHandler ["Fired", _EH_Fired_Vehicle];
  274. };
  275. };
  276.  
  277. if ( AGN_safeZone_Players_DisableWeaponFiring ) then
  278. {
  279. _thePlayer removeEventHandler ["Fired", _EH_Fired];
  280. };
  281.  
  282. if ( AGN_safeZoneGodmode ) then
  283. {
  284. player_zombieCheck = compile preprocessFileLineNumbers "\z\addons\dayz_code\compile\player_zombieCheck.sqf";
  285. fnc_usec_damageHandler = compile preprocessFileLineNumbers "\z\addons\dayz_code\compile\fn_damageHandler.sqf";
  286. _thePlayer addEventHandler ["handleDamage", {true}];
  287. _thePlayer removeAllEventHandlers "handleDamage";
  288. _thePlayer allowDamage true;
  289. _inVehicle allowDamage true;
  290. };
  291. _inSafezoneFinished = true;
  292. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement