Jump to content
  • 0

Godmode vehicles in safe zones


Diox

Question

Hi,

 

I use maca134s "Better Safezone" script to enable player godmode in trade cities.

Is there any way to give vehicles godmode aswell?

 

I have DZAI (Bandit AI) and they tend to swarm trade cities and shoot in from the outside and destroying vehicles.

 

I tried to add 

vehicle_handleDamage ={};
vehicle_handleKilled ={};
 
and 
 
vehicle_handleDamage = compile preprocessFileLineNumbers "\z\addons\dayz_code\compile\vehicle_handleDamage.sqf";
vehicle_handleKilled = compile preprocessFileLineNumbers "\z\addons\dayz_code\compile\vehicle_handleKilled.sqf";

 

So it looks like this:

Private ["_EH_Fired"];

if (isNil "inSafezone") then {
	inSafezone = false;
};

while {true} do {
	waitUntil { inSafeZone };
	titleText [format["Entering Safe Zone. Your weapons have been deactivated."],"PLAIN DOWN"]; titleFadeOut 4;

	waitUntil { player == vehicle player };

	thePlayer = vehicle player;
	_EH_Fired = thePlayer addEventHandler ["Fired", {
		titleText ["You can not fire your weapon in a safe zone.","PLAIN DOWN"]; titleFadeOut 4;
		NearestObject [_this select 0,_this select 4] setPos[0,0,0];
	}];

	player_zombieCheck = {};
	fnc_usec_damageHandler = {};
	fnc_usec_unconscious  = {};
	vehicle_handleDamage ={};
	vehicle_handleKilled ={};
	thePlayer removeAllEventHandlers "handleDamage";
	thePlayer addEventHandler ["handleDamage", {false}];
	thePlayer allowDamage false;

	waitUntil { !inSafeZone };

	titleText [format["Exiting Safe Zone. Your weapons have been reactivated."],"PLAIN DOWN"]; titleFadeOut 4;
	thePlayer removeEventHandler ["Fired", _EH_Fired];

	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";
	fnc_usec_unconscious = compile preprocessFileLineNumbers "\z\addons\dayz_code\compile\fn_unconscious.sqf";
	vehicle_handleDamage = compile preprocessFileLineNumbers "\z\addons\dayz_code\compile\vehicle_handleDamage.sqf";
	vehicle_handleKilled = compile preprocessFileLineNumbers "\z\addons\dayz_code\compile\vehicle_handleKilled.sqf";
	thePlayer addEventHandler ["handleDamage", {true}];
	thePlayer removeAllEventHandlers "handleDamage";
	thePlayer allowDamage true;
}; 

This only seem to work when you sit inside of the vehicle, once you go out you can damage it again. At least I think you can't damage it while inside of the car. I'm all alone testing, so I haven't been able to test it with players, but at least AIs stop attacking my car when I'm inside of it.

 

Anyone knows how I can give vehicles godmode inside safe zones permanently, without having players inside of them?

 

Edit

The above code does not work at all. 

Link to comment
Share on other sites

15 answers to this question

Recommended Posts

  • 0

I have now tested this a bit better, and it does NOT work like I first thought.

No idea what to do to make this work, I'm not very familiar with the Arma 2 scripting, and even less the DayZ Epoch code.

 

Anyone with some superb scripting skills that knows how this can be done?  :rolleyes:

Link to comment
Share on other sites

  • 0

Well at a quick look and without testing this myself in theory you should be able to do the below. This will only work if you enter the safe zone in a vehicle that is local. You would also need to call a server function to turn off/on taking damage globally. Anyway this should point you in the right direction. I added in some hints for you to test with, let me know how it goes.

 

Code:

Private ["_EH_Fired","_PlayerVehicle"];

if (isNil "inSafezone") then {
	inSafezone = false;
};

while {true} do {
	waitUntil { inSafeZone };
	titleText [format["Entering Safe Zone. Your weapons have been deactivated."],"PLAIN DOWN"]; titleFadeOut 4;
    
	_PlayerVehicle = vehicle player;
	if(player != _PlayerVehicle) then {
		if(local (_PlayerVehicle) ) then {
			hintSilent "Entered safe zone in local vehicle godmode ON";
			_PlayerVehicle allowDamage false;
		};
		//Call public server variable
	};

	waitUntil { player == vehicle player };

	thePlayer = vehicle player;
	_EH_Fired = thePlayer addEventHandler ["Fired", {
		titleText ["You can not fire your weapon in a safe zone.","PLAIN DOWN"]; titleFadeOut 4;
		NearestObject [_this select 0,_this select 4] setPos[0,0,0];
	}];

	player_zombieCheck = {};
	fnc_usec_damageHandler = {};
	fnc_usec_unconscious  = {};
	vehicle_handleDamage ={};
	vehicle_handleKilled ={};
	thePlayer removeAllEventHandlers "handleDamage";
	thePlayer addEventHandler ["handleDamage", {false}];
	thePlayer allowDamage false;

	waitUntil { !inSafeZone };

	titleText [format["Exiting Safe Zone. Your weapons have been reactivated."],"PLAIN DOWN"]; titleFadeOut 4;
	thePlayer removeEventHandler ["Fired", _EH_Fired];

	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";
	fnc_usec_unconscious = compile preprocessFileLineNumbers "\z\addons\dayz_code\compile\fn_unconscious.sqf";
	vehicle_handleDamage = compile preprocessFileLineNumbers "\z\addons\dayz_code\compile\vehicle_handleDamage.sqf";
	vehicle_handleKilled = compile preprocessFileLineNumbers "\z\addons\dayz_code\compile\vehicle_handleKilled.sqf";
	thePlayer addEventHandler ["handleDamage", {true}];
	thePlayer removeAllEventHandlers "handleDamage";
	thePlayer allowDamage true;
    
	_PlayerVehicle = vehicle player;
	if(player != _PlayerVehicle) then {
		if(local (_PlayerVehicle) ) then {
			hintSilent "Leaving safe zone in local vehicle godmode OFF";
			_PlayerVehicle allowDamage true;
		};
		//Call public server variable
	};
};

Link to comment
Share on other sites

  • 0

I believe I have come up with a solution that works. Could anyone with better testing possibilities then me please test this?

 

How to install

Create new file safezone_vehicles.sqf:

Private ["_EH_VFired"];

if (isNil "inSafezone") then {
	inSafezone = false;
};

while {true} do {
	waitUntil { inSafeZone };

	waitUntil { player != vehicle player };

	theVehicle = vehicle player;
	_EH_VFired = theVehicle addEventHandler ["Fired", {
		titleText ["You can not fire your weapon in a safe zone.","PLAIN DOWN"]; titleFadeOut 4;
		NearestObject [_this select 0,_this select 4] setPos[0,0,0];
	}];

	theVehicle removeAllEventHandlers "handleDamage";
	theVehicle addEventHandler ["handleDamage", {false}];
	theVehicle allowDamage false;
	
	fnc_usec_damageVehicle ={};
	vehicle_handleDamage ={};
	vehicle_handleKilled ={};
	//hintSilent "Vehicle godmode ON"; // Uncomment this to help see when it actually turns on and off
	
	waitUntil { !inSafeZone };

	theVehicle removeEventHandler ["Fired", _EH_VFired];

	theVehicle removeAllEventHandlers "handleDamage";
	theVehicle addEventHandler ["handleDamage", {true}];
	theVehicle allowDamage true;
	
	fnc_usec_damageVehicle = compile preprocessFileLineNumbers "\z\addons\dayz_code\compile\fn_damageHandlerVehicle.sqf";
	vehicle_handleDamage = compile preprocessFileLineNumbers "\z\addons\dayz_code\compile\vehicle_handleDamage.sqf";
	vehicle_handleKilled = compile preprocessFileLineNumbers "\z\addons\dayz_code\compile\vehicle_handleKilled.sqf";
	//hintSilent "Vehicle godmode OFF"; // Uncomment this to help see when it actually turns on and off
	
};

In init.sqf inside of the if(!isDedicated) branch, add:

[] execVM "Scripts\safezone_vehicles.sqf";

I have my safezone_vehicles.sqf in a Scripts folder, if you don't have it like that just change the path to reflect your structure. 

 

This is an addition to maca134's "Better safezone" script, and is reliant on the same markers/sensors. This script is also based on maca134's script, so all credits to him.

 

 

As far as I know this only works after you have entered the car. If someone could please stress test this script and give me feedback that would be nice. 

 

Also be aware that I am in no way any familiar with Arma II scripting, and there could be a lots of things that could have been done differently in here, feel free to correct me.

 

Edit

I just realized that this might be abused by the towing script. If you enter safe zone with a vehicle it will get godmode untill someone drives it out. If you tow the car out of the safe zone I think it might have godmode forever. I'm not sure though, but if someone could test this that would be nice :)

Link to comment
Share on other sites

  • 0

It happens to be that I am OP  B)

 

The first code didn't work after all so I managed to create something that seem to work, but only if you enter the vehicle once. 

Anyone feel free to come with suggestions how to solve this for all vehicles, even those who haven't been entered by a player  :)

Link to comment
Share on other sites

  • 0

One solution I was testing was just making all locked vehicles indestructible, so at least players can't destroy vehicles parked in bases or whatever but I can be abused so easily I guess :/

e.g. get inside a vehicle and somebody else locks it, so you are indestructible.. or if you are being chased just get out of your car and lock it and use it as indestructible cover, so meh :/

Link to comment
Share on other sites

  • 0

//OFF TOPIC 

I have DZAI (Bandit AI) and they tend to swarm trade cities and shoot in from the outside and destroying vehicles.

 

 

Do you use SHK_pos to spawn your AI groups ?
If no, you should.

If Yes you can prevent them to spawn somewhere by using makers

like this 

http://derfel.org/arma2/scripts/SHK_pos/img/marker_ellipse_blacklist_waternotok.jpg

 

 

example I used:

_coords =[WholeMap,false,["SAFEbash","SAFEklen"]] call SHK_pos;

 

WholeMap =  maker for the whole map

SAFEbash,SAFEklen = exclusions makers to prenvent them to spawn "near" bash or klen

 

they can still come if they "decide" to go there but if you create a safe marker big enough the probability will come close to 0

 

//OFF TOPIC

Link to comment
Share on other sites

  • 0

I think i found a bug with this,

 

It seems to make vehicles very fragile when leaving the safezone again. One hit with any vehicle against anything (trees, buildings) with even the lowest speed, will cause it to explode.

 

Can anyone else confirm this? I want vehicles to have god mode in safe zones, but this is a big bug....

Link to comment
Share on other sites

  • 0

Can anyone else confirm this? I want vehicles to have god mode in safe zones, but this is a big bug....

All i can tell you is that i had the same "bug" when itried to make locked vehicles indestructible.. Seems they safe the damage somewhere and if the vehicles takes a little damage well all damage applied while in god mode will be released and boom.. Lol

Link to comment
Share on other sites

  • 0

I can confirm this as well. Sorry, I'm not a good DayZ developer, I just tried to put something together that did the job, but that bug kind of makes it useless. I have disabled this on my own server as well.

 

If someone actually find a fix for this that would be great.

Link to comment
Share on other sites

  • 0

Change:

theVehicle addEventHandler ["handleDamage", {true}];

To:

theVehicle addEventHandler ["handleDamage", {_this select 2}];

Because "true" is the same as "1". The handler should return the amount of damage it wishes to be done. The range is from 0.0 to 1.0. Returning true is insta-death. The original damage ARMA2 wanted to propagate is stored in '_this select 2' as per documentation of the HandleDamage event handler.

 

(I see I'm a little late answering, hope it's still of use! ;-))

Link to comment
Share on other sites

  • 0

I took all this knowledge and built the script into the AGN safezone commander.. it works great and doesnt allow people to exploit the cargod while gone cause once they leave the trader zone it no longer is safe. I want to thank you all for the great work and knowledge.. without this i wouldnt have been able to figure it out.. 

 

to execute the file you create the file " SafeZoneCommander.sqf " file in the notepad ++ and place it in your custom folder where you store your scripts and in the Init.sqf file in the mission PBO 

 

Place under the if (!isDedicated) then {[]

 

//Trader safe zone

[] execvm 'custom\SafeZoneCommander.sqf';
 
 
In the SafeZoneCommander.sqf file place this
 
/*
 * Safezone Commander Script by AlienX Edited By DizzY DizzAsteR
 * 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 Safe-zone 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 ["AGN_safeZoneGodmode","LAC_safeZone_Vehicle_God","AGN_safeZoneMessages","AGN_safeZone_Backpack_AllowGearFromLootPiles",
"AGN_safeZone_Backpack_AllowGearFromVehicles","AGN_safeZone_Backpack_AllowGearFromDeadPlayers",
"AGN_safeZone_Vehicles_DisableMountedGuns","AGN_safeZone_Players_DisableWeaponFiring",
"AGN_safeZone_Backpack_EnableAntiBackpack","AGN_safeZone_Vehicles_AllowGearFromWithinVehicles"];
 
 
//SCRIPT SETTINGS
AGN_safeZoneDebug = false; //Debug notes on screen.
AGN_safeZoneGodmode = true; //Should safezone Godmode be enabled?
LAC_safeZone_Vehicle_God = true;                            //Vehicle Godmode
AGN_safeZoneMessages = false; //Should players get messages when entering and exiting the safe zone?
AGN_safeZone_Backpack_EnableAntiBackpack = true; //Should players not be able to take from peoples bags?
AGN_safeZone_Backpack_AllowGearFromLootPiles = true; //Should players be able to loot from loot piles?
AGN_safeZone_Backpack_AllowGearFromVehicles = true; //Should players be able to loot from a vehicles gear?
AGN_safeZone_Backpack_AllowGearFromDeadPlayers = true; //Should players be able to loot from a dead players corpse?
AGN_safeZone_Backpack_AllowFriendlyTaggedAccess = true; //Should players who are tagged friendly be able to access eachothers bags?
AGN_safeZone_Vehicles_DisableMountedGuns = true; //Should players not be able to shoot bullets/projectiles from mounted guns?
AGN_safeZone_Vehicles_AllowGearFromWithinVehicles = true; //Should players be able to open the gear screen while they are inside a vehicle?
AGN_safeZone_Players_DisableWeaponFiring = true; //Should players not be able to shoot bullets/projectiles from their weapon(s)?
 
//Probs not needed, but meh :)
disableSerialization;
 
waitUntil {!isNil "dayz_animalCheck"};
if ( AGN_safeZoneMessages ) then { systemChat ( "[AGN] Trader Zone Commander Loaded!" ); };
 
_inVehicle = objNull;
_inVehicleLast = objNull;
 
while {true} do {
 
waitUntil { !canBuild };
 
_inSafezoneFinished = false;
if ( AGN_safeZoneMessages ) then { systemChat ("[AGN] Entering Trader Area - God Mode Enabled"); };
_thePlayer = player;
_inVehicleLast = vehicle player;
 
if ( AGN_safeZoneGodmode ) then
{
player_zombieCheck = {};
fnc_usec_damageHandler = {};
_thePlayer removeAllEventHandlers "handleDamage";
_thePlayer addEventHandler ["handleDamage", {false}];
_thePlayer allowDamage false;
};
If ( LAC_safeZone_Vehicle_God) then
{
fnc_usec_damageVehicle ={};
vehicle_handleDamage ={};
vehicle_handleKilled ={};
_inVehicleLast removeAllEventHandlers "handleDamage";
_inVehicleLast addEventHandler ["handleDamage", {false}];
_inVehicleLast allowDamage false;
 
 
};
if ( AGN_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 ( AGN_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","_ctOwnerID","_friendlies","_if"];
_ctOwnerID = 0;
while {!canBuild} do
{
_ct = cursorTarget;
_skip = false;
 
if ( !isNull (_ct) ) then
{
_to = typeOf _ct;
_dis = _ct distance player;
_inchk = ["WeaponHolder","ReammoBox"];
 
_lp = false;
{
if ( (_to isKindOf _x) && (_dis < 10) && AGN_safeZone_Backpack_AllowGearFromLootPiles ) then
{
_lp = true;
};
} forEach ( _inchk );
 
_ip = isPlayer _ct;
_ia = alive _ct;
_iv = _ct isKindOf "AllVehicles";
_inv = (vehicle player != player);
 
_if = false;
if ( _ip ) then {
_ctOwnerID = _ct getVariable["CharacterID","0"];
_friendlies = player getVariable ["friendlyTo",[]];
if(_ctOwnerID in _friendlies) then {
if ( AGN_safeZone_Backpack_AllowFriendlyTaggedAccess ) then
{
_if = true;
};
};
};
if ( AGN_safeZoneDebug ) then {
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",
                                                _ct, _dis, _lp, _ip, _ia, _iv, _inv, _if, AGN_safeZone_Backpack_AllowGearFromLootPiles, AGN_safeZone_Backpack_AllowFriendlyTaggedAccess, _skip, _ctOwnerID] );
};
 
 
//Lootpile check
if ( _lp ) then {_skip = true;};
 
//Dead body check
if ( !(_ia) && AGN_safeZone_Backpack_AllowGearFromDeadPlayers ) then {_skip = true;};
 
//Vehicle check
if ( _iv && (_dis < 10) && !(_ip) && AGN_safeZone_Backpack_AllowGearFromVehicles ) then {_skip = true;};
 
//In a vehicle check
if ( _inv && AGN_safeZone_Vehicles_AllowGearFromWithinVehicles ) then { _skip = true; };
 
//Is player friendly?
if ( _if ) 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 ( AGN_safeZoneMessages ) then { systemChat ("Anti Backpack Stealing - Redirecting you to your own gear!"); };
waitUntil { isNull (FindDisplay 106) };
} else {
if ( AGN_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 ( _skip && _if ) then {
if ( AGN_safeZoneMessages ) then { systemChat ("This player is tagged friendly, you have access to this players bag") };
};
};
};
};
 
if ( AGN_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 (AGN_safeZoneMessages) then { systemChat ( "[AGN] No Firing Vehicle Guns Enabled" ); };
_inVehicle = vehicle player;
_inVehicleDamage = getDammage _inVehicle;
_EH_Fired_Vehicle = _inVehicle addEventHandler ["Fired", {
systemChat ("[AGN] 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 ( AGN_safeZoneMessages ) then { systemChat ("[AGN] Exiting Trader Area - God Mode Disabled"); };
 
if ( AGN_safeZone_Vehicles_DisableMountedGuns ) then
{
if ( !(isNull _inVehicle) ) then
{
if ( AGN_safeZoneMessages ) then { systemChat ( "[AGN] No Firing Vehicle Guns Disabled" ); };
_inVehicle removeEventHandler ["Fired", _EH_Fired_Vehicle];
};
 
if ( !(isNull _inVehicleLast) ) then
{
if ( AGN_safeZoneMessages ) then { systemChat ( "[AGN] No Firing Vehicle Guns Disabled" ); };
_inVehicleLast removeEventHandler ["Fired", _EH_Fired_Vehicle];
};
};
 
if ( AGN_safeZone_Players_DisableWeaponFiring ) then
{
_thePlayer removeEventHandler ["Fired", _EH_Fired];
};
 
if ( AGN_safeZoneGodmode ) then
{
player_zombieCheck = compile preprocessFileLineNumbers "custom\player_zombieCheck.sqf";
fnc_usec_damageHandler = compile preprocessFileLineNumbers "custom\fn_damageHandler.sqf";
_thePlayer addEventHandler ["handleDamage", {true}];
_thePlayer removeAllEventHandlers "handleDamage";
_thePlayer allowDamage true;
};
If ( LAC_safeZone_Vehicle_God) then
{
fnc_usec_damageVehicle = compile preprocessFileLineNumbers "custom\fn_damageHandlerVehicle.sqf";
vehicle_handleDamage = compile preprocessFileLineNumbers "custom\vehicle_handleDamage.sqf";
vehicle_handleKilled = compile preprocessFileLineNumbers "custom\vehicle_handleKilled.sqf";
_inVehicleLast removeAllEventHandlers "handleDamage";
_inVehicleLast addEventHandler ["handleDamage", {_this select 2}];
_inVehicleLast allowDamage true;
};
_inSafezoneFinished = true;
};

 

 

not quiet sure how you make that look better but if anyone needs the file then i can share it.. 

 

 

once again thank you all for the great scripts and allowing me to be able to gain this on my server. 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Advertisement
  • Discord

×
×
  • Create New...