-
Notifications
You must be signed in to change notification settings - Fork 149
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 dropWeapon, dropMagazine, add dropItem, weaponComponents #296
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
/* ---------------------------------------------------------------------------- | ||
Function: CBA_fnc_dropItem | ||
|
||
Description: | ||
Drops an item. | ||
|
||
Function which verifies existence of _item and _unit, returns false in case | ||
of trouble, or when able to remove _item from _unit true in case of success | ||
|
||
Parameters: | ||
_unit - the unit that should drop the item <OBJECT> | ||
_item - class name of the item to drop <STRING> | ||
|
||
Returns: | ||
true if successful, false otherwise <BOOLEAN> | ||
|
||
Examples: | ||
(begin example) | ||
_result = [player, "FirstAidKit"] call CBA_fnc_dropItem | ||
(end) | ||
|
||
Author: | ||
commy2 | ||
---------------------------------------------------------------------------- */ | ||
#include "script_component.hpp" | ||
SCRIPT(dropItem); | ||
|
||
params [["_unit", objNull, [objNull]], ["_item", "", [""]]]; | ||
|
||
private _return = [_unit, _item] call CBA_fnc_removeItem; | ||
|
||
if (_return) then { | ||
_unit switchMove "ainvpknlmstpslaywrfldnon_1"; | ||
|
||
private _weaponHolder = nearestObject [_unit, "WeaponHolder"]; | ||
|
||
if (isNull _weaponHolder || {_unit distance _weaponHolder > 2}) then { | ||
_weaponHolder = createVehicle ["GroundWeaponHolder", [0,0,0], [], 0, "NONE"]; | ||
_weaponHolder setPosASL getPosASL _unit; | ||
}; | ||
|
||
_weaponHolder addItemCargoGlobal [_item, 1]; | ||
}; | ||
|
||
_return |
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,64 @@ | ||
/* ---------------------------------------------------------------------------- | ||
Function: CBA_fnc_weaponComponents | ||
|
||
Description: | ||
Reports class name of base weapon without attachments and all attachments belonging to a pre equipped weapon. | ||
Base weapon and attachments are reported in lower case capitalization. | ||
Fixed version of BIS_fnc_weaponComponents. | ||
|
||
Parameters: | ||
_weapon - a weapons class name with attachments build in <STRING> | ||
|
||
Returns: | ||
_components - class names of base weapon + attachments. <ARRAY> | ||
attachments are in random order, but weapon is always at first position | ||
empty array if weapon does not exist in config | ||
|
||
Examples: | ||
(begin example) | ||
_components = (primaryWeapon player) call CBA_fnc_weaponComponents; | ||
(end) | ||
|
||
Author: | ||
commy2, based on BIS_fnc_weaponComponents by Jiri Wainar | ||
---------------------------------------------------------------------------- */ | ||
#include "script_component.hpp" | ||
SCRIPT(weaponComponents); | ||
|
||
params [["_weapon", "", [""]]]; | ||
|
||
if (isNil QGVAR(weaponComponentsCache)) then { | ||
GVAR(weaponComponentsCache) = [] call CBA_fnc_createNamespace; | ||
}; | ||
|
||
private _components = GVAR(weaponComponentsCache) getVariable _weapon; | ||
|
||
if (isNil "_components") then { | ||
private _config = configfile >> "CfgWeapons" >> _weapon; | ||
|
||
// return empty array if the weapon doesn't exist | ||
if (!isClass _config) exitWith {[]}; | ||
|
||
// get attachments | ||
private _attachments = []; | ||
|
||
{ | ||
_attachments pushBack toLower getText (_x >> "item"); | ||
} forEach ("true" configClasses (_config >> "LinkedItems")); // inheritance is apparently disabled for these | ||
|
||
// get first parent without attachments | ||
while {isClass _config && {getNumber (_config >> "scope") == 2}} do { | ||
if (count (_config >> "LinkedItems") == 0) exitWith { | ||
_weapon = configName _config; | ||
}; | ||
|
||
_config = inheritsFrom _config; | ||
}; | ||
|
||
_components = [toLower _weapon]; | ||
_components append _attachments; | ||
|
||
GVAR(weaponComponentsCache) setVariable [_weapon, _components]; | ||
}; | ||
|
||
+ _components |
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
Oops, something went wrong.
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.
Document this behaviour in the function header
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.
done. also changed
selectRandom
toBIS_fnc_selectRandom
for the Linux build.