Jump to content

Custom Music


HighFlyer

Recommended Posts

Hey guys,

I have a problem, I have scripted a race on MTA Race, but wanted to make custom music. I added this into meta.xml

<meta>
   <info author="Puzi" description="FastSpeed Raceway" version="1.2" type="map" />
<map src="raceway.map" />
<script src="music-somethinggood.lua" type="client"/>
<file src="somethinggood.mp3" />
</meta>

My song is in a MP3 file. This is the music-somethinggood.lua file:

function startMusic()
   setRadioChannel(0)
   song = playSound("somethinggood.mp3",true)
outputChatBox("Toggle music on/off using M")
end
 
function makeRadioStayOff()
   setRadioChannel(0)
   cancelEvent()
end
 
function toggleSong()
   if not songOff then
    setSoundVolume(song,0)
	songOff = true
	removeEventHandler("onClientPlayerRadioSwitch",getRootElement(),makeRadioStayOff)
else
    setSoundVolume(song,1)
	songOff = false
	setRadioChannel(0)
	addEventHandler("onClientPlayerRadioSwitch",getRootElement(),makeRadioStayOff)
end
end
 
addEventHandler("onClientResourceStart",getResourceRootElement(getThisResource()),startMusic)
addEventHandler("onClientPlayerRadioSwitch",getRootElement(),makeRadioStayOff)
addEventHandler("onClientPlayerVehicleEnter",getRootElement(),makeRadioStayOff)
addCommandHandler("musicsomethinggood",toggleSong)
bindKey("m","down","musicsomethinggood")

The problem although is that the script doesnt want to open, it failes to load on the console. Any ideas?

Thanks,

Puzi

Link to comment

It appears the problem is not with the music file, but with the script. Things like too little/many "(" and ")" or "," in the wrong place can cause a script to fail. But it should ouput that error on debugscript. I can't actually find any errors in your script. And line 8 is useless, if you're cancelling the event they won't switch the station in the first place. Maybe you should add that to an onVehicleEnter function, because when entering a vehicle for the first time by default a radio station comes on.

By the way, if it's commercial music it's illegal to give all the clients a copy of it.

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