Overwrite Global Function

I want to overwrite SoundDuration so it actually works on the server without having to add “…/…/hl2/sound” for all of my sounds. How exactly do I do that?

–Snip

[lua]local oldSoundDuration = SoundDuration
function SoundDuration(str)
if SERVER then str = “…/…/hl2/sound”…str end
return oldSoundDuration(str)
end[/lua]

Is that what you mean to do? :confused:

[editline]10:37PM[/editline]

Of course if that’s actually what you’re looking for you can get rid of the condition and only declare it serverside :

[lua]local oldSoundDuration = SoundDuration
function SoundDuration(str)
return oldSoundDuration("…/…/hl2/sound"…str)
end[/lua]

Yes, I believe so. So in my gamemode, if I establish that in the init.lua, will it affect all other files including entities and addons that use that function?

Yup. If you declare it serverside globally then you can use it anywhere serverside.
Oh and actually it would be much better pratice not to overwrite it and to simply name a new function, especially if you ever intend to distribute it.

[lua]function MyNewFunc(str)
return SoundDuration("…/…/hl2/sound"…str)
end[/lua]