--adjust how far player can interact with the switch local use_range = 140 local use_angle = 25 local switch_delay_init = 6 --how many seconds door will remain unlocked for --set prompts here local prompt1 = "This must unlock a door somewhere... press it? 'E'" local prompt2 = "You hear the sound of a door unlocking somewhere" local prompt3 = "This switch appears to have no further use" switch_delay = {} local door = {} switch_activated = {} switch_delay_init = switch_delay_init * 1000 --use with door_with_switch.lua function door_switch_init_name(e,name) weapon_name[e] = name switch_delay[e] = switch_delay_init switch_activated[e] = 0 end function door_switch_main(e) if door[e] == nil then for a = 1,9999 do if weapon_name[a] ~= nil and a ~= e then if weapon_name[a] == weapon_name[e] then SetActivated(e,1) door[e] = a break end end end else if PlayerLooking(e,use_range,use_angle) == 1 then if switch_activated[e] < 2 then if g_Entity[e]['activated'] == 1 then Prompt(prompt1) if g_KeyPressE == 1 then SetAnimation(0) PlayAnimation(e) PlaySound(e,0) switch_delay[e] = g_Time + switch_delay_init switch_activated[e] = 1 SetActivated(door[e],2) SetActivated(e,2) end elseif g_Entity[e]['activated'] == 2 then PromptDuration(prompt2,2000) if g_Entity[e]['animating'] == 0 and g_Time > switch_delay[e] - (switch_delay_init / 6) then SetActivated(e,1) end end else Prompt(prompt3) end end end --door set end --main(e) function door_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