Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * Safezone Commander Script by AlienX
- * www.opendayz.net
- * Thanks to everyone who has provided other scripts of the same format, without you I would not have been able to make this.
- */
- diag_log ( "Starting Trader City Safezone Commander!" );
- if ( isDedicated || isServer ) exitWith {diag_log ( "Error: Attempting to start AGN products on a server where it should not be!" );};
- Private ["_EH_Fired", "_ehID", "_fix","_inVehicle","_inVehicleLast","_EH_Fired_Vehicle",
- "_inVehicleDamage","_antiBackpackThread","_antiBackpackThread2"];
- private ["_safeZoneGodmode","_safeZoneMessages","_safeZone_Backpack_AllowGearFromLootPiles",
- "_safeZone_Backpack_AllowGearFromVehicles","_safeZone_Backpack_AllowGearFromDeadPlayers",
- "_safeZone_Vehicles_DisableMountedGuns","_safeZone_Players_DisableWeaponFiring",
- "_safeZone_Backpack_EnableAntiBackpack","_safeZone_Vehicles_AllowGearFromWithinVehicles"];
- //SCRIPT SETTINGS
- _safeZoneGodmode = true; //Should safezone Godmode be enabled?
- _safeZoneMessages = true; //Should players get messages when entering and exiting the safe zone?
- _safeZone_Backpack_EnableAntiBackpack = true; //Should players not be able to take from peoples bags?
- _safeZone_Backpack_AllowGearFromLootPiles = true; //Should players be able to loot from loot piles?
- _safeZone_Backpack_AllowGearFromVehicles = true; //Should players be able to loot from a vehicles gear?
- _safeZone_Backpack_AllowGearFromDeadPlayers = true; //Should players be able to loot from a dead players corpse?
- _safeZone_Vehicles_DisableMountedGuns = true; //Should players not be able to shoot bullets/projectiles from mounted guns?
- _safeZone_Vehicles_AllowGearFromWithinVehicles = true; //Should players be able to open the gear screen while they are inside a vehicle?
- _safeZone_Players_DisableWeaponFiring = true; //Should players not be able to shoot bullets/projectiles from their weapon(s)?
- waitUntil {!isNil "dayz_animalCheck"};
- if ( _safeZoneMessages ) then { systemChat ( " Trader Safe Zones Loaded!" ); };
- _inVehicle = objNull;
- _inVehicleLast = objNull;
- while {true} do {
- waitUntil { !canBuild };
- _inSafezoneFinished = false;
- if ( _safeZoneMessages ) then { systemChat ("Entering Trader Area - God Mode Enabled"); };
- _thePlayer = player;
- if ( _safeZoneGodmode ) then
- {
- player_zombieCheck = {};
- fnc_usec_damageHandler = {};
- _thePlayer removeAllEventHandlers "handleDamage";
- _thePlayer addEventHandler ["handleDamage", {false}];
- _thePlayer allowDamage false;
- };
- if ( _safeZone_Players_DisableWeaponFiring ) then
- {
- _EH_Fired = _thePlayer addEventHandler ["Fired", {
- systemChat ("You can not fire your weapon in a Trader City Area");
- NearestObject [_this select 0,_this select 4] setPos[0,0,0];
- }];
- };
- if ( _safeZone_Backpack_EnableAntiBackpack ) then
- {
- AGN_LastPlayerLookedAt = objNull;
- AGN_LastPlayerLookedAtCountDown = 5;
- _antiBackpackThread = [] spawn {
- private [ "_ct","_ip","_ia","_dis"] ;
- while {!canBuild} do
- {
- if ( isNull AGN_LastPlayerLookedAt ) then
- {
- waitUntil {!isNull cursorTarget};
- _ct = cursorTarget;
- _ip = isPlayer _ct;
- if ( _ip ) then { _ia = alive _ct; _dis = _ct distance player; } else { _ia = false; _dis = 1000; };
- if ( (_ip && _ia) && (_dis < 6.5) ) then
- {
- AGN_LastPlayerLookedAt = _ct;
- };
- } else {
- AGN_LastPlayerLookedAtCountDown = AGN_LastPlayerLookedAtCountDown - 1;
- if ( AGN_LastPlayerLookedAtCountDown < 0 ) then { AGN_LastPlayerLookedAtCountDown = 5; AGN_LastPlayerLookedAt = objNull; };
- sleep 1;
- };
- };
- };
- _antiBackpackThread2 = [] spawn {
- private ["_to","_dis","_inchk","_ip","_ia","_skip","_ct","_iv","_lp","_inv"];
- while {!canBuild} do
- {
- _ct = cursorTarget;
- _skip = false;
- if ( !isNull (_ct) ) then
- {
- _to = typeOf _ct;
- _dis = _ct distance player;
- _inchk = ["WeaponHolder","ReammoBox"];
- _lp = ((_to in _inchk) && (_dis < 10) && _safeZone_Backpack_AllowGearFromLootPiles);
- _ip = isPlayer _ct;
- if ( _ip ) then { _ia = alive _ct; } else { _ia = true; };
- _iv = _ct isKindOf "AllVehicles";
- _inv = (vehicle player != player);
- //Lootpile check
- if ( _lp ) then {_skip = true;};
- //Dead body check
- if ( !_ia && _safeZone_Backpack_AllowGearFromDeadPlayers ) then {_skip = true;};
- //Vehicle check
- if ( _iv && (_dis < 10) && !_ip && _safeZone_Backpack_AllowGearFromVehicles ) then {_skip = true;};
- //In a vehicle check
- if ( _inv && _safeZone_Vehicles_AllowGearFromWithinVehicles ) then { _skip = true; };
- };
- if( !isNull (FindDisplay 106) && !_skip ) then
- {
- if ( isNull AGN_LastPlayerLookedAt ) then
- {
- (findDisplay 106) closeDisplay 1;
- waitUntil { isNull (FindDisplay 106) };
- createGearDialog [(player), 'RscDisplayGear'];
- if ( _safeZoneMessages ) then { systemChat ("Anti Backpack Stealing - Redirecting you to your own gear!"); };
- waitUntil { isNull (FindDisplay 106) };
- } else {
- if ( _safeZoneMessages ) then { systemChat (format["You cannot open your gear at this time as you have looked at a player in the last 5 seconds."]); };
- (findDisplay 106) closeDisplay 1;
- waitUntil { isNull (FindDisplay 106) };
- };
- };
- };
- };
- };
- if ( _safeZone_Vehicles_DisableMountedGuns ) then
- {
- while { !canBuild } do
- {
- sleep 0.1;
- if ( !(isNull _inVehicle) && (vehicle player == player) ) then
- {
- _inVehicle removeEventHandler ["Fired", _EH_Fired_Vehicle];
- _inVehicleLast = _inVehicle;
- _inVehicleLast removeEventHandler ["Fired", _EH_Fired_Vehicle];
- _inVehicle = objNull;
- };
- if ( vehicle player != player && isNull _inVehicle ) then
- {
- if (_safeZoneMessages) then { systemChat ( "No Firing! Vehicle Guns Enabled" ); };
- _inVehicle = vehicle player;
- _inVehicleDamage = getDammage _inVehicle;
- _EH_Fired_Vehicle = _inVehicle addEventHandler ["Fired", {
- systemChat ("You can not fire your vehicles weapon in a Trader City Area");
- NearestObject [_this select 0,_this select 4] setPos[0,0,0];
- }];
- };
- };
- } else {
- waitUntil { canBuild };
- };
- AGN_LastPlayerLookedAt = objNull;
- AGN_LastPlayerLookedAtCountDown = 5;
- terminate _antiBackpackThread;
- terminate _antiBackpackThread2;
- if ( _safeZoneMessages ) then { systemChat ("Exiting Trader Area - God Mode Disabled"); };
- if ( _safeZone_Vehicles_DisableMountedGuns ) then
- {
- if ( !(isNull _inVehicle) ) then
- {
- if ( _safeZoneMessages ) then { systemChat ( "No Firing! Vehicle Guns Disabled" ); };
- _inVehicle removeEventHandler ["Fired", _EH_Fired_Vehicle];
- };
- if ( !(isNull _inVehicleLast) ) then
- {
- if ( _safeZoneMessages ) then { systemChat ( "No Firing! Vehicle Guns Disabled" ); };
- _inVehicleLast removeEventHandler ["Fired", _EH_Fired_Vehicle];
- };
- };
- if ( _safeZone_Players_DisableWeaponFiring ) then
- {
- _thePlayer removeEventHandler ["Fired", _EH_Fired];
- };
- if ( _safeZoneGodmode ) then
- {
- player_zombieCheck = compile preprocessFileLineNumbers "\z\addons\dayz_code\compile\player_zombieCheck.sqf";
- fnc_usec_damageHandler = compile preprocessFileLineNumbers "\z\addons\dayz_code\compile\fn_damageHandler.sqf";
- _thePlayer addEventHandler ["handleDamage", {true}];
- _thePlayer removeAllEventHandlers "handleDamage";
- _thePlayer allowDamage true;
- };
- _inSafezoneFinished = true;
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement