Hey, A friend approached me earlier today as he’s trying to make a map replicate of a TV game show in Hammer, but can’t do things such as pause/resume sounds. He told me it should be possible using Lua scripts, if I could take a look for him.
I popped open a guide on LUA on the GMod Wiki as I’d never touched it before about 2 hours ago (Although I do know a fair amount of Python) and took a look.
I fiddled for a bit got my bearings and this worked to create a hook to play a sound when the button was pressed:
local function finalchase(ply, ent) if ent:GetName() == "FinalChaseTest" then sound.Play("chase/finalchase.wav", Vector(0,0,0), 180, 100, 1) end end hook.Add( "PlayerUse", "FinalChaseTest", finalchase )
This worked all good however after researching how to pause/resume I realised I needed to use sound.PlayFile/sound.PlayURL in order to utilise the IGmodAudio Functions.
so I came up with this:
local function finalchase(ply, ent) if ent:GetName() == "FinalChaseTest" then sound.PlayFile("chase/finalchase.wav", "", function( station ) if ( IsValid( station ) ) then station:Play() end end) hook.Add( "PlayerUse", "FinalChaseTest", finalchase )
However I get the Error:
[ERROR] addons/mapcontent/lua/test.lua:6: attempt to call field 'PlayFile' (a nil value) 1. v - addons/mapcontent/lua/test.lua:6 2. unknown - lua/includes/modules/hook.lua:84
This leads me to believe that sound.PlayFile Doesn’t actually exist? However it is fully documented on the wiki?
Can someone shed some light on this?