Jump to content
Sign in to follow this  
General McTavish

Spawn Weapon with ammo on ground

Recommended Posts

So I have a list box that has rifles/pistols/launchers that will spawn on the ground when we double-click the selected weapon.

 

Spawning the weapon works fine, however, it is empty.

 

I am trying to spawn ammo for the selected weapon but no ammo spawns when I try (empty weapon does), I have tried multiple different ways but nothing works.

 

Spawn script

private["_classname","_magazines"];

_classname = lbData [9871, (lbCurSel 9871)];
_magazines = getArray (configFile >> "CfgWeapons" >> _classname >> "magazines");

_wep = createVehicle ["GroundWeaponHolder", position player, [], 0, "CAN_COLLIDE"];
_wep addWeaponCargoGlobal [_classname, 1];

_mag = createVehicle ["GroundWeaponHolder", position player, [], 0, "CAN_COLLIDE"];
_mag addMagazineCargoGlobal [_magazines, 3];

hint format["You have spawned a %1",_classname];

 

Listbox

disableSerialization;

_lbList = (findDisplay 9801) displayCtrl 9871;

lbclear _lblist;

_Weapons = [];

_Rifles = "getnumber (_x >> 'type') isEqualTo 1 && getNumber (_x>> 'scope') isEqualTo 2" configClasses (configfile >> "CfgWeapons");
_Pistols = "getnumber (_x >> 'type') isEqualTo 2 && getNumber (_x>> 'scope') isEqualTo 2" configClasses (configfile >> "CfgWeapons");
_Launchers = "getnumber (_x >> 'type') isEqualTo 4 && getNumber (_x>> 'scope') isEqualTo 2" configClasses (configfile >> "CfgWeapons");
_Weapons pushBack _Rifles;
_Weapons pushBack _Pistols;
_Weapons pushBack _Launchers;

_Weapons = _Rifles + _Pistols + _Launchers;
{
    _className = configName _x;
    _weapon = getText(configFile >> "CfgWeapons" >> _className >> "displayName");
    _picture = getText(configFile >> "CfgWeapons" >> _className >> "picture");

   if !(_className isEqualTo "") then {

    	_index = _lbList lbAdd _weapon;
        _lbList lbSetPicture [_index,_picture];
        _lbList lbSetData [_index,_className];
        _lbList lbSetTooltip [_index,_className];
   }; 
} forEach _Weapons;

 

 

 

Share this post


Link to post
Share on other sites

_magazines is an array, you need to select an element from it.

_magazine = selectRandom _magazines;

//time passes...

_mag addMagazineCargoGlobal [_magazine, 3];

Or however.

  • Like 3

Share this post


Link to post
Share on other sites
1 hour ago, Harzach said:

_magazines is an array, you need to select an element from it.


_magazine = selectRandom _magazines;

//time passes...

_mag addMagazineCargoGlobal [_magazine, 3];

Or however.

 

Totally missed the array bit haha

 

Fixed it, thanks for the help m8 😄

  • Like 2

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
Sign in to follow this  

×