The download hangar is currently disabled. We're doing our best to bring it back as soon as possible.

XML for Newbies Part 7 - Other Useful Opertators

The Tutorials forum section is the place where you can learn the various techniques that go into the creation of AI traffic packages.
Post Reply
User avatar
Weescotty
MAIW Developer
MAIW Developer
Posts: 2770
Joined: 11 Aug 2006, 22:15
Version: FS9
Location: Sydney

XML for Newbies Part 7 - Other Useful Opertators

Post by Weescotty »

Parts 1 through 6 are here - http://www.militaryaiworks.com/forums/33/16902

A few other useful operators.

a) rng = range

Rather than do a > and < to check if a values is between two other values, use rng.

10 100 (A:RADIO HEIGHT,feet) rng

Would check if the aircrafts current height is between 10 -> 100ft, and return TRUE ( 1 ) if it is.


b) scmp = string compare case sensitive

(A:ATC AIRLINE) 'Delta' scmp 0 ==
if{ A } els{ B }

Returns true and executes A if the ATC AIRLINE entry in the aircraft config file is Delta, else executes B

NOTE Why 0 == ?
Strings are subtracted so if they are the same the result is 0, checking for 0 == returns TRUE if the strings are the same.


c) scmi = string compare case insensitive

(A:ATC AIRLINE) 'DeLTtA' scmi 0 ==
if{ A } els{ B }

Returns true and executes A if the ATC AIRLINE entry in the aircraft config file is 'dEltA' in any upper/lower case combination.

NOTE Why 0 == ?
Strings are subtracted so if they are the same the result is 0, checking for 0 == returns TRUE if the strings are the same, else executes B


d) ssub = Find a substring

(A:ATC AIRLINE) 'elt' sstr 0 >

Checks for 'elt' in the aircraft config file ATC AIRLINE entry
If the entry contains 'elt' the result is TRUE (any number greater than 0 is a match)


NOTE - On string operators....
Originally I wanted to use them to check for the (A:AI TRAFFIC STATE, string) variables.
A subset of what is listed on the FSX variables page is supposed to be available to FS9.
As usual NONE of them can be used by AI aircraft, or at least I never got them to work.
Thanks Microsoft!

If you would like to experiment with the AI TRAFFIC STATE variables, they are listed here
https://msdn.microsoft.com/en-au/library/cc526981.aspx
The main list is FSX, the small list of 5 is FS9.

A good place to start is..
<code>
(A:AI TRAFFIC STATE, string) 'axi' sstr 0 &gt;
if{ 1 } els{ 0 }
</code>
This should check for 'axi' in the current TRAFFIC STATE string, but as I said it doesn't seem to work!
Which either means the code is wrong or as I suspect AI Aircraft can't use those variables.
User avatar
Weescotty
MAIW Developer
MAIW Developer
Posts: 2770
Joined: 11 Aug 2006, 22:15
Version: FS9
Location: Sydney

XML for Newbies Part 8 - Animations

Post by Weescotty »

The same XML triggers can be used for animations, but instead of visible/invisible you tell it which keyframe to go to.

a) Example 1 - Canopy open / closed.

Keyframes
0 - closed
50 - open
100 - closed

<part>
<name>anim_canopy</name>
<animation>
<parameter>
<code>
(A:LIGHT NAV, bool) (A:LIGHT RECOGNITION, bool) + 50 *
</code>
<lag>20</lag>
</parameter>
</animation>
</part>

What happens -
(A:LIGHT NAV, bool) (A:LIGHT RECOGNITION, bool) + ... Checks if lights are on and adds them, so the result can be
0 + 0
1 + 0
1 + 1
0 + 1 No recognition light without nav lights, so not possible

50 * ... It then takes this value and multiplies it by 50

So aircraft inactive is ( 0 + 0 ) * 50 = 0 canopy is closed
Nav lights come on is ( 1 + 0 ) * 50 = 50 canopy opens
Recognition light comes on ( 1 + 1 ) * 50 = 100 canopy closes, and aircraft toddles off to the runway


b) Example 2 - Refuel boom extend / retract

Just an example of nested if els, removing the code....

T = TEST
R = RESULT

TEST1
if{ T1R1 TEST2 if{ T2R1 } els{ T2R2 } }
els{ T1R2 }


Keyframes
0 - retracted
100 - extended

<part>
<name>anim_rboom</name>
<animation>
<parameter>
<code>
(A:RADIO HEIGHT,feet) 25000 &gt;
if{ -2 2 (A:PLANE PITCH DEGREES,degrees) rng -2 2 (A:PLANE BANK DEGREES,degrees) rng and if{ 100 } els{ 0 } }
els{ 0 }
</code>
<lag>20</lag>
</parameter>
</animation>
</part>

What happens
(A:RADIO HEIGHT,feet) 25000 &gt; .. Checks if aircraft is over 25000ft.
If NOT it uses the last line of code .. els{ 0 }
If TRUE it uses the first line of code .. if{ -2 2 (A:PLANE PITCH DEGREES,degrees) rng -2 2 (A:PLANE BANK DEGREES,degrees) rng and if{ 100 } els{ 0 } }

The second line of code checks if the pitch AND roll variables are both between -2 and 2 degrees
-2 2 (A:PLANE PITCH DEGREES,degrees) rng
-2 2 (A:PLANE BANK DEGREES,degrees) rng
and

If TRUE it returns 100 (extend boom)
If FALSE it returns 0 (boom retracted)
User avatar
Weescotty
MAIW Developer
MAIW Developer
Posts: 2770
Joined: 11 Aug 2006, 22:15
Version: FS9
Location: Sydney

XML for Newbies Part 9 - Combined Visibility and Animation

Post by Weescotty »

This can be done using a parent part for visibility and animating a linked part then using two seperate pieces of XML code.
BUT you can combine into one part and one block of code.


We always wanted to do tie downs, blade folding etc on helos, but as you know the slow speed prop part stops at a random postion.

The fix -
Have an XML controlled part for slow/stopped 'prop'.
You still need the other two default parts, but the slow/stopped will be XML controlled.

Call the part in FSDS or GMax AI_PROP_STILL_ENG1
Then set your part at the stopped position and animate the following keyframes

100 keyframes...
0 - 0 degrees
25 - 90 degrees
50 - 180 degrees
75 - 270 degrees
100 - 360 degrees (same as 0)


XML Code

<part>
<name>AI_PROP_STILL_ENG1</name>
<visible_in_range>
<parameter>
<code>
(A:PROP MAX RPM PERCENT:1,percent) 6.25 &lt;
if{ 1 } els{ 0 }
</code>
</parameter>
<minvalue>1</minvalue>
</visible_in_range>
<animation>
<parameter>
<code>
0.05 6.25 (A:PROP MAX RPM PERCENT:1,percent) rng
if{ (A:PROP MAX RPM PERCENT:1,percent) 6 * (E:ABSOLUTE TIME,second) * 360 % }
els{ 0 }
</code>
<lag>100</lag>
</parameter>
</animation>
</part>


The only new part of the code is the % (modulo) sign.
It divides two numbers returning the 'whole' part of the result and throwing away the fraction (everything after the decimal point).
For eg
10 3 / results in 3.3333 recurring
10 3 % results in 3

In the code above if all are max values it returns keyframe 100
100 6 * 60 * 360 %
600 60 * 360 %
36000 360 %
100

If all are minvalues it returns keyframe 0
0 6 * 1 * 360 %
0 1 * 360 %
0 360 %
0

All other values in-between return keyframes 1 to 99.

The rest of the code you should be able to work out.

One question might be where I got the 6.25 value from.
Easy answer - 6.25 is the transition speed from slow/stopped prop to the next one in FSX so guessed FS9 was the same (it was).

Now everytime the helo shuts down, the rotor stops at 0.
Post Reply