Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix vehicle crashes #3323

Merged
merged 3 commits into from
Feb 17, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion addons/medical/functions/fnc_determineIfFatal.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ private ["_damageThreshold", "_damageBodyPart", "_chanceFatal"];
params ["_unit", "_part", ["_withDamage", 0]];

if (!alive _unit) exitWith {true};
if (_part < 0 || _part > 5) exitWith {false};
if ((vehicle _unit != _unit) && {!alive (vehicle _unit)}) exitWith { true };
if (_part < 0 || _part > 5) exitWith {false};

// Find the correct Damage threshold for unit.
_damageThreshold = [1,1,1];
Expand Down
19 changes: 8 additions & 11 deletions addons/medical/functions/fnc_handleDamage.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -77,13 +77,15 @@ _minLethalDamage = if (_typeIndex >= 0) then {
0.01
};

if (vehicle _unit != _unit && {!(vehicle _unit isKindOf "StaticWeapon")} && {isNull _shooter} && {_projectile == ""} && {_selection == ""}) then {
private _vehicle = vehicle _unit;
private _effectiveSelectionName = _selection;
if ((_vehicle != _unit) && {!(_vehicle isKindOf "StaticWeapon")} && {_shooter in [objNull, driver _vehicle, _vehicle]} && {_projectile == ""} && {_selection == ""}) then {
if (GVAR(enableVehicleCrashes)) then {
_selection = GVAR(SELECTIONS) select (floor(random(count GVAR(SELECTIONS))));
_effectiveSelectionName = _this select 1; //pull random selection from HDC
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are we doing this? Isn't selection "" here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On crash, handle damage caching will convert the "" into a random selection,
I think we want the same value for passing to FUNC(determineIfFatal)
But we don't want to overwrite _selection for the _selection in ["", "head", "body"] checks on instantDeath/revive.

};
};

if ((_minLethalDamage <= _newDamage) && {[_unit, [_selection] call FUNC(selectionNameToNumber), _newDamage] call FUNC(determineIfFatal)}) then {
if ((_minLethalDamage <= _newDamage) && {[_unit, [_effectiveSelectionName] call FUNC(selectionNameToNumber), _newDamage] call FUNC(determineIfFatal)}) then {
if ((_unit getVariable [QGVAR(preventInstaDeath), GVAR(preventInstaDeath)])) exitwith {
_damageReturn = 0.9;
};
Expand All @@ -99,13 +101,8 @@ if ((_minLethalDamage <= _newDamage) && {[_unit, [_selection] call FUNC(selectio
[_unit] call FUNC(addToInjuredCollection);

if (_unit getVariable [QGVAR(preventInstaDeath), GVAR(preventInstaDeath)]) exitWith {
if (vehicle _unit != _unit and {damage (vehicle _unit) >= 1}) then {
[_unit] call EFUNC(common,unloadPerson);
};

private "_delayedUnconsicous";
_delayedUnconsicous = false;
if (vehicle _unit != _unit and {damage (vehicle _unit) >= 1}) then {
private _delayedUnconsicous = false;
if (_vehicle != _unit and {damage _vehicle >= 1}) then {
[_unit] call EFUNC(common,unloadPerson);
_delayedUnconsicous = true;
};
Expand All @@ -118,7 +115,7 @@ if (_unit getVariable [QGVAR(preventInstaDeath), GVAR(preventInstaDeath)]) exitW
if (_delayedUnconsicous) then {
[{
[_this select 0, true] call FUNC(setUnconscious);
}, [_unit], 0.7, 0] call EFUNC(common,waitAndExecute);
}, [_unit], 0.7] call EFUNC(common,waitAndExecute);
} else {
[{
[_this select 0, true] call FUNC(setUnconscious);
Expand Down
5 changes: 3 additions & 2 deletions addons/medical/functions/fnc_handleDamage_caching.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ if (_hitPointIndex >= 0) then {_newDamage = _damage - (_unit getHitIndex _hitPoi
TRACE_7("ACE_DEBUG: HandleDamage_Caching Called",_unit, _selectionName, _damage, _source, _projectile,_hitPointIndex,_newDamage);

// Check for vehicle crash
if (vehicle _unit != _unit && {!(vehicle _unit isKindOf "StaticWeapon")} && {isNull _source} && {_projectile == ""} && {_selectionName == ""}) then {
private _vehicle = vehicle _unit;
if ((_vehicle != _unit) && {!(_vehicle isKindOf "StaticWeapon")} && {_source in [objNull, driver _vehicle, _vehicle]} && {_projectile == ""} && {_selectionName == ""}) then {
if (GVAR(enableVehicleCrashes)) then {
_selectionName = _hitSelections select (floor(random(count _hitSelections)));
_projectile = "vehiclecrash";
Expand All @@ -40,7 +41,7 @@ if (vehicle _unit != _unit && {!(vehicle _unit isKindOf "StaticWeapon")} && {isN

// Handle falling damage
_impactVelocity = (velocity _unit) select 2;
if (_impactVelocity < -5 && {vehicle _unit == _unit}) then {
if (_impactVelocity < -5 && {_vehicle == _unit}) then {
TRACE_1("Starting isFalling", time);
_unit setVariable [QGVAR(isFalling), true];
_unit setVariable [QGVAR(impactVelocity), _impactVelocity];
Expand Down
6 changes: 6 additions & 0 deletions addons/medical/functions/fnc_setDead.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,12 @@ if (((_reviveVal == 1 && {[_unit] call EFUNC(common,isPlayer)} || _reviveVal ==
_args params ["_unit"];
_startTime = _unit getVariable [QGVAR(reviveStartTime), 0];

//If we are in reivie state in a blown up vehicle, try to unload so that people can access the body
if ((alive _unit) && {(vehicle _unit) != _unit} && {!alive (vehicle _unit)}) then {
TRACE_2("Unloading", _unit, vehicle _unit);
[_unit] call EFUNC(common,unloadPerson);
};

if (GVAR(maxReviveTime) > 0 && {ACE_time - _startTime > GVAR(maxReviveTime)}) exitwith {
[_idPFH] call CBA_fnc_removePerFrameHandler;
_unit setVariable [QGVAR(inReviveState), nil, true];
Expand Down