--adjust how far player can interact with door local use_range = 100 local use_angle = 25 local collision_delay_init = 1.15 --time delay till collision toggles on/off (1000 = 1s) --set prompts here local prompt1 = "Door is locked, activate the switch to proceed" local prompt2 = "Press 'E' to open the door" local prompt3 = "You hear the sound of a door locking somewhere" local prompt4 = "Press 'E' to close the door" local collision_delay = {} local switch = {} collision_delay_init = collision_delay_init * 1000 --use with door_switch.lua function door_with_switch_init_name(e,name) weapon_name[e] = name collision_delay[e] = collision_delay_init end function door_with_switch_main(e) if switch[e] == nil then for a = 1,9999 do if g_Entity[a] ~= nil and a ~= e then if weapon_name[a] == weapon_name[e] then SetActivated(e,1) switch[e] = a break end end end else if g_Time > switch_delay[switch[e]] and switch_activated[switch[e]] == 1 then if g_Entity[e]['activated'] > 2 then SetAnimation(1) PlayAnimation(e) g_Entity[e]['animating'] = 1 CollisionOn(e) end PromptDuration(prompt3,2000) PlaySound(e,1) SetActivated(e,1) switch_activated[switch[e]] = 0 end if PlayerLooking(e,use_range,use_angle) == 1 then if g_Entity[e]['activated'] == 1 then Prompt(prompt1) elseif g_Entity[e]['activated'] == 2 then if g_Entity[e]['animating'] == 0 then Prompt(prompt2) if g_KeyPressE == 1 then switch_activated[switch[e]] = 2 collision_delay[e] = g_Time + collision_delay_init SetAnimation(0) PlayAnimation(e) PlaySound(e,0) g_Entity[e]['animating'] = 1 SetActivated(e,3) end end elseif g_Entity[e]['activated'] == 3 then if g_Time > collision_delay[e] then CollisionOff(e) SetActivated(e,4) end elseif g_Entity[e]['activated'] == 4 then if g_Entity[e]['animating'] == 0 then Prompt(prompt4) if g_KeyPressE == 1 then collision_delay[e] = g_Time + collision_delay_init SetAnimation(1) PlayAnimation(e) PlaySound(e,1) g_Entity[e]['animating'] = 1 SetActivated(e,5) end end elseif g_Entity[e]['activated'] == 5 then if g_Time > collision_delay[e] then CollisionOn(e) SetActivated(e,6) end elseif g_Entity[e]['activated'] == 6 then if g_Entity[e]['animating'] == 0 then Prompt(prompt2) if g_KeyPressE == 1 then collision_delay[e] = g_Time + collision_delay_init SetAnimation(0) PlayAnimation(e) PlaySound(e,0) g_Entity[e]['animating'] = 1 SetActivated(e,3) end end end --activated end --player looking end --switch set end --main(e) function door_with_switch_exit(e) 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