local maxsongs = {} local sounddropoff = {} local interactrange = 150 local interactangle = 30 local state = {} local currentstation = {} U = U or require "scriptbank\\utillib" presse = 0 changestation = 0 --use the entity name to set the number of songs and health to set how quickly the sound fades function radio_init(e) state[e] = "off" currentstation[e] = 0 maxsongs[e] = tonumber(GetEntityName(e)) --number of stations to cycle through (i.e. number of sound slots filled up) if maxsongs[e] == nil then maxsongs[e] = 1 end sounddropoff[e] = g_Entity[e]['health'] --how quickly the volume changes based on player distance end function radio_main(e) if state[e] == "on" then if U.PlayerLookingNear(e, interactrange, interactangle) == true then PromptLocal(e, "Change station - < / > (Radio "..currentstation[e]..") , Turn off the radio - (E)") if g_KeyPressE == 1 then if presse == 0 then state[e] = "off" StopSound(e, currentstation[e]) presse = 1 return end else presse = 0 if g_Scancode == 51 then if changestation == 0 then StopSound(e, currentstation[e]) currentstation[e] = currentstation[e] - 1 if currentstation[e] < 0 then currentstation[e] = maxsongs[e]-1 end end changestation = 1 elseif g_Scancode == 52 then if changestation == 0 then StopSound(e, currentstation[e]) currentstation[e] = currentstation[e] + 1 if currentstation[e] >= maxsongs[e] then currentstation[e] = 0 end end changestation = 1 else changestation = 0 end end end LoopSound(e, currentstation[e]) local vol = 101 - (GetPlayerDistance(e) / sounddropoff[e]) if vol > 100 then vol = 100 elseif vol < 1 then vol = 1 end SetSoundVolume(vol) else if U.PlayerLookingNear(e, interactrange, interactangle) == true then PromptLocal(e, "Turn on the radio - (E)") if g_KeyPressE == 1 then if presse == 0 then state[e] = "on" end presse = 1 else presse = 0 end end end end