-- LUA Script - precede every function and global member with lowercase name of script + '_main' local Q = require "scriptbank\\quatlib" local U = require "scriptbank\\utillib" local P = require "scriptbank\\physlib" local rad = math.rad local deg = math.deg local atan = math.atan2 local modf = math.modf local abs = math.abs local mouse_spr = mouse_spr or CreateSprite( LoadImage( "scriptbank\\images\\mouse_cursor.png" )) function aircraft_init( e ) Include( "utillib.lua" ) Include( "quatlib.lua" ) Include( "physlib.lua" ) SetSpriteSize( mouse_spr, 2.5 ) SetSpriteOffset( mouse_spr, 1.25, 2.1 ) SetSpritePosition( mouse_spr, 200, 200 ) end local aircraft = {} local controlEnt = nil local timeLastFrame = nil local timeDiff = 0 local hoverHeight = 60 local liftFactor = 10 local maxLift = 16 local minLift = 2 local playerPos1 = { xo = 0, yo = 18, zo = -12 } local playerPos2 = { xo = 0, yo = 30, zo = -55 } local function AttachPlayer( h, xa, ya, za ) local xo, yo, zo = U.Rotate3D( h.pp.xo, h.pp.yo, h.pp.zo, xa, ya, za ) cx, cy, cz = h.pos.x + xo, h.pos.y + yo, h.pos.z + zo SetCameraPosition ( 0, cx, cy, cz ) SetCameraAngle ( 0, deg( xa ) + 15, deg( ya ), deg( za ) ) SetFreezePosition( h.pos.x, h.pos.y + hoverHeight + 80, h.pos.z ) TransportToFreezePositionOnly() end local function posObject( h ) local xA, yA, zA = Q.ToEuler( h.quat ) local vx, vy, vz = U.Rotate3D( 0, 0, h.vec.z, xA, yA, zA ) h.pos.x, h.pos.y, h.pos.z = h.pos.x + vx, h.pos.y + vy, h.pos.z + vz CollisionOff( h.ent ) PositionObject( h.obj, h.pos.x, h.pos.y, h.pos.z ) RotateObject( h.obj, deg( xA ), deg( yA ), deg( zA ) ) CollisionOn( h.ent ) AttachPlayer( h, xA, yA, zA ) end local EPressed = false function aircraft_main( e ) local h = aircraft[ e ] if h == nil then local Ent = g_Entity[ e ] local x, y, z, xa, ya, za = GetObjectPosAng( Ent.obj ) aircraft[ e ] = { ent = e, state = 'init', timer = math.huge, obj = Ent.obj, pos = { x = x, y = y, z = z }, quat = Q.FromEuler( rad( xa ), rad( ya ), rad( za ) ), vec = { x = 0, y = 0, z = 0 }, height = 0, pp = playerPos2 } return end local timeNow = g_Time if h.state == 'init' then h.state = 'start' h.timer = timeNow + 1000 end if controlEnt == nil then controlEnt = e end if controlEnt == e then if timeLastFrame == nil then timeLastFrame = timeNow timeDiff = 1 else timeDiff = ( timeNow - timeLastFrame ) / 20 timeLastFrame = timeNow end end if h.state == 'start' then if h.inCab then if g_KeyPressE == 1 then if not EPressed then EPressed = true SetCameraOverride( 0 ) DeactivateMouse() SetSpritePosition( mouse_spr, 200, 200 ) SetPlayerWeapons( 1 ) h.inCab = false h.height = 2 StopSound( e, 0 ) end else EPressed = false end if g_KeyPressR == 1 then if not RPressed then RPressed = true if h.pp == playerPos1 then h.pp = playerPos2 else h.pp = playerPos1 end end else RPressed = false end if g_KeyPressW == 1 then PlaySoundIfSilent( e, 1 ) if h.vec.z < 5 then h.vec.z = h.vec.z + 0.01 * timeDiff end elseif g_KeyPressS == 1 then PlaySoundIfSilent( e, 1 ) if h.vec.z > -5 then h.vec.z = h.vec.z - 0.01 * timeDiff end else if h.vec.z > 0.05 then h.vec.z = h.vec.z - 0.05 * timeDiff elseif h.vec.z < -0.05 then h.vec.z = h.vec.z + 0.05 * timeDiff else h.vec.z = 0 end StopSound( e, 1 ) end local omx, omy = ( g_MouseX - 50 ) / 50, ( g_MouseY - 50 ) / 50 if abs( omx ) < 0.05 then omx = 0 end if abs( omy ) < 0.05 then omy = 0 end SetSpritePosition( mouse_spr, g_MouseX, g_MouseY ) --Prompt( omy .. ", " .. omx ) local pitchQ = Q.FromEuler( -rad( omy ), 0, 0 ) local rollQ = Q.FromEuler( 0, 0, -rad( omx ) ) h.quat = Q.Mul( h.quat, pitchQ ) h.quat = Q.Mul( h.quat, rollQ ) posObject( h) if g_KeyPressA == 1 then elseif g_KeyPressD == 1 then else end --CheckForCollision( h.obj ) else if U.PlayerLookingNear( e, 200, 180 ) then Prompt( "E to fly me" ) if g_KeyPressE == 1 then if not EPressed then PositionMouse( GetDeviceWidth() / 2, GetDeviceHeight() / 2 ) ActivateMouse() LoopNon3DSound( e, 0 ) EPressed = true SetPlayerWeapons( 0 ) SetCameraOverride( 3 ) h.inCab = true end else EPressed = false end end end end end