Advertisement
Guest User

Untitled

a guest
Jun 16th, 2016
308
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
E 5.53 KB | None | 0 0
  1. @name Starkkz's Auto Landing Gear x3 [Forward, Left, Right]
  2. @inputs Parent:entity Wheels:array
  3. @persist [FrontWheel LeftWheel RightWheel]:entity
  4. @persist [FrontHolo LeftHolo RightHolo]:entity
  5. @persist Update FirstUpdate Active
  6.  
  7. if (first()){
  8.    runOnLast(1)
  9.    rangerPersist(1)
  10.    rangerFilter(Wheels)
  11.    
  12.    local HighestX = 0
  13.    local HighestY = 0
  14.    local LowestY = 0
  15.    foreach (I, Wheel:entity = Wheels){
  16.        local Position = Parent:toLocal(Wheel:pos())
  17.        if (abs(Position:x()) > HighestX){
  18.            HighestX = abs(Position:x())
  19.            FrontWheel = Wheel
  20.        }
  21.        if (Position:y() < LowestY){
  22.            RightWheel = Wheel
  23.            LowestY = Position:y()
  24.        }
  25.        if (Position:y() > HighestY){
  26.            LeftWheel = Wheel
  27.            HighestY = Position:y()
  28.        }
  29.        Wheel:setAlpha(0)
  30.    }
  31.    FrontRanger = rangerOffset(100, FrontWheel:pos(), vec(0, 0, 1))
  32.    LeftRanger = rangerOffset(100, LeftWheel:pos(), vec(0, 0, 1))
  33.    RightRanger = rangerOffset(100, RightWheel:pos(), vec(0, 0, 1))
  34.    
  35.    FrontHolo = holoCreate(1)
  36.    holoAlpha(1, 0)
  37.    holoPos(1, FrontRanger:pos() + vec(0, 0, FrontWheel:boxSize():z()/2))
  38.    holoAng(1, Parent:angles())
  39.    holoParent(1, Parent)
  40.    
  41.    LeftHolo = holoCreate(2)
  42.    holoAlpha(2, 0)
  43.    holoPos(2, LeftRanger:pos() + vec(0, -LeftWheel:boxSize():y()/2, 0))
  44.    holoAng(2, Parent:angles())
  45.    holoParent(2, Parent)
  46.    
  47.    RightHolo = holoCreate(3)
  48.    holoAlpha(3, 0)
  49.    holoPos(3, RightRanger:pos() + vec(0, RightWheel:boxSize():y()/2, 0))
  50.    holoAng(3, Parent:angles())
  51.    holoParent(3, Parent)
  52.    
  53.    holoCreate(4)
  54.    holoPos(4, FrontWheel:pos())
  55.    holoAng(4, FrontWheel:angles())
  56.    holoModel(4, FrontWheel:model())
  57.    holoParent(4, 1)
  58.    
  59.    holoCreate(5)
  60.    holoPos(5, LeftWheel:pos())
  61.    holoAng(5, LeftWheel:angles())
  62.    holoModel(5, LeftWheel:model())
  63.    holoParent(5, 2)
  64.    
  65.    holoCreate(6)
  66.    holoPos(6, RightWheel:pos())
  67.    holoAng(6, RightWheel:angles())
  68.    holoModel(6, RightWheel:model())
  69.    holoParent(6, 3)
  70.    
  71.    holoCreate(7)
  72.    holoAng(7, Parent:toWorld(ang(0, 90, 0)))
  73.    holoPos(7, FrontWheel:toWorld(vec(0, -FrontWheel:boxSize():y()/2, 0)))
  74.    holoScale(7, vec(1, 1, (FrontRanger:distance() + FrontWheel:boxSize():z()/2)/23))
  75.    holoModel(7, "models/sprops/trans/misc/shock_3.mdl")
  76.    holoParent(7, 1)
  77.    
  78.    holoCreate(8)
  79.    holoAng(8, Parent:toWorld(ang(0, 90, 0)))
  80.    holoPos(8, FrontWheel:toWorld(vec(0, FrontWheel:boxSize():y()/2, 0)))
  81.    holoScale(8, vec(1, 1, (FrontRanger:distance() + FrontWheel:boxSize():z()/2)/23))
  82.    holoModel(8, "models/sprops/trans/misc/shock_3.mdl")
  83.    holoParent(8, 1)
  84.    
  85.    holoCreate(9)
  86.    holoAng(9, Parent:toWorld(ang(0, 90, 0)))
  87.    holoPos(9, LeftWheel:toWorld(vec(0, -LeftWheel:boxSize():y()/2, 0)))
  88.    holoScale(9, vec(1, 1, (LeftRanger:distance() + LeftWheel:boxSize():y()/2)/23))
  89.    holoModel(9, "models/sprops/trans/misc/shock_3.mdl")
  90.    holoParent(9, 2)
  91.    
  92.    holoCreate(10)
  93.    holoAng(10, Parent:toWorld(ang(0, 90, 0)))
  94.    holoPos(10, RightWheel:toWorld(vec(0, RightWheel:boxSize():y()/2, 0)))
  95.    holoScale(10, vec(1, 1, (RightRanger:distance() + RightWheel:boxSize():y()/2)/23))
  96.    holoModel(10, "models/sprops/trans/misc/shock_3.mdl")
  97.    holoParent(10, 3)
  98.    
  99.    rangerFilter(Parent)
  100.    rangerFilter(Parent:getConstraints())
  101.    
  102.    timer("Rotate", 100)
  103.    timer("CheckGround", 100)
  104. }elseif (dupefinished()){
  105.    rangerFilter(Parent)
  106.    rangerFilter(Parent:getConstraints())
  107. }elseif (clk("Gear")){
  108.    Update = 0
  109.    FirstUpdate = 0
  110.    local FrontAngle = round(Parent:toLocal(FrontHolo:angles()))
  111.    local LeftAngle = round(Parent:toLocal(LeftHolo:angles()))
  112.    local RightAngle = round(Parent:toLocal(RightHolo:angles()))
  113.    if (Active){
  114.        if (FrontAngle:pitch() < 90){
  115.            FrontAngle = FrontAngle + ang(10, 0, 0)
  116.            Update = 1
  117.        }
  118.        if (LeftAngle:roll() > -90){
  119.            LeftAngle = LeftAngle - ang(0, 0, 10)
  120.            Update = 1
  121.        }
  122.        if (RightAngle:roll() < 90){
  123.            RightAngle = RightAngle + ang(0, 0, 10)
  124.            Update = 1
  125.        }
  126.    }else{
  127.        if (FrontAngle:pitch() > 0){
  128.            FrontAngle = FrontAngle - ang(10, 0, 0)
  129.            Update = 1
  130.        }
  131.        if (LeftAngle:roll() < 0){
  132.            LeftAngle = LeftAngle + ang(0, 0, 10)
  133.            Update = 1
  134.        }
  135.        if (RightAngle:roll() > 0){
  136.            RightAngle = RightAngle - ang(0, 0, 10)
  137.            Update = 1
  138.        }
  139.    }
  140.    if (Update){
  141.        holoAng(1, Parent:toWorld(FrontAngle))
  142.        holoAng(2, Parent:toWorld(LeftAngle))
  143.        holoAng(3, Parent:toWorld(RightAngle))
  144.        timer("Gear", 100)
  145.    }
  146. }elseif (clk("Rotate")){
  147.    if (!Active & !Update & !FirstUpdate){
  148.        holoAng(4, FrontWheel:angles())
  149.        holoAng(5, LeftWheel:angles())
  150.        holoAng(6, RightWheel:angles())
  151.    }
  152.    timer("Rotate", 100)
  153. }elseif (clk("CheckGround")){
  154.    local Flies = 1
  155.    foreach (I, Entity:entity = Wheels){
  156.        local Ranger = rangerOffset(100, Entity:pos(), vec(0, 0, -1))
  157.        if (Ranger:hit()){
  158.            Flies = 0
  159.            break
  160.        }
  161.    }
  162.    if (Flies != Active){
  163.        FirstUpdate = 1
  164.        Active = Flies
  165.        stoptimer("Gear")
  166.        timer("Gear", 100)
  167.    }
  168.    timer("CheckGround", 100)
  169. }elseif (last()){
  170.    FrontWheel:setAlpha(255)
  171.    LeftWheel:setAlpha(255)
  172.    RightWheel:setAlpha(255)
  173. }elseif (~Wheels | ~Parent){
  174.    reset()
  175. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement