-
Notifications
You must be signed in to change notification settings - Fork 737
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
Allow damage handler (also block only collision damage) #2758
Closed
Closed
Changes from 4 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
4cc47ee
Allow Damage Handler
PabstMirror 05c9301
Fix Litter Module Setting
PabstMirror 6ceeac9
Fix allowDamage in fixFloating for PR #2230
PabstMirror 6d15f17
Change fixCollision
PabstMirror 964bc83
Merge remote-tracking branch 'refs/remotes/origin/master' into allowD…
PabstMirror 06fc6fa
Remove handleDamageEH and just use medical
PabstMirror File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
/* | ||
* Author: PabstMirror | ||
* Handles the "ace_common_allowDamage" synced event | ||
* | ||
* Arguments: | ||
* 0: object<OBJECT> | ||
* | ||
* Return Value: | ||
* None | ||
* | ||
* Example: | ||
* [box1] call ace_common_fnc_handleAllowDamage; | ||
* | ||
* Public: No | ||
*/ | ||
#define DEBUG_MODE_FULL | ||
#include "script_component.hpp" | ||
|
||
params ["_object"]; | ||
(_object getVariable [QGVAR(allowDamage), [-1, -1]]) params ["_blockCollisionNum", "_blockDamageNum"]; | ||
|
||
TRACE_3("",_object,_blockCollisionNum,_blockDamageNum); | ||
|
||
if (_blockDamageNum > 0) then { | ||
TRACE_1("allowDamage false",_blockDamageNum); | ||
_object allowDamage false; | ||
} else { | ||
TRACE_1("allowDamage true",_blockDamageNum); | ||
_object allowDamage true; | ||
}; | ||
|
||
local _collisionHandler = _object getVariable [QGVAR(allowCollisionHandler), -1]; | ||
if (_blockCollisionNum > 0) then { | ||
if (_collisionHandler == -1) then { | ||
TRACE_1("Adding HandleDamage EH", _collisionHandler); | ||
_collisionHandler = _object addEventHandler ["HandleDamage", { | ||
params ["_object", "", "", "", "_projectile", "_index"]; | ||
TRACE_1("HD",_this); | ||
if (!local _unit) exitWith {nil}; | ||
if (_projectile != "") exitWith {nil}; | ||
local _return = if (_index < 0) then {damage _object} else {_object getHitIndex _index}; | ||
TRACE_1("blocking",_return); | ||
_return | ||
}]; | ||
_object setVariable [QGVAR(allowCollisionHandler), _collisionHandler]; | ||
}; | ||
} else { | ||
if (_collisionHandler != -1) then { | ||
TRACE_1("Removing HandleDamage EH", _collisionHandler); | ||
_object removeEventHandler ["HandleDamage", _collisionHandler]; | ||
_object setVariable [QGVAR(allowCollisionHandler), nil]; | ||
}; | ||
}; | ||
|
||
nil |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
/* | ||
* Author: PabstMirror | ||
* Allows multiple sources to block all or just collision damage on objects | ||
* | ||
* Arguments: | ||
* 0: Object <OBJECT> | ||
* 1: Source Reason <STRING> | ||
* 2: State (0 = allow all, 1 = block colision, 2 = block all) <NUMBER> | ||
* | ||
* Return Value: | ||
* None | ||
* | ||
* Example: | ||
* [box1, "preventColision", 1] call ace_common_fnc_setAllowDamage; | ||
* | ||
* Public: Yes | ||
*/ | ||
#define DEBUG_MODE_FULL | ||
#include "script_component.hpp" | ||
|
||
params ["_object", "_reason", "_state"]; | ||
|
||
TRACE_3("params",_object,_reason,_state); | ||
|
||
_allowDamageReasons = missionNamespace getVariable [QGVAR(allowDamageReasons), []]; | ||
|
||
_objectAllowDamage = _object getVariable [QGVAR(allowDamage), [0,0]]; | ||
_objectAllowDamage params ["_blockCollisionNum", "_blockDamageNum"]; | ||
|
||
_blockCollisionArray = [_blockCollisionNum, count _allowDamageReasons] call FUNC(binarizeNumber); | ||
_blockDamageArray = [_blockDamageNum, count _allowDamageReasons] call FUNC(binarizeNumber); | ||
|
||
//If there is a reason, set it in the arrays: | ||
if (_reason != "") then { | ||
_reason = toLower _reason; | ||
// register new reason (these reasons are shared publicly, since units can change ownership, but keep their forceWalk status) | ||
if !(_reason in _allowDamageReasons) then { | ||
_allowDamageReasons pushBack _reason; | ||
GVAR(allowDamageReasons) = _allowDamageReasons; | ||
publicVariable QGVAR(allowDamageReasons); | ||
}; | ||
_index = _allowDamageReasons find _reason; | ||
switch (_state) do { | ||
case (0): { | ||
_blockCollisionArray set [_index, false]; | ||
_blockDamageArray set [_index, false]; | ||
}; | ||
case (1): { | ||
_blockCollisionArray set [_index, true]; | ||
_blockDamageArray set [_index, false]; | ||
}; | ||
case (2): { | ||
_blockCollisionArray set [_index, false]; | ||
_blockDamageArray set [_index, true]; | ||
}; | ||
}; | ||
}; | ||
|
||
_newBlockCollisionNum = _blockCollisionArray call FUNC(toBitmask); | ||
_newBlockDamageNum = _blockDamageArray call FUNC(toBitmask); | ||
|
||
if ((_newBlockDamageNum == _blockDamageNum) && {_newBlockCollisionNum == _blockCollisionNum}) exitWith { | ||
TRACE_2("No Change",_newBlockCollisionNum, _newBlockDamageNum); | ||
}; | ||
|
||
TRACE_2("Updating",_newBlockCollisionNum, _newBlockDamageNum); | ||
_object setVariable [QGVAR(allowDamage), [_newBlockCollisionNum, _newBlockDamageNum], true]; | ||
|
||
if ((_object isKindOf "CAManBase") && {["ace_medical"] call FUNC(isModLoaded)}) exitWith { | ||
//ACE_medical already has a handleDamage installed on the Unit and we can just setVariables for it | ||
TRACE_1("handled by ace medical", _object); | ||
}; | ||
|
||
if ((_newBlockCollisionNum + _newBlockDamageNum) > 0) then { | ||
local _ttlCondition = { | ||
((_this select 1) select 1) params ["_object", "_statusArray"]; | ||
TRACE_1("TTL Check", _object); | ||
//Only keep event if getVariable is same as event variable (also handles objNull) | ||
(_statusArray isEqualTo (_object getVariable [QGVAR(allowDamage), [-1, -1]])) | ||
}; | ||
TRACE_1("allowDamage event IS synced", _object); | ||
[QGVAR(allowDamage), [_object, [_newBlockCollisionNum, _newBlockDamageNum]], _ttlCondition] call EFUNC(common,syncedEvent); | ||
} else { | ||
TRACE_1("allowDamage event IS NOT synced", _object); | ||
[QGVAR(allowDamage), [_object, [_newBlockCollisionNum, _newBlockDamageNum]], -1] call EFUNC(common,syncedEvent); | ||
}; | ||
|
||
nil |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.