Jump to content
BrodieHeadford

Determining Which Type of Weapon Player is Holding.

Recommended Posts

Hi there, 

I'm after a piece of script that will determine whether the player calling the script is holding a primaryWeapon, secondaryWeapon or handgunWeapon.
As I have a different animation I'd like to call for each weapon type.

e.g:

(if player is holding primaryWeapon then "run animation1")
(if player is holding secondaryWeapon then "run animation2")
(if player is holding handgunWeapon then "run animation3")

I've been looking around, but can only find script that gives me the exact class name of the current weapon the unit is holding e.g: "hgun_Rook40_F", Which is not what I'm after.

- Cheers.

EDIT: 

Solution - credit to gc8.

 

_man = player;

_curw = currentWeapon _man;

if(_curw != "") then // Has any weapon selected?
{

 if(_curw == (primaryWeapon _man)) then // Primary weapon selected?
{
 // Play animation here
};

 if(_curw == (secondaryWeapon  _man)) then
{
 // Play animation here
};

 if(_curw == (handgunWeapon  _man)) then
{
 // Play animation here
};

};

Share this post


Link to post
Share on other sites

How about:

 

primaryWeapon player == currentWeapon player

 

  • Like 1

Share this post


Link to post
Share on other sites
13 minutes ago, gc8 said:

How about:

 


primaryWeapon player == currentWeapon player

 

Hey gc8! Thanks for the fast response.

I'm unsure how I'd implement that - is there any chance you could work it into what I've explained?
Such as an 'if' statement, if possible? That would be great.

e.g
if "weapon is primary" then "primaryanimation" 

if "weapon is secondary" then "secondaryanimation" 

if "weapon is handgun" then "handgunanimation" 

Hoping what I'm communicating makes sense.

-Cheers.

Share this post


Link to post
Share on other sites

Something like:

_man = player;

_curw = currentWeapon _man;

if(_curw != "") then // Has any weapon selected?
{

 if(_curw == (primaryWeapon _man)) then // Primary weapon selected?
{
 // Play animation here
};

 if(_curw == (secondaryWeapon  _man)) then
{
 // Play animation here
};

 if(_curw == (handgunWeapon  _man)) then
{
 // Play animation here
};

};

 

  • Thanks 1

Share this post


Link to post
Share on other sites

It's time to "optimize" your code. The if then .... if then...  cascade is never a must, checking for all cases. One day you'll have far heavier conditions to be tested, so take some good ways:

 

replace all if... then {...}  lines by:

call {

   if... exitWith {...};

   if... exitWith {...};

};

Don't forget the wrapping call {} and try to place the most frequent occurrence first. Here the order could be primaryWeapon, handGun, secondaryWeapon

 

or even, something like:

_selection = [primaryWeapon _man,handGun _man,secondaryWeapon _man] find _curw;

_anim = ["firstAnim","secondAnim","thirdAnim"] select _selection;

_man playMove _anim; // or what ever you script for that

 

 

  • Like 1
  • Thanks 1

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

×