Guest User

Untitled

a guest
Mar 8th, 2016
97
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. @name Garuda - Fighter Control
  2. @inputs CanopyEnts:array CanopyToggle
  3. @inputs PilotPod:wirelink CopilotPod:wirelink
  4. @inputs Effects:wirelink
  5. @outputs EngineThrottle VTOLFXToggle EngineFXToggle
  6. @outputs Flight_State Offset:vector GroundDist LGear_InAnim Canopy_InAnim CurAng:angle TargetAng:angle
  7. #Ship Vars
  8. @persist Parts:array Parent:entity LastFrame
  9. #Input Vars
  10. @outputs Key_Forward Key_Back Key_Up Key_Down Key_Left Key_Right Mouse_Offset:angle
  11. #Flight Variables
  12. @persist FLIGHT_STATE_VTOL FLIGHT_STATE_FREE FLIGHT_STATE_GROUND
  13. @persist Ground_Accel Ground_Decel Ground_AccelKick Ground_DecelKick Ground_ForwardSpeed Ground_BackSpeed Ground_TurnRate Ground_WheelRotateRate
  14. @persist VTOL_Accel VTOL_Decel VTOL_AngDamping VTOL_MaxSpeed VTOL_UpSpeed VTOL_DownSpeed VTOL_Gravity VTOL_MaxBank VTOL_BankSpeed VTOL_YawSpeed VTOL_LGearRestDist
  15. @persist Flight_Accel Flight_Decel Flight_MaxSpeed Flight_PitchSpeed Flight_YawSpeed Flight_RollSpeed
  16. #Canopy Movement
  17. @persist Canopy_SlideDelay Canopy_MaxHeight Canopy_MaxSlide Canopy_SlideSpeed_Vert Canopy_SlideSpeed_Hori
  18. @persist Canopy_RestartTime Canopy_CurHeight Canopy_CurSlide
  19. @persist Canopy_ParentIndex Canopy_ParentEnt:entity
  20. #Landing Gear
  21. @persist LGear_Down LGear_FrontWheelAng LGear_GroundPlaneDir:vector LGear_GroundPlaneOrigin:vector
  22. @persist LGear_Doors:array LGear_GearAnchors:array LGear_PistonShafts:array LGear_WheelDists:array
  23. @persist LGear_Axels:array LGear_AxelLastPos:array LGear_WheelOnGround:array LGear_FrontPiston
  24. @persist LGear_DoorSpeed LGear_DoorMaxAng LGear_DoorCurAng
  25. @persist LGear_MinAng LGear_MaxAng LGear_Speed LGear_CurAng
  26. @persist LGear_WheelMaxDist LGear_WheelDist LGear_WheelRadius LGear_WheelCircum
  27. @persist LGear_SmallWheelSpring LGear_LargeWheelSpring
  28. #Setup Vars
  29. @persist Setup_Complete Setup_HoloIndex Setup_Index
  30. @autoupdate
  31.  
  32. if(first()|duped()) { #--Program Header
  33.  
  34. runOnChat(1)
  35.  
  36. #------------------------
  37. # EDITABLE VARS
  38. #------------------------
  39.  
  40. Canopy_SlideDelay = 0.75
  41. Canopy_MaxHeight = 4
  42. Canopy_MaxSlide = 115
  43. Canopy_SlideSpeed_Vert = 16
  44. Canopy_SlideSpeed_Hori = 90
  45.  
  46. LGear_DoorSpeed = 150
  47. LGear_DoorMaxAng = 130
  48.  
  49. LGear_Speed = 90
  50. LGear_MinAng = 4
  51. LGear_MaxAng = 90
  52.  
  53. LGear_WheelMaxDist = 43.7 #Oddly Specific, but this is how it fits in the bay
  54. LGear_WheelRadius = 15.5/2 #Found using BoxSize on the wheel prop in use
  55.  
  56. Ground_Accel = 150
  57. Ground_Decel = 150
  58. Ground_AccelKick = 2
  59. Ground_DecelKick = 3
  60. Ground_ForwardSpeed = 75
  61. Ground_BackSpeed = 45
  62. Ground_TurnRate = 15
  63. Ground_WheelRotateRate = 70
  64.  
  65. VTOL_Accel = 150
  66. VTOL_Decel = 150
  67. VTOL_AngDamping = 15
  68. VTOL_MaxSpeed = 500
  69. VTOL_UpSpeed = 150
  70. VTOL_DownSpeed = 100
  71. VTOL_Gravity = 35
  72. VTOL_MaxBank = 15
  73. VTOL_BankSpeed = 90
  74. VTOL_YawSpeed = 65
  75. VTOL_LGearRestDist = 21
  76.  
  77. Flight_Accel = 150
  78. Flight_Decel = 50
  79. Flight_MaxSpeed = 5000
  80. Flight_PitchSpeed = 45
  81. Flight_YawSpeed = 25
  82. Flight_RollSpeed = 50
  83.  
  84. #--End of Editable Vars--
  85.  
  86. #Fake Enums
  87. FLIGHT_STATE_GROUND = 0
  88. FLIGHT_STATE_VTOL = 1
  89. FLIGHT_STATE_FREE = 2
  90.  
  91. #Defaults
  92. Setup_HoloIndex = 1
  93. Setup_Index = 1
  94.  
  95. LGear_Doors = array()
  96. LGear_GearAnchors = array()
  97. LGear_Axels = array()
  98. LGear_AxelLastPos = array()
  99. LGear_WheelDists = array()
  100. LGear_PistonShafts = array()
  101. LGear_WheelOnGround = array()
  102. LGear_FrontWheelAng = 0
  103.  
  104. LGear_GroundPlaneDir = vec(0, 0, 1)
  105. LGear_GroundPlaneOrigin = vec(0, 0, 0)
  106.  
  107. LGear_WheelCircum = pi() * LGear_WheelRadius * 2
  108.  
  109. Flight_State = FLIGHT_STATE_GROUND
  110.  
  111. LastFrame = systime()
  112.  
  113.  
  114. #-------------------------
  115. # UTILITY FUNCTIONS
  116. #-------------------------
  117.  
  118. function void generateLGearPlane(GearPoints:array)
  119. {
  120. local Dir1 = GearPoints[2,vector] - GearPoints[1,vector]
  121. local Dir2 = GearPoints[3,vector] - GearPoints[1,vector]
  122. local Dir3 = GearPoints[3,vector] - GearPoints[2,vector]
  123.  
  124. LGear_GroundPlaneOrigin = (GearPoints[1,vector] + GearPoints[2,vector] + GearPoints[3,vector]) / 3
  125. LGear_GroundPlaneNormal = (Dir2:cross(Dir1)):normalized()
  126. }
  127.  
  128. #--End Utility Functions--
  129.  
  130.  
  131. #----------------------------
  132. # GEAR/ENGINE HOLOS
  133. #----------------------------
  134.  
  135. #Animation Loop
  136. function void animateGear(Open)
  137. {
  138. local Finished = 0
  139. LGear_InAnim = 1
  140.  
  141. #Opening Animation
  142. if(Open)
  143. {
  144. #---------
  145. # DOORS
  146. #---------
  147. if(LGear_DoorCurAng < LGear_DoorMaxAng)
  148. {
  149. #Play Sound and Start Anim
  150. if(LGear_DoorCurAng == 0)
  151. {
  152. #Play Sound
  153. for(Index = 1, LGear_Doors:count())
  154. {
  155. local Holo = LGear_Doors[Index,number]
  156. local HoloEnt = holoEntity(Holo)
  157. HoloEnt:soundPlay("LGear Doors Unlock"+Holo, 2.4, "buttons/og_button_down_0" + randint(1,3) + ".wav")
  158. soundVolume("LGear Doors Unlock"+Holo, 0.10)
  159. soundPitch("LGear Doors Unlock"+Holo, randint(95, 115))
  160. }
  161. }
  162.  
  163. #Rotate Doors
  164. local DoorSpeed = LGear_DoorSpeed * 0.05
  165. if(LGear_DoorCurAng + DoorSpeed > LGear_DoorMaxAng)
  166. {
  167. DoorSpeed = LGear_DoorMaxAng - LGear_DoorCurAng
  168. }
  169.  
  170. LGear_DoorCurAng += DoorSpeed
  171. for(Index = 1, LGear_Doors:count())
  172. {
  173. local Holo = LGear_Doors[Index,number]
  174.  
  175. holoAng(Holo, holoEntity(Holo):toWorld(ang(0, 0, -DoorSpeed)))
  176. }
  177. }
  178.  
  179. #---------
  180. # GEAR
  181. #---------
  182. if(LGear_CurAng < LGear_MaxAng && LGear_DoorCurAng > 40)
  183. {
  184. #Play Sound and Start Gear Anim
  185. if(LGear_CurAng == LGear_MinAng)
  186. {
  187. #Play Sound
  188. for(Index = 1, LGear_GearAnchors:count())
  189. {
  190. local Holo = LGear_GearAnchors[Index,number]
  191. local HoloEnt = holoEntity(Holo)
  192. HoloEnt:soundPlay("LGear Drop"+Holo, 1.5, "plats/door_round_blue_unlock_01.wav")
  193. soundVolume("LGear Drop"+Holo, 2)
  194. soundPitch("LGear Drop"+Holo, randint(45, 55))
  195. }
  196. }
  197.  
  198. #Rotate Gear
  199. local GearSpeed = LGear_Speed * 0.05
  200. if(LGear_CurAng + GearSpeed > LGear_MaxAng)
  201. {
  202. GearSpeed = LGear_MaxAng - LGear_CurAng
  203. }
  204.  
  205. LGear_CurAng += GearSpeed
  206. for(Index = 1, LGear_GearAnchors:count())
  207. {
  208. local Holo = LGear_GearAnchors[Index,number]
  209.  
  210. holoAng(Holo, holoEntity(Holo):toWorld(ang(GearSpeed, 0, 0)))
  211. }
  212. }
  213.  
  214. #--Final Check
  215. if(LGear_DoorCurAng == LGear_DoorMaxAng && LGear_CurAng == LGear_MaxAng)
  216. {
  217. Finished = 1
  218. LGear_InAnim = 0
  219. }
  220. }
  221. #Closing Animation
  222. else
  223. {
  224. #---------
  225. # DOORS
  226. #---------
  227. if(LGear_DoorCurAng > 0 && LGear_CurAng < LGear_MaxAng - 40)
  228. {
  229. #Play Sound and Start Anim
  230. if(LGear_DoorCurAng == LGear_DoorMaxAng)
  231. {
  232. #Play Sound
  233. for(Index = 1, LGear_Doors:count())
  234. {
  235. local Holo = LGear_Doors[Index,number]
  236. local HoloEnt = holoEntity(Holo)
  237. HoloEnt:soundPlay("LGear Doors Close"+Holo, 2.4, "buttons/og_button_up_0" + randint(1,3) + ".wav")
  238. soundVolume("LGear Doors Close"+Holo, 0.10)
  239. soundPitch("LGear Doors Close"+Holo, randint(95, 115))
  240. }
  241. }
  242.  
  243. #Rotate Doors
  244. local DoorSpeed = LGear_DoorSpeed * 0.05
  245. if(LGear_DoorCurAng - DoorSpeed < 0)
  246. {
  247. DoorSpeed = LGear_DoorCurAng
  248. }
  249.  
  250. LGear_DoorCurAng -= DoorSpeed
  251. for(Index = 1, LGear_Doors:count())
  252. {
  253. local Holo = LGear_Doors[Index,number]
  254.  
  255. holoAng(Holo, holoEntity(Holo):toWorld(ang(0, 0, DoorSpeed)))
  256. }
  257. }
  258.  
  259. #---------
  260. # GEAR
  261. #---------
  262. if(LGear_CurAng > LGear_MinAng)
  263. {
  264. #Play Sound and Start Gear Anim
  265. if(LGear_CurAng == LGear_MaxAng)
  266. {
  267. #Play Sound
  268. for(Index = 1, LGear_GearAnchors:count())
  269. {
  270. local Holo = LGear_GearAnchors[Index,number]
  271. local HoloEnt = holoEntity(Holo)
  272. HoloEnt:soundPlay("LGear Pull"+Holo, 1.4, "plats/door_round_blue_lock_01.wav")
  273. soundVolume("LGear Pull"+Holo, 2)
  274. soundPitch("LGear Pull"+Holo, randint(45, 55))
  275. }
  276. }
  277.  
  278. #Rotate Gear
  279. local GearSpeed = LGear_Speed * 0.05
  280. if(LGear_CurAng - GearSpeed < LGear_MinAng)
  281. {
  282. GearSpeed = LGear_CurAng - LGear_MinAng
  283. }
  284.  
  285. LGear_CurAng -= GearSpeed
  286. for(Index = 1, LGear_GearAnchors:count())
  287. {
  288. local Holo = LGear_GearAnchors[Index,number]
  289.  
  290. holoAng(Holo, holoEntity(Holo):toWorld(ang(-GearSpeed, 0, 0)))
  291. }
  292. }
  293.  
  294. #Final Check
  295. if(LGear_DoorCurAng == 0 && LGear_CurAng == LGear_MinAng)
  296. {
  297. Finished = 1
  298. LGear_InAnim = 0
  299. }
  300. }
  301.  
  302. if(!Finished)
  303. {
  304. timer(50, 1, "Landing Gear Animation", "animateGear(n)", Open)
  305. }
  306. }
  307.  
  308. #Toggle Landing Gear
  309. function void toggleGear(Toggle)
  310. {
  311. if(Toggle != LGear_Down)
  312. {
  313. LGear_Down = Toggle
  314. animateGear(Toggle)
  315. }
  316. }
  317.  
  318. function void createSmallGear(Offset:vector)
  319. {
  320. #Base Assembly
  321. holoCreate(Setup_HoloIndex)
  322. holoModel(Setup_HoloIndex, "models/lt_c/sci_fi/support_beam_48.mdl")
  323. holoPos(Setup_HoloIndex, entity():toWorld(Offset + vec(-12, 0, -24)))
  324. holoAng(Setup_HoloIndex, entity():toWorld(ang(0, 0, 0)))
  325. holoColor(Setup_HoloIndex, vec(106, 106, 106))
  326. holoScaleUnits(Setup_HoloIndex, vec(12, 18, 48))
  327. holoParent(Setup_HoloIndex, entity())
  328. Setup_HoloIndex++
  329.  
  330. #Left Panel Rotator
  331. holoCreate(Setup_HoloIndex)
  332. holoPos(Setup_HoloIndex, entity():toWorld(Offset + vec(0, 9, 0)))
  333. holoAng(Setup_HoloIndex, entity():toWorld(ang(90, 0, 0)))
  334. holoAlpha(Setup_HoloIndex, 0)
  335. holoParent(Setup_HoloIndex, entity())
  336. LGear_Doors:pushNumber(Setup_HoloIndex)
  337. Setup_HoloIndex++
  338.  
  339. #Left Panel
  340. holoCreate(Setup_HoloIndex)
  341. holoModel(Setup_HoloIndex, "models/sprops/rectangles/size_2_5/rect_18x48x3.mdl")
  342. holoMaterial(Setup_HoloIndex, "spacebuild/sblight5")
  343. holoPos(Setup_HoloIndex, entity():toWorld(Offset + vec(0, 4.5, 0)))
  344. holoAng(Setup_HoloIndex, entity():toWorld(ang(90, 0, 0)))
  345. holoScale(Setup_HoloIndex, vec(1, 0.5, 0.25))
  346. holoParent(Setup_HoloIndex, Setup_HoloIndex - 1)
  347. Setup_HoloIndex++
  348.  
  349. #Right Panel Rotator
  350. holoCreate(Setup_HoloIndex)
  351. holoPos(Setup_HoloIndex, entity():toWorld(Offset + vec(0, -9, 0)))
  352. holoAng(Setup_HoloIndex, entity():toWorld(ang(-90, 0, 0)))
  353. holoAlpha(Setup_HoloIndex, 0)
  354. holoParent(Setup_HoloIndex, entity())
  355. LGear_Doors:pushNumber(Setup_HoloIndex)
  356. Setup_HoloIndex++
  357.  
  358. #Right Panel
  359. holoCreate(Setup_HoloIndex)
  360. holoModel(Setup_HoloIndex, "models/sprops/rectangles/size_2_5/rect_18x48x3.mdl")
  361. holoMaterial(Setup_HoloIndex, "spacebuild/sblight5")
  362. holoPos(Setup_HoloIndex, entity():toWorld(Offset + vec(0, -4.5, 0)))
  363. holoAng(Setup_HoloIndex, entity():toWorld(ang(90, 0, 0)))
  364. holoScale(Setup_HoloIndex, vec(1, 0.5, 0.25))
  365. holoParent(Setup_HoloIndex, Setup_HoloIndex - 1)
  366. Setup_HoloIndex++
  367.  
  368. #Piston Rotator
  369. holoCreate(Setup_HoloIndex)
  370. holoPos(Setup_HoloIndex, entity():toWorld(Offset + vec(-10, 0, -21)))
  371. holoAng(Setup_HoloIndex, entity():toWorld(ang(-90, 0, 0)))
  372. holoAlpha(Setup_HoloIndex, 0)
  373. holoParent(Setup_HoloIndex, entity())
  374. LGear_GearAnchors:pushNumber(Setup_HoloIndex)
  375. LGear_WheelDists:pushNumber(LGear_WheelMaxDist)
  376. LGear_WheelOnGround:pushNumber(0)
  377. Setup_HoloIndex++
  378.  
  379. #Main Piston Housing
  380. holoCreate(Setup_HoloIndex)
  381. holoModel(Setup_HoloIndex, "hqcylinder")
  382. holoMaterial(Setup_HoloIndex, "models/props_vents/borealis_vent001")
  383. holoPos(Setup_HoloIndex, entity():toWorld(Offset + vec(-10, 0, -8)))
  384. holoAng(Setup_HoloIndex, entity():toWorld(ang(0, 0, 0)))
  385. holoScaleUnits(Setup_HoloIndex, vec(3, 3, 25))
  386. holoParent(Setup_HoloIndex, Setup_HoloIndex - 1) #Parent to Anchor
  387. Setup_HoloIndex++
  388.  
  389. #Main Piston Shaft
  390. holoCreate(Setup_HoloIndex)
  391. holoModel(Setup_HoloIndex, "hqcylinder")
  392. holoMaterial(Setup_HoloIndex, "phoenix_storms/fender_chrome")
  393. holoColor(Setup_HoloIndex, vec(128, 128, 128))
  394. holoPos(Setup_HoloIndex, entity():toWorld(Offset + vec(-10, 0, 8)))
  395. holoAng(Setup_HoloIndex, entity():toWorld(ang(0, 0, 0)))
  396. holoScaleUnits(Setup_HoloIndex, vec(2.5, 2.5, 15))
  397. holoParent(Setup_HoloIndex, Setup_HoloIndex - 2) #Parent to Anchor
  398. LGear_PistonShafts:pushNumber(Setup_HoloIndex)
  399. Setup_HoloIndex++
  400.  
  401. #Axel
  402. holoCreate(Setup_HoloIndex)
  403. holoModel(Setup_HoloIndex, "hqcylinder")
  404. holoColor(Setup_HoloIndex, vec(128, 128, 128))
  405. holoMaterial(Setup_HoloIndex, "phoenix_storms/fender_chrome")
  406. holoPos(Setup_HoloIndex, entity():toWorld(Offset + vec(-10, 0, 16)))
  407. holoAng(Setup_HoloIndex, entity():toWorld(ang(0, 0, -90)))
  408. holoScaleUnits(Setup_HoloIndex, vec(2.5, 2.5, 8))
  409. holoParent(Setup_HoloIndex, Setup_HoloIndex - 1) #Parent to Shaft
  410. LGear_Axels:pushNumber(Setup_HoloIndex)
  411. Setup_HoloIndex++
  412.  
  413. #Left Wheel
  414. holoCreate(Setup_HoloIndex)
  415. holoModel(Setup_HoloIndex, "models/sprops/trans/wheel_a/t_wheel15.mdl")
  416. holoPos(Setup_HoloIndex, entity():toWorld(Offset + vec(-10, 4, 16)))
  417. holoAng(Setup_HoloIndex, entity():toWorld(ang(0, 0, 0)))
  418. holoScale(Setup_HoloIndex, vec(1, 1, 1))
  419. holoParent(Setup_HoloIndex, Setup_HoloIndex - 1) #Parent to Axel
  420. Setup_HoloIndex++
  421.  
  422. #Right Wheel
  423. holoCreate(Setup_HoloIndex)
  424. holoModel(Setup_HoloIndex, "models/sprops/trans/wheel_a/t_wheel15.mdl")
  425. holoPos(Setup_HoloIndex, entity():toWorld(Offset + vec(-10, -4, 16)))
  426. holoAng(Setup_HoloIndex, entity():toWorld(ang(0, 0, 0)))
  427. holoScale(Setup_HoloIndex, vec(1, 1, 1))
  428. holoParent(Setup_HoloIndex, Setup_HoloIndex - 2) #Parent to Axel
  429. Setup_HoloIndex++
  430. }
  431.  
  432. function void createLargeGear(Offset:vector)
  433. {
  434. #Base Assembly
  435. holoCreate(Setup_HoloIndex)
  436. holoModel(Setup_HoloIndex, "models/lt_c/sci_fi/support_beam_48.mdl")
  437. holoPos(Setup_HoloIndex, entity():toWorld(Offset + vec(-12, 0, 24)))
  438. holoAng(Setup_HoloIndex, entity():toWorld(ang(0, 0, 180)))
  439. holoColor(Setup_HoloIndex, vec(106, 106, 106))
  440. holoScaleUnits(Setup_HoloIndex, vec(12, 24, 48))
  441. holoParent(Setup_HoloIndex, entity())
  442. Setup_HoloIndex++
  443.  
  444. #Left Panel Rotator
  445. holoCreate(Setup_HoloIndex)
  446. holoPos(Setup_HoloIndex, entity():toWorld(Offset + vec(0, 12, 0)))
  447. holoAng(Setup_HoloIndex, entity():toWorld(ang(90, 0, 0)))
  448. holoAlpha(Setup_HoloIndex, 0)
  449. holoParent(Setup_HoloIndex, entity())
  450. LGear_Doors:pushNumber(Setup_HoloIndex)
  451. LGear_WheelDists:pushNumber(LGear_WheelMaxDist)
  452. Setup_HoloIndex++
  453.  
  454. #Left Panel
  455. holoCreate(Setup_HoloIndex)
  456. holoModel(Setup_HoloIndex, "models/sprops/rectangles/size_2/rect_12x48x3.mdl")
  457. holoMaterial(Setup_HoloIndex, "spacebuild/sblight5")
  458. holoPos(Setup_HoloIndex, entity():toWorld(Offset + vec(0, 6, 0)))
  459. holoAng(Setup_HoloIndex, entity():toWorld(ang(90, 0, 0)))
  460. holoScale(Setup_HoloIndex, vec(0.95, 1, 0.25))
  461. holoParent(Setup_HoloIndex, Setup_HoloIndex - 1)
  462. Setup_HoloIndex++
  463.  
  464. #Right Panel Rotator
  465. holoCreate(Setup_HoloIndex)
  466. holoPos(Setup_HoloIndex, entity():toWorld(Offset + vec(0, -12, 0)))
  467. holoAng(Setup_HoloIndex, entity():toWorld(ang(-90, 0, 0)))
  468. holoAlpha(Setup_HoloIndex, 0)
  469. holoParent(Setup_HoloIndex, entity())
  470. LGear_Doors:pushNumber(Setup_HoloIndex)
  471. Setup_HoloIndex++
  472.  
  473. #Right Panel
  474. holoCreate(Setup_HoloIndex)
  475. holoModel(Setup_HoloIndex, "models/sprops/rectangles/size_2/rect_12x48x3.mdl")
  476. holoMaterial(Setup_HoloIndex, "spacebuild/sblight5")
  477. holoPos(Setup_HoloIndex, entity():toWorld(Offset + vec(0, -6, 0)))
  478. holoAng(Setup_HoloIndex, entity():toWorld(ang(90, 0, 0)))
  479. holoScale(Setup_HoloIndex, vec(0.95, 1, 0.25))
  480. holoParent(Setup_HoloIndex, Setup_HoloIndex - 1)
  481. Setup_HoloIndex++
  482.  
  483. #Piston Rotator
  484. holoCreate(Setup_HoloIndex)
  485. holoPos(Setup_HoloIndex, entity():toWorld(Offset + vec(-10, 0, 21)))
  486. holoAng(Setup_HoloIndex, entity():toWorld(ang(90, 0, 180)))
  487. holoAlpha(Setup_HoloIndex, 0)
  488. holoParent(Setup_HoloIndex, entity())
  489. LGear_GearAnchors:pushNumber(Setup_HoloIndex)
  490. Setup_HoloIndex++
  491.  
  492. #Main Piston Housing
  493. holoCreate(Setup_HoloIndex)
  494. holoModel(Setup_HoloIndex, "hqcylinder")
  495. holoMaterial(Setup_HoloIndex, "models/props_vents/borealis_vent001")
  496. holoPos(Setup_HoloIndex, entity():toWorld(Offset + vec(-10, 0, 8)))
  497. holoAng(Setup_HoloIndex, entity():toWorld(ang(0, 0, 0)))
  498. holoScaleUnits(Setup_HoloIndex, vec(3, 3, 25))
  499. holoParent(Setup_HoloIndex, Setup_HoloIndex - 1) #Parent to Anchor
  500. Setup_HoloIndex++
  501.  
  502. #Main Piston Shaft
  503. holoCreate(Setup_HoloIndex)
  504. holoModel(Setup_HoloIndex, "hqcylinder")
  505. holoMaterial(Setup_HoloIndex, "phoenix_storms/fender_chrome")
  506. holoColor(Setup_HoloIndex, vec(128, 128, 128))
  507. holoPos(Setup_HoloIndex, entity():toWorld(Offset + vec(-10, 0, -8)))
  508. holoAng(Setup_HoloIndex, entity():toWorld(ang(180, 0, 0)))
  509. holoScaleUnits(Setup_HoloIndex, vec(2.5, 2.5, 15))
  510. holoParent(Setup_HoloIndex, Setup_HoloIndex - 2) #Parent to Anchor
  511. LGear_PistonShafts:pushNumber(Setup_HoloIndex)
  512. LGear_FrontPiston = Setup_HoloIndex
  513. Setup_HoloIndex++
  514.  
  515. #Axel
  516. holoCreate(Setup_HoloIndex)
  517. holoModel(Setup_HoloIndex, "hqcylinder")
  518. holoColor(Setup_HoloIndex, vec(128, 128, 128))
  519. holoMaterial(Setup_HoloIndex, "phoenix_storms/fender_chrome")
  520. holoPos(Setup_HoloIndex, entity():toWorld(Offset + vec(-10, 0, -16)))
  521. holoAng(Setup_HoloIndex, entity():toWorld(ang(0, 0, -90)))
  522. holoScaleUnits(Setup_HoloIndex, vec(2.5, 2.5, 8))
  523. holoParent(Setup_HoloIndex, Setup_HoloIndex - 1) #Parent to Shaft
  524. LGear_Axels:pushNumber(Setup_HoloIndex)
  525. Setup_HoloIndex++
  526.  
  527. #Left Wheel
  528. holoCreate(Setup_HoloIndex)
  529. holoModel(Setup_HoloIndex, "models/sprops/trans/wheel_a/t_wheel15.mdl")
  530. holoPos(Setup_HoloIndex, entity():toWorld(Offset + vec(-10, 4, -16)))
  531. holoAng(Setup_HoloIndex, entity():toWorld(ang(0, 0, 0)))
  532. holoScale(Setup_HoloIndex, vec(1, 1, 1))
  533. holoParent(Setup_HoloIndex, Setup_HoloIndex - 1) #Parent to Axel
  534. Setup_HoloIndex++
  535.  
  536. #Right Wheel
  537. holoCreate(Setup_HoloIndex)
  538. holoModel(Setup_HoloIndex, "models/sprops/trans/wheel_a/t_wheel15.mdl")
  539. holoPos(Setup_HoloIndex, entity():toWorld(Offset + vec(-10, -4, -16)))
  540. holoAng(Setup_HoloIndex, entity():toWorld(ang(0, 0, 0)))
  541. holoScale(Setup_HoloIndex, vec(1, 1, 1))
  542. holoParent(Setup_HoloIndex, Setup_HoloIndex - 2) #Parent to Axel
  543. Setup_HoloIndex++
  544. }
  545.  
  546. function void setupHullHolos()
  547. {
  548. #Front Intake Vent
  549. holoCreate(Setup_HoloIndex)
  550. holoModel(Setup_HoloIndex, "models/slyfo_2/protorover_eng_sf2m.mdl")
  551. holoPos(Setup_HoloIndex, entity():toWorld(vec(0, 0, 42)))
  552. holoAng(Setup_HoloIndex, entity():toWorld(ang(-90, 0, 0)))
  553. holoScale(Setup_HoloIndex, vec(0.65, 0.85, 0.65))
  554. holoParent(Setup_HoloIndex, entity())
  555. Setup_HoloIndex++
  556.  
  557. #Front Right VTOL Thruster
  558. holoCreate(Setup_HoloIndex)
  559. holoModel(Setup_HoloIndex, "models/slyfo_2/protorover_eng_sf2m.mdl")
  560. holoPos(Setup_HoloIndex, entity():toWorld(vec(6, -40, -120)))
  561. holoAng(Setup_HoloIndex, entity():toWorld(ang(0, -15, 90)))
  562. holoScale(Setup_HoloIndex, vec(0.35, 2, 0.8))
  563. holoParent(Setup_HoloIndex, entity())
  564. Setup_HoloIndex++
  565.  
  566. #Front Left VTOL Thruster
  567. holoCreate(Setup_HoloIndex)
  568. holoModel(Setup_HoloIndex, "models/slyfo_2/protorover_eng_sf2m.mdl")
  569. holoPos(Setup_HoloIndex, entity():toWorld(vec(6, 40, -120)))
  570. holoAng(Setup_HoloIndex, entity():toWorld(ang(0, 15, -90)))
  571. holoScale(Setup_HoloIndex, vec(0.35, 2, 0.8))
  572. holoParent(Setup_HoloIndex, entity())
  573. Setup_HoloIndex++
  574.  
  575. #Back Right VTOL Thruster
  576. holoCreate(Setup_HoloIndex)
  577. holoModel(Setup_HoloIndex, "models/slyfo_2/protorover_eng_sf2m.mdl")
  578. holoPos(Setup_HoloIndex, entity():toWorld(vec(0, -32, -405)))
  579. holoAng(Setup_HoloIndex, entity():toWorld(ang(0, -30, 90)))
  580. holoScale(Setup_HoloIndex, vec(0.5, 1.5, 0.8))
  581. holoParent(Setup_HoloIndex, entity())
  582. Setup_HoloIndex++
  583.  
  584. #Back Left VTOL Thruster
  585. holoCreate(Setup_HoloIndex)
  586. holoModel(Setup_HoloIndex, "models/slyfo_2/protorover_eng_sf2m.mdl")
  587. holoPos(Setup_HoloIndex, entity():toWorld(vec(0, 32, -405)))
  588. holoAng(Setup_HoloIndex, entity():toWorld(ang(0, 30, -90)))
  589. holoScale(Setup_HoloIndex, vec(0.5, 1.5, 0.8))
  590. holoParent(Setup_HoloIndex, entity())
  591. Setup_HoloIndex++
  592.  
  593. print("Hull Holos Created.")
  594. print("Setup Complete!")
  595. Setup_Complete = 1
  596. }
  597.  
  598. function void setupLandingGear()
  599. {
  600. #Landing Gear
  601. createSmallGear(vec(29.3, -15, -337.2))
  602. createSmallGear(vec(29.3, 15, -337.2))
  603. createLargeGear(vec(29.3, 0, -98.5))
  604.  
  605. print("Landing Gear Created.")
  606.  
  607. timer(1000, 1, "Setup Hull Holos", "setupHullHolos()")
  608. }
  609.  
  610. function void landingGearThink(Delta)
  611. {
  612. local GearPoints = array()
  613.  
  614. #Animate Landing Gear
  615. for(Index = 1, LGear_GearAnchors:count())
  616. {
  617. #Do gear hydraulics
  618. local AnchorEnt = holoEntity(LGear_GearAnchors[Index,number])
  619. local DownTrace = rangerOffset(LGear_WheelMaxDist, AnchorEnt:pos(), AnchorEnt:forward())
  620. local Dist = clamp(DownTrace:distance() - 0.5, 0, LGear_WheelMaxDist)
  621. local Diff = Dist - LGear_WheelDists[Index,number]
  622. local Shaft = LGear_PistonShafts[Index,number]
  623. holoPos(Shaft, holoEntity(Shaft):toWorld(vec(0, 0, Diff)))
  624. LGear_WheelDists[Index,number] = Dist
  625.  
  626. #Wheel Rolling
  627. if(DownTrace:hit())
  628. {
  629. if(DownTrace:distance() < LGear_WheelMaxDist)
  630. {
  631. local Piston = LGear_PistonShafts[Index,number]
  632. local Axel = LGear_Axels[Index,number]
  633. local PistonEnt = holoEntity(Piston)
  634. local AxelEnt = holoEntity(Axel)
  635.  
  636. #Just contacted?
  637. if(!LGear_WheelOnGround[Index,number])
  638. {
  639. LGear_WheelOnGround[Index,number] = 1
  640. LGear_AxelLastPos[Index,vector] = AxelEnt:pos()
  641. }
  642.  
  643. local PosDiff = PistonEnt:toLocal(LGear_AxelLastPos[Index,vector]) - PistonEnt:toLocal(AxelEnt:pos())
  644. local Vel = PosDiff:x() / Delta
  645. local AngVel = (Vel / LGear_WheelCircum) / 2
  646.  
  647. LGear_AxelLastPos[Index,vector] = AxelEnt:pos()
  648.  
  649. holoAng(Axel, AxelEnt:toWorld(ang(0, toDeg(AngVel), 0)))
  650. }
  651. }
  652. else
  653. {
  654. LGear_WheelOnGround[Index,number] = 0
  655. }
  656.  
  657. GearPoints:pushVector(DownTrace:pos())
  658. }
  659.  
  660. generateLGearPlane(GearPoints)
  661. }
  662.  
  663. #--End of Gear/Engine Holos--
  664.  
  665.  
  666. #------------------------
  667. # CANOPY FUNCTIONS
  668. #------------------------
  669.  
  670. #Animation Loop
  671. function void animateCanopy(Open)
  672. {
  673. local Finished = 0
  674. Canopy_InAnim = 1
  675.  
  676. #Opening Animation
  677. if(Open)
  678. {
  679. #Play Sound and Start Anim
  680. if(Canopy_CurHeight == 0)
  681. {
  682. #Play Sound
  683. Canopy_ParentEnt:soundPlay("Pressure Release Up", 2.4, "ambient/machines/steam_release_2.wav")
  684. soundPitch("Pressure Release Up", 150)
  685. }
  686.  
  687. #Slide Up
  688. if(Canopy_CurHeight < Canopy_MaxHeight)
  689. {
  690. local SlideSpeed = Canopy_SlideSpeed_Vert * 0.05
  691. if(Canopy_CurHeight + SlideSpeed > Canopy_MaxHeight)
  692. {
  693. SlideSpeed = Canopy_MaxHeight - Canopy_CurHeight
  694. }
  695.  
  696. holoPos(Canopy_ParentIndex, holoEntity(Canopy_ParentIndex):toWorld(vec(-SlideSpeed, 0, 0)))
  697. Canopy_CurHeight += SlideSpeed
  698.  
  699. #Finished Sliding
  700. if(Canopy_CurHeight == Canopy_MaxHeight)
  701. {
  702. Canopy_RestartTime = curtime() + Canopy_SlideDelay
  703. }
  704. }
  705. #Slide Forward After Delay
  706. elseif(curtime() > Canopy_RestartTime)
  707. {
  708. #Play Sound
  709. if(Canopy_CurSlide == 0)
  710. {
  711. #Play Sound
  712. Canopy_ParentEnt:soundPlay("Canopy Slide Forward", 2.5, "plats/elevator_door_open_01.wav")
  713. }
  714.  
  715. local SlideSpeed = Canopy_SlideSpeed_Hori * 0.05
  716. if(Canopy_CurSlide + SlideSpeed > Canopy_MaxSlide)
  717. {
  718. SlideSpeed = Canopy_MaxSlide - Canopy_CurSlide
  719. }
  720.  
  721. holoPos(Canopy_ParentIndex, holoEntity(Canopy_ParentIndex):toWorld(vec(0, 0, SlideSpeed)))
  722. Canopy_CurSlide += SlideSpeed
  723. }
  724.  
  725. if(Canopy_CurSlide == Canopy_MaxSlide && Canopy_CurHeight == Canopy_MaxHeight)
  726. {
  727. Finished = 1
  728. Canopy_InAnim = 0
  729. }
  730. }
  731. #Closing Animation
  732. else
  733. {
  734. #Play Sound and Start Anim
  735. if(Canopy_CurSlide == Canopy_MaxSlide)
  736. {
  737. #Play Sound
  738. Canopy_ParentEnt:soundPlay("Canopy Slide Back", 2.75, "plats/elevator_door_close_01.wav")
  739. soundPitch("Canopy Slide Back", 85)
  740. }
  741.  
  742. #Slide Back
  743. if(Canopy_CurSlide > 0)
  744. {
  745. local SlideSpeed = Canopy_SlideSpeed_Hori * 0.05
  746. if(Canopy_CurSlide - SlideSpeed < 0)
  747. {
  748. SlideSpeed = Canopy_CurSlide
  749. }
  750.  
  751. holoPos(Canopy_ParentIndex, holoEntity(Canopy_ParentIndex):toWorld(vec(0, 0, -SlideSpeed)))
  752. Canopy_CurSlide -= SlideSpeed
  753.  
  754. #Finished Sliding
  755. if(Canopy_CurSlide == 0)
  756. {
  757. Canopy_RestartTime = curtime() + Canopy_SlideDelay
  758. }
  759. }
  760. #Slide back Down after Delay
  761. elseif(curtime() > Canopy_RestartTime)
  762. {
  763. #Play Sound
  764. if(Canopy_CurHeight == Canopy_MaxHeight)
  765. {
  766. #Play Sound
  767. Canopy_ParentEnt:soundPlay("Pressure Seal", 1.1, "plats/door_round_blue_close_01.wav")
  768. }
  769.  
  770. local SlideSpeed = Canopy_SlideSpeed_Vert * 0.05
  771. if(Canopy_CurHeight - SlideSpeed < 0)
  772. {
  773. SlideSpeed = Canopy_CurHeight
  774. }
  775.  
  776. holoPos(Canopy_ParentIndex, holoEntity(Canopy_ParentIndex):toWorld(vec(SlideSpeed, 0, 0)))
  777. Canopy_CurHeight -= SlideSpeed
  778. }
  779.  
  780. if(Canopy_CurSlide == 0 && Canopy_CurHeight == 0)
  781. {
  782. Finished = 1
  783. Canopy_InAnim = 0
  784. }
  785. }
  786.  
  787. if(!Finished)
  788. {
  789. timer(50, 1, "Cockpit Animation", "animateCanopy(n)", Open)
  790. }
  791. }
  792.  
  793. #Toggle Canopy Solidity/Animation
  794. function void toggleCanopy(Toggle)
  795. {
  796. for(Index = 1, CanopyEnts:count())
  797. {
  798. local Ent = CanopyEnts[Index,entity]
  799.  
  800. if(Ent:type() != "detail_prop") #Detail props have weird physics when solid, ignore
  801. {
  802. Ent:setSolid(!Toggle)
  803. }
  804. }
  805.  
  806. animateCanopy(Toggle)
  807. }
  808.  
  809. #Create Canopy Holos
  810. function void constructCanopy()
  811. {
  812. local Finished = 0
  813. while(perf(70) && holoCanCreate() && !Finished)
  814. {
  815. local Part = CanopyEnts[Setup_Index, entity]
  816.  
  817. holoCreate(Setup_HoloIndex)
  818. holoModel(Setup_HoloIndex, Part:model())
  819. holoMaterial(Setup_HoloIndex, Part:getMaterial())
  820. holoColor(Setup_HoloIndex, Part:getColor())
  821. holoPos(Setup_HoloIndex, Part:pos())
  822. holoAng(Setup_HoloIndex, Part:angles())
  823. holoParent(Setup_HoloIndex, Canopy_ParentEnt)
  824.  
  825. #Window?
  826. if(Part:getMaterial() == "models/debug/debugwhite" && Part:getColor() == vec(0, 0, 0))
  827. {
  828. holoAlpha(Setup_HoloIndex, 192)
  829. holoEntity(Setup_HoloIndex):setRenderMode(9) #9 = WorldGlow
  830.  
  831. #Scale to flat
  832. if(Part:model():find("rtri"))
  833. {
  834. holoScale(Setup_HoloIndex, vec(1, 0.01, 1))
  835. }
  836. else
  837. {
  838. holoScale(Setup_HoloIndex, vec(1, 1, 0.01))
  839. }
  840. }
  841.  
  842. Setup_HoloIndex++
  843.  
  844. Part:setAlpha(0)
  845.  
  846. Setup_Index++
  847. if(Setup_Index > CanopyEnts:count())
  848. {
  849. Finished = 1
  850. break
  851. }
  852. }
  853.  
  854. if(!Finished)
  855. {
  856. timer(5, 1, "Construct Canopy", "constructCanopy()")
  857. }
  858. else
  859. {
  860. print("Canopy Constructed")
  861.  
  862. timer(1000, 1, "Construct Landing Gear", "setupLandingGear()")
  863. }
  864. }
  865.  
  866. #Create parent holo and start creation loop for canopy
  867. function void initCanopy()
  868. {
  869. Setup_HoloIndex = 1
  870.  
  871. holoCreate(Setup_HoloIndex)
  872. holoPos(Setup_HoloIndex, entity():pos())
  873. holoParent(Setup_HoloIndex, entity())
  874. holoAlpha(Setup_HoloIndex, 0)
  875.  
  876. Canopy_ParentIndex = Setup_HoloIndex
  877. Canopy_ParentEnt = holoEntity(Setup_HoloIndex)
  878.  
  879. Setup_HoloIndex++
  880.  
  881. timer(5, 1, "Construct Canopy", "constructCanopy()")
  882. }
  883.  
  884. #Glass Worldglow-ify
  885. function void worldglowGlass()
  886. {
  887. local Finished = 0
  888. while(perf(70) && !Finished)
  889. {
  890. local Part = Parts[Setup_Index, entity]
  891.  
  892. #Check if this is a window (DebugWhite + Transparent)
  893. if(Part:getMaterial() == "models/debug/debugwhite" && Part:getColor() == vec(0, 0, 0))
  894. {
  895. Part:setRenderMode(9) #9 = Worldglow
  896. }
  897.  
  898. Setup_Index++
  899. if(Setup_Index > Parts:count())
  900. {
  901. Finished = 1
  902. break
  903. }
  904. }
  905.  
  906. if(!Finished)
  907. {
  908. timer(5, 1, "Worldglow Glass", "worldglowGlass()")
  909. }
  910. else
  911. {
  912. print("Glass Worldglowed.")
  913.  
  914. Setup_Index = 1
  915. initCanopy()
  916. }
  917. }
  918.  
  919. #--End Canopy Functions--
  920.  
  921.  
  922. #------------------------
  923. # FLIGHT FUNCTIONS
  924. #------------------------
  925.  
  926. function void toggleGravity(Toggle)
  927. {
  928. for(Index = 1, Parts:count())
  929. {
  930. local Part = Parts[Index,entity]
  931. Part:sbSetDragOverride(!Toggle)
  932. Part:sbSetGravityOverride(!Toggle)
  933. Part:propGravity(Toggle)
  934. Part:propDrag(Toggle)
  935. }
  936. }
  937.  
  938. function void toggleFreeze(Freeze)
  939. {
  940. #--Block unparented ship from unfreezing
  941. if(!Freeze && !entity():parent())
  942. {
  943. print("Cannot unfreeze! Ship not parented!")
  944. return
  945. }
  946.  
  947. for(Index = 1, Parts:count())
  948. {
  949. Parts[Index,entity]:propFreeze(Freeze)
  950. }
  951. }
  952.  
  953. function void toggleEngine(Toggle)
  954. {
  955.  
  956. }
  957.  
  958. function void toggleVTOL(VTOL)
  959. {
  960.  
  961. }
  962.  
  963. function void applyFlightForce(Force:vector, Torque:vector)
  964. {
  965. Parent:applyForce(Force * Parent:mass())
  966. Parent:applyTorque(Torque * Parent:inertia())
  967. }
  968.  
  969. function void applyFlightCalcs(Force:vector, AngVel:angle)
  970. {
  971. Parent:applyForce(Force * Parent:mass())
  972. Parent:setAngVel(ang(AngVel:roll(), AngVel:pitch(), AngVel:yaw())) #What the fuck even...
  973. }
  974.  
  975. #Movement calcs go here
  976. function void flightThink(Delta)
  977. {
  978. #Check to Ground
  979. local TracePos = Parent:toWorld(vec(0, 0, -Parent:boxSize():z() * 0.6))
  980. local GroundTrace = rangerOffset(1000, TracePos, vec(0, 0, -1))
  981. GroundDist = GroundTrace:distance()
  982.  
  983. #Toggle Gear and enter VTOL if near the ground
  984. if(GroundTrace:hit() && GroundTrace:entity():getCoreEnt() != entity():getCoreEnt())
  985. {
  986. toggleGear(1)
  987. }
  988. else
  989. {
  990. toggleGear(0)
  991. }
  992.  
  993. #------------------------------
  994. # FLIGHT CALCULATIONS
  995. #------------------------------
  996. local ForceVec = vec()
  997. local TorqueVec = vec()
  998. local CurSpeed = Parent:vel()
  999. local CurSpeedLocal = Parent:velL()
  1000. local CurAngSpeed = Parent:angVelVector()
  1001.  
  1002. local CurQuat = quat(Parent)
  1003. local TargetQuat = quat(Parent)
  1004. local PitchQuat = quat(1)
  1005. local YawQuat = quat(1)
  1006. local RollQuat = quat(1)
  1007.  
  1008. local CurAng = Parent:angles()
  1009. local TargetAng = ang(0, Parent:angles():yaw(), 0)
  1010.  
  1011. #--Shared Behavior between Ground and VTOL modes
  1012. if(Flight_State == FLIGHT_STATE_GROUND || Flight_State == FLIGHT_STATE_VTOL)
  1013. {
  1014. #Make sure engine effects are on
  1015. if(!VTOLFXToggle) { VTOLFXToggle = 1 }
  1016.  
  1017. #--Up
  1018. if(Key_Up)
  1019. {
  1020. if(CurSpeedLocal:z() < VTOL_UpSpeed)
  1021. {
  1022. ForceVec += Parent:up() * (VTOL_Accel + VTOL_Decel) * Delta
  1023. }
  1024.  
  1025. Effects["VTOLThrottle", number] = 1.0
  1026. }
  1027. #--Let Gravity take us Down
  1028. elseif(CurSpeed:z() > -VTOL_Gravity && GroundDist < 350)
  1029. {
  1030. #Landing Gear Piston Check
  1031. local MaxDist = LGear_WheelMaxDist - 17
  1032. if(GroundDist < MaxDist)
  1033. {
  1034. local Fraction = max(MaxDist - GroundDist, 0)
  1035. local PistonForce = VTOL_Gravity - (VTOL_Gravity * Fraction)
  1036. ForceVec -= vec(0, 0, PistonForce * Delta)
  1037. }
  1038. #Drop Normally
  1039. else
  1040. {
  1041. ForceVec -= vec(0, 0, (VTOL_Gravity + VTOL_Decel) * Delta)
  1042. }
  1043. }
  1044. }
  1045.  
  1046. #--Taxi
  1047. if(Flight_State == FLIGHT_STATE_GROUND)
  1048. {
  1049. if(!Key_Up) { Effects["VTOLThrottle", number] = 0 }
  1050.  
  1051. #--Decelerate
  1052. local Vel = CurSpeed:length()
  1053. local Dir = CurSpeed:normalized()
  1054. ForceVec += -Dir * clamp(Vel, -Ground_Decel * Delta, Ground_Decel * Delta)
  1055.  
  1056. #--Angle to Ground
  1057. local GroundNrm = LGear_GroundPlaneNormal:cross(Parent:forward()):normalized():cross(LGear_GroundPlaneNormal)
  1058. local GroundQuat = quat(GroundNrm, LGear_GroundPlaneNormal)
  1059. local GroundAng = GroundQuat:toAngle()
  1060. TargetAng = TargetAng:setPitch(GroundAng:pitch()):setRoll(GroundAng:roll())
  1061.  
  1062. #--State Switch
  1063. if(GroundDist > LGear_WheelMaxDist)
  1064. {
  1065. Flight_State = FLIGHT_STATE_VTOL
  1066. }
  1067.  
  1068. #--Forward
  1069. if(Key_Forward)
  1070. {
  1071. if(CurSpeedLocal:x() < Ground_ForwardSpeed)
  1072. {
  1073. ForceVec += Parent:forward() * (Ground_Accel + VTOL_Decel) * Delta
  1074. }
  1075. }
  1076.  
  1077. #--Back
  1078. elseif(Key_Back)
  1079. {
  1080. if(CurSpeedLocal:x() > -Ground_BackSpeed)
  1081. {
  1082. ForceVec -= Parent:forward() * (Ground_Accel + VTOL_Decel) * Delta
  1083. }
  1084. }
  1085.  
  1086. #--Braking anims
  1087. else
  1088. {
  1089. #Forward Brake
  1090. if(CurSpeedLocal:x() > 1)
  1091. {
  1092. TargetAng = TargetAng:setPitch(TargetAng:pitch() + Ground_DecelKick)
  1093. }
  1094. #Reverse Brake
  1095. elseif(CurSpeedLocal:x() < -1)
  1096. {
  1097. TargetAng = TargetAng:setPitch(TargetAng:pitch() - Ground_AccelKick)
  1098. }
  1099. }
  1100.  
  1101.  
  1102. #---------
  1103. # TURNING
  1104. #---------
  1105. local Offset = 0
  1106. #--Left
  1107. if(Key_Left)
  1108. {
  1109. Offset = -35 - LGear_FrontWheelAng
  1110. }
  1111. #--Right
  1112. elseif(Key_Right)
  1113. {
  1114. Offset = 35 - LGear_FrontWheelAng
  1115. }
  1116. #--Return
  1117. else
  1118. {
  1119. Offset = -LGear_FrontWheelAng
  1120. }
  1121. Offset = clamp(Offset, -Ground_WheelRotateRate, Ground_WheelRotateRate) * Delta
  1122.  
  1123. local YawSpeed = -Ground_TurnRate * (LGear_FrontWheelAng / 35)
  1124. YawSpeed *= CurSpeedLocal:x() / Ground_ForwardSpeed
  1125.  
  1126. TargetAng = TargetAng:setYaw(TargetAng:yaw() + YawSpeed)
  1127.  
  1128. #Angle Front Gear
  1129. holoAng(LGear_FrontPiston, holoEntity(LGear_FrontPiston):toWorld(ang(0, Offset, 0)))
  1130.  
  1131. LGear_FrontWheelAng += Offset
  1132. }
  1133.  
  1134.  
  1135. #--VTOL Mode
  1136. elseif(Flight_State == FLIGHT_STATE_VTOL)
  1137. {
  1138. #--Decelerate
  1139. local Vel = CurSpeed:length()
  1140. local Dir = CurSpeed:normalized()
  1141. ForceVec += -Dir * clamp(Vel, -VTOL_Decel * Delta, VTOL_Decel * Delta)
  1142.  
  1143. #--State Switch
  1144. if(GroundDist < LGear_WheelMaxDist)
  1145. {
  1146. Flight_State = FLIGHT_STATE_GROUND
  1147. }
  1148.  
  1149. #Reset Front Gear
  1150. holoAng(LGear_FrontPiston, holoEntity(LGear_FrontPiston):toWorld(ang(0, -LGear_FrontWheelAng, 0)))
  1151. LGear_FrontWheelAng = 0
  1152.  
  1153. #--Up (Up-force calculated in shared, this is just for effects)
  1154. if(Key_Up)
  1155. {
  1156. Effects["VTOLThrottle", number] = 1.0
  1157. }
  1158.  
  1159. #--Down
  1160. elseif(Key_Down)
  1161. {
  1162. if(CurSpeedLocal:z() > -VTOL_DownSpeed)
  1163. {
  1164. ForceVec -= Parent:up() * (VTOL_Accel + VTOL_Decel) * Delta
  1165. }
  1166.  
  1167. Effects["VTOLThrottle", number] = 0.35
  1168. }
  1169. else
  1170. {
  1171. Effects["VTOLThrottle", number] = 0.5
  1172. }
  1173.  
  1174. #--Forward
  1175. if(Key_Forward)
  1176. {
  1177. if(CurSpeedLocal:x() < VTOL_MaxSpeed)
  1178. {
  1179. ForceVec += Parent:forward() * (VTOL_Accel + VTOL_Decel) * Delta
  1180. }
  1181.  
  1182. TargetAng = TargetAng:setPitch(VTOL_MaxBank)
  1183. }
  1184.  
  1185. #--Back
  1186. elseif(Key_Back)
  1187. {
  1188. if(CurSpeedLocal:x() > -VTOL_MaxSpeed)
  1189. {
  1190. ForceVec -= Parent:forward() * (VTOL_Accel + VTOL_Decel) * Delta
  1191. }
  1192.  
  1193. TargetAng = TargetAng:setPitch(-VTOL_MaxBank)
  1194. }
  1195.  
  1196. #--Pan Right
  1197. if(Key_Right)
  1198. {
  1199. if(CurSpeedLocal:y() > -VTOL_MaxSpeed)
  1200. {
  1201. ForceVec += Parent:right() * (VTOL_Accel + VTOL_Decel) * Delta
  1202. }
  1203.  
  1204. TargetAng = TargetAng:setRoll(VTOL_MaxBank)
  1205. }
  1206.  
  1207. #--Pan Left
  1208. elseif(Key_Left)
  1209. {
  1210. if(CurSpeedLocal:y() < VTOL_MaxSpeed)
  1211. {
  1212. ForceVec -= Parent:right() * (VTOL_Accel + VTOL_Decel) * Delta
  1213. }
  1214.  
  1215. TargetAng = TargetAng:setRoll(-VTOL_MaxBank)
  1216. }
  1217.  
  1218. #--Mouse Yaw
  1219. YawMult = clamp(Mouse_Offset:yaw() / 45, -1, 1)
  1220. YawSpeed = VTOL_YawSpeed * YawMult
  1221.  
  1222. TargetAng = TargetAng:setYaw(TargetAng:yaw() + YawSpeed)
  1223. }
  1224.  
  1225.  
  1226. #--Flight Mode
  1227. elseif(Flight_State == FLIGHT_STATE_FREE)
  1228. {
  1229. #--Decelerate
  1230. local Vel = CurSpeed:length()
  1231. local Dir = CurSpeed:normalized()
  1232. ForceVec += -Dir * clamp(Vel, -Flight_Decel * Delta, Flight_Decel * Delta)
  1233. }
  1234.  
  1235.  
  1236. #Apply Calculations
  1237. PitchQuat = qRotation(quat(1):right(), CurAng:pitch() - TargetAng:pitch())
  1238. YawQuat = qRotation(quat(1):up(), TargetAng:yaw() - CurAng:yaw())
  1239. RollQuat = qRotation(quat(1):forward(), TargetAng:roll() - CurAng:roll())
  1240.  
  1241. TargetQuat = (PitchQuat * YawQuat * RollQuat) * TargetQuat
  1242.  
  1243. DiffQuat = TargetQuat/CurQuat
  1244. DiffQuatAng = DiffQuat:toAngle()
  1245. applyFlightCalcs(ForceVec, DiffQuat:toAngle())
  1246.  
  1247. #--End of Flight Calculations--
  1248. }
  1249.  
  1250. #--End Flight Functions--
  1251.  
  1252. #---------------------
  1253. # THINK LOOP
  1254. #---------------------
  1255. function void think()
  1256. {
  1257. Offset = entity():toLocal(owner():pos())
  1258. local Delta = systime() - LastFrame
  1259.  
  1260. #Resync Ranger Filters
  1261. local Filter = players()
  1262. Filter:pushEntity(Parent)
  1263. rangerFilter(Filter)
  1264. rangerPersist(1)
  1265.  
  1266. if(Setup_Complete)
  1267. {
  1268. #Update Input
  1269. Key_Forward = PilotPod["W",number]
  1270. Key_Back = PilotPod["S",number]
  1271. Key_Left = PilotPod["A",number]
  1272. Key_Right = PilotPod["D",number]
  1273. Key_Up = PilotPod["Space",number]
  1274. Key_Down = PilotPod["Shift",number]
  1275.  
  1276. local Pod = PilotPod["Entity",entity]
  1277. local Driver = Pod:driver()
  1278. if(Driver:isValid())
  1279. {
  1280. Mouse_Offset = Pod:toLocal(Driver:eyeAngles())
  1281. }
  1282. else
  1283. {
  1284. Mouse_Offset = ang()
  1285. }
  1286.  
  1287. landingGearThink(Delta)
  1288. flightThink(Delta)
  1289. }
  1290.  
  1291. LastFrame = systime()
  1292. }
  1293. #--End of Think Loop--
  1294.  
  1295. } #--End of Program Header
  1296.  
  1297.  
  1298. #------------------------
  1299. # WIRE TRIGGERS
  1300. #------------------------
  1301. if(inputClk())
  1302. {
  1303. if(~CanopyToggle)
  1304. {
  1305. toggleCanopy(CanopyToggle)
  1306. }
  1307. }
  1308. #--End of Wire Triggers--
  1309.  
  1310.  
  1311. #--REMOVEME: Temporary chat commands for testing.
  1312. if(chatClk(owner()))
  1313. {
  1314. if(lastSaid():lower() == "!reset")
  1315. {
  1316. hideChat(1)
  1317. entity():remoteUpload("garuda_-_fighter_control.txt")
  1318. }
  1319.  
  1320. if(lastSaid():lower() == "!freeze")
  1321. {
  1322. hideChat(1)
  1323. toggleFreeze(1)
  1324. }
  1325.  
  1326. if(lastSaid():lower() == "!unfreeze")
  1327. {
  1328. hideChat(1)
  1329. toggleFreeze(0)
  1330. }
  1331.  
  1332. if(lastSaid():lower() == "!gravityon")
  1333. {
  1334. hideChat(1)
  1335. toggleGravity(1)
  1336. }
  1337.  
  1338. if(lastSaid():lower() == "!gravityoff")
  1339. {
  1340. hideChat(1)
  1341. toggleGravity(0)
  1342. }
  1343. }
  1344.  
  1345.  
  1346. #-----------------------
  1347. # PROGRAM ENTRY POINT
  1348. #-----------------------
  1349. if(dupefinished()) { reset() }
  1350. elseif(first())
  1351. {
  1352. holoDeleteAll() #For resets
  1353. Parts = entity():getConstraints()
  1354. Parent = entity():isConstrainedTo()
  1355.  
  1356. #Setup
  1357. PilotPod["Crosshairs",number] = 1
  1358. CopilotPod["Crosshairs",number] = 1
  1359. PilotPod["Allow Buttons",number] = 1
  1360. CopilotPod["Allow Buttons",number] = 1
  1361. worldglowGlass()
  1362.  
  1363. timer("Think", 50)
  1364. }
  1365.  
  1366. if(clk("Think"))
  1367. {
  1368. think()
  1369. timer("Think", 50)
  1370. }
RAW Paste Data