-- LUA Script - precede every function and global member with lowercase name of script + '_main' local U = require "scriptbank\\utillib" local Q = require "scriptbank\\quatlib" local rad = math.rad local deg = math.deg local spaceship_list = {} function spaceship_init( e ) Include( "utillib.lua" ) spaceship_list[ e ] = nil end -- 0.2 degree up pitch i.e. entity x axis -ve rotation local rotQuat = Q.FromEuler( rad( -0.2 ), 0, 0 ) function spaceship_main( e ) local de = spaceship_list[ e ] if de == nil then spaceship_list[ e ] = { state = 'init', timer = math.huge } return end if de.state == 'init' then -- register for dynamic entities if DE_Register == nil then return end -- four flame decals for exhaust ports DE_Register( e, 'Flame Blue' ) DE_Register( e, 'Flame Blue' ) DE_Register( e, 'Flame Blue' ) DE_Register( e, 'Flame Blue' ) de.state = 'show' -- wait 5 seconds de.timer = g_Time + 5000 return end if de.state == 'show' then DE_Show( e, 'Flame Blue' ) de.state = 'idle' end local Ent = g_Entity[e] local nx, ny, nz = Ent.x, Ent.y, Ent.z local quat = Q.FromEuler(rad(Ent.anglex), rad(Ent.angley), rad(Ent.anglez)) if de.state == 'idle' and g_Time > de.timer then -- apply rotation quat = Q.Mul( quat, rotQuat ) -- get new Euler angles local xa, ya, za = Q.ToEuler( quat ) -- move forward by 2 units local XO, YO, ZO = U.Rotate3D( 0, 0, 2, xa, ya, za ) nx, ny, nz = nx + XO, ny + YO, nz + ZO -- reposition spaceship CollisionOff( e ) ResetRotation( e, deg( xa ), deg( ya ), deg( za ) ) ResetPosition( e, nx, ny, nz ) CollisionOn( e ) end -- update 'attached' decals DE_Update( e, nx, ny, nz, quat ) end