OFPEC Forum
Editors Depot - Mission Editing and Scripting => OFP - Editing/Scripting General => Topic started by: Protector_Pulch 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.
_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
_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?
-
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
-
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):
{
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.
-
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 {_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"
-
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)
? _gun in _NonStanWeapons: goto "Unarm"
Basically, check to see if the gun being used is non-standard.
Edit:
Maybe test it by:
? _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.
-
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.
-
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
-
Try this code:
_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
-
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.
-
Correct. Variables beginning with an underscore (_) are only used by the sqs they are defined in.
Thus init.sqsNonStanWeaps = ["lsr_car15_sd","lsr_car15_acog","lsr_car15_acog_sd","lsr_car15_aim","lsr_car15_aim_sd"]and in the event handler script...
#UnArm
{_user removeweapon _x} forEach NonStanWeaps
...would have worked as well.