Home   Help Search Login Register  

Author Topic: Removing Weapons via Array won't work - why?  (Read 1846 times)

0 Members and 1 Guest are viewing this topic.

Offline Protector_Pulch

  • Members
  • *
Removing Weapons via Array won't work - why?
« on: 23 Feb 2009, 15:55:29 »
Hey there.

my problem is that I want to remove a gun from an unit - but only if its one of the guns included in this array.
Code: [Select]
_NonStanWeaps = ["lsr_car15_sd","lsr_car15_acog","lsr_car15_acog_sd","lsr_car15_aim","lsr_car15_aim_sd"]
to achieve this, i'm using a "fired"-eventhandler and the following lines
Code: [Select]
_gun = _this select 1
_user =_this select 0

_ammo = _this select 4

?_gun = LSR_m9 : goto "UnArm"

#UnArm
{_user removeweapon _x} forEach _NonStanWeaps

exit

but for some reason, this won't work.

 has anybody got an idea why this won't work?

Offline Planck

  • Honoured
  • Former Staff
  • ****
  • I'm never wrong ....I'm just not always right !
Re: Removing Weapons via Array won't work - why?
« Reply #1 on: 23 Feb 2009, 16:17:39 »
You must use == to test for conditions of equality.

?_gun = LSR_m9 : goto "UnArm"

try

? {_gun == LSR_m9} : goto "UnArm"

btw, the line under #Unarm will run whether the condition was true or false


Planck
« Last Edit: 24 Feb 2009, 15:15:34 by Planck »
I know a little about a lot, and a lot about a little.

Offline Trexian

  • Members
  • *
Re: Removing Weapons via Array won't work - why?
« Reply #2 on: 23 Feb 2009, 16:26:29 »
A slightly different idea (but go with Planck if in doubt).... ;)

Let me make sure I understand what you want.  You only run the check if the unit fires that specific gun?

How about something like this (oh, and sorry for the sqf, I've never done sqs):

Code: [Select]

{
if (_x in _NonStanWeaps) then
{
_user removeWeapon _x;
};
} forEach weapons _user;
Basically, run through the weapons of the user and compare if it is in the array, if it is, then remove it.
Sic semper tyrannosauro.

Offline Protector_Pulch

  • Members
  • *
Re: Removing Weapons via Array won't work - why?
« Reply #3 on: 23 Feb 2009, 16:28:27 »
Bad news - even after changing the code according to your suggestion, things still won't work - my test dummy still keeps his "LSR_car15_sd".

My main concern is that
Code: [Select]
{_user removeweapon _x} forEach _NonStanWeaps is wrong.
Can you verify that?


And as to Trexian:
No, I only want to have the unit's weapon removed in case it one of the weapon in "_NonStanWeaps"

Offline Trexian

  • Members
  • *
Re: Removing Weapons via Array won't work - why?
« Reply #4 on: 23 Feb 2009, 17:40:40 »
Well, I think I can kinda tell why your CAR didn't work... from your original code, you only check to see if the gun being used is the M9. :)

I think what you want is something like (again, not sqs-savvy)

Code: [Select]
? _gun in _NonStanWeapons: goto "Unarm"

Basically, check to see if the gun being used is non-standard.

Edit:
Maybe test it by:
Code: [Select]
? _gun == "LSR_car15_sd": goto "Unarm"

Not sure of the quotes in the conditional.

Edit2:
Looked again at Planck's stuff.  Use his parens for the code. ;)

Also, do away with the conditional completely, maybe.  You really don't care WHAT they are firing, you just want to make sure it isn't one of the nonstandards.
« Last Edit: 23 Feb 2009, 17:44:44 by Trexian »
Sic semper tyrannosauro.

Offline Protector_Pulch

  • Members
  • *
Re: Removing Weapons via Array won't work - why?
« Reply #5 on: 23 Feb 2009, 18:24:04 »
Aaa...we seem to have a major misunderstanding here.

I don't care about the whole M9 part...this part actually does what it's supposed to do.

BUT:
I want the following:

Once firing the M9 has started the whole sequence,
I want the player's gun removed - IF his gun is one of the guns in "_NonStanWeaps"
Else there should be no action after all.

Offline Trexian

  • Members
  • *
Re: Removing Weapons via Array won't work - why?
« Reply #6 on: 23 Feb 2009, 18:31:27 »
Aaa...we seem to have a major misunderstanding here.
Indeed. :)

I'm afraid I'm too n00bish to be of much assistance.  Please be sure to post if/when it gets worked out, though! I'm going to follow this to see the answer. :D
Sic semper tyrannosauro.

Offline Worldeater

  • Former Staff
  • ****
  • Suum cuique
Re: Removing Weapons via Array won't work - why?
« Reply #7 on: 23 Feb 2009, 18:41:37 »
Try this code:
Code: [Select]
_user = _this select 0
_gun  = _this select 1

? _gun != "lsr_m9" : exit

_gunList = ["lsr_car15_sd","lsr_car15_acog","lsr_car15_acog_sd","lsr_car15_aim","lsr_car15_aim_sd"]
{ _user removeWeapon _x } forEach _gunList
try { return true; } finally { return false; }

Offline Protector_Pulch

  • Members
  • *
Re: Removing Weapons via Array won't work - why?
« Reply #8 on: 23 Feb 2009, 20:01:56 »
Wackelt, sitzt und hat Luft.
(German saying for something running smoothly)
- - - - - - - - - -
Things are working perfectly right now.

Still, I'm wondering why my version didn't work - maybe I should have included the definition of _gunLust in the script itself instead of outsourcing it to init.sqs.

Thanks.

Walter_E_Kurtz

  • Guest
Re: Removing Weapons via Array won't work - why?
« Reply #9 on: 24 Feb 2009, 00:36:32 »
Correct. Variables beginning with an underscore (_) are only used by the sqs they are defined in.


Thus init.sqs
Code: [Select]
NonStanWeaps = ["lsr_car15_sd","lsr_car15_acog","lsr_car15_acog_sd","lsr_car15_aim","lsr_car15_aim_sd"]and in the event handler script
Code: [Select]
...
#UnArm
{_user removeweapon _x} forEach NonStanWeaps
...
would have worked as well.