Jump to content
johnnyboy

AI take weapon using TakeWeapon action [SOLVED]

Recommended Posts

I would like to script having AI take weapon from nearby ground weapon holders.  I know I can fake it by using addWeapon, and deleting the nearby WeaponHolder.  But it seems I should be able to use action TakeWeapon.

 

After forcing an AI unit to drop a weapon, there is a weaponHolder object near him with that weapon.  I wrote the following script:

cop2 action ["TakeWeapon",  
    cop2 nearObjects ["WeaponHolderSimulated", 15], // returns near weaponHolder object: "1259b1600# 164141: dummyweapon.p3d"
    (weaponsitemscargo  (cop2 nearObjects ["WeaponHolderSimulated", 20] select 0) select 0) select 0  // returns name of weapon in holder
];

The AI unit plays the TakeWeapon animation, but does not actually take the weapon.

 

Updated: Here's the solution thanks to HazJ:


_box = (cop2 nearObjects ["WeaponHolderSimulated", 6]) select 0;
_boxContents = weaponCargo _box;
_weapon = _boxContents select 0;
cop2 action ["TakeWeapon", _box, _weapon];

 

  • Like 2

Share this post


Link to post
Share on other sites

I placed myself down in Eden with an AI named Bov. Then placed a basic weapons box near. In debug:

box = (Bov nearObjects ["ReammoBox_F", 25]) select 0;
boxContents = weaponCargo box;
randomWeapon = boxContents select (random (count boxContents));
hintSilent format ["> %1", randomWeapon];
Bov action ["TakeWeapon", box, randomWeapon];

You can't put code inside by the way. Syntax is as followed:

unit action ["TakeWeapon", vehicle, weaponName];

Vehicle is the object the weapon is being taken from, in this case it is: box

  • Like 3

Share this post


Link to post
Share on other sites

Thanks @Hazj, thanks to your great example, I have this working with the nearby weaponholder.  Solution:


_box = (cop2 nearObjects ["WeaponHolderSimulated", 6]) select 0;
_boxContents = weaponCargo _box;
_weapon = _boxContents select 0;
cop2 action ["TakeWeapon", _box, _weapon];

 

  • Like 1
  • Thanks 1

Share this post


Link to post
Share on other sites

Can you make the AI take the weapon so that he doesn't put it on back but instead keeps it on arms ready to fire?

 

Share this post


Link to post
Share on other sites

Could maybe have AI use the selectWeapon command to make him switch to that weapon. May be a good idea to add a sleep before selecting weapon, just to be safe.

Share this post


Link to post
Share on other sites
22 hours ago, phronk said:

Could maybe have AI use the selectWeapon command to make him switch to that weapon. May be a good idea to add a sleep before selecting weapon, just to be safe.

 

Tried that just now but didn't work. I think the AI is already "selecting" it

 

thx!

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

×