понимаю что тема подобная создавалась, но не чем не помогло(((( вот собственно вопрос:
какие строчки добавить в скрипт чтоб была музыка из авто на расстоянии
вот скрипт
Клиент:
sx,sy = guiGetScreenSize ()
local volume = 0.3
local guiShowing = false
local currentPlaying = nil
local state = nil
musicPlayerGUI = {}
width,height = 200,350
function createGui ()
musicPlayerGUI.window = guiCreateWindow(sx-width,sy/2-height/2,width,height,"Radio player",false)
musicPlayerGUI.grid = guiCreateGridList(5,25,width-10,height-95,false,musicPlayerGUI.window)
addEventHandler ( "onClientGUIDoubleClick", musicPlayerGUI.grid, onGuiClick, true ) -- klikanie w grid odpala radio stacje
musicPlayerGUI.column = guiGridListAddColumn(musicPlayerGUI.grid,"Radio stations",0.9)
musicPlayerGUI.button1 = guiCreateButton(10,height-65,25,20,">",false,musicPlayerGUI.window)
addEventHandler ( "onClientGUIClick", musicPlayerGUI.button1, onGuiClick,true)
musicPlayerGUI.button2 = guiCreateButton (40, height-65,25,20,"||",false,musicPlayerGUI.window)
addEventHandler ( "onClientGUIClick", musicPlayerGUI.button2, onGuiClick, true )
musicPlayerGUI.button3 = guiCreateButton(70,height-65,60,20,"Play 3D",false,musicPlayerGUI.window)
addEventHandler ( "onClientGUIClick", musicPlayerGUI.button3, onGuiClick, true )
musicPlayerGUI.button4 = guiCreateButton (135, height-65,60,20,"Close",false,musicPlayerGUI.window)
addEventHandler ( "onClientGUIClick", musicPlayerGUI.button4, onGuiClick, true )
musicPlayerGUI.label = guiCreateLabel (5,height-45,width-10,20,"Volume",false,musicPlayerGUI.window)
guiSetFont (musicPlayerGUI.label, "default-bold-small")
guiLabelSetHorizontalAlign (musicPlayerGUI.label, "center")
musicPlayerGUI.volumeBar = guiCreateScrollBar(5,height-30,width-10,20,true,false,musicPlayerGUI.window)
guiScrollBarSetScrollPosition (musicPlayerGUI.volumeBar, volume*100)
guiWindowSetMovable (musicPlayerGUI.window, false)
guiWindowSetSizable (musicPlayerGUI.window, false)
guiSetVisible (musicPlayerGUI.window, false)
end
stationsNames = {}
stations = {}
function showGui ()
if guiShowing then
guiShowing = false
guiSetVisible (musicPlayerGUI.window, false)
showCursor (false)
else
guiShowing = true
guiSetVisible (musicPlayerGUI.window, true)
showCursor (true)
end
end
bindKey("m","down", showGui)
function onGuiClick (button, state, x,y)
if source == musicPlayerGUI.button1 and state == "up" then --play button
local selected = guiGridListGetSelectedItem (musicPlayerGUI.grid)
if selected then
local stationName = guiGridListGetItemText (musicPlayerGUI.grid, selected, musicPlayerGUI.column)
if stationName then
if currentPlaying then
stopSound (currentPlaying)
end
currentPlaying = playSound (stations[stationName])
setSoundVolume (currentPlaying, volume)
state = "play"
else
outputChatBox ("unknown error")
end
elseif state == "pause" and isSoundPaused(currentPlaying) then
setSoundPaused (currentPlaying, false)
end
end
if source == musicPlayerGUI.button2 and state == "up" then --pause button
if isSoundPaused (currentPlaying) == false then
setSoundPaused (currentPlaying, true)
end
end
if source == musicPlayerGUI.button3 and state == "up" then -- 3d
local selected = guiGridListGetSelectedItem (musicPlayerGUI.grid)
if selected then
local stationName = guiGridListGetItemText (musicPlayerGUI.grid, selected, musicPlayerGUI.column)
if stationName then
triggerServerEvent ("onClientRadioCreate", getLocalPlayer(), getLocalPlayer(), stationName)
end
end
end
if source == musicPlayerGUI.button4 and state == "up" then -- close
showGui ()
end
if source == musicPlayerGUI.grid and state == "up" then -- grid list click
local selected = guiGridListGetSelectedItem (musicPlayerGUI.grid)
if selected then
local stationName = guiGridListGetItemText (musicPlayerGUI.grid, selected, musicPlayerGUI.column)
if stationName then
if currentPlaying then
stopSound (currentPlaying)
end
currentPlaying = playSound (stations[stationName])
setSoundVolume (currentPlaying, volume)
else
outputChatBox ("unknown error")
end
end
end
end
function OnScroll(Scrolled)
if source == musicPlayerGUI.volumeBar then
volume = guiScrollBarGetScrollPosition (source) / 100
if currentPlaying then
setSoundVolume (currentPlaying, volume)
end
end
end
addEventHandler("onClientGUIScroll",getRootElement(),OnScroll)
function onRadioCreate (x,y,z,path)
local sound = playSound3D (path, x,y,z)
setSoundVolume (sound, volume)
setSoundMaxDistance (sound, 20)
end
addEvent ("onNewRadioCreate", true)
addEventHandler ("onNewRadioCreate", getRootElement(), onRadioCreate)
function onStart ()
triggerServerEvent ("requestForRadios", getLocalPlayer(), getLocalPlayer())
end
addEventHandler ("onClientResourceStart", getResourceRootElement(getThisResource()), onStart)
function onJoin (radia, names, st)
for k,v in ipairs(radia) do
local sound = playSound3D (v[4], v[1], v[2], v[3])
setSoundVolume (sound, volume/100)
setSoundMaxDistance (sound, 20)
end
stationsNames = names
stations = st
for k,v in ipairs(stationsNames) do
local row = guiGridListAddRow ( musicPlayerGUI.grid )
guiGridListSetItemText ( musicPlayerGUI.grid, row, musicPlayerGUI.column, v, false, false )
end
end
addEvent ("sendAllRadios", true)
addEventHandler ("sendAllRadios", getRootElement(), onJoin)
createGui ()
server
function getPointFromDistanceRotation(x, y, dist, angle)
local a = math.rad(angle+90)
local plusX = math.cos(a) * dist
local plusY = math.sin(a) * dist
return x+plusX, y+plusY
end
xmlFile = xmlLoadFile ("radios.xml")
radios = {}
stations = {}
stationsNames = {}
function loadStations ()
if xmlFile then
local children = xmlNodeGetChildren (xmlFile)
for k,v in ipairs(children) do
local radioTable = xmlNodeGetAttributes (v)
for name,value in pairs(radioTable) do
--outputChatBox (tostring(value))
if name == "name" then
stationName = value
elseif name == "path" then
stationPath = value
end
end
--outputChatBox ("name = " .. tostring(stationName) .. ", path = " .. tostring(stationPath))
stations[stationName] = stationPath
table.insert (stationsNames, 1, stationName)
end
table.sort (stationsNames)
end
end
loadStations ()
--stacje["kwejk"] = "http://fm.kwejk.pl/kwejkfm_aac.m3u"
--stacje["zet"] = "http://www.radiozet.pl/content/stream/radiozet.pls"
--stacje["rmf"] = "http://www.miastomuzyki.pl/odbior/rmf_aacp.pls"
--stacje["rmf fm"] = "http://www.miastomuzyki.pl/odbior/rmf_aacp.pls"
--nazwyStacji = {"kwejk", "zet", "rmf fm"}
function createRadio (player,station)
if station then
local stationPath = stations[station]
if stationPath then
local x,y,z = getElementPosition( player )
local rx,ry,rz = getElementRotation ( player )
local newX, newY = getPointFromDistanceRotation (x,y, 1.5, rz)
local newZ = z - 1
local obiekt = createObject (2226, newX, newY, newZ, rx,ry,rz)
triggerClientEvent ("onNewRadioCreate", getRootElement(), newX, newY, newZ, stationPath) -- wysyla informacje do clientow o nowym radiu
outputChatBox ("New station: " .. station .. " created, path: " .. tostring(stationPath), 0,220,0)
table.insert (radios, 1, {newX, newY, newZ, stationPath}) -- zapisuje informacje o radiu dla nowych graczy
else
outputChatBox ("error", player, 220, 0, 0)
--outputChatBox ("You choose wrong station, avaible stations:", player, 220, 0, 0)
--for k,v in ipairs(stationsNames) do
--outputChatBox ("-" .. v, player)
--end
end
else
outputChatBox ("error", player, 220, 0, 0)
--outputChatBox ("Choose radio to create, avaible stations:", player,220,0,0)
--for k,v in ipairs(stationsNames) do
-- outputChatBox ("-" .. v, player)
--end
end
end
addEvent ("onClientRadioCreate", true)
addEventHandler ("onClientRadioCreate", getRootElement(), createRadio)
--addCommandHandler ("radio", createRadio)
function onJoin (player)
if radios then
triggerClientEvent (player, "sendAllRadios", getRootElement(), radios, stationsNames, stations)
end
end
addEvent ("requestForRadios", true)
addEventHandler ("requestForRadios", getRootElement(), onJoin)