-- 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' open = {} local timer = {} local collision_mode = {} function door_auto_init(e) open[e] = 0 collision_mode[e] = 1 timer[e] = 0 end function door_auto_main(e) PlayerDist = GetPlayerDistance(e) if open[e] == 0 then if PlayerDist < 150 then if g_Entity[e]['activated'] == 0 then if PlayerLooking(e,150,30) == 1 then if g_Entity[e]['haskey'] == -1 then SetActivated(e,1) else if g_Entity[e]['haskey'] == 1 then Panel(40,95,60,98) Prompt("Unlock the door?") if g_KeyPressE == 1 then SetActivated(e,1) PlaySound(e,0) end else Panel(40,95,60,98) Prompt("This door is locked") end end end else if g_Entity[e]['activated'] == 1 then if g_Entity[e]['animating'] == 0 then --StartTimer(e) timer[e] = os.time() SetAnimation(0) PlayAnimation(e) g_Entity[e]['animating'] = 1 SetActivated(e,2) ActivateIfUsed(e) PlaySound(e,1) end else if g_Entity[e]['activated'] == 2 then -- door collision off after 1 second if os.time() > timer[e] + 2 and collision_mode[e] == 1 then collision_mode[e] = 0 --CollisionOff(e) open[e] = 1 end end end end end else if GetPlayerDistance(e) > 180 then -- door is open if g_Entity[e]['activated'] == 2 then if g_Entity[e]['animating'] == 0 then --StartTimer(e) timer[e] = os.time() SetAnimation(1) PlayAnimation(e) g_Entity[e]['animating'] = 1 SetActivated(e,1) PlaySound(e,1) end else if os.time() > timer[e] + 1 and collision_mode[e] == 0 then collision_mode[e] = 1 --CollisionOn(e) open[e] = 0 end end end end end function PlayerLooking(e,dis,v) if g_Entity[e] ~= nil then if dis == nil then dis = 3000 end if v == nil then v = 0.5 end if GetPlayerDistance(e) <= dis then local destx = g_Entity[e]['x'] - g_PlayerPosX local destz = g_Entity[e]['z'] - g_PlayerPosZ local angle = math.atan2(destx,destz) angle = angle * (180.0 / math.pi) if angle <= 0 then angle = 360 + angle elseif angle > 360 then angle = angle - 360 end while g_PlayerAngY < 0 or g_PlayerAngY > 360 do if g_PlayerAngY <= 0 then g_PlayerAngY = 360 + g_PlayerAngY elseif g_PlayerAngY > 360 then g_PlayerAngY = g_PlayerAngY - 360 end end local L = angle - v local R = angle + v if L <= 0 then L = 360 + L elseif L > 360 then L = L - 360 end if R <= 0 then R = 360 + R elseif R > 360 then R = R - 360 end if (L < R and math.abs(g_PlayerAngY) > L and math.abs(g_PlayerAngY) < R) then return 1 elseif (L > R and (math.abs(g_PlayerAngY) > L or math.abs(g_PlayerAngY) < R)) then return 1 else return 0 end else return 0 end end end