Jump to content

[help] table and playSound3D


raynner

Recommended Posts

Good'm creating a tuning shop for my RPG server. most did not want to use files files to decrease the MB script ... so I had the idea of creating music using random using playSound3D URL .. but I have two errors.

ERROR 1 = Table does not work.

ERROR 2 = He is not changing the interior or the size of the element.

can anyone point me a correct direction or point out the error in my script?

 

Client Sid

local URLMusics =
    {
        {'https://albireo1.sscdn.co/palcomp3/2/a/b/9/equipeinsanos-tribo-da-periferia-mussoumano-convida-6ec60699.mp3'},
		{'https://japeto.sscdn.co/palcomp3/a/5/4/a/equipeinsanos-tribodaperiferia-carro-velho-ec4211d7-e7b4a010.mp3'}
    }

function ShowDxMenuStartTuning()
	addEventHandler("onClientRender", root, DXMenuPrincipal)
	showCursor(true)
	PainelMenuPrincipal = true
	MusicTuning()
end
addEvent("ShowPainelMenuStartTuning", true)
addEventHandler("ShowPainelMenuStartTuning", getRootElement(), ShowDxMenuStartTuning)

function MusicTuning()
	local randomize = math.random ( #URLMusics )
	local TuningSound = playSound3D('URLMusics[randomize]',1383,-22,1001,true)
	setSoundMaxDistance(TuningSound,50)
	triggerServerEvent("StartSond", root, TuningSound)
end

Server Sid

DIMS___ = 1
function DimensionSond(TuningSound)
	setElementDimension(TuningSound,DIMS___)
	setElementInterior(TuningSound,1)
	setElementPosition(TuningSound,1383,-22,1001)
	DIMS___ = DIMS___  + 1
end
addEvent("StartSond", true)
addEventHandler("StartSond", getRootElement(), DimensionSond)

 

Link to comment

your usage of tables is wrong, i corrected it for you here: 

 

local TuningSound = playSound3D(URLMusics[randomize], 1383, -22, 1001, true) -- you don't need to turn it into a string and it's not how turning a variable/table into a string is done. you should use tostring for that but in your case, table member returns a string value (your url) so you don't need it at all

secondly you don't need to set sound's dimension and interior on serverside, and you can't because it's not synced. so you can basically do move your "DimensionSond" script to client side and run it. here's how it should look like:

function MusicTuning()
  local randomize = math.random ( #URLMusics )
  local TuningSound = playSound3D(URLMusics[randomize],1383,-22,1001,true)
  setSoundMaxDistance(TuningSound,50)
  DimensionSond (TuningSound)
end

DIMS___ = 1
function DimensionSond(TuningSound)
  setElementDimension(TuningSound,DIMS___)
  setElementInterior(TuningSound,1)
  setElementPosition(TuningSound,1383,-22,1001)
  DIMS___ = DIMS___ + 1
end

in the end, your code should look like:


local URLMusics =
{
{'https://albireo1.sscdn.co/palcomp3/2/a/b/9/equipeinsanos-tribo-da-periferia-mussoumano-convida-6ec60699.mp3'},
{'https://japeto.sscdn.co/palcomp3/a/5/4/a/equipeinsanos-tribodaperiferia-carro-velho-ec4211d7-e7b4a010.mp3'}
}

function ShowDxMenuStartTuning()
  addEventHandler("onClientRender", root, DXMenuPrincipal)
  showCursor(true)
  PainelMenuPrincipal = true
  MusicTuning()
end
addEvent("ShowPainelMenuStartTuning", true)
addEventHandler("ShowPainelMenuStartTuning", getRootElement(), ShowDxMenuStartTuning)

function MusicTuning()
  local randomize = math.random ( #URLMusics )
  local TuningSound = playSound3D(URLMusics[randomize],1383,-22,1001,true)
  setSoundMaxDistance(TuningSound,50)
  DimensionSond (TuningSound)
end

DIMS___ = 1
function DimensionSond(TuningSound)
  setElementDimension(TuningSound,DIMS___)
  setElementInterior(TuningSound,1)
  setElementPosition(TuningSound,1383,-22,1001)
  DIMS___ = DIMS___ + 1
end

 

Link to comment
25 minutes ago, Adolfram said:

in the end, your code should look like:


local URLMusics ={{'https://albireo1.sscdn.co/palcomp3/2/a/b/9/equipeinsanos-tribo-da-periferia-mussoumano-convida-6ec60699.mp3'},{'https://japeto.sscdn.co/palcomp3/a/5/4/a/equipeinsanos-tribodaperiferia-carro-velho-ec4211d7-e7b4a010.mp3'}}
function ShowDxMenuStartTuning()
  addEventHandler("onClientRender", root, DXMenuPrincipal)
  showCursor(true)
  PainelMenuPrincipal = true
  MusicTuning()
end
addEvent("ShowPainelMenuStartTuning", true)
addEventHandler("ShowPainelMenuStartTuning", getRootElement(), ShowDxMenuStartTuning)

function MusicTuning()
  local randomize = math.random ( #URLMusics )
  local TuningSound = playSound3D(URLMusics[randomize],1383,-22,1001,true)
  setSoundMaxDistance(TuningSound,50)
  DimensionSond (TuningSound)
end

DIMS___ = 1
function DimensionSond(TuningSound)
  setElementDimension(TuningSound,DIMS___)
  setElementInterior(TuningSound,1)
  setElementPosition(TuningSound,1383,-22,1001)
  DIMS___ = DIMS___ + 1
end

Well I did not know that it was now possible to use setElementDimension and setElementInterior in Client Sid .. so no need to do so in a new function ...

good yet still I have an error with the table he asks the first argument in playSound3D as a string and ....

current code.

Client sid


local URLMusics ={{'https://albireo1.sscdn.co/palcomp3/2/a/b/9/equipeinsanos-tribo-da-periferia-mussoumano-convida-6ec60699.mp3'},
{'https://japeto.sscdn.co/palcomp3/a/5/4/a/equipeinsanos-tribodaperiferia-carro-velho-ec4211d7-e7b4a010.mp3'}
}

DIMS___ = 1
function MusicTuning()
	local randomize = math.random ( #URLMusics )
	local TuningSound = playSound3D(URLMusics[randomize],1383,-22,1001,true) --> put a string table as it emits no more mistakes does not work
	setSoundMaxDistance(TuningSound,50)
	setElementDimension(TuningSound,DIMS___)
	setElementInterior(TuningSound,1)
	setElementPosition(TuningSound,1383,-22,1001)
	DIMS___ = DIMS___ + 1
end

 

 

Link to comment
2 minutes ago, Adolfram said:

right. you should remove {} tags around the URL strings, it should be like 


local URLMusics = {  'url',
  'url'
}

 

hehe :D We forget that text table is = {'abc', 'abc'} have not tested more this will work for sure my carelessness ^_^

solved :D Working perfectly

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...