Jump to content
Sign in to follow this  
Tankbuster

complex code in trigger condition

Recommended Posts

Guys,

I've come up against a lack of talent while writing this condition field. I passed it on to one of my tame code wranglers, but he couldn't make it work either.

It's an IED detonation trigger that's supposed to go off only if a AI spotter is still alive and there's a group of east or west players either more than 3 in number or in a land vehicle. I don't want aircraft to set it off unless they are very low and hovering.

Basically, This trigger is server side and I need this it to activate if;

The boolean variable d_no_more_observers is false

and

players are not in an aircraft (altitude less than 3m)

and

(

There are 3 or more players on foot

or

there are players in a vehicle

)

Note that these players might be blufor or opfor, but not AI. Also note that the sek tr large bomb is an addon.

Here's what I have so far.

_t_iedtrigger = createTrigger ["EmptyDetector", [_t_xpos, _t_ypos]];
_t_iedtrigger setTriggerArea[5, 5, 0, false];
_t_iedtrigger setTriggerActivation["ANY", "PRESENT", false];
_t_strinf = format ["_tankylargeied%1 = createVehicle [""SEK_TR_GUE_largebomb"", [%2,%3], [], 0, ""NONE""];",_t_largeiedcount,_t_xpos,_t_ypos];

// in a vehicle or 3 or more players in the trigger, under 3m height and 
// arty observers alive - d_no_more_observers <boolean> - d_nr_observers <number>

_t_iedtrigger setTriggerStatements ["({ if(vehicle _x != _x) then { { isPlayer _x; } foreach (crew (vehicle _x)); }else{ ({isPlayer _x} count thislist) > 2;};} foreach thislist) && !d_no_more_observers && ({((getposATL _x) select 2) < 3} foreach thislist)", _t_strinf, ""];

Share this post


Link to post
Share on other sites

You're not returning boolean values from the two conditions with forEach thisList.

Try it like this instead: https://gist.github.com/1066932

(Might not fully fit your wanted conditions, but should be easy to adjust)

Also, you seem to be creating unneeded local variables: _tankylargeied%1 =

that variable should not be accessible from anywhere and therefor seems useless :)

Edited by Sickboy

Share this post


Link to post
Share on other sites

Ah yes, that tankyied is local only to the scope of that loop. Not sure why I did that. :)

Thanks very much for the code. I've skimmed over it and will have a good look later.

Share this post


Link to post
Share on other sites
I passed it on to one of my tame code wranglers, but he couldn't make it work either.

Sorry, I was busy waxing my growler..

Share this post


Link to post
Share on other sites
Sorry, I was busy waxing my growler..

I know what that means and it still sounds dirty.

Share this post


Link to post
Share on other sites

OK SB, I've had a chance to look over what you did.

I didn't know that the code is evaluated by compile pfln in that way. I looked at it and thought "You can't put 'if' in the condition field, but now I realise that the code is EVALUATED, not 'proxied' into the condition field. It's clearly MUCH easier to write the code in a blocked series of 'ifs' and cpfln it rather than trying to cram complex brackets and stuff onto the condition field.

I had no idea it worked that way. I've learnt something today. Thank you very much. :)

Share this post


Link to post
Share on other sites

SB, a quick follow up question, because one of my triggers isn't working.

The one you described above works just fine. It only goes off if (the observers are still alive) and you drive into the trigger or walk in with 3 guys. Aircraft don't ever set it off. Also, foot mobiles can approach it in the crawl. It's excellent and I'm most grateful.

I tried to write another one to set of a smaller 'splode which is meant to be anti-personnel.

Basically, aircraft never set it off and again, foot mobiles can approach it in the crawl, but otherwise, any player will set it off.

if ({((getposATL _x) select 2) > 3} count _this > 0) exitWith { false }; // Flying vehicles in trigger area, exit.
if ((_x selectionPosition "Neck" select 2) < 1.5) exitWith { false };
if (_x isKindOf "Man") exitWith { true };
true;

But it never goes off. Am I doing something blindingly obvious wrong?

Tank -Paul-

Share this post


Link to post
Share on other sites

NP :)

Anything in the rpt?

if ((_x selectionPosition "Neck" select 2) < 1.5) exitWith { false };

Might error, perhaps try

if (((_x selectionPosition "Neck") select 2) < 1.5) exitWith { false };

I'm unfamiliar with selectionPosition and unsure if the usage is correct, I suppose you've tried the command and logged the result to see if it works as intended?

The last exitWith condition isn't needed:

if (_x isKindOf "Man") exitWith { true };
true;

Since you already return true (below it) anyway.

Share this post


Link to post
Share on other sites

I think the RPT is clear of anything relevant, though we're testing again right now. I can monitor the RPT in real time so will keep and eye on it

Yeah, I've done tests with selectionPosition, it's pretty reliable. Actually 1.5 will cover both the crawl and the crouched walk.

I suspect you're right though, a bracket snafu would be a likely candidate and it is exiting with false and that's the behaviour, albiet undesired that I'm seeing.

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  

×