local Q = require "scriptbank\\quatlib" local U = require "scriptbank\\utillib" local deg = math.deg local rad = math.rad local doors = {} -- DESCRIPTION: Rotates a non-animating door. -- DESCRIPTION: Hinge type [@TYP=1(1=Right,2=Left)] -- DESCRIPTION: Opening time (seconds) [Period#=3] -- DESCRIPTION: When the door is opening, play and when closing, play . local hingeTypes = {'left','right'} function door_rotate_properties( e, typ, period ) local door = doors[ e ] if door == nil then return end door.hinge = hingeTypes[ typ ] door.period = period * 1000 / 20 end local keyPressed = false function door_rotate_init( e ) doors[ e ] ={ state = 'init' } end local function rotateDoor( e, door ) local rotAng = door.angle if door.hinge == 'right' then rotAng = -rotAng end local rotq = Q.FromEuler( 0, rad( rotAng ), 0 ) local ax, ay, az = Q.ToEuler( Q.Mul( door.quat, rotq ) ) CollisionOff( e ) ResetRotation( e, deg( ax ), deg( ay ), deg( az ) ) CollisionOn( e ) end local timeLastFrame = nil local timeDiff = 1 local controlEnt = nil function door_rotate_main( e ) local door = doors[ e ] if door == nil then return end local Ent = g_Entity[ e ] if controlEnt == nil then controlEnt = e end local timeThisFrame = g_Time if controlEnt == e then if timeLastFrame == nil then timeLastFrame = timeThisFrame timeDiff = 1 else timeDiff = ( timeThisFrame - timeLastFrame ) / 20 timeLastFrame = timeThisFrame end end if door.state == 'init' then local x, y, z, ax, ay, az = GetObjectPosAng( Ent.obj ) door.obj = Ent.obj door.timer = math.huge door.quat = Q.FromEuler( rad( ax ), rad( ay ), rad( az ) ) door.origx = Ent.x door.origy = Ent.y door.origz = Ent.z door.actvd = Ent.activated == 1 door.rInc = 90 / door.period if door.actvd then door.angle = 90 door.state = 'open' rotateDoor( e, door ) else door.angle = 0 door.state = 'closed' RDBlockNavMesh( door.origx, door.origy, door.origz, 30, 1 ) end elseif door.state == 'closed' then if Ent.activated == 1 then door.state = 'opening' PlaySound( e, 1 ) elseif U.PlayerLookingNear( e, 100, 140 ) then -- looking at door so prompt Prompt( "Press E to open door" ) if g_KeyPressE == 1 then PlaySound( e, 1 ) door.state = 'opening' keyPressed = true end end elseif door.state == 'open' then if Ent.activated == 0 then door.state = 'closing' PlaySound( e, 2 ) elseif U.PlayerLookingNear( e, 100, 140 ) then Prompt( "Press E to close door" ) if g_KeyPressE == 1 then door.state = 'closing' keyPressed = true PlaySound( e, 2 ) end end elseif door.state == 'opening' then if door.angle < 90 then door.angle = door.angle + door.rInc * timeDiff rotateDoor( e, door ) else door.state = 'open' SetEntityActivated( e, 1 ) RDBlockNavMesh( door.origx, door.origy, door.origz, 30, 0 ) end elseif door.state == 'closing' then if door.angle > 0 then door.angle = door.angle - door.rInc * timeDiff rotateDoor( e, door ) else door.state = 'closed' SetEntityActivated( e, 0 ) RDBlockNavMesh( door.origx, door.origy, door.origz, 30, 1 ) end end end