-
Notifications
You must be signed in to change notification settings - Fork 148
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #296 from commy2/fixdropfunctions
fix dropWeapon, dropMagazine, add dropItem, weaponComponents
- Loading branch information
Showing
7 changed files
with
236 additions
and
105 deletions.
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.