Advertisement
netripper

SafeZoneCommander + cargod

Jun 3rd, 2014
233
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 15.52 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. * 2014-05-30: Added cargod (Martijn Stolk/netripper)
  7. */
  8.  
  9. diag_log ( "[AGN] Starting Trader City Safezone Commander!" );
  10.  
  11. if ( isDedicated || isServer ) exitWith {diag_log ( "Error: Attempting to start AGN products on a server where it should not be!" );};
  12.  
  13. Private ["_EH_Fired", "_ehID", "_fix","_inVehicle","_inVehicleLast","_EH_Fired_Vehicle",
  14. "_inVehicleDamage","_antiBackpackThread","_antiBackpackThread2","_anti_zombie",
  15. "_vehicle","_veh_array","_y","_veh_total","_godmodeThread"];
  16.  
  17. //SCRIPT SETTINGS
  18. AGN_safeZoneDebug = false; //Debug notes on screen.
  19. AGN_safeZoneGodmode = true; //Should safezone Godmode 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. AGN_safeZone_Players_RemoveZombies= true; //Players allowed to delete zombies while in safe zone?
  30.  
  31. //Probs not needed, but meh :)
  32. disableSerialization;
  33.  
  34. waitUntil {!isNil "dayz_animalCheck"};
  35. if ( AGN_safeZoneMessages ) then { systemChat ( "[AGN] Trader Zone Commander Loaded!" ); };
  36.  
  37. _inVehicle = objNull;
  38. _inVehicleLast = objNull;
  39.  
  40. while {true} do {
  41.  
  42. waitUntil { !canBuild };
  43.  
  44. _inSafezoneFinished = false;
  45. if ( AGN_safeZoneMessages ) then { systemChat ("[AGN] Entering Trader Area - God Mode Enabled"); };
  46. _thePlayer = player;
  47.  
  48. if ( AGN_safeZoneGodmode ) then
  49. {
  50. _godmodeThread = [] spawn {
  51. while {!canBuild} do
  52. {
  53. if (AGN_safeZoneDebug) then { diag_log format["[AGN-MST] Godmode check, Player = %1, Vehicle = %2", player, vehicle player]; };
  54.  
  55. // Disable handlers
  56. player_zombieCheck = {};
  57. fnc_usec_damageHandler = {};
  58.  
  59. // Disable damage on player
  60. player removeAllEventHandlers "HandleDamage";
  61. player addEventHandler ["HandleDamage", {false}];
  62. player allowDamage false;
  63.  
  64. // Disable damage on vehicle
  65. fnc_usec_damageVehicle = {};
  66. vehicle_handleDamage = {};
  67. vehicle_handleKilled = {};
  68. if (vehicle player != player) then {
  69. if (AGN_safeZoneDebug) then { diag_log format["[AGN-MST] In vehicle, setting cargod mode on this car"]; };
  70. // Setting godmode on this vehicle
  71. vehicle player removeAllEventHandlers "handleDamage";
  72. vehicle player addEventHandler ["handleDamage", {false}];
  73. vehicle player allowDamage false;
  74.  
  75. // Check for towed vehicles
  76. {
  77. if (!isNull _x) then
  78. {
  79. private ["_attachedObj"];
  80. diag_log format["[AGN-MST] Testing nearby object for tow/lift: %1", _x];
  81. _attachedObj = _x getVariable["R3F_LOG_est_transporte_par", objNull];
  82. if (!isNull _attachedObj) then {
  83. // Found a vehicle being towed
  84. diag_log format["[AGN-MST] Setting cargod on my towed/lifted object: %1", _x];
  85. _x removeAllEventHandlers "handleDamage";
  86. _x addEventHandler ["handleDamage", {_this select 2}];
  87. _x allowDamage true;
  88. };
  89. };
  90. } forEach ((vehicle player) nearEntities ['AllVehicles', 50]);
  91. };
  92. sleep 1;
  93. };
  94. };
  95. };
  96.  
  97. if ( AGN_safeZone_Players_RemoveZombies ) then
  98. {
  99. _anti_zombie = [] spawn {
  100. private ["_entity_array"];
  101. while {!canBuild} do
  102. {
  103. _entity_array = (getPos player) nearEntities ["CAManBase",50];
  104. {
  105. if (_x isKindof "zZombie_Base") then {
  106. deletevehicle _x;
  107. };
  108. } forEach _entity_array;
  109. sleep 4;
  110. };
  111. };
  112. };
  113.  
  114. if ( AGN_safeZone_Players_DisableWeaponFiring ) then
  115. {
  116. _EH_Fired = _thePlayer addEventHandler ["Fired", {
  117. systemChat ("[AGN] You can not fire your weapon in a Trader City Area");
  118. NearestObject [_this select 0,_this select 4] setPos[0,0,0];
  119. }];
  120. };
  121.  
  122. if ( AGN_safeZone_Backpack_EnableAntiBackpack ) then
  123. {
  124. AGN_LastPlayerLookedAt = objNull;
  125. AGN_LastPlayerLookedAtCountDown = 5;
  126. _antiBackpackThread = [] spawn {
  127. private [ "_ct","_ip","_ia","_dis"] ;
  128. while {!canBuild} do
  129. {
  130. if ( isNull AGN_LastPlayerLookedAt ) then
  131. {
  132. waitUntil {!isNull cursorTarget};
  133. _ct = cursorTarget;
  134. _ip = isPlayer _ct;
  135. if ( _ip ) then { _ia = alive _ct; _dis = _ct distance player; } else { _ia = false; _dis = 1000; };
  136.  
  137. if ( (_ip && _ia) && (_dis < 6.5) ) then
  138. {
  139. AGN_LastPlayerLookedAt = _ct;
  140. };
  141. } else {
  142. AGN_LastPlayerLookedAtCountDown = AGN_LastPlayerLookedAtCountDown - 1;
  143. if ( AGN_LastPlayerLookedAtCountDown < 0 ) then { AGN_LastPlayerLookedAtCountDown = 5; AGN_LastPlayerLookedAt = objNull; };
  144. sleep 1;
  145. };
  146. };
  147. };
  148.  
  149. _antiBackpackThread2 = [] spawn {
  150. private ["_to","_dis","_inchk","_ip","_ia","_skip","_ct","_iv","_lp","_inv","_ctOwnerID","_friendlies","_if"];
  151. _ctOwnerID = 0;
  152. while {!canBuild} do
  153. {
  154. _ct = cursorTarget;
  155. _if = false;
  156. _skip = false;
  157.  
  158. if ( !isNull (_ct) ) then
  159. {
  160. _to = typeOf _ct;
  161. _dis = _ct distance player;
  162. _inchk = ["WeaponHolder","ReammoBox"];
  163.  
  164. _lp = false;
  165. {
  166. if ( (_to isKindOf _x) && (_dis < 10) && AGN_safeZone_Backpack_AllowGearFromLootPiles ) then
  167. {
  168. _lp = true;
  169. };
  170. } forEach ( _inchk );
  171.  
  172. _ip = isPlayer _ct;
  173. _ia = alive _ct;
  174. _iv = _ct isKindOf "AllVehicles";
  175. _inv = (vehicle player != player);
  176.  
  177. _if = false;
  178. if ( _ip ) then {
  179. _ctOwnerID = _ct getVariable["CharacterID","0"];
  180. _friendlies = player getVariable ["friendlyTo",[]];
  181. if(_ctOwnerID in _friendlies) then {
  182. if ( AGN_safeZone_Backpack_AllowFriendlyTaggedAccess ) then
  183. {
  184. _if = true;
  185. };
  186. };
  187. };
  188. if ( AGN_safeZoneDebug ) then {
  189. 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",
  190. _ct, _dis, _lp, _ip, _ia, _iv, _inv, _if, AGN_safeZone_Backpack_AllowGearFromLootPiles, AGN_safeZone_Backpack_AllowFriendlyTaggedAccess, _skip, _ctOwnerID] );
  191. };
  192.  
  193. //Lootpile check
  194. if ( _lp ) then {_skip = true;};
  195.  
  196. //Dead body check
  197. if ( !(_ia) && AGN_safeZone_Backpack_AllowGearFromDeadPlayers ) then {_skip = true;};
  198.  
  199. //Vehicle check
  200. if ( _iv && (_dis < 10) && !(_ip) && AGN_safeZone_Backpack_AllowGearFromVehicles ) then {_skip = true;};
  201.  
  202. //In a vehicle check
  203. if ( _inv && AGN_safeZone_Vehicles_AllowGearFromWithinVehicles ) then { _skip = true; };
  204.  
  205. //Is player friendly?
  206. if ( _if ) then { _skip = true; };
  207. };
  208.  
  209. if( !isNull (FindDisplay 106) && !_skip ) then
  210. {
  211. if ( isNull AGN_LastPlayerLookedAt ) then
  212. {
  213. (findDisplay 106) closeDisplay 1;
  214. waitUntil { isNull (FindDisplay 106) };
  215. createGearDialog [(player), 'RscDisplayGear'];
  216. if ( AGN_safeZoneMessages ) then { systemChat ("[AGN] Anti Backpack Stealing - Redirecting you to your own gear!"); };
  217. waitUntil { isNull (FindDisplay 106) };
  218. } else {
  219. 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."]); };
  220. (findDisplay 106) closeDisplay 1;
  221. waitUntil { isNull (FindDisplay 106) };
  222. };
  223. };
  224. if ( _skip && _if ) then {
  225. // MST - Disabled due to spam
  226. //if ( AGN_safeZoneMessages ) then { systemChat ("[AGN] This player is tagged friendly, you have access to this players bag") };
  227. };
  228. };
  229. };
  230. };
  231.  
  232. if ( AGN_safeZone_Vehicles_DisableMountedGuns ) then
  233. {
  234. while { !canBuild } do
  235. {
  236. sleep 0.1;
  237. if ( !(isNull _inVehicle) && (vehicle player == player) ) then
  238. {
  239. _inVehicle removeEventHandler ["Fired", _EH_Fired_Vehicle];
  240. _inVehicleLast = _inVehicle;
  241. _inVehicleLast removeEventHandler ["Fired", _EH_Fired_Vehicle];
  242. _inVehicle = objNull;
  243. };
  244.  
  245. if ( vehicle player != player && isNull _inVehicle ) then
  246. {
  247. if (AGN_safeZoneMessages) then { systemChat ( "[AGN] No Firing Vehicle Guns Enabled" ); };
  248. _inVehicle = vehicle player;
  249. _inVehicleDamage = getDammage _inVehicle;
  250. _EH_Fired_Vehicle = _inVehicle addEventHandler ["Fired", {
  251. systemChat ("[AGN] You can not fire your vehicles weapon in a Trader City Area");
  252. NearestObject [_this select 0,_this select 4] setPos[0,0,0];
  253. }];
  254. };
  255. };
  256. } else {
  257. waitUntil { canBuild };
  258. };
  259.  
  260. AGN_LastPlayerLookedAt = objNull;
  261. AGN_LastPlayerLookedAtCountDown = 5;
  262. terminate _antiBackpackThread;
  263. terminate _antiBackpackThread2;
  264. terminate _anti_zombie;
  265. terminate _godmodeThread;
  266. if ( AGN_safeZoneMessages ) then { systemChat ("[AGN] Exiting Trader Area - God Mode Disabled"); };
  267.  
  268. if ( AGN_safeZone_Vehicles_DisableMountedGuns ) then
  269. {
  270. if ( !(isNull _inVehicle) ) then
  271. {
  272. if ( AGN_safeZoneMessages ) then { systemChat ( "[AGN] No Firing Vehicle Guns Disabled" ); };
  273. _inVehicle removeEventHandler ["Fired", _EH_Fired_Vehicle];
  274. };
  275.  
  276. if ( !(isNull _inVehicleLast) ) then
  277. {
  278. if ( AGN_safeZoneMessages ) then { systemChat ( "[AGN] No Firing Vehicle Guns Disabled" ); };
  279. _inVehicleLast removeEventHandler ["Fired", _EH_Fired_Vehicle];
  280. };
  281. };
  282.  
  283. if ( AGN_safeZone_Players_DisableWeaponFiring ) then
  284. {
  285. _thePlayer removeEventHandler ["Fired", _EH_Fired];
  286. };
  287.  
  288. if ( AGN_safeZoneGodmode ) then
  289. {
  290. if (AGN_safeZoneDebug) then { diag_log format["[AGN-MST] Leaving godmode"]; };
  291.  
  292. // Reload handlers
  293. player_zombieCheck = compile preprocessFileLineNumbers "\z\addons\dayz_code\compile\player_zombieCheck.sqf";
  294. fnc_usec_damageHandler = compile preprocessFileLineNumbers "\z\addons\dayz_code\compile\fn_damageHandler.sqf";
  295. fnc_usec_damageVehicle = compile preprocessFileLineNumbers "\z\addons\dayz_code\compile\fn_damageHandlerVehicle.sqf";
  296. vehicle_handleDamage = compile preprocessFileLineNumbers "\z\addons\dayz_code\compile\vehicle_handleDamage.sqf";
  297. vehicle_handleKilled = compile preprocessFileLineNumbers "\z\addons\dayz_code\compile\vehicle_handleKilled.sqf";
  298.  
  299. // Re-enable damage on player
  300. _thePlayer removeAllEventHandlers "HandleDamage";
  301. _thePlayer addEventHandler ["HandleDamage", {_this call fnc_usec_damageHandler}];
  302. _thePlayer allowDamage true;
  303.  
  304. // Re-enable damage on vehicle
  305. if (vehicle player != player) then {
  306. if (AGN_safeZoneDebug) then { diag_log format["[AGN-MST] Leaving cargodmode, fixing my car: %1", vehicle player]; };
  307. vehicle player removeAllEventHandlers "handleDamage";
  308. vehicle player addEventHandler ["handleDamage", {_this select 2}];
  309. vehicle player allowDamage true;
  310. // Re-enable damage on any towed vehicles
  311. {
  312. if (!isNull _x) then
  313. {
  314. private ["_attachedObj"];
  315. if (AGN_safeZoneDebug) then { diag_log format["[AGN-MST] Testing nearby object for tow/lift: %1", _x]; };
  316. _attachedObj = _x getVariable["R3F_LOG_est_transporte_par", objNull];
  317. if (!isNull _attachedObj) then {
  318. if (AGN_safeZoneDebug) then { diag_log format["[AGN-MST] Removing cargod on my tow/lifted object: %1", _x]; };
  319. _x removeAllEventHandlers "handleDamage";
  320. _x addEventHandler ["handleDamage", {_this select 2}];
  321. _x allowDamage true;
  322. };
  323. };
  324. } forEach ((vehicle player) nearEntities ['AllVehicles', 50]);
  325. };
  326. };
  327. _inSafezoneFinished = true;
  328. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement