BlackNeonx_O 0 Posted June 13, 2017 Hello everyone I'm trying to write a "take magazines for my weapon" script. I added a button in the inventory display and when i press it i want the script to get all the magazines for my weapon out of the (ammo-)box, vehilce storage. How can i get the item list from that storage when i press the button on the inventory display and move them into my inventory? Thanks for your help :) -BlackNeon Share this post Link to post Share on other sites
sarogahtyp 1109 Posted June 13, 2017 With getMagazineCargo u can get classnames for all magazines and its count stored in the cargo object. Use addMagazine to add a specific magazine count to a unit using magazines classname. Use clearMagazineCargoGlobal to delete all magazines in ur cargo object. Use addMagazineCargoGlobal to add the remaining magazines to ur prior cleared cargo object. Share this post Link to post Share on other sites
BlackNeonx_O 0 Posted June 13, 2017 1 hour ago, sarogahtyp said: With getMagazineCargo u can get classnames for all magazines and its count stored in the cargo object. Use addMagazine to add a specific magazine count to a unit using magazines classname. Use clearMagazineCargoGlobal to delete all magazines in ur cargo object. Use addMagazineCargoGlobal to add the remaining magazines to ur prior cleared cargo object. Nice Thanks! The last problem i have is how can i get the object of the vehicle or (ammo-)box which i'm interacting with? Is there a better solution than the cursorTarget command? How the script should work: 1. I open the cargo of an vehicle 2. Inventory opens (including my added button) 3. When i press the button the script should get the object of the vehicle (mention the inventory is displayed). 4. The command getMagazineCargo _object returns the magazine list 5. ... What is the best solution for step 3? Or am i thinking to far? -BlackNeon Share this post Link to post Share on other sites
sarogahtyp 1109 Posted June 13, 2017 I think cursorTarget is good to get the object. Maybe cursorObject works better but idk. just test it. Do u ve any issues with cursorTarget? Share this post Link to post Share on other sites
BlackNeonx_O 0 Posted June 13, 2017 32 minutes ago, sarogahtyp said: I think cursorTarget is good to get the object. Maybe cursorObject works better but idk. just test it. Do u ve any issues with cursorTarget? Okey thank you :) No, i was just curios if there is a better solution ;) Share this post Link to post Share on other sites
Larrow 2823 Posted June 13, 2017 Use the InventoryOpened EH, this will automatically supply the container(box/vehicle/holder) you are currently interacting with. Spoiler TAG_fnc_takeAllMags = { params[ "_playerID", "_containerID", "_type" ]; _player = _playerID call BIS_fnc_objectFromNetId; _container = _containerID call BIS_fnc_objectFromNetId; _mags = magazinesAmmoCargo _container call BIS_fnc_consolidateArray; _weapon = _player call compile format[ "%1weapon _this", _type ]; _weaponCfg = configFile >> "CfgWeapons" >> _weapon; _compatibleMags = []; { if ( _x == "this" ) then { _compatibleMags = _compatibleMags + getArray( _weaponCfg >> "magazines" ); }else{ _compatibleMags = _compatibleMags + getArray( _weaponCfg >> _x >> "magazines" ); }; }forEach getArray( _weaponCfg >> "muzzles" ); { _magType = _x; { _x params[ "_magInfo", "_count" ]; _magInfo params[ "_mag", "_ammo" ]; if ( _mag == _magType ) then { _taken = for "_i" from 1 to _count do { if !( _player canAdd _mag ) exitWith { _i - 1 }; _player addMagazine [ _mag, _ammo ]; }; systemChat format[ "Taken %1 %2", if ( isNil "_taken" ) then { _count }else{ _taken }, _mag ]; }; }forEach _mags; }forEach _compatibleMags; }; this addEventHandler [ "InventoryOpened", { params[ "_unit", [ "_container", objNull ], "_secContainer" ]; if !( isNull _container ) then { _nul = _this spawn { disableSerialization; params[ "_unit", "_container", "_secContainer" ]; _btnHeight = 0.02 * safeZoneH; _btnWidth = 0.1 * safeZoneWAbs; _btnGap = 0.01 * safeZoneWAbs; waitUntil{ !isNull findDisplay 602 }; _inventoryDisplay = findDisplay 602; { _x params[ "_btnText", "_type" ]; if ( call compile format[ "%1weapon _unit", _type ] != "" ) then { _ctrl = _inventoryDisplay ctrlCreate [ "RscButton", 20000 + _forEachIndex ]; _ctrl ctrlSetPosition[ 0 + (( _btnWidth + _btnGap ) * _forEachIndex ), 0 - _btnHeight, _btnWidth, _btnHeight ]; _ctrl ctrlSetText format[ "Take %1", _btnText ]; _ctrl buttonSetAction format[ "[ %1, %2, %3 ] call TAG_fnc_takeAllMags", str ( _unit call BIS_fnc_netId ), str ( _container call BIS_fnc_netId ), str _type ]; _ctrl ctrlCommit 0; }; }forEach [ [ "Primary Mags", "Primary" ], [ "Hand Gun Mags", "HandGun" ], [ "Secondary Mags", "Secondary" ] ]; }; }; }]; Place in player init box, will add loads of primary mags if the container has lots of them leaving no room for secondary muzzle mags. Also will not remove mags from container producing dupe. Needs further refinement but will do as an example. 1 Share this post Link to post Share on other sites