Jump to content

Vehicles Lokced No Damage


S4M

Recommended Posts

Old script the @Donnovan that together with @juandayz we got it working on 1.0.6.1
All my compliment to @Donnovan and @juandayz.

 

1. in your init.sqf, you look for the line where the compiles.sqf is called and under this you paste this

Spoiler

Call compile preprocessFileLineNumbers "custom \ lock_god.sqf";

2. create lock_god.sqf 

Spoiler

if (isServer) then {
	"cad_pvar_set_veh" addPublicVariableEventHandler {
		private ["_veh","_godOn"];
		_veh = _this select 1 select 0;
		_godOn = _this select 1 select 1;
		if (_godOn) then {
			_veh allowDamage false;
			_veh RemoveAllEventHandlers "handleDamage";
			_veh addEventHandler ["handleDamage",{0}];
		} else {
			_veh allowDamage true;
			_veh RemoveAllEventHandlers "handleDamage";
			_veh addEventHandler ["handleDamage",{_this call veh_handleDam;}];
		};
	};
};

local_lockUnlock = {
	private ["_vehicle","_status"];
	_vehicle = _this select 0;
	_status = _this select 1;

	if (local _vehicle || isServer) then {
		if(_status) then {
			_vehicle setVehicleLock "LOCKED";
			if (((locked _vehicle && (count(crew _vehicle)) == 0))) then {  //MIKE POST
				_vehicle allowDamage false;
				_vehicle RemoveAllEventHandlers "handleDamage";
				_vehicle addEventHandler ["handleDamage",{0}];
				cad_pvar_set_veh = [_vehicle,true];
				publicVariableServer "cad_pvar_set_veh";
			}; //MIKE POST

		} else {
			_vehicle setVehicleLock "UNLOCKED";
			_vehicle allowDamage true;
			_vehicle RemoveAllEventHandlers "handleDamage";
			_vehicle addEventHandler ["handleDamage",{_this call veh_handleDam;}];
			cad_pvar_set_veh = [_vehicle,false];
			publicVariableServer "cad_pvar_set_veh";
		};
	};
};

 

3. Open server_monitor.sql and look for this line

Spoiler

if (_ownerID != "0" && {!(_object isKindOf "Bicycle")}) then {_object setVehicleLock "locked";};

And replace with


if(_ownerID != "0" && !(_object isKindOf "Bicycle")) then {
	_object setvehiclelock "locked";
	//LOCK GOD BEGIN
	_object allowDamage false;
	_object RemoveAllEventHandlers "handleDamage";
	_object addEventHandler ["handleDamage",{0}];						
	//LOCK GOD END
};

Done!

  Another option thanks @Cherdenko

1-you will need a custom compiles.sqf

2-in the custom compiles.sqf find:

fnc_veh_handleDam = compile preprocessFileLineNumbers "\z\addons\dayz_code\compile\veh_handleDam.sqf";

change the line by:

fnc_veh_handleDam = compile preprocessFileLineNumbers "custom\veh_handleDam.sqf";

3.create this new sqf and paste in mpmissions\your_instance\custom\ 

veh_handleDam.sqf

  Reveal hidden contents

////////Vehicles With GodMode by Cherdenko
/*
        Created exclusively for ArmA2:OA - DayZMod.
        Please request permission to use/alter/distribute from project leader (R4Z0R49) AND the author ([email protected])
*/

/***********************************************************
ASSIGN DAMAGE TO A UNIT.
Called by "HandleDamage" vehicle Event Handler
or by "PVCDZ_veh_SH" PV
or by zombie_attack

- Function fnc_veh_handleDam
- [unit, selectionName, damage, source, projectile, broadcast] call fnc_veh_handleDam;
- return : updated damage for that part
broadcast: boolean. if true, then the request will be sent to all players if the vehicle is not local.
************************************************************/
private["_unit","_selection","_strH","_total","_damage","_needUpdate","_totalDmg"];

_unit = _this select 0;
_selection = _this select 1;
_total = _this select 2;
if (((locked _unit && (count(crew _unit)) == 0)))) then {

_unit addEventHandler ["HandleDamage", {false}];
_unit enableSimulation false;

}else{



if (_selection != "") then {
	_strH = "hit_" + _selection;
	_totalDmg = false;
} else {
	_strH = "totalDmg";
	_totalDmg = true;
};

if (_total >= 0.98) then {
        _total = 1.0;
};

if (local _unit) then {
	if (_total > 0) then {
		if (!_totalDmg) then {
			_unit setVariable [_strH, _total, true];
		};
		_unit setHit [_selection, _total];

		PVDZ_veh_Save = [_unit,"damage",false,_totalDmg];
		if (!isServer) then {
			publicVariableServer "PVDZ_veh_Save";
		} else {
			PVDZ_veh_Save call server_updateObject;
		};
	};
} else {
	//if ( (count _this > 5) AND {(_this select 5)}) then {
		// vehicle is not local to this client, ask the client which vehicle is local to set damage
		//_this resize 5; // delete "broadcast" boolean
		PVDZ_send = [_unit,"VehHandleDam",_this];
		publicVariableServer "PVDZ_send";
	//};
};

// all "HandleDamage event" functions should return the effective damage that the engine will record for that part
_total
};

 

 

Link to comment
Share on other sites

well i would call it where the source of the problem exists(vehDamageHandler)

like this:

Spoiler

/*
        Created exclusively for ArmA2:OA - DayZMod.
        Please request permission to use/alter/distribute from project leader (R4Z0R49) AND the author ([email protected])
*/

/***********************************************************
ASSIGN DAMAGE TO A UNIT.
Called by "HandleDamage" vehicle Event Handler
or by "PVCDZ_veh_SH" PV
or by zombie_attack

- Function fnc_veh_handleDam
- [unit, selectionName, damage, source, projectile, broadcast] call fnc_veh_handleDam;
- return : updated damage for that part
broadcast: boolean. if true, then the request will be sent to all players if the vehicle is not local.
************************************************************/
private["_unit","_selection","_strH","_total","_damage","_needUpdate","_totalDmg"];

_unit = _this select 0;
_selection = _this select 1;
_total = _this select 2;
if (((locked _unit && (count(crew _unit)) == 0)))) then {

_unit addEventHandler ["HandleDamage", {false}];
_unit enableSimulation false;

}else{



if (_selection != "") then {
	_strH = "hit_" + _selection;
	_totalDmg = false;
} else {
	_strH = "totalDmg";
	_totalDmg = true;
};

if (_total >= 0.98) then {
        _total = 1.0;
};

if (local _unit) then {
	if (_total > 0) then {
		if (!_totalDmg) then {
			_unit setVariable [_strH, _total, true];
		};
		_unit setHit [_selection, _total];

		PVDZ_veh_Save = [_unit,"damage",false,_totalDmg];
		if (!isServer) then {
			publicVariableServer "PVDZ_veh_Save";
		} else {
			PVDZ_veh_Save call server_updateObject;
		};
	};
} else {
	//if ( (count _this > 5) AND {(_this select 5)}) then {
		// vehicle is not local to this client, ask the client which vehicle is local to set damage
		//_this resize 5; // delete "broadcast" boolean
		PVDZ_send = [_unit,"VehHandleDam",_this];
		publicVariableServer "PVDZ_send";
	//};
};

// all "HandleDamage event" functions should return the effective damage that the engine will record for that part
_total
};

 

 

Link to comment
Share on other sites

30 minutes ago, Cherdenko said:

well i would call it where the source of the problem exists(vehDamageHandler)

like this:

  Reveal hidden contents


/*
        Created exclusively for ArmA2:OA - DayZMod.
        Please request permission to use/alter/distribute from project leader (R4Z0R49) AND the author ([email protected])
*/

/***********************************************************
ASSIGN DAMAGE TO A UNIT.
Called by "HandleDamage" vehicle Event Handler
or by "PVCDZ_veh_SH" PV
or by zombie_attack

- Function fnc_veh_handleDam
- [unit, selectionName, damage, source, projectile, broadcast] call fnc_veh_handleDam;
- return : updated damage for that part
broadcast: boolean. if true, then the request will be sent to all players if the vehicle is not local.
************************************************************/
private["_unit","_selection","_strH","_total","_damage","_needUpdate","_totalDmg"];

_unit = _this select 0;
_selection = _this select 1;
_total = _this select 2;
if (((locked _unit && (count(crew _unit)) == 0)))) then {

_unit addEventHandler ["HandleDamage", {false}];
_unit enableSimulation false;

}else{



if (_selection != "") then {
	_strH = "hit_" + _selection;
	_totalDmg = false;
} else {
	_strH = "totalDmg";
	_totalDmg = true;
};

if (_total >= 0.98) then {
        _total = 1.0;
};

if (local _unit) then {
	if (_total > 0) then {
		if (!_totalDmg) then {
			_unit setVariable [_strH, _total, true];
		};
		_unit setHit [_selection, _total];

		PVDZ_veh_Save = [_unit,"damage",false,_totalDmg];
		if (!isServer) then {
			publicVariableServer "PVDZ_veh_Save";
		} else {
			PVDZ_veh_Save call server_updateObject;
		};
	};
} else {
	//if ( (count _this > 5) AND {(_this select 5)}) then {
		// vehicle is not local to this client, ask the client which vehicle is local to set damage
		//_this resize 5; // delete "broadcast" boolean
		PVDZ_send = [_unit,"VehHandleDam",_this];
		publicVariableServer "PVDZ_send";
	//};
};

// all "HandleDamage event" functions should return the effective damage that the engine will record for that part
_total
};

 

 

How do you say all vehicles god...

Link to comment
Share on other sites

To add sound and light

description.ext

Spoiler

class CfgSounds
{
    sounds[] =
    {
        Radio_Message_Sound,lock
    };
    class Radio_Message_Sound
    {
        name = "Radio_Message_Sound";
        sound[] = {scripts\radio\radio.ogg,0.4,1};
        titles[] = {};
    };
    class lock
    {
        name="lock";
        sound[]={scripts\sounds\lock.ogg,0.2,1};
        titles[] = {};
    }
;
};

lock_god.sqf

Spoiler

if (isServer) then {
    "cad_pvar_set_veh" addPublicVariableEventHandler {
        private ["_veh","_godOn"];
        _veh = _this select 1 select 0;
        _godOn = _this select 1 select 1;
        if (_godOn) then {
            _veh allowDamage false;
            _veh RemoveAllEventHandlers "handleDamage";
            _veh addEventHandler ["handleDamage",{0}];
        } else {
            _veh allowDamage true;
            _veh RemoveAllEventHandlers "handleDamage";
            _veh addEventHandler ["handleDamage",{_this call veh_handleDam;}];
        };
    };
};

local_lockUnlock = {
    private ["_vehicle","_status","_sounddist"];
    _vehicle = _this select 0;
    _status = _this select 1;
    _sounddist = 30;

    if (local _vehicle || isServer) then {
        if(_status) then {
            _vehicle setVehicleLock "LOCKED";
            if (((locked _vehicle && (count(crew _vehicle)) == 0))) then {  //MIKE POST
                _nul = [objNull, _vehicle, rSAY, "lock", _sounddist] call RE;
                _vehicle allowDamage false;
                _vehicle RemoveAllEventHandlers "handleDamage";
                _vehicle addEventHandler ["handleDamage",{0}];
                cad_pvar_set_veh = [_vehicle,true];
                publicVariableServer "cad_pvar_set_veh";
                player action ["lightOn", _vehicle];
                sleep 0.5;
                player action ["lightOff", _vehicle];
            }; //MIKE POST

        } else {
            _vehicle setVehicleLock "UNLOCKED";
            _nul = [objNull, _vehicle, rSAY, "lock", _sounddist] call RE;
            _vehicle allowDamage true;
            _vehicle RemoveAllEventHandlers "handleDamage";
            _vehicle addEventHandler ["handleDamage",{_this call veh_handleDam;}];
            cad_pvar_set_veh = [_vehicle,false];
            publicVariableServer "cad_pvar_set_veh";
            player action ["lightOn", _vehicle];
            sleep 0.5;
            player action ["lightOff", _vehicle];
        };
    };
};

Lock.ogg

I've taken it from here

 

Link to comment
Share on other sites

Hi!

I have 2 problems:

1. After unlocking vehicle it still in godmode. No errors about this problem in both RPTs.

2. I get an error in server's RPT when I lock vehicle inside vehicle.

 

13:23:07 Suspending not allowed in this context
13:23:07 Error in expression <";
player action ["lightOn", _vehicle];
sleep 0.5;
player action ["lightOff", _v>
13:23:07   Error position: <sleep 0.5;
player action ["lightOff", _v>
13:23:07   Error Generic error in expression
13:23:07 File mpmissions\DayZ_Epoch_11.Chernarus\custom\lock_god.sqf, line 50
13:23:12 Suspending not allowed in this context
13:23:12 Error in expression <";
player action ["lightOn", _vehicle];
sleep 0.5;
player action ["lightOff", _v>
13:23:12   Error position: <sleep 0.5;
player action ["lightOff", _v>
13:23:12   Error Generic error in expression
13:23:12 File mpmissions\DayZ_Epoch_11.Chernarus\custom\lock_god.sqf, line 50

 

Link to comment
Share on other sites

5 hours ago, WLF said:

Hi!

I have 2 problems:

1. After unlocking vehicle it still in godmode. No errors about this problem in both RPTs.

2. I get an error in server's RPT when I lock vehicle inside vehicle.

 


13:23:07 Suspending not allowed in this context
13:23:07 Error in expression <";
player action ["lightOn", _vehicle];
sleep 0.5;
player action ["lightOff", _v>
13:23:07   Error position: <sleep 0.5;
player action ["lightOff", _v>
13:23:07   Error Generic error in expression
13:23:07 File mpmissions\DayZ_Epoch_11.Chernarus\custom\lock_god.sqf, line 50
13:23:12 Suspending not allowed in this context
13:23:12 Error in expression <";
player action ["lightOn", _vehicle];
sleep 0.5;
player action ["lightOff", _v>
13:23:12   Error position: <sleep 0.5;
player action ["lightOff", _v>
13:23:12   Error Generic error in expression
13:23:12 File mpmissions\DayZ_Epoch_11.Chernarus\custom\lock_god.sqf, line 50

 

i guess the errors become from the "sleep" command , S4M is working now to fix it. the way that scripts its executed not allow the sleep command.

Link to comment
Share on other sites

Everything works fine but gives that error.

I will try with this

Spoiler

if (isServer) then {
    "cad_pvar_set_veh" addPublicVariableEventHandler {
        private ["_veh","_godOn"];
        _veh = _this select 1 select 0;
        _godOn = _this select 1 select 1;
        if (_godOn) then {
            _veh allowDamage false;
            _veh RemoveAllEventHandlers "handleDamage";
            _veh addEventHandler ["handleDamage",{0}];
        } else {
            _veh allowDamage true;
            _veh RemoveAllEventHandlers "handleDamage";
            _veh addEventHandler ["handleDamage",{_this call veh_handleDam;}];
        };
    };
};

local_lockUnlock = {
    private ["_vehicle","_status","_sounddist","_wait_time"];
    _vehicle = _this select 0;
    _status = _this select 1;
    _sounddist = 20;
    _wait_time = 0.5;

    if (local _vehicle || isServer) then {
        if(_status) then {
            _vehicle setVehicleLock "LOCKED";
            if (((locked _vehicle && (count(crew _vehicle)) == 0))) then {  //MIKE POST
                _nul = [objNull, _vehicle, rSAY, "lock", _sounddist] call RE;
                player action ["lightOn", _vehicle];
            sleep _wait_time;
                player action ["lightOff", _vehicle];
                _vehicle allowDamage false;
                _vehicle RemoveAllEventHandlers "handleDamage";
                _vehicle addEventHandler ["handleDamage",{0}];
                cad_pvar_set_veh = [_vehicle,true];
                publicVariableServer "cad_pvar_set_veh";
            };
        } else {
            _vehicle setVehicleLock "UNLOCKED";
            _nul = [objNull, _vehicle, rSAY, "lock", _sounddist] call RE;
            player action ["lightOn", _vehicle];
            sleep _wait_time;
            player action ["lightOff", _vehicle];
            _vehicle allowDamage true;
            _vehicle RemoveAllEventHandlers "handleDamage";
            _vehicle addEventHandler ["handleDamage",{_this call veh_handleDam;}];
            cad_pvar_set_veh = [_vehicle,false];
            publicVariableServer "cad_pvar_set_veh";
        };
    };
};

 

Link to comment
Share on other sites

Without getting error in server's RPT, The only light just lock:unsure:

Spoiler

if (isServer) then {
    "cad_pvar_set_veh" addPublicVariableEventHandler {
        private ["_veh","_godOn"];
        _veh = _this select 1 select 0;
        _godOn = _this select 1 select 1;
        if (_godOn) then {
            _veh allowDamage false;
            _veh RemoveAllEventHandlers "handleDamage";
            _veh addEventHandler ["handleDamage",{0}];
        } else {
            _veh allowDamage true;
            _veh RemoveAllEventHandlers "handleDamage";
            _veh addEventHandler ["handleDamage",{_this call veh_handleDam;}];
        };
    };
};

local_lockUnlock = {
    private ["_vehicle","_status","_sounddist","_wait_time"];
    _vehicle = _this select 0;
    _status = _this select 1;
    _sounddist = 20;
    _wait_time = 0.5;

    if (local _vehicle || isServer) then {
        if(_status) then {
            _vehicle setVehicleLock "LOCKED";
            if (((locked _vehicle && (count(crew _vehicle)) == 0))) then {  //MIKE POST
                _nul = [objNull, _vehicle, rSAY, "lock", _sounddist] call RE;
                player action ["lightOn", _vehicle];
            sleep _wait_time;
                player action ["lightOff", _vehicle];
                _vehicle allowDamage false;
                _vehicle RemoveAllEventHandlers "handleDamage";
                _vehicle addEventHandler ["handleDamage",{0}];
                cad_pvar_set_veh = [_vehicle,true];
                publicVariableServer "cad_pvar_set_veh";
            };
        } else {
            _vehicle setVehicleLock "UNLOCKED";
            _nul = [objNull, _vehicle, rSAY, "lock", _sounddist] call RE;
            _vehicle allowDamage true;
            _vehicle RemoveAllEventHandlers "handleDamage";
            _vehicle addEventHandler ["handleDamage",{_this call veh_handleDam;}];
            cad_pvar_set_veh = [_vehicle,false];
            publicVariableServer "cad_pvar_set_veh";
        };
    };
};

 

Link to comment
Share on other sites

  • 3 weeks later...

@WLF @Kimarik @DAmNRelentless

custom compiles.sqf

Spoiler

find:

  Hide contents


fnc_veh_handleDam = compile preprocessFileLineNumbers "\z\addons\dayz_code\compile\veh_handleDam.sqf";

replace by:



fnc_veh_handleDam = compile preprocessFileLineNumbers "custom\veh_handleDam.sqf";

 

veh_handleDam.sqf (mpmissions\the instance youre using\custom\ )

Spoiler

/*
        Created exclusively for ArmA2:OA - DayZMod.
        Please request permission to use/alter/distribute from project leader (R4Z0R49) AND the author ([email protected])
*/

/***********************************************************
ASSIGN DAMAGE TO A UNIT.
Called by "HandleDamage" vehicle Event Handler
or by "PVCDZ_veh_SH" PV
or by zombie_attack

- Function fnc_veh_handleDam
- [unit, selectionName, damage, source, projectile, broadcast] call fnc_veh_handleDam;
- return : updated damage for that part
broadcast: boolean. if true, then the request will be sent to all players if the vehicle is not local.
************************************************************/
private["_unit","_selection","_strH","_total","_damage","_needUpdate","_totalDmg"];

_unit = _this select 0;
_selection = _this select 1;
_total = _this select 2;
if (((locked _unit && (count(crew _unit)) == 0))) exitWith{};


if (_selection != "") then {
	_strH = "hit_" + _selection;
	_totalDmg = false;
} else {
	_strH = "totalDmg";
	_totalDmg = true;
};

if (_total >= 0.98) then {
        _total = 1.0;
};

if (local _unit) then {
	if (_total > 0) then {
		if (!_totalDmg) then {
			_unit setVariable [_strH, _total, true];
		};
		_unit setHit [_selection, _total];

		PVDZ_veh_Save = [_unit,"damage",false,_totalDmg];
		if (!isServer) then {
			publicVariableServer "PVDZ_veh_Save";
		} else {
			PVDZ_veh_Save call server_updateObject;
		};
	};
} else {
	//if ( (count _this > 5) AND {(_this select 5)}) then {
		// vehicle is not local to this client, ask the client which vehicle is local to set damage
		//_this resize 5; // delete "broadcast" boolean
		PVDZ_send = [_unit,"VehHandleDam",_this];
		publicVariableServer "PVDZ_send";
	//};
};

// all "HandleDamage event" functions should return the effective damage that the engine will record for that part
_total

 

this line:

if (((locked _unit && (count(crew _unit)) == 0))) exitWith{};

do not allow use godmode while thers players inside

(count(crew _unit)) == 0)

 

Link to comment
Share on other sites

  • 1 year later...

I want to have vehicles invincible while locked within plot pole range and invincible in trader zones, but otherwise not invincible when locked out and about in the rest of the map, anyone know how I can achieve this?

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...