Advertisement
Guest User

Untitled

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