Jump to content
Sign in to follow this  
lozz08

Addweapon problem

Recommended Posts

I want to be able to instantly add a weapon to a soldier in-game. But when I try to do so by an in-game trigger, a strange problem occurs.

The gun is given to me, but I cannot fire it, or look down the sights. In order to use the weapon, I must then drop then weapon and pick it up again.

When I pick the weapon up again, my soldier goes through the animation of changing to a rocket launcher weapon before unslinging his rifle and holding it.

Seems pretty strange...

Share this post


Link to post
Share on other sites

You have to remove the old weapon first...

OldWeapon = primaryWeapon player; player removeWeapon OldWeapon; player addWeapon "NewGun";

Share this post


Link to post
Share on other sites

Ah, you champion, it works. Before I was using removeallweapons _caller command in my .sqs file but it didn't work.

Share this post


Link to post
Share on other sites

Also sometimes you need to select the new weapon - That is, add a player selectWeapon "NewGun"; command at the end.

In order to make this work for primary weapons with a grenade launcher, use this at the end instead of the above:

_primaryWeapon = primaryWeapon player;
if (_primaryWeapon!="") then
{
player selectweapon _primaryWeapon;
// Fix for weapons with grenade launcher
_muzzles = getArray(configFile>>"cfgWeapons" >> _primaryWeapon >> "muzzles");
player selectWeapon (_muzzles select 0);
};

Of course if the unit doesn't have a primary weapon (ex, if you added a pistol and he has no primary weapon), then you need to first add the first command (player selectWeapon "NewGun";) and then add this code. It will select whatever primaryWeapon returns and then if the unit has a primary weapon with a GL it'll correctly pick the right muzzle for it.

Edited by galzohar

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  

×