Beerkan 71 Posted September 19, 2014 (edited) Gotta problem with a script I'm trying to put together. Scenario: In my Mission enemies are plentiful and ammo is a very scarce and a very valuable resource. So what I want to do is give all OPFOR AI units unlimited Ammo to make life difficult for the player, but when you kill an AI unit (and have the time to browse their inventory) find only 1 ammo clip (of their primary weapon) in their inventory. Which may or may not be the ammo you need for your weapon. This is my script (abbreviated) { if (side _x == EAST) then {if (_x IsKindof "Man") then { removeAllWeapons _x; _x setVehicleAmmo 0; [_x, "hgun_Pistol_heavy_01_MRD_F",1] call BIS_fnc_addWeapon;//Works _x addeventhandler ["Fired", {_this setvehicleammo 1}];//Doesn't work _mag = currentMagazine _x;// Also tried _mag = currentMagazine _this _x addEventHandler ["Killed", {_this addItemToUniform _mag}];//Nope doesn't work either }; }; } forEach allUnits; Note.. later on in the mission I will be giving AI units better weapons, but I still need to leave their dead body with only 1 full clip of their primary weapon. Unfortunately the above script does't work on a number of issues. Can anyone point me in the right direction on this? Thanks.. Beer. Edited September 20, 2014 by Beerkan Share this post Link to post Share on other sites
jshock 513 Posted September 19, 2014 It may be that the unit only has his one magazine that is preloaded into the weapon, and when he shoots the Fired EH just refills that magazine, but I don't know the full function of the setAmmo command. Share this post Link to post Share on other sites
Beerkan 71 Posted September 19, 2014 It may be that the unit only has his one magazine that is preloaded into the weapon, and when he shoots the Fired EH just refills that magazine, but I don't know the full function of the setAmmo command.Thanks for your suggestion. However, to test this I set myself to allowdamage false. During testing AI unit will only unload one single clip into my ass.. (in my example 11 shots)That proves unlimited ammo is not working.. When I kill him his gun ammo is empty, and he as no clips in his inventory. Share this post Link to post Share on other sites
Larrow 2823 Posted September 19, 2014 (edited) Hey BeerKan setVehicleAmmo does not work that way. Read the comments under the command in the wiki. It gives a percentage of ammo to the unit. e.g lets say you start as a standard BLUFOR soldier. He starts with 10 mags for his primary weapon, one in the weapon , 9 on his person. player setVehicleAmmo 0.5, so 50% will leave him with 5 mags, the one in his weapon and 4 on his person. player setVehicleAmmo 1 will not fill him back to 10 mags but leaves him with 100% of what he currently has, so still 5 mags player setVehicleAmmom 0.5 will half his mags again, 1 in weapon, 1.5 on his person, .5 as it actually removes half the bullets from one of the clips Could try something like.. { if (side _x == east) then { _mag = (primaryWeaponMagazine _x) select 0; _x removeMagazines _mag; _x addEventHandler ["fired", { _unit = _this select 0; if (_unit ammo (primaryWeapon _unit) == 0) then { _mag = (primaryWeaponMagazine _unit) select 0; _unit addMagazine _mag; hint format["adding %1 to %2", _mag, _unit]; }; }]; }; }forEach allUnits; And this will do the same for both primary and handgun { _unit = _x; if (side _unit in [east, west]) then { { _unit removeMagazines _x; }forEach [(primaryWeaponMagazine _unit) select 0, (handgunMagazine _unit) select 0]; _x addEventHandler ["fired", { _unit = _this select 0; if (_unit ammo ( currentWeapon _unit) == 0) then { _mag = (currentMagazine _unit); _unit addMagazine _mag; hint format["adding %1 to %2", _mag, _unit]; }; }]; }; }forEach allUnits; Edited September 19, 2014 by Larrow Share this post Link to post Share on other sites
Beerkan 71 Posted September 20, 2014 Mmm... understandable Larrow... I'll give it a try. Many thanks for your input. Share this post Link to post Share on other sites