Jump to content

Bad argument @ 'addEventHandler' [Expected function at argument 3, got nill]


Tony Brand

Recommended Posts

hi, i am newbie in lua,
i want to make a radio system that plays sound from vehicle for all players
so i downloaded radio :O system from here
but it doesn't have server side, so i made it
my problem is that i get error when running resource but i think i don't have any mitake...
error is Bad argument radio/server.lua:2 @ 'addEventHandler' [Expected function at argument 3, got nill]
& radio/server.lua:10@ 'addEventHandler' [Expected function at argument 3, got nill]

whole the server side is this:
 

addEvent("getSoundStopForAll", true)
addEventHandler("getSoundStopForAll", root, getSoundStopForAll )
	function getSoundStopForAll( )
		stopSound(Stream[source])
		Stream[source] = nil
		sPath[source] = nil
	end

addEvent("sendSoundForAll", true)
addEventHandler("sendSoundForAll", root, sendSoundForAll )
	function sendSoundForAll( )
		triggerClientEvent(root, "syncradio",  sendSoundForAll)
	end

also here is syncradio ClientEvent
 

addEvent("syncradio", true)
addEventHandler("syncradio", root,
	function( )
		local x, y, z = getElementPosition(source)
		Stream[source] = playSound3D(channelTable[channelTable[path]], x, y, z)
		setSoundEffectEnabled ( Stream[source], "compressor", true )
		sPath[source] = path
		setSoundVolume(Stream[source], volume)
		setSoundMaxDistance(Stream[source], 50)
		attachElements(Stream[source], source)
	end)

 

Link to comment
6 minutes ago, iMr.WiFi..! said:

addEvent("getSoundStopForAll", true)
addEventHandler("getSoundStopForAll", root, 
	function ( )
		stopSound(Stream[source])
		Stream[source] = nil
		sPath[source] = nil
	end
)
addEvent("sendSoundForAll", true)
addEventHandler("sendSoundForAll", root,
	function ( )
		triggerClientEvent(root, "syncradio", root)
	end 
)

 

errors solved but now there are 4 warnings in debugscript gui and music doesn't play!
https://pasteboard.co/HDRcH1e.png
the part of that client side that made errors:

addEvent("syncradio", true)
addEventHandler("syncradio", root,
	function( )
		local x, y, z = getElementPosition(source)
		Stream[source] = playSound3D(channelTable[channelTable[path]], x, y, z)
		setSoundEffectEnabled ( Stream[source], "compressor", true )
		sPath[source] = path
		setSoundVolume(Stream[source], volume)
		setSoundMaxDistance(Stream[source], 50)
		attachElements(Stream[source], source)
	end)


 

Link to comment
channelTable =
{
	["The Beat FM"] = "http://thebeat.no/thebeatlisten.m3u",
	[1] = "The Beat FM",
	
	["101.9FM Chicago - The Mix"] = "http://playerservices.streamtheworld.com/pls/WTMXFM.pls",
	[2] = "101.9FM Chicago - The Mix",
	
	["100.3FM Chicago - Rewind"] = "http://playerservices.streamtheworld.com/pls/WILVFM.pls",
	[3] = "100.3FM Chicago - Rewind",
}
local veh = getPedOccupiedVehicle(localPlayer)
function onClientChangeStreamState_Handler()
local veh = getPedOccupiedVehicle(localPlayer)
if isPedInVehicle(localPlayer) then
if getVehicleController(veh) == localPlayer then
	if(source == radioPlayerPlayButton) then
if iAllowed == false then showWarning("Please Wait few seconds!") return false end
iAllowed = false
setTimer(setAllowed, 5000, 1)
		if Stream[veh] == nil then
			triggerServerEvent("sendSoundForAll", localPlayer, veh, currentChannel, radioVolume)
			guiSetVisible(radioPlayerPlayButton, false)
			guiSetVisible(radioPlayerStopButton, true)
			isMouseOverStop = true
		end

	elseif(source == radioPlayerStopButton) then
		if Stream[veh] then
			triggerServerEvent("getSoundStopForAll", veh)
			guiSetVisible(radioPlayerStopButton, false)
			guiSetVisible(radioPlayerPlayButton, true)
			guiSetText(radioMetaArtistLabel, "Artist: "..streamArtist)
			guiSetText(radioMetaTitleLabel, "Title: "..streamTitle)
		end
	end
	end
end
end
addEventHandler("onClientGUIClick", getRootElement(), onClientChangeStreamState_Handler)

 

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...