Dreamcraft

View previous topic View next topic Go down

Dreamcraft

Post by bwansy on Fri Jul 16, 2010 10:23 am

This is my signature vehicle, the Dreamcraft. Its concept appeared in my dream long time ago, hence the name. It is a helicopter as well as a plane, somewhat like the thingy from the film "The 6th Day". Controls are in game.

Code:

// [RCD]
Val
{
   ELEV(default=0, min=-400, max=400, disp=0)
   GEARANG1(default=45, min=-400, max=400, disp=0)
   GEARANG2(default=60, min=-400, max=400, disp=0)
   GEARBRAKE(default=0, max=999999999, step=999999999, disp=0)
   KEYPITCH(default=0, min=-10, max=10, step=2, disp=0)
   KEYROLL(default=0, min=-10, max=10, step=2, disp=0)
   KEYTHR(default=0, min=-3, max=10, disp=0)
   KEYYAW(default=0, min=-10, max=10, step=2, disp=0)
   NOSEANG1(default=15, min=-400, max=400, disp=0)
   NOSEANG2(default=150, min=-400, max=400, disp=0)
   NOSEANG3(default=75, min=-400, max=400, disp=0)
   NOSESTEER(default=90, min=-400, max=400, disp=0)
   PROPANGB1(default=90, min=-400, max=400, disp=0)
   PROPANGB2(default=90, min=-400, max=400, disp=0)
   PROPANGD1(default=0, min=-400, max=400, disp=0)
   PROPANGD2(default=0, min=-400, max=400, disp=0)
   PROPANGF1(default=-90, min=-400, max=400, disp=0)
   PROPANGF2(default=-90, min=-400, max=400, disp=0)
   PROPANGU1(default=0, min=-400, max=400, disp=0)
   PROPANGU2(default=0, min=-400, max=400, disp=0)
   RUDDER(default=0, min=-400, max=400, disp=0)
   WHLBRAKEB(default=0, max=999999999, step=999999999, disp=0)
   WHLBRAKED(default=0, max=999999999, step=999999999, disp=0)
   WHLBRAKEF(default=0, max=999999999, step=999999999, disp=0)
   WHLBRAKEU(default=0, max=999999999, step=999999999, disp=0)
   WHLPWRB(default=0, min=-999999999, max=999999999, disp=0)
   WHLPWRD(default=0, min=-999999999, max=999999999, disp=0)
   WHLPWRF(default=0, min=-999999999, max=999999999, disp=0)
   WHLPWRU(default=0, min=-999999999, max=999999999, disp=0)
}
Key
{
   0:KEYPITCH(step=2)
   1:KEYPITCH(step=-2)
   2:KEYROLL(step=2)
   3:KEYROLL(step=-2)
   4:KEYYAW(step=2)
   5:KEYTHR(step=-0.2)
   6:KEYYAW(step=-2)
   8:KEYTHR(step=0.2)
}
Body
{
   Core() {
      S:Weight(angle=180, option=2) { }
      S:Frame(angle=30, option=2, damper=1) {
         S:Frame(angle=-30, damper=1, name=WHLREFH) {
            S:RLW(angle=-90, power=WHLPWRB, brake=WHLBRAKEB, name=WHLB) {
               W:Trim(angle=PROPANGB1, color=#4040FF) { }
               E:Trim(angle=PROPANGB2, color=#4040FF) { }
            }
            N:RLW(angle=-90, power=WHLPWRF, brake=WHLBRAKEF, name=WHLF) {
               E:Trim(angle=PROPANGF2, color=#4040FF) { }
               W:Trim(angle=PROPANGF1, color=#4040FF) { }
            }
            N:RLW(angle=180, power=WHLPWRD, brake=WHLBRAKED, name=WHLD) {
               E:Trim(angle=PROPANGD2, color=#4040FF) {
                  E:Chip(color=#4040FF) {
                     E:Chip(color=#4040FF) { }
                  }
               }
               W:Trim(angle=PROPANGD1, color=#4040FF) {
                  W:Chip(color=#4040FF) {
                     W:Chip(color=#4040FF) { }
                  }
               }
            }
            N:Frame(angle=-90, name=WHLREFV) {
               N:RLW(angle=-90, power=WHLPWRU, brake=WHLBRAKEU, name=WHLU) {
                  E:Trim(angle=PROPANGU2, color=#4040FF) {
                     E:Chip(color=#4040FF) {
                        E:Chip(color=#4040FF) { }
                     }
                  }
                  W:Trim(angle=PROPANGU1, color=#4040FF) {
                     W:Chip(color=#4040FF) {
                        W:Chip(color=#4040FF) { }
                     }
                  }
               }
               N:Cowl(angle=100, color=#808080) {
                  N:Cowl(angle=10, effect=#A0FB) {
                     E:Cowl(angle=120, option=3, effect=#A0FB) { }
                     W:Cowl(angle=120, option=4, effect=#A0FB) { }
                  }
                  S:Cowl(angle=10, color=#808080) {
                     S:Cowl(angle=30, option=5, color=#808080) { }
                  }
                  E:Cowl(angle=135, color=#808080) { }
                  W:Cowl(angle=135, color=#808080) { }
               }
               S:Cowl(angle=100, color=#808080) {
                  S:Cowl(angle=10, effect=#A0FB) {
                     W:Cowl(angle=120, option=3, effect=#A0FB) { }
                     E:Cowl(angle=120, option=4, effect=#A0FB) { }
                  }
                  E:Cowl(angle=135, color=#808080) { }
                  W:Cowl(angle=135, color=#808080) { }
               }
               E:Cowl(angle=-90, color=#808080) {
                  E:Cowl(angle=-30, option=5, color=#808080) { }
               }
               W:Cowl(angle=-90, color=#808080) {
                  W:Cowl(angle=-30, option=5, color=#808080) { }
               }
            }
            S:Frame(angle=-30) {
               S:Frame(angle=30) {
                  N:Chip() { }
                  S:Frame() {
                     S:Chip(angle=ELEV) {
                        W:Chip() {
                           N:Cowl(option=3, color=#808080) { }
                        }
                        E:Chip() {
                           N:Cowl(option=4, color=#808080) { }
                        }
                     }
                     S:TrimF(angle=90, option=1) {
                        N:Chip(angle=RUDDER) {
                           S:Chip() {
                              E:Chip() { }
                           }
                           E:Cowl(option=3, color=#808080) { }
                        }
                     }
                     N:Cowl(angle=180, color=#808080) { }
                  }
                  N:Cowl(angle=180, color=#808080) { }
               }
            }
            E:Frame(angle=GEARANG1, option=1) {
               S:RudderF(angle=-GEARANG2, option=1) {
                  S:RLW(angle=180, brake=GEARBRAKE) { }
               }
               S:Cowl(angle=180, option=3, color=#808080) { }
            }
            W:Frame(angle=GEARANG1, option=1) {
               S:RudderF(angle=GEARANG2, option=1) {
                  S:RLW(angle=180, brake=GEARBRAKE) { }
               }
               S:Cowl(angle=180, option=4, color=#808080) { }
            }
            S:Cowl(angle=-30, option=5, color=#808080) { }
         }
      }
      S:RudderF(angle=NOSESTEER) {
         N:Frame(angle=NOSEANG1, option=1) {
            N:Frame(angle=NOSEANG2, option=1) {
               N:RLW(angle=-NOSEANG3, brake=GEARBRAKE) { }
            }
         }
      }
   }
}
Lua
{require("Bernard/Bernard.lua")


function init()
   engflag = 0
   gearflag = 1
   nosebaseang = 90
   helimode = 1

   rotorcoll = 0

   pi = math.pi
   dt = 10*_DT()

   autoflag = 0

   basex = _X(WHLREFH)
   basey = _Y(WHLREFH)
   basez = _Z(WHLREFH)
   
   mouseflag = 1
   scrx = _WIDTH()
   scry = _HEIGHT()
end
function OnInit()
   init()
end
function OnReset()
   init()
end

function getpropstate()
   wu = _WY(WHLU)
   wd = _WY(WHLD)
   wf = _WY(WHLF)
   wb = _WY(WHLB)

   ryu = normalrad(_RY(WHLU,WHLREFH)-dt*wu)
   ryd = normalrad(_RY(WHLD,WHLREFH)-dt*wd)
   ryf = normalrad(_RY(WHLF,WHLREFV)-dt*wf)
   ryb = normalrad(_RY(WHLB,WHLREFV)+pi-dt*wb)
end

function inputmouse()
   dzone = 0.03
   _SETCOLOR(rgb(255,255,0))
   _MOVE2D(0.8,0.9)
   _LINE2D(0.9,0.9)
   _LINE2D(0.9,0.8)
   _MOVE2D(-0.8,0.9)
   _LINE2D(-0.9,0.9)
   _LINE2D(-0.9,0.8)
   _MOVE2D(0.8,-0.9)
   _LINE2D(0.9,-0.9)
   _LINE2D(0.9,-0.8)
   _MOVE2D(-0.8,-0.9)
   _LINE2D(-0.9,-0.9)
   _LINE2D(-0.9,-0.8)
   
   _MOVE2D(0.1,dzone)
   _LINE2D(-0.1,dzone)
   _MOVE2D(0.1,-dzone)
   _LINE2D(-0.1,-dzone)
   _MOVE2D(-dzone,0.1)
   _LINE2D(-dzone,-0.1)
   _MOVE2D(dzone,0.1)
   _LINE2D(dzone,-0.1)
   
   mousex = limit((1-(_MX()/(scrx))*2)*(scrx/scry)/0.9,-1,1)
   mousey = limit((1-(_MY()/(scry))*2)/0.9,-1,1)
   if math.abs(mousex) < dzone then mousex = 0 end
   if math.abs(mousey) < dzone then mousey = 0 end
   mousepitch = mousey*10
   mouseroll = mousex*10
end

function inputctrl()
   inpthr = KEYTHR
   if mouseflag > 0 then
      inppitch = limit(KEYPITCH+mousepitch,-10,10)
      inproll = limit(KEYROLL+mouseroll,-10,10)
   else
      inppitch = KEYPITCH
      inproll = KEYROLL
   end
   inpyaw = KEYYAW
end

function heli()
   WHLPWRU = (WHLPWRU+(40-wu)*300)*engflag
   WHLPWRD = (WHLPWRD+(40+wd)*-300)*engflag

   WHLPWRF = -ryf*4000-(wf-_WZ(0)*0.3)*3000
   if math.abs(ryf) < 0.05 and math.abs(wf) < 0.1 then WHLBRAKEF = 1000 end

   WHLPWRB = ryb*4000-(wb+_WZ(0)*0.3)*3000
   if math.abs(ryb) < 0.05 and math.abs(wb) < 0.1 then WHLBRAKEB = 1000 end

   if autoflag == 0 and engflag == 1 and math.abs(KEYTHR-5) < 0.5 and inproll == 0 and inppitch == 0 and math.abs(_VY(WHLREFH)) < 1.5 and math.len2(_VX(WHLREFH),_VZ(WHLREFH)) < 4 then autoflag = 1 end
   if math.abs(KEYTHR-5) > 0.5 or inproll ~= 0 or inppitch ~= 0  then autoflag = 0 end
   if _KEYDOWN(9) > 0 then
      autoflag = 2
      tgtx = basex
      tgtz = basez
      tgty = hcy
      end
   if autoflag == 0 then
      pitcht = 1.5*inppitch-_ZY(0)*30+1
      rollt = 1.5*inproll+_XY(0)*30
   
      rotorcoll = animate(rotorcoll,1.7*KEYTHR,3)

      tgtx = _X(WHLREFH)
      tgty = _Y(WHLREFH)
      tgtz = _Z(WHLREFH)
   else
      hcx = _X(WHLREFH)
      hcy = _Y(WHLREFH)
      hcz = _Z(WHLREFH)
      dist = math.len2(hcx-tgtx,hcz-tgtz)
      if autoflag == 2 and dist < 30 then tgty = animate(tgty,basey,0.15) end
      corehead = math.atan2(_ZX(0),_ZZ(0))
      tgtdir = math.atan2(-tgtx+hcx,-tgtz+hcz)
      tgthead = tgtdir
      reldir = normalrad(tgtdir-corehead)
      pitchset = limit(dist*4*math.cos(reldir)+_VZ(WHLREFH)*20,-20,20)
      rollset = limit(-dist*4*math.sin(reldir)-_VX(WHLREFH)*20,-20,20)
      pitcht = (math.rad(pitchset)-math.asin(_ZY(0)))*20+1
      rollt = (math.rad(rollset)+math.asin(_XY(0)))*20
      rotorcoll = 8.5+(tgty-hcy)*40-_VY(WHLREFH)*5

      if autoflag == 1 then out(6,"Autopilot: Hover")
      elseif autoflag == 2 then out(6,"Autopilot: Return to base") end
   end

   yawt = KEYYAW+_WY(0)*10

   PROPANGU1 = limit(rotorcoll+pitcht*math.sin(ryu)+rollt*math.cos(ryu),-30,30)
   PROPANGU2 = limit(rotorcoll-pitcht*math.sin(ryu)-rollt*math.cos(ryu),-30,30)

   PROPANGD1 = limit(-rotorcoll-pitcht*math.sin(ryd)-rollt*math.cos(ryd),-30,30)
   PROPANGD2 = limit(-rotorcoll-pitcht*math.sin(ryd)+rollt*math.cos(ryd),-30,30)

   WHLBRAKEU = yawt*30
   WHLBRAKED = yawt*-30

   PROPANGF1 = animate(PROPANGF1,-90,10)
   PROPANGF2 = PROPANGF1
   PROPANGB1 = animate(PROPANGB1,90,10)
   PROPANGB2 = PROPANGB1

   ELEV = animate(ELEV,0,5)
   RUDDER = animate(RUDDER,0,5)

   if _KEYDOWN(14) > 0 then
      helimode = 0
      autoflag = 0
   end

   out(5,"[D] : RTB autopilot")
end

function plane()
   vel = -_VZ(0)
   velcorr = 1/(1+(vel*0.02))
   WHLPWRU = normalrad(ryu+pi)*80000-wu*15000
   if math.abs(wu) < 0.3 then WHLBRAKEU = 20000 end
   WHLPWRD = normalrad(ryd+pi)*80000-wd*15000
   if math.abs(wd) < 0.3 then WHLBRAKED = 20000 end

   if engflag > 0 then
--[[      WHLPWRF = WHLPWRF-(75+wf)*150
      WHLPWRB = WHLPWRB-(75+wb)*150
      out(10,WHLPWRF)
      out(11,WHLPWRF)]]
      WHLPWRF = -300000
      WHLPWRB = -300000
      propangset = limit((1+math.sin(math.atan(vel/10)))*KEYTHR*3,-10,70)
   else
      WHLPWRF = -ryf*5000-(wf-_WZ(0))*3000
      if math.abs(ryf) < 0.05 and math.abs(wf) < 0.1 then WHLBRAKEF = 1000 end

      WHLPWRB = ryb*5000-(wb+_WZ(0))*3000
      if math.abs(ryb) < 0.05 and math.abs(wb) < 0.1 then WHLBRAKEB = 1000 end
      propangset = 90
   end
   
   rotorcoll = animate(rotorcoll,0,3)

   if autoflag == 0 then
      pitcht = 1.7*inppitch
      rollt = 1.5*inproll*velcorr
      yawt = KEYYAW
      tgty = _Y(WHLREFH)
   else
      hcx = _X(WHLREFH)
      hcy = _Y(WHLREFH)
      hcz = _Z(WHLREFH)

      if autoflag == 1 then
         tgty = limit(tgty-inppitch*0.08*vel/60*_YY(0),7,3000)
         rollset = math.rad(limit(inproll*6*(vel/60),-65,65))
         if vel < 15 then autoflag = 0 end
         KEYTHR = limit(KEYTHR,6,10)
         out(6,"Autopilot: Level flight")
      elseif autoflag == 2 then
         corehead = math.atan2(_ZX(0),_ZZ(0))
         tgty = animate(tgty,basey+80,0.5*vel/60*_YY(0))
         tgtdir = math.atan2(-basex+hcx,-basez+hcz)
--         tgtdir = 0
         reldir = normalrad(tgtdir-corehead)   
         dist = math.len2(hcx-basex,hcz-basez)
         rollset = math.rad(limit(-reldir*vel*3,-60,60))
         if dist > 250 then KEYTHR = animate(KEYTHR,limit(math.floor((dist-100)*0.2)*0.2,0,10),0.2)
         else KEYTHR = animate(KEYTHR,0,0.2) end
         if KEYTHR == 0 then
            helimode = 1
            KEYTHR = 5
            tgtx = basex
            tgtz = basez
            tgty = hcy-4
            end
         out(6,"Autopilot: Return to base")
      end
      liftcomp = 10*velcorr
      pitchset = (hcy-tgty)*2-liftcomp
      pitcht = (-_ZY(0)+math.rad(pitchset))*50
      rollt = (math.asin(_XY(WHLREFH))+rollset)*10*velcorr
      yawt = 0
   end
   PROPANGU1 = limit(rotorcoll+pitcht+rollt,-30,30)
   PROPANGU2 = limit(rotorcoll-pitcht+rollt,-30,30)

   PROPANGD1 = limit(-rotorcoll+pitcht+rollt,-30,30)
   PROPANGD2 = limit(-rotorcoll-pitcht+rollt,-30,30)

   PROPANGF1 = animate(PROPANGF1,-propangset,10)
   PROPANGF2 = PROPANGF1
   PROPANGB1 = animate(PROPANGB1,propangset,10)
   PROPANGB2 = PROPANGB1

   ELEV = animate(limit(ELEV,-40,40),0.9*pitcht,5)
   RUDDER = animate(limit(RUDDER,-10,10),yawt,5)

   if _KEYDOWN(7) > 0 then
      if autoflag == 1 then autoflag = 0
      else autoflag = 1 end
   end
   if _KEYDOWN(9) > 0 then
      if autoflag == 2 then autoflag = 0
      else autoflag = 2 end
   end
   if _KEYDOWN(14) > 0 then
      helimode = 1
      autoflag = 0
   end
   out(5,"[A]: Level flight; [D] : Return to base")
end

function OnFrame()
   getpropstate()
   if mouseflag > 0 then inputmouse() end
   inputctrl()
   engflag = math.mod(engflag+_KEYDOWN(16),2)
   mouseflag = math.mod(mouseflag+_KEYDOWN(15),2)


   if helimode == 1 then
      heli()
      out(2,"[Q] Mode: Helicopter")
   else
      plane()
      out(2,"[Q] Mode: Plane")
   end

   out(0,"Dreamcraft by Bernard 'bwansy'")
   if engflag == 0 then
      out(1,"[E] Engine OFF")
   else
      out(1,"[E] Engine ON")
   end
   gearflag = math.mod(gearflag+_KEYDOWN(13),2)
   if gearflag == 1 then
      NOSEANG1 = animate(NOSEANG1,15,2)
      NOSEANG2 = 180-2*NOSEANG1
      NOSEANG3 = animate(NOSEANG3,75,6)
      if NOSEANG3 == 75 then
         nosebaseang = animate(nosebaseang,90*gearflag,10)
         NOSESTEER = nosebaseang-KEYYAW
      end
   else
      nosebaseang = animate(nosebaseang,90*gearflag,10)
      NOSESTEER = nosebaseang
      if NOSESTEER == 0 then
         NOSEANG1 = animate(NOSEANG1,0,2)
         NOSEANG2 = 180-2*NOSEANG1
         NOSEANG3 = animate(NOSEANG3,0,6)
      end
   end
   GEARANG1 = animate(GEARANG1,-90+135*gearflag,5)
   GEARANG2 = animate(GEARANG2,180-120*gearflag,5)
   GEARBRAKE = math.max(helimode,(1-gearflag))*50
   if helimode == 0 and engflag < 0 and vel < 20 then brake = 70 end
   if _KEYDOWN(11) > 0 then
      basex = _X(WHLREFH)
      basey = _Y(WHLREFH)
      basez = _Z(WHLREFH)
   end
   if engflag == 0 then autoflag = 0 end
   out(3,"[S/X] Throttle: ",KEYTHR*10," %")
   out(4,"[Z/C] Yaw")
   out(8,"[B] set base point")
   mark3d(basex,basey,basez,rgb(255,0,0))
   _ZOOM(45)
end}

_________________
A.K.A. Bernard

bwansy
Admin

Posts : 170
Join date : 2010-07-15

View user profile http://rigidchips.forum-motion.com

Back to top Go down

Re: Dreamcraft

Post by JHaskly on Fri Jul 16, 2010 4:37 pm

One of the best models ever, in my view.

JHaskly
Admin

Posts : 235
Join date : 2010-07-16
Age : 21
Location : Brisbane

View user profile

Back to top Go down

Re: Dreamcraft

Post by Kedji on Sat Jul 17, 2010 5:27 pm

Is this the advanced version of your first one?

Kedji
Plane
Plane

Posts : 26
Join date : 2010-07-16
Age : 22
Location : Philippines

View user profile http://rigidchips.forum-motion.com

Back to top Go down

Re: Dreamcraft

Post by Timothy Ashtön on Tue Jul 20, 2010 6:53 pm

Cool! I like it!
avatar
Timothy Ashtön
Walker
Walker

Posts : 289
Join date : 2010-07-17
Age : 24
Location : Ontario

View user profile http://wildfrontierguidecomplete.blogspot.com/

Back to top Go down

Re: Dreamcraft

Post by speak51 on Sat Aug 20, 2011 7:29 am

LUA compile error? wont load
avatar
speak51
Car
Car

Posts : 9
Join date : 2011-05-07

View user profile

Back to top Go down

Re: Dreamcraft

Post by speak51 on Sat Aug 20, 2011 7:31 am

LUA compile error? wont load
avatar
speak51
Car
Car

Posts : 9
Join date : 2011-05-07

View user profile

Back to top Go down

Re: Dreamcraft

Post by RA2lover on Sat Aug 20, 2011 10:44 am

try this model. it's the same, with bernard's basic.lua copypasted to it

Code:

// [RCD]
Val
{
  ELEV(default=0, min=-400, max=400, disp=0)
  GEARANG1(default=45, min=-400, max=400, disp=0)
  GEARANG2(default=60, min=-400, max=400, disp=0)
  GEARBRAKE(default=0, max=999999999, step=999999999, disp=0)
  KEYPITCH(default=0, min=-10, max=10, step=2, disp=0)
  KEYROLL(default=0, min=-10, max=10, step=2, disp=0)
  KEYTHR(default=0, min=-3, max=10, disp=0)
  KEYYAW(default=0, min=-10, max=10, step=2, disp=0)
  NOSEANG1(default=15, min=-400, max=400, disp=0)
  NOSEANG2(default=150, min=-400, max=400, disp=0)
  NOSEANG3(default=75, min=-400, max=400, disp=0)
  NOSESTEER(default=90, min=-400, max=400, disp=0)
  PROPANGB1(default=90, min=-400, max=400, disp=0)
  PROPANGB2(default=90, min=-400, max=400, disp=0)
  PROPANGD1(default=0, min=-400, max=400, disp=0)
  PROPANGD2(default=0, min=-400, max=400, disp=0)
  PROPANGF1(default=-90, min=-400, max=400, disp=0)
  PROPANGF2(default=-90, min=-400, max=400, disp=0)
  PROPANGU1(default=0, min=-400, max=400, disp=0)
  PROPANGU2(default=0, min=-400, max=400, disp=0)
  RUDDER(default=0, min=-400, max=400, disp=0)
  WHLBRAKEB(default=0, max=999999999, step=999999999, disp=0)
  WHLBRAKED(default=0, max=999999999, step=999999999, disp=0)
  WHLBRAKEF(default=0, max=999999999, step=999999999, disp=0)
  WHLBRAKEU(default=0, max=999999999, step=999999999, disp=0)
  WHLPWRB(default=0, min=-999999999, max=999999999, disp=0)
  WHLPWRD(default=0, min=-999999999, max=999999999, disp=0)
  WHLPWRF(default=0, min=-999999999, max=999999999, disp=0)
  WHLPWRU(default=0, min=-999999999, max=999999999, disp=0)
}
Key
{
  0:KEYPITCH(step=2)
  1:KEYPITCH(step=-2)
  2:KEYROLL(step=2)
  3:KEYROLL(step=-2)
  4:KEYYAW(step=2)
  5:KEYTHR(step=-0.2)
  6:KEYYAW(step=-2)
  8:KEYTHR(step=0.2)
}
Body
{
  Core() {
      S:Weight(angle=180, option=2) { }
      S:Frame(angle=30, option=2, damper=1) {
        S:Frame(angle=-30, damper=1, name=WHLREFH) {
            S:RLW(angle=-90, power=WHLPWRB, brake=WHLBRAKEB, name=WHLB) {
              W:Trim(angle=PROPANGB1, color=#4040FF) { }
              E:Trim(angle=PROPANGB2, color=#4040FF) { }
            }
            N:RLW(angle=-90, power=WHLPWRF, brake=WHLBRAKEF, name=WHLF) {
              E:Trim(angle=PROPANGF2, color=#4040FF) { }
              W:Trim(angle=PROPANGF1, color=#4040FF) { }
            }
            N:RLW(angle=180, power=WHLPWRD, brake=WHLBRAKED, name=WHLD) {
              E:Trim(angle=PROPANGD2, color=#4040FF) {
                  E:Chip(color=#4040FF) {
                    E:Chip(color=#4040FF) { }
                  }
              }
              W:Trim(angle=PROPANGD1, color=#4040FF) {
                  W:Chip(color=#4040FF) {
                    W:Chip(color=#4040FF) { }
                  }
              }
            }
            N:Frame(angle=-90, name=WHLREFV) {
              N:RLW(angle=-90, power=WHLPWRU, brake=WHLBRAKEU, name=WHLU) {
                  E:Trim(angle=PROPANGU2, color=#4040FF) {
                    E:Chip(color=#4040FF) {
                        E:Chip(color=#4040FF) { }
                    }
                  }
                  W:Trim(angle=PROPANGU1, color=#4040FF) {
                    W:Chip(color=#4040FF) {
                        W:Chip(color=#4040FF) { }
                    }
                  }
              }
              N:Cowl(angle=100, color=#808080) {
                  N:Cowl(angle=10, effect=#A0FB) {
                    E:Cowl(angle=120, option=3, effect=#A0FB) { }
                    W:Cowl(angle=120, option=4, effect=#A0FB) { }
                  }
                  S:Cowl(angle=10, color=#808080) {
                    S:Cowl(angle=30, option=5, color=#808080) { }
                  }
                  E:Cowl(angle=135, color=#808080) { }
                  W:Cowl(angle=135, color=#808080) { }
              }
              S:Cowl(angle=100, color=#808080) {
                  S:Cowl(angle=10, effect=#A0FB) {
                    W:Cowl(angle=120, option=3, effect=#A0FB) { }
                    E:Cowl(angle=120, option=4, effect=#A0FB) { }
                  }
                  E:Cowl(angle=135, color=#808080) { }
                  W:Cowl(angle=135, color=#808080) { }
              }
              E:Cowl(angle=-90, color=#808080) {
                  E:Cowl(angle=-30, option=5, color=#808080) { }
              }
              W:Cowl(angle=-90, color=#808080) {
                  W:Cowl(angle=-30, option=5, color=#808080) { }
              }
            }
            S:Frame(angle=-30) {
              S:Frame(angle=30) {
                  N:Chip() { }
                  S:Frame() {
                    S:Chip(angle=ELEV) {
                        W:Chip() {
                          N:Cowl(option=3, color=#808080) { }
                        }
                        E:Chip() {
                          N:Cowl(option=4, color=#808080) { }
                        }
                    }
                    S:TrimF(angle=90, option=1) {
                        N:Chip(angle=RUDDER) {
                          S:Chip() {
                              E:Chip() { }
                          }
                          E:Cowl(option=3, color=#808080) { }
                        }
                    }
                    N:Cowl(angle=180, color=#808080) { }
                  }
                  N:Cowl(angle=180, color=#808080) { }
              }
            }
            E:Frame(angle=GEARANG1, option=1) {
              S:RudderF(angle=-GEARANG2, option=1) {
                  S:RLW(angle=180, brake=GEARBRAKE) { }
              }
              S:Cowl(angle=180, option=3, color=#808080) { }
            }
            W:Frame(angle=GEARANG1, option=1) {
              S:RudderF(angle=GEARANG2, option=1) {
                  S:RLW(angle=180, brake=GEARBRAKE) { }
              }
              S:Cowl(angle=180, option=4, color=#808080) { }
            }
            S:Cowl(angle=-30, option=5, color=#808080) { }
        }
      }
      S:RudderF(angle=NOSESTEER) {
        N:Frame(angle=NOSEANG1, option=1) {
            N:Frame(angle=NOSEANG2, option=1) {
              N:RLW(angle=-NOSEANG3, brake=GEARBRAKE) { }
            }
        }
      }
  }
}
Lua
{--Bernard.lua, for common functions, basic drawing functions
--Version 100317

--copied from Japanese wiki
math.int = function (x) if x < 0 then return math.ceil(x) else return math.floor(x) end end
math.fix = math.int
math.round = function (x) return math.int(x + 0.5*math.sgn(x)) end
math.sgn = function (x) if x < 0 then return -1 elseif x == 0 then return 0 else return 1 end end
math.len2 = function (a, b) return math.sqrt(a*a+b*b) end
math.len3 = function (a, b, c) return math.sqrt(a*a+b*b+c*c) end


-- removing "math."
pi = math.pi

int = function (x) return math.int(x) end
fix = function (x) return math.fix(x) end
round = function (x) return math.round(x) end
sgn = function (x) return math.sgn(x) end
len2 = function (x,y,z) return math.len2(x,y,z) end
len3 = function (x,y,z) return math.len3(x,y,z) end
ceil = math.ceil
floor = math.floor
abs = math.abs
mod = math.mod
sqrt = math.sqrt
sin = math.sin
cos = math.cos
tan = math.tan
asin = math.asin
acos = math.acos
atan = math.atan
atan2 = math.atan2
deg = math.deg
rad = math.rad
sinh = math.sinh
cosh = math.cosh
tanh = math.tanh
exp = math.exp
log = math.log
log10 = math.log10


-- Degree trig functions
sind = function (x) return sin(rad(x)) end
cosd = function (x) return cos(rad(x)) end
tand = function (x) return tan(rad(x)) end
asind = function (x) return deg(asin(x)) end
acosd = function (x) return deg(acos(x)) end
atand = function (x) return deg(atan(x)) end
atand2 = function (y,x) return deg(atan2(y,x)) end


-- Additional functions
ceil2 = function(x,b) return ceil(x/b)*b end
floor2 = function(x,b) return floor(x/b)*b end
round2 = function(x,b) return round(x/b)*b end
int2 = function(x,b) return int(x/b)*b end
sqrt2 = function(x) return sgn(x)*sqrt(abs(x)) end
pow2 = function(x,b) return sgn(x)*(abs(x)^b) end

triwave = function(t,a) -- a = lambda/2
   a = ifnil(a,1)
   local temp = floor(t/a+0.5)
   return 2/a*(t-a*temp)*(-1)^temp
end

factorial = function(n)
   n = floor(n)
   prod = 1
   if n > 0 then
      for i = 1,n do
         prod = prod*i
      end
   end
   return prod
end

mean = function(...)
   if arg == nil then return 0
   else
      local s = 0
      for k,v in ipairs(arg) do
         s = s+v
      end
      return s/table.getn(arg)
   end
end

function getht(chip)
   local ht = _H(chip)
   if ht < 0 then ht = _Y(chip) end
   return ht
end

-- Increments the value from v1 to v2 by dv each frame.
function animate(v1,v2,dv)
   if math.abs(v1-v2) < dv then v1 = v2
   else
      if v1 < v2 then v1 = v1+dv end
      if v1 > v2 then v1 = v1-dv end
   end
   return v1
end

-- Same as above, for rotations in degrees
function animatedeg(v1,v2,dv)
   local diff = normaldeg(v2-v1)
   if math.abs(diff) < dv then v1 = v2
   else
      if diff > 0 then v1 = normaldeg(v1+dv) end
      if diff < 0 then v1 = normaldeg(v1-dv) end
   end
   return v1
end

-- Same as above, but for radians instead. Not sure if it will ever be used at all
function animaterad(v1,v2,dv)
   local diff = normalrad(v2-v1)
   if math.abs(diff) < dv then v1 = v2
   else
      if diff > 0 then v1 = normalrad(v1+dv) end
      if diff < 0 then v1 = normalrad(v1-dv) end
   end
   return v1
end

-- Similar to mod but min. value is one. Mainly for gattling gun controls.
function cycle(num,base)
   local n = math.mod(num,base)
   if n <= 0 then n = n+base end
   return n
end

function mod2(num,base)
   return cycle(num+1,base)-1
end

-- Sets range for value x
function limit(x,n1,n2)
   if n1 > n2 then
      maxx,minx = n1,n2
   else
      maxx,minx = n2,n1
   end
   if x < minx then x = minx end
   if x > maxx then x = maxx end
   return x
end

-- Normalises angle a1 so that -pi < a1 <= pi
function normalrad(a1)
   while a1 <= -pi do a1 = a1+pi*2 end
   while a1 > pi do a1 = a1-pi*2 end
   return a1
end

-- Same as above, but for degrees. -180 < a1 <= 180
function normaldeg(a1)
   while a1 <= -180 do a1= a1+360 end
   while a1 > 180 do a1 = a1-360 end
   return a1
end

-- Same as normaldeg, but outputs 0 <= a1 < 360
function pvedeg(a1)
   while a1 < 0 do a1 = a1+360 end
   while a1 >= 360 do a1 = a1-360 end
   return a1
end

function lininterp(x1,x2,p,mode)
   if mode == "r" then
      return x1+(x2-x1)*p
   elseif mode == "x" then
      return limit((p-x1)/(x2-x1),0,1) end
end

-- Converts rgb to 3-byte integer
function rgb(r,g,b)
   r = floor(limit(ifnil(r),0,255))
   g = floor(limit(ifnil(g),0,255))
   b = floor(limit(ifnil(b),0,255))
   return r*65536+g*256+b
end

function rgb1(r,g,b)
   return rgb(r*255,g*255,b*255)
end

function setrgb(r,g,b)
   _SETCOLOR(rgb(r,g,b))
end

-- Hue, Saturation, Lightness
-- 0 <= h < 360, 0 <= 1 <= s, 0 <= l <= 1
function hsl(h,s,l)
   h = pvedeg(ifnil(h))
   s = limit(ifnil(s),0,1)
   l = limit(ifnil(l),0,1)
   
   local c
   if l <= 0.5 then
      c = 2*l*s
   else
      c = 2*(1-l)*s
   end
   local x = c*(1-abs(mod(h,120)/60-1))
   
   if h >= 0 and h < 60 then
      r,g,b = c,x,0
   elseif h >= 60 and h < 120 then
      r,g,b = x,c,0
   elseif h >= 120 and h < 180 then
      r,g,b = 0,c,x
   elseif h >= 180 and h < 240 then
      r,g,b = 0,x,c
   elseif h >= 240 and h < 300 then
      r,g,b = x,0,c
   elseif h >= 300 and h < 360 then
      r,g,b = c,0,x
   end

   local m = l-c/2
   
   return rgb1(r+m,g+m,b+m)
end


function hexcol(s)
   return limit(floor(ifnil(tonumber(s,16))),256*256*256,0)
end

function decodecol(col,mode)
   mode = string.lower(mode)
   if mode == "rgb" then
      r = floor(col/65536)
      rem = mod(col,65536)
      g = floor(rem/256)
      b = mod(rem,256)
      return r,g,b
   end
end

function ifnil(x,d)
   if d == nil then d = 0 end
   if x == nil then x = d end
   return x
end

function switch(var,key)
   return math.mod(var+_KEYDOWN(key),2)
end

function vcorr(v,b1,b2)
   return b1+(1-b1)/sqrt(1+(v*b2)^2)
end

function ctrllock(v,v1,v2)
   return limit((abs(v)-v1)/(v2-v1),0,1)
end

function chipdist(c1,c2)
   return len3(_X(c1)-_X(c2),_Y(c1)-_Y(c2),_Z(c1)-_Z(c2))
end

function num2time(x) -- converts number into time format
   x = limit(x,-5999.99,5999.99)
   local minute,second = floor(abs(x)/60),mod(abs(x),60)
   smin,ssec = string.format("%i",minute),string.format("%.2f",second)
   if minute < 10 then smin = "0"..smin end
   if x < 0 then smin = "-"..smin end
   if second < 10 then ssec = "0"..ssec end
   return smin..":"..ssec
end

-- Laser sight shooting from chip [chip] with colour (3-byte value),
-- along [axis] axis: 1 = x, 2 = y, 3 = z, negative value reverses direction
function laser(chip,colour,axis)
   local x,y,z,dx,dy,dz
   local len = math.sgn(axis)*2000
   local m = math.abs(axis)
   local x,y,z = _X(chip),_Y(chip),_Z(chip)
   if m == 1 then
      dx = _XX(chip)*len
      dy = _XY(chip)*len
      dz = _XZ(chip)*len
   elseif m == 2 then
      dx = _YX(chip)*len
      dy = _YY(chip)*len
      dz = _YZ(chip)*len
   else
      dx = _ZX(chip)*len
      dy = _ZY(chip)*len
      dz = _ZZ(chip)*len
   end
   _SETCOLOR(colour)
   _MOVE3D(x,y,z)
   _LINE3D(x+dx,y+dy,z+dz)
end

function showaxes(chip)
   laser(chip,rgb(255,0,0),1)
   laser(chip,rgb(0,255,0),2)
   laser(chip,rgb(0,0,255),3)
end

-- Creates a 3D marker
function mark3d(param1,param2,param3,param4)
   if type(param1) == "table" then
      markx,marky,markz = vtr3.uvtr(param1)
      col = param2
   else
      markx,marky,markz,col = param1,param2,param3,param4
   end
   if col ~= nil then _SETCOLOR(col) end
   _MOVE3D(markx+2,marky,markz)
   _LINE3D(markx-2,marky,markz)
   _MOVE3D(markx,marky+2,markz)
   _LINE3D(markx,marky-2,markz)
   _MOVE3D(markx,marky,markz+2)
   _LINE3D(markx,marky,markz-2)
end

function mark2d(markx,marky,col,msize)
   msize = ifnil(msize,0.04)
   if col ~= nil then _SETCOLOR(col) end
   _MOVE2D(markx,marky-msize)
   _LINE2D(markx-msize,marky)
   _LINE2D(markx,marky+msize)
   _LINE2D(markx+msize,marky)
   _LINE2D(markx,marky-msize)
end

function inputmouse(dzone,dcross)
   local scrx = _WIDTH()
   local scry = _HEIGHT()
   if dzone == nil then dzone = 0 end
   if dcross == nil then dcross = 1 end
   if dcross > 0 then
      _SETCOLOR(rgb(255,255,0))
      _MOVE2D(dzone,dzone)
      _LINE2D(-dzone,dzone)
      _MOVE2D(dzone,-dzone)
      _LINE2D(-dzone,-dzone)
      _MOVE2D(-dzone,dzone)
      _LINE2D(-dzone,-dzone)
      _MOVE2D(dzone,dzone)
      _LINE2D(dzone,-dzone)
      _MOVE2D(dzone,0)
      _LINE2D(dzone+0.05,0)
      _MOVE2D(-dzone,0)
      _LINE2D(-dzone-0.05,0)
      _MOVE2D(0,dzone)
      _LINE2D(0,dzone+0.05)
      _MOVE2D(0,-dzone)
      _LINE2D(0,-dzone-0.05)
   end
   local mousex = limit((1-(_MX()/(scrx))*2)*(scrx/scry)/0.9,-1,1)
   local mousey = limit((1-(_MY()/(scry))*2)/0.9,-1,1)
   if math.abs(mousex) < dzone and math.abs(mousey) < dzone then mousex,mousey = 0,0 end
--   if math.abs(mousey) < dzone then mousey = 0 end
   return mousex,mousey
end

-- draws a small origin-pointing compass
function compass(chip,dir)
   if chip == nil then chip = 0 end
   if dir == nil then dir = -3 end
   local cx,cy = -(_WIDTH()/_HEIGHT())+0.2,-0.8
   local r,step = 0.05,20
   local r2,r3 = 0.06,0.07
   _SETCOLOR(rgb(0,255,0))
   _MOVE2D(cx,cy+r)
   for i = 1,step do
      local th = i*pi*2/step
      _LINE2D(cx+r*sin(th),cy+r*cos(th))
   end
   _MOVE2D(cx,cy+r2)
   for i = 1,step do
      local th = i*pi*2/step
      _LINE2D(cx+r2*sin(th),cy+r2*cos(th))
   end
   local ang = atan2(_X(chip),_Z(chip))
   local head
   local axis = abs(dir)
   if axis == 1 then
      head = atan2(_XX(chip),_XZ(chip))
   elseif axis == 2 then
      head = atan2(_YX(chip),_YZ(chip))
   else
      head = atan2(_ZX(chip),_ZZ(chip))
   end
   if sgn(dir) > 0 then head = head+pi end
   local rel = normalrad(ang-head)
   _SETCOLOR(rgb(0,255,0))
   _MOVE2D(cx,cy)
   _LINE2D(cx,cy+r)
   
   _MOVE2D(cx+r*cos(-head),cy-r*sin(-head))
   _LINE2D(cx+r3*cos(-head),cy-r3*sin(-head))
   _MOVE2D(cx-r*cos(-head),cy+r*sin(-head))
   _LINE2D(cx-r3*cos(-head),cy+r3*sin(-head))
   
   _MOVE2D(cx-r*sin(-head),cy-r*cos(-head))
   _LINE2D(cx-r3*sin(-head),cy-r3*cos(-head))
   _SETCOLOR(rgb(255,0,0))
   _MOVE2D(cx+r*sin(-head),cy+r*cos(-head))   
   _LINE2D(cx+r3*sin(-head),cy+r3*cos(-head))   
   _SETCOLOR(rgb(255,255,255))
   _MOVE2D(cx,cy)
   _LINE2D(cx+r*sin(rel),cy+r*cos(rel))
end


function init()
  engflag = 0
  gearflag = 1
  nosebaseang = 90
  helimode = 1

  rotorcoll = 0

  pi = math.pi
  dt = 10*_DT()

  autoflag = 0

  basex = _X(WHLREFH)
  basey = _Y(WHLREFH)
  basez = _Z(WHLREFH)
 
  mouseflag = 1
  scrx = _WIDTH()
  scry = _HEIGHT()
end
function OnInit()
  init()
end
function OnReset()
  init()
end

function getpropstate()
  wu = _WY(WHLU)
  wd = _WY(WHLD)
  wf = _WY(WHLF)
  wb = _WY(WHLB)

  ryu = normalrad(_RY(WHLU,WHLREFH)-dt*wu)
  ryd = normalrad(_RY(WHLD,WHLREFH)-dt*wd)
  ryf = normalrad(_RY(WHLF,WHLREFV)-dt*wf)
  ryb = normalrad(_RY(WHLB,WHLREFV)+pi-dt*wb)
end

function inputmouse()
  dzone = 0.03
  _SETCOLOR(rgb(255,255,0))
  _MOVE2D(0.8,0.9)
  _LINE2D(0.9,0.9)
  _LINE2D(0.9,0.8)
  _MOVE2D(-0.8,0.9)
  _LINE2D(-0.9,0.9)
  _LINE2D(-0.9,0.8)
  _MOVE2D(0.8,-0.9)
  _LINE2D(0.9,-0.9)
  _LINE2D(0.9,-0.8)
  _MOVE2D(-0.8,-0.9)
  _LINE2D(-0.9,-0.9)
  _LINE2D(-0.9,-0.8)
 
  _MOVE2D(0.1,dzone)
  _LINE2D(-0.1,dzone)
  _MOVE2D(0.1,-dzone)
  _LINE2D(-0.1,-dzone)
  _MOVE2D(-dzone,0.1)
  _LINE2D(-dzone,-0.1)
  _MOVE2D(dzone,0.1)
  _LINE2D(dzone,-0.1)
 
  mousex = limit((1-(_MX()/(scrx))*2)*(scrx/scry)/0.9,-1,1)
  mousey = limit((1-(_MY()/(scry))*2)/0.9,-1,1)
  if math.abs(mousex) < dzone then mousex = 0 end
  if math.abs(mousey) < dzone then mousey = 0 end
  mousepitch = mousey*10
  mouseroll = mousex*10
end

function inputctrl()
  inpthr = KEYTHR
  if mouseflag > 0 then
      inppitch = limit(KEYPITCH+mousepitch,-10,10)
      inproll = limit(KEYROLL+mouseroll,-10,10)
  else
      inppitch = KEYPITCH
      inproll = KEYROLL
  end
  inpyaw = KEYYAW
end

function heli()
  WHLPWRU = (WHLPWRU+(40-wu)*300)*engflag
  WHLPWRD = (WHLPWRD+(40+wd)*-300)*engflag

  WHLPWRF = -ryf*4000-(wf-_WZ(0)*0.3)*3000
  if math.abs(ryf) < 0.05 and math.abs(wf) < 0.1 then WHLBRAKEF = 1000 end

  WHLPWRB = ryb*4000-(wb+_WZ(0)*0.3)*3000
  if math.abs(ryb) < 0.05 and math.abs(wb) < 0.1 then WHLBRAKEB = 1000 end

  if autoflag == 0 and engflag == 1 and math.abs(KEYTHR-5) < 0.5 and inproll == 0 and inppitch == 0 and math.abs(_VY(WHLREFH)) < 1.5 and math.len2(_VX(WHLREFH),_VZ(WHLREFH)) < 4 then autoflag = 1 end
  if math.abs(KEYTHR-5) > 0.5 or inproll ~= 0 or inppitch ~= 0  then autoflag = 0 end
  if _KEYDOWN(9) > 0 then
      autoflag = 2
      tgtx = basex
      tgtz = basez
      tgty = hcy
      end
  if autoflag == 0 then
      pitcht = 1.5*inppitch-_ZY(0)*30+1
      rollt = 1.5*inproll+_XY(0)*30
 
      rotorcoll = animate(rotorcoll,1.7*KEYTHR,3)

      tgtx = _X(WHLREFH)
      tgty = _Y(WHLREFH)
      tgtz = _Z(WHLREFH)
  else
      hcx = _X(WHLREFH)
      hcy = _Y(WHLREFH)
      hcz = _Z(WHLREFH)
      dist = math.len2(hcx-tgtx,hcz-tgtz)
      if autoflag == 2 and dist < 30 then tgty = animate(tgty,basey,0.15) end
      corehead = math.atan2(_ZX(0),_ZZ(0))
      tgtdir = math.atan2(-tgtx+hcx,-tgtz+hcz)
      tgthead = tgtdir
      reldir = normalrad(tgtdir-corehead)
      pitchset = limit(dist*4*math.cos(reldir)+_VZ(WHLREFH)*20,-20,20)
      rollset = limit(-dist*4*math.sin(reldir)-_VX(WHLREFH)*20,-20,20)
      pitcht = (math.rad(pitchset)-math.asin(_ZY(0)))*20+1
      rollt = (math.rad(rollset)+math.asin(_XY(0)))*20
      rotorcoll = 8.5+(tgty-hcy)*40-_VY(WHLREFH)*5

      if autoflag == 1 then out(6,"Autopilot: Hover")
      elseif autoflag == 2 then out(6,"Autopilot: Return to base") end
  end

  yawt = KEYYAW+_WY(0)*10

  PROPANGU1 = limit(rotorcoll+pitcht*math.sin(ryu)+rollt*math.cos(ryu),-30,30)
  PROPANGU2 = limit(rotorcoll-pitcht*math.sin(ryu)-rollt*math.cos(ryu),-30,30)

  PROPANGD1 = limit(-rotorcoll-pitcht*math.sin(ryd)-rollt*math.cos(ryd),-30,30)
  PROPANGD2 = limit(-rotorcoll-pitcht*math.sin(ryd)+rollt*math.cos(ryd),-30,30)

  WHLBRAKEU = yawt*30
  WHLBRAKED = yawt*-30

  PROPANGF1 = animate(PROPANGF1,-90,10)
  PROPANGF2 = PROPANGF1
  PROPANGB1 = animate(PROPANGB1,90,10)
  PROPANGB2 = PROPANGB1

  ELEV = animate(ELEV,0,5)
  RUDDER = animate(RUDDER,0,5)

  if _KEYDOWN(14) > 0 then
      helimode = 0
      autoflag = 0
  end

  out(5,"[D] : RTB autopilot")
end

function plane()
  vel = -_VZ(0)
  velcorr = 1/(1+(vel*0.02))
  WHLPWRU = normalrad(ryu+pi)*80000-wu*15000
  if math.abs(wu) < 0.3 then WHLBRAKEU = 20000 end
  WHLPWRD = normalrad(ryd+pi)*80000-wd*15000
  if math.abs(wd) < 0.3 then WHLBRAKED = 20000 end

  if engflag > 0 then
--[[      WHLPWRF = WHLPWRF-(75+wf)*150
      WHLPWRB = WHLPWRB-(75+wb)*150
      out(10,WHLPWRF)
      out(11,WHLPWRF)]]
      WHLPWRF = -300000
      WHLPWRB = -300000
      propangset = limit((1+math.sin(math.atan(vel/10)))*KEYTHR*3,-10,70)
  else
      WHLPWRF = -ryf*5000-(wf-_WZ(0))*3000
      if math.abs(ryf) < 0.05 and math.abs(wf) < 0.1 then WHLBRAKEF = 1000 end

      WHLPWRB = ryb*5000-(wb+_WZ(0))*3000
      if math.abs(ryb) < 0.05 and math.abs(wb) < 0.1 then WHLBRAKEB = 1000 end
      propangset = 90
  end
 
  rotorcoll = animate(rotorcoll,0,3)

  if autoflag == 0 then
      pitcht = 1.7*inppitch
      rollt = 1.5*inproll*velcorr
      yawt = KEYYAW
      tgty = _Y(WHLREFH)
  else
      hcx = _X(WHLREFH)
      hcy = _Y(WHLREFH)
      hcz = _Z(WHLREFH)

      if autoflag == 1 then
        tgty = limit(tgty-inppitch*0.08*vel/60*_YY(0),7,3000)
        rollset = math.rad(limit(inproll*6*(vel/60),-65,65))
        if vel < 15 then autoflag = 0 end
        KEYTHR = limit(KEYTHR,6,10)
        out(6,"Autopilot: Level flight")
      elseif autoflag == 2 then
        corehead = math.atan2(_ZX(0),_ZZ(0))
        tgty = animate(tgty,basey+80,0.5*vel/60*_YY(0))
        tgtdir = math.atan2(-basex+hcx,-basez+hcz)
--        tgtdir = 0
        reldir = normalrad(tgtdir-corehead) 
        dist = math.len2(hcx-basex,hcz-basez)
        rollset = math.rad(limit(-reldir*vel*3,-60,60))
        if dist > 250 then KEYTHR = animate(KEYTHR,limit(math.floor((dist-100)*0.2)*0.2,0,10),0.2)
        else KEYTHR = animate(KEYTHR,0,0.2) end
        if KEYTHR == 0 then
            helimode = 1
            KEYTHR = 5
            tgtx = basex
            tgtz = basez
            tgty = hcy-4
            end
        out(6,"Autopilot: Return to base")
      end
      liftcomp = 10*velcorr
      pitchset = (hcy-tgty)*2-liftcomp
      pitcht = (-_ZY(0)+math.rad(pitchset))*50
      rollt = (math.asin(_XY(WHLREFH))+rollset)*10*velcorr
      yawt = 0
  end
  PROPANGU1 = limit(rotorcoll+pitcht+rollt,-30,30)
  PROPANGU2 = limit(rotorcoll-pitcht+rollt,-30,30)

  PROPANGD1 = limit(-rotorcoll+pitcht+rollt,-30,30)
  PROPANGD2 = limit(-rotorcoll-pitcht+rollt,-30,30)

  PROPANGF1 = animate(PROPANGF1,-propangset,10)
  PROPANGF2 = PROPANGF1
  PROPANGB1 = animate(PROPANGB1,propangset,10)
  PROPANGB2 = PROPANGB1

  ELEV = animate(limit(ELEV,-40,40),0.9*pitcht,5)
  RUDDER = animate(limit(RUDDER,-10,10),yawt,5)

  if _KEYDOWN(7) > 0 then
      if autoflag == 1 then autoflag = 0
      else autoflag = 1 end
  end
  if _KEYDOWN(9) > 0 then
      if autoflag == 2 then autoflag = 0
      else autoflag = 2 end
  end
  if _KEYDOWN(14) > 0 then
      helimode = 1
      autoflag = 0
  end
  out(5,"[A]: Level flight; [D] : Return to base")
end

function OnFrame()
  getpropstate()
  if mouseflag > 0 then inputmouse() end
  inputctrl()
  engflag = math.mod(engflag+_KEYDOWN(16),2)
  mouseflag = math.mod(mouseflag+_KEYDOWN(15),2)


  if helimode == 1 then
      heli()
      out(2,"[Q] Mode: Helicopter")
  else
      plane()
      out(2,"[Q] Mode: Plane")
  end

  out(0,"Dreamcraft by Bernard 'bwansy'")
  if engflag == 0 then
      out(1,"[E] Engine OFF")
  else
      out(1,"[E] Engine ON")
  end
  gearflag = math.mod(gearflag+_KEYDOWN(13),2)
  if gearflag == 1 then
      NOSEANG1 = animate(NOSEANG1,15,2)
      NOSEANG2 = 180-2*NOSEANG1
      NOSEANG3 = animate(NOSEANG3,75,6)
      if NOSEANG3 == 75 then
        nosebaseang = animate(nosebaseang,90*gearflag,10)
        NOSESTEER = nosebaseang-KEYYAW
      end
  else
      nosebaseang = animate(nosebaseang,90*gearflag,10)
      NOSESTEER = nosebaseang
      if NOSESTEER == 0 then
        NOSEANG1 = animate(NOSEANG1,0,2)
        NOSEANG2 = 180-2*NOSEANG1
        NOSEANG3 = animate(NOSEANG3,0,6)
      end
  end
  GEARANG1 = animate(GEARANG1,-90+135*gearflag,5)
  GEARANG2 = animate(GEARANG2,180-120*gearflag,5)
  GEARBRAKE = math.max(helimode,(1-gearflag))*50
  if helimode == 0 and engflag < 0 and vel < 20 then brake = 70 end
  if _KEYDOWN(11) > 0 then
      basex = _X(WHLREFH)
      basey = _Y(WHLREFH)
      basez = _Z(WHLREFH)
  end
  if engflag == 0 then autoflag = 0 end
  out(3,"[S/X] Throttle: ",KEYTHR*10," %")
  out(4,"[Z/C] Yaw")
  out(8,"[B] set base point")
  mark3d(basex,basey,basez,rgb(255,0,0))
  _ZOOM(45)
end}
avatar
RA2lover
Walker
Walker

Posts : 382
Join date : 2010-10-11
Age : 22
Location : Brazil

View user profile

Back to top Go down

Re: Dreamcraft

Post by Timothy Ashtön on Sat Aug 20, 2011 6:25 pm

It might be a Library error. If so, in the script section of RC, update to >bwansy's latest library.<


Last edited by Timothy Ashtön on Mon Nov 26, 2012 6:38 am; edited 2 times in total
avatar
Timothy Ashtön
Walker
Walker

Posts : 289
Join date : 2010-07-17
Age : 24
Location : Ontario

View user profile http://wildfrontierguidecomplete.blogspot.com/

Back to top Go down

Re: Dreamcraft

Post by speak51 on Sun Nov 25, 2012 12:39 am

WOW it's AWESOME!!! thanks for helping out by making another link =D
avatar
speak51
Car
Car

Posts : 9
Join date : 2011-05-07

View user profile

Back to top Go down

Re: Dreamcraft

Post by Sponsored content


Sponsored content


Back to top Go down

View previous topic View next topic Back to top

- Similar topics

 
Permissions in this forum:
You cannot reply to topics in this forum