-- LUA Script - precede every function and global member with lowercase name of script + '_main' -- sb_door script has been adapted from the default gg door script -- modified by Reliquia -- Script Purpose: -- Player must have key if door is locked - specified by 'USE KEY' field -- Allow player to Open\Close door when unlocked -- Ensure door Collision point is altered depending on it being in open or closed positions -- sr_door model resources: -- Two animations stored in the model: 0=opening 1=closing -- scriptbank\reliquia\sr_door: This script to facilitate animations -- Audio -- Opening: specified in sound0 field -- Closing: specified in sound1 field -- variables used by sb_door sbdoor_pressed = 0 -- state to ensure user must release E key before can open/close again function sb_door_init(e) end function sb_door_main(e) PlayerDist = GetPlayerDistance(e) if (PlayerDist < 85 ) and g_PlayerHealth > 0 then -- If door not activated check if key required if g_Entity[e]['activated'] == 0 then if g_Entity[e]['haskey'] == -1 then -- key not required activate the door SetActivated(e,1) else -- key is required - check if player has one if g_Entity[e]['haskey'] == 1 then -- player has key - prompt to use it Prompt("The door is locked - E to use key") if g_KeyPressE == 1 then -- player used key - activate door SetActivated(e,1) sbdoor_pressed = 1 -- state to ensure user must release E key before can open/close again end else -- player has no key - promt to find one Prompt("The door is locked - find the key for it") end end else -- door is active if g_Entity[e]['activated'] == 1 then -- door is closed -- display prompt if door is not currently animating -- not animating, prompt player to open if g_Entity[e]['animating'] == 0 then Prompt("E to open the door") end -- player pressed e, open door if g_KeyPressE == 1 and g_Entity[e]['animating'] == 0 and sbdoor_pressed == 0 then SetAnimation(0) -- set opening animation PlayAnimation(e) -- play the animation g_Entity[e]['animating'] = 1 -- set flag so system knows it is animatng SetActivated(e,2) -- set activated state to 2 so system knows it is in open state ActivateIfUsed(e) PlaySound(e,0) -- play the open door sound sbdoor_pressed = 1 -- state to ensure user must release E key before can open/close again CollisionOff(e) -- turn off collisions StartTimer(e) -- start timer to turn collisions off after 1 second g_Entity[e]['timer'] = g_Time end else if g_Entity[e]['activated'] == 2 then -- door is open -- display prompt if door is not currently animating -- not animating, prompt player to close if g_Entity[e]['animating'] == 0 then Prompt("E to close the door") end -- player pressed e, close the canopy if g_KeyPressE == 1 and g_Entity[e]['animating'] == 0 and sbdoor_pressed == 0 then SetAnimation(1) -- set closing animation PlayAnimation(e) -- play the animation g_Entity[e]['animating'] = 1 -- set flag so system knows it is animatng SetActivated(e,1) -- set activated state to 1 so system knows it is in closed state PlaySound(e,1) -- play the close door sound sbdoor_pressed = 1 -- state to ensure user must release E key before can open/close again CollisionOn(e) -- turn off collisions end end end end end -- TURN COLLISIONS OFF - OPENING SEQUENCE ONLY if g_Entity[e]['activated'] == 2 then -- door collision off after 1 second when opening if GetTimer(e)>1000 then --CollisionOff(e) end end -- check if player has released the E key -- if so reset sbdoor_pressed var so user can open/close again if g_KeyPressE == 0 then sbdoor_pressed = 0 end -- TURN COLLISIONS ON WHEN ANIMATION FINISHED -- Check if animation has finished if g_Entity[e]['animating'] == 0 then -- turn door collision on --CollisionOn(e) end --PromptLocal ( e, "activated=" .. g_Entity[e]['activated'] .. "PlayerDist=" .. PlayerDist .. " plrvisible=" .. g_Entity[e]['plrvisible'] .. " haskey=" .. g_Entity[e]['haskey'] ) --PromptLocal ( e, "is activated=" .. g_Entity[e]['activated'] .. " is anmimating = " .. g_Entity[e]['animating'] ) end