Advertisement
Guest User

Untitled

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