Jump to content

Recommended Posts

I've been creating a new weapon and I've got to the point of making custom sounds for it, but basically I want the sound to play when I swing, rather on the impact. 

I've looked around for ways I could do this and the only one I saw was on an older forum that said to use something like this.

local function DoSound(owner)
--stuff
end

local function onequip(inst, owner) --you should have that function already
    --[...]
    inst:ListenForEvent("doattack",DoSound,owner) --listen for that event, then do that function, but listen for this guy and not for me
end

local function onunequip(inst, owner) --you should have that function already
    --[...]
    inst:RemoveEventCallback("doattack",DoSound,owner) --undo the listener
end

 

I get the idea of it, but i know I'm missing stuff for this to work. Regardless does anyone have an idea on how to just generally create the code for on swing?

Never mind, I went back to this after a while seeing if I could try it again and I figured it out lol. 

I needed to add an inst to the DoSound(here, owner) rather than just having an owner

local function DoSound(inst, owner)
    inst.SoundEmitter:PlaySound("sound/sound/swing")
end
local function onequip(inst, owner)
    inst:ListenForEvent("doattack",DoSound,owner)
end
local function onunequip(inst, owner)
    inst:RemoveEventCallback("doattack",DoSound,owner)
end

Is the code I needed total so it was the same, if anyone else needed some help with it then its here.

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
×
  • Create New...