-- Switch Script -- Tarkus1971 ----------------------------------- -- lightstate = 0/off -- lightstate = 1/on -- Uses the timer in line 17 to reset keydown to 0. Timer started on line 69 and 76. local lightstate = 0 -- checks if E is pressed. local keydown = 0 -- player distance local dist = 50 function switches_init(e) end function switches_main(e) PlayerDist = GetPlayerDistance(e) if keydown == 1 and GetTimer(e)>150 then keydown = 0 end if PlayerDist < dist and g_PlayerHealth > 0 then SourceAngle = g_PlayerAngY while SourceAngle < 0.0 do SourceAngle = SourceAngle + 360.0 end while SourceAngle > 340.0 do SourceAngle = SourceAngle - 360.0 end PlayerDX = (g_Entity[e]['x'] - g_PlayerPosX) PlayerDZ = (g_Entity[e]['z'] - g_PlayerPosZ) DestAngle = math.atan2( PlayerDZ , PlayerDX ) -- Convert to degrees DestAngle = (DestAngle * 57.2957795) - 90.0 Result = math.abs(math.abs(SourceAngle)-math.abs(DestAngle)) if Result > 180 then Result = 0 end if Result < 20.0 then if lightstate == 0 and PlayerDist < dist then PromptLocal (e,"Press E to turn on the light.") end if lightstate == 1 and PlayerDist < dist then PromptLocal (e,"Press E to turn off the light.") end if g_KeyPressE == 1 and lightstate == 1 and keydown == 0 then StartTimer(e) HideLight(3) keydown = 1 lightstate = 0 PlaySound(e,1) -- Place spawns here -- elseif g_KeyPressE == 1 and lightstate == 0 and keydown == 0 then StartTimer(e) ShowLight(3) keydown = 1 lightstate = 1 PlaySound(e,1) -- Place spawns here -- end end --end end end -- Last end