Yeah, just like that and it should work.
In your original, the condition was if the player was pressing M (which you should change to 50) and the action was then to play the music.
So only if M was being pressed, it would play the music.
Also, in your revised script above, you had the music as a condition. for it to play you would need an action instead.
;Artificial intelligence script
;Header
desc = player uses code to play a song
;Triggers
:state=0,plrdistwithin=50:state=1
:state=1,scancodekeypressed=50:state=2
:state=2:music=audiobank\song0.wav,musicvolume=100,state=0
;End of script
I havent tested it yet, and I am nothing of a scripter, but that should solve the problem.
EDIT:
I am loading a testgame now, to see if it will work, but by looking at it, I realized at the end of state 2, it goes straight back to state 1. That could also be a problem there, but I am not sure until I try it myself.
EDIT 2:
Yeah, change it to this, and apply the script to any DNYAMIC entity. Or light if you want to get real tricky. Its also a good idea to keep the music in the music folder of the audiobank.
;Header
desc = player uses code to play a song
;Triggers
:state=0,plrdistwithin=50:state=1
:state=1,scancodekeypressed=50:state=2
:state=2:music=audiobank\music\song0.wav,musicvolume=100,state=3
;End of script