-
Notifications
You must be signed in to change notification settings - Fork 150
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
add weapon eventhandler framework #829
Changes from 2 commits
71fd9dd
230d21e
bb82058
6c36967
699d609
28610f3
5678a80
6b2dc28
a99b2e7
fe7c10e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
/* ---------------------------------------------------------------------------- | ||
Function: CBA_fnc_weaponEvents | ||
|
||
Description: | ||
Execute weapon events framework. | ||
|
||
class MyWeapon: MyWeapon_base { | ||
class EventHandlers { | ||
fired = "_this call CBA_fnc_weaponEvents"; | ||
}; | ||
}; | ||
|
||
Parameters: | ||
_unit - Unit that fired the weapon <OBJECT> | ||
_weapon - The weapon fired by the unit <STRING> | ||
|
||
Returns: | ||
Nothing | ||
|
||
Examples: | ||
(begin example) | ||
fired = "_this call CBA_fnc_weaponEvents"; | ||
(end) | ||
|
||
Author: | ||
commy2 | ||
---------------------------------------------------------------------------- */ | ||
#include "script_component.hpp" | ||
|
||
params ["_unit", "_weapon"]; | ||
|
||
private _config = configFile >> "CfgWeapons" >> _weapon >> "CBA_WeaponEvents"; | ||
|
||
private _isEmpty = _unit ammo _weapon == 0; | ||
private _onEmpty = true; | ||
|
||
if (isNumber (_config >> "onEmpty")) then { | ||
_onEmpty = getNumber (_config >> "onEmpty") == 1; | ||
}; | ||
|
||
private _fnc_soundSource = { | ||
private _soundSourceName = format [QGVAR(soundSource_%1), _soundLocation]; | ||
private _soundSource = _unit getVariable [_soundSourceName, objNull]; | ||
|
||
if !(_soundSource in attachedObjects _unit) then { | ||
_soundSource = "Building" createVehicleLocal [0,0,0]; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. using #particlesource is faster
VS
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How long does it live? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. until you delete it There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Perfect, thanks! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Any reason to not use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
vs
i think there is more stuff run in the background There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nvm, seems like those don't work with There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. what does not work with createVehicleLocal? |
||
_soundSource attachTo [_unit, [0,0,0], _soundLocation]; | ||
_unit setVariable [_soundSourceName, _soundSource]; | ||
}; | ||
|
||
_soundSource | ||
}; | ||
|
||
if (isEmpty) then { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. missing _ |
||
private _sound = getText (_config >> "soundEmpty"); | ||
private _soundLocation = getText (_config >> "soundLocationEmpty"); | ||
|
||
if (_sound != "") then { | ||
(call _fnc_soundSource) say3D _sound; | ||
}; | ||
}; | ||
|
||
if (!_isEmpty || _onEmpty) then { | ||
private _handAction = getText (_config >> "handAction"); | ||
private _sound = getText (_config >> "sound"); | ||
private _soundLocation = getText (_config >> "soundLocation"); | ||
private _delay = getNumber (_config >> "delay"); | ||
|
||
[{ | ||
params ["_unit", "_handAction", "_sound", "_soundSource"]; | ||
|
||
if (local _unit) then { | ||
_unit playAction _handAction; | ||
}; | ||
|
||
if (_sound != "") then { | ||
_soundSource say3D _sound; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the sound object dont get delete anywhere so they would stack up. or did i miss something? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No point in deleting it, if you can recycle it instead. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. See L45 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. aha i oversaw that sorry :D There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. but maybe delete it when the unit dies? because else when some units would use that and die they would eather way stack up. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Question is if the gain would be worth the effort. I have my doubts. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i think it would. else you could take a look at what i did within the ammo cookoff. Object Pooling would be the perfect thing for this i think. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I changed it to reuse the sound source from the corpse. But I still don't want to delete them after use. |
||
}; | ||
}, [_unit, _handAction, _sound, call _fnc_soundSource], _delay] call CBA_fnc_waitAndExecute; | ||
}; |
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.
default returns 0, so can probably skip
isNumber
?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.
But I want 1/true to be the default.
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.
why not
CBA_fnc_getConfigEntry
?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.
Overhead.