Jump to content
froggyluv

Multiple 'If' Conditions Fail

Recommended Posts

SK = 0;
Rep = 0;
Brute = 0;
HS = 0;


{
_x addEventHandler ["Killed", {call fnc_death}];
} forEach allUnits;

fnc_death = {


_group = [a2,a3,a4,a5,a6];
_target = _this select 0;
_killer = _this select 1;
_ammo = _this select 5;

if ((_killer in _group) && ({side _target == East}))  then {


hint format["%1 Well Done!!", name _killer]

    ;
Sk = Sk + 1; Rep = Rep + 25
};

if (player == _killer) && ({side_target == East})) then {
hint format [ "Good Job!"];
rep = rep + 50;

};

So this works fine UNTIL i added the bolded:

 

'&&({side_target == East})'

 

in which just kills the whole script. Ideally would like to add even more multiple conditions but cant see why this doesn't work

 

Hmmm, apparently you cant bold code -so its the second parameter on each condition

Share this post


Link to post
Share on other sites

replace

 if (player == _killer) && ({side_target == East})) then { 

with

 if ((player == _killer) && (side _target == East)) then { 

Share this post


Link to post
Share on other sites

I an not too keen on the == condition, as it may not work with some commands such as booleans. I suggest you try isEqualTo as well as the above post to find your solution.

Hope it helps,

Rawner135

Share this post


Link to post
Share on other sites

replace

 if (player == _killer) && ({side_target == East})) then { 

with

 if ((player == _killer) && (side _target == East)) then { 

This will actually make the script perform worse than before because it removes the lazy evaluation, with no change to it's effect. The issue you're having is that you're trying to see what side a unit is from, however, you can't do that because dead units get added to the CIV faction (this might have been a band-aid fix, I assume that in early stages of development the AI units would not stop shooting at a dead unit because it was still on the "enemy team"). The way you should probably do this is by setting a variable in the object namespace for enemy units after you spawn them. Then you can use some code like this in place of what you have:

if ((player == _killer) && {(_target getVariable "obj_side") == east}) then

You also don't need to put the parenthesis around the curly braces, you can consider the curly braces to work as a substitute for them (in this very specific and particular case).

  • Like 1

Share this post


Link to post
Share on other sites

Check the side of the group of _target.

if (player isEqualTo _killer && {side group _target isEqualTo east}) then

Share this post


Link to post
Share on other sites

I an not too keen on the == condition, as it may not work with some commands such as booleans. I suggest you try isEqualTo as well as the above post to find your solution.

Hope it helps,

Rawner135

Check the side of the group of _target.

if (player isEqualTo _killer && {side group _target isEqualTo east}) then
Exactly.. ;)

Share this post


Link to post
Share on other sites

I an not too keen on the == condition, as it may not work with some commands such as booleans.

 

I wonder where you got that from... Some differences between "==" and "isEqualTo" are (among others) that latter is more "nitpicky" (case sensitive on strings) and works properly when comparing arrays and different data types. It's also a very tiny bit faster. But both work properly on anything else, including booleans. Hell, how would people have created content using "==" if it wasn't working properly?

  • Like 1

Share this post


Link to post
Share on other sites

I wonder where you got that from... Some differences between "==" and "isEqualTo" are (among others) that latter is more "nitpicky" (case sensitive on strings) and works properly when comparing arrays and different data types. It's also a very tiny bit faster. But both work properly on anything else, including booleans. Hell, how would people have created content using "==" if it wasn't working properly?

True,

But sometimes I get errors in the .rpt if I use otherwise. :huh:

Nevertheless, having isEqualTo is not the best option, like you said, for strings in this case if you do not want it to be case-sensitive.

Share this post


Link to post
Share on other sites

True,

But sometimes I get errors in the .rpt if I use otherwise. :huh:

I could imagine this to happen when you're trying to compare arrays or different data types, because I haven't had other issues with "==" yet.

 

Nevertheless, having isEqualTo is not the best option, like you said, for strings in this case if you do not want it to be case-sensitive.

I wouldn't say it's not the best option. I use it wherever I can for two reasons:

1) stability and efficiency (as stated above)

2) no accidental assignments or "needle in haystack" searches if I accidently missed on "="

  • Like 1

Share this post


Link to post
Share on other sites

But sometimes I get errors in the .rpt if I use otherwise. :huh:

Yes, those are called "user errors". It's not that == sometimes just refuses to work. It's like saying {True} doesn't always return True but "Yes!... No! Mmm I dunno.... Maybe?"

 

You just need to know the difference between the two operators. :)

  • Like 1

Share this post


Link to post
Share on other sites

I could imagine this to happen when you're trying to compare arrays or different data types, because I haven't had other issues with "==" yet. I wouldn't say it's not the best option. I use it wherever I can for two reasons:1) stability and efficiency (as stated above)2) no accidental assignments or "needle in haystack" searches if I accidently missed on "="

Yes, those are called "user errors". It's not that == sometimes just refuses to work. It's like saying {True} doesn't always return True but "Yes!... No! Mmm I dunno.... Maybe?"

You just need to know the difference between the two operators. :)

Ah, now I get it! :D

Darn, no wonder my sunrise event handler didn't work. :p (I'll also have to review my mod's code again)

Thanks for the info, Johnny and Greenfist. Now I have an itch to look on the biki now. ;)

Share this post


Link to post
Share on other sites
SK = 0;
Rep = 0;
Brute = 0;
HS = 0;


{
_x addEventHandler ["Killed", {call fnc_death}];
} forEach allUnits;

fnc_death = {


_group = [a2,a3,a4,a5,a6];
_target = _this select 0;
_killer = _this select 1;
_ammo = _this select 5;

if ((_killer in _group) && ({side _target == East}))  then {


hint format["%1 Well Done!!", name _killer]

    ;
Sk = Sk + 1; Rep = Rep + 25
};

if (player == _killer) && ({side_target == East})) then {
hint format [ "Good Job!"];
rep = rep + 50;

};

So this works fine UNTIL i added the bolded:

 

'&&({side_target == East})'

 

in which just kills the whole script. Ideally would like to add even more multiple conditions but cant see why this doesn't work

 

Hmmm, apparently you cant bold code -so its the second parameter on each condition

 

side_target - undefined variable

side _target - side of the _target

Also _this select 5 doesn't exist in "Killed" EH https://community.bistudio.com/wiki/Arma_3:_Event_Handlers#Killed

Share this post


Link to post
Share on other sites

Check the side of the group of _target.

if (player isEqualTo _killer && {side group _target isEqualTo east}) then

 

Oh man thank you -how did I not come across this anywhere :/

side_target - undefined variable

side _target - side of the _target

Also _this select 5 doesn't exist in "Killed" EH https://community.bistudio.com/wiki/Arma_3:_Event_Handlers#Killed

 

 LOl, yes that was a quick typing typo and the second me trying to impose my will on a non-compliant EH :P

 Needed a way to detect if the manner of death was by explosive to reward the bomber but alas, not possible it seems.

 

 So it was the Group after all, I tried all the different syntax suggestions ie isEqualTo and the different bracket schemes and they all seem to work as long as Group was added but pretty interesting all the different takes on it.

Share this post


Link to post
Share on other sites

 

 Needed a way to detect if the manner of death was by explosive to reward the bomber but alas, not possible it seems.

 

 

 

This would maybe be possible by using the "hitPart" eventHandler, the wiki says it returns objNull if unit was hit by an explosion.

Share this post


Link to post
Share on other sites

This would maybe be possible by using the "hitPart" eventHandler, the wiki says it returns objNull if unit was hit by a explosion.

 

 Hmm, interesting. I was able to get a return of [100,1000,3,1, "demoCharge_Remote_ammo"]; by using the hitPart

 

this addEventHandler ["HitPart", { BMB = ((_this select 0) select 6) ; hint format["%1", BMB] }];

 

..but not sure yet how to  extract and match just the string. Very helpful tho :)

Share this post


Link to post
Share on other sites

 [100,1000,3,1, "demoCharge_Remote_ammo"];

 

Not at a PC right now, but if that is an array, why not simply do a select 4 on it? If it is a string, why not do a (call compile _return) select 4 on it?

Share this post


Link to post
Share on other sites

Not at a PC right now, but if that is an array, why not simply do a select 4 on it? If it is a string, why not do a (call compile _return) select 4 on it?

 

 Do you mean this addEventHandler ["HitPart", { BMB = ((_this select 4) select 6) ; hint format["%1", BMB] }]; ? I

 

 

Could you help as Im really lost in the syntax at this point as Im already at an array within an array within another array :blink:

Share this post


Link to post
Share on other sites

I'm still not at my home PC (where A3 is installed). Actually, I wonder how (_this select 0) select 6 could return the ammo array since I thought _this select 0 was the target that got hit/injured.

 

Any way, you've got the ammo array looking like this:

[100, 1000, 3, 1, "demoCharge_Remote_ammo"]

Let's call this array _ammo. Now, if you want to get the string inside that array (the ammo class name), simply do _ammo select 4.

  • Like 1

Share this post


Link to post
Share on other sites

 this addEventHandler ["HitPart", { BMB = ((_this select 0) select 6) ; ammo1 select 4;hint format["%1", ammo1]  }];

 

 Works man :)

 

 This is really great, hugely appreciated. My problem has always been syntax as i get the concepts. I am getting a zero divider type script error but it is working.

 

 Lastly I placed this code into a unit and get the correct ["demoCharge_remote_ammo"] after blowing his a$$ up but I've placed a trigger with the Condition: ammo1 = ["demoCharge_remote_ammo"; Activation hint "Success" but for some reason its not firing. Once I can get this recognized I can award the bomber his point and Im off and running

Share this post


Link to post
Share on other sites

 this addEventHandler ["HitPart", { BMB = ((_this select 0) select 6) ; ammo1 select 4;hint format["%1", ammo1]  }];

 

Actually, I wonder how that could work, made me wonder already in the first place... I don't know what BMB should be and where you get ammo1 from, but the zero deviser error probably comes from ammo1 select 4, because there is nothing at position 4 if ammo1 doesn't exist. To tell you how this thing works:

 

If you add an event handler, like "HitPart" here, the code gets a variable called _this, which contains some data. In case of "HitPart" it's actually a lot (11 parameters), but let's focus on only a few ones. Read the BIKI for more.

this addEventHandler ["HitPart", {
    _target = _this select 0; comment "Object that got injured/damaged";
    _shooter = _this select 1; comment "Unit that inflicted the damage";
    _bullet = _this select 2; comment "Object that was fired";
    _position = _this select 3; comment "Position the bullet impacted (ASL)";

    comment "Ammo info: [hit value, indirect hit value, indirect hit range, explosive damage, ammo class name] OR
    if there is no shot object: [impulse value on object collided with,0,0,0]";
    _ammoArray = _this select 6;
    _ammoClass = _ammoArray select 4;
    hintSilent _ammoClass;
}];

That's hopefully gonna solve your problem(s).

 

EDIT: The above code is seemingly wrong. Read here.

Share this post


Link to post
Share on other sites

OK, put an "str" between the "hintSilent" and the _ammoClass and see what the result is. Like so:

hintSilent str _ammoClass;

And did you do anything different than I posted?

Share this post


Link to post
Share on other sites

 returning [0,0,0]

 

 No I'm using only this code in the init line of the unit to be bombed in a small test mission. I generally use in the editor before attempting to script it in just cause im dumb like that :)

Share this post


Link to post
Share on other sites

Alright, seems like the BIKI is not clear about this EH. It's actually returning an array of injured parts, at least when it comes to explosives. That's why _this select ... is just the selection of the hit part and then you select according to the BIKI. So this finally works:

this addEventHandler ["HitPart", {
    _hitPart	= _this select 0; comment "First part in array that got hit";
    _ammoArray	= _hitPart select 6;
    _ammoClass	= _ammoArray select 4;
    hintSilent _ammoClass;
}];

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

×