-- LUA Script - precede every function and global member with lowercase name of script + '_main' -- Door Prompts 'Closed' can be opened with entity collected specified by 'USE KEY' local U = require "scriptbank\\utillib" -- state to ensure user must release E key before can open/close again local keyPressed = false function door_init( e ) end local lockedStringY = "The door is locked. Press Y button to unlock door" local lockedStringE = "The door is locked. Press E button to unlock door" local openStringY = "Press Y button to open door" local openStringE = "Press E to open door" function door_main( e ) if not U.PlayerLookingNear( e, 100, 90 ) or g_PlayerHealth <= 0 then return end local Ent = g_Entity[ e ] -- if not Ent.plrvisible == 1 then return end local Ekey = g_KeyPressE == 1 if not Ekey then keyPressed = false end if Ent.activated == 0 then if Ent.haskey == -1 then SetActivated( e, 1 ) else if Ent.haskey == 1 then if GetGamePlayerStateXBOX() == 1 then PromptLocalForVR( e, lockedStringY ) else Prompt( lockedStringE ) end if Ekey then SetActivated( e, 1 ) end else Prompt("The door is locked. Find a key to unlock door") end end elseif Ent.activated == 1 then -- door is unlocked and closed if GetGamePlayerStateXBOX() == 1 then PromptLocalForVR( e, openStringY ) else Prompt( openStringE ) end if not keyPressed and Ekey then if Ent.animating == 0 then SetAnimation( 0 ) PlayAnimation( e ) Ent.animating = 1 SetActivated( e, 2 ) ActivateIfUsed( e ) PlaySound( e, 0 ) StartTimer( e ) Ent.timer = g_Time + 2000 keyPressed = true end end elseif Ent.activated == 2 then if g_Time < Ent.timer then return end CollisionOff( e ) -- door is open if not keyPressed and Ekey then if Ent.animating == 0 then SetAnimation( 1 ) PlayAnimation( e ) Ent.animating = 1 SetActivated( e, 1 ) PlaySound( e, 1 ) CollisionOn( e ) keyPressed = true end end end end