CreateSound Problem

I’m trying to get a Nextbot to play sounds using CreateSound. My problem here is that instead of emitting from my bot, it emits from the middle of the map, and i’m not sure why.

Here’s what i have:


local talk = CreateSound(self, Sound("npc/overwatch/radiovoice/lostbiosignalforunit.wav"))

i later call this sound in a timer:


function disp2()
talk:Play()
end

timer.Simple(len2, function() disp2() end)

but like i said, it comes from the middle of the map, which means if me or my Bot is far enough away, i am unable to hear the sound at all, which is really frustrating.

Well, they only error i can think of is that the variable “self” is not set as the NextBot

Use Entity:EmitSound to play a voice, etc… It should only play once, it’ll come from the entity location, and if it has movable lips, it’ll lip sync.

i’d use EmitSound if i could, but i need these sounds to play on a timer, and for some reason, saying “self:EmitSound()” in a timer doesn’t work.

If you create the timer inside of the ENT:Init function, then self will work. I’d recommend changing the timer name to something dynamic so new entities don’t overwrite it for old entities; ie include self:EntIndex( ) in the name.

When the entity is removed / killed, etc… remove the timer.

How would the sounds play if the timer is removed?

If the npc dies, should it still make sound?

Can you show us some code, or give us some context of how it’ll be used?

Show us where you started your timer; if self is nil it may default to the worldspawn entity, ie entity 0, meaning the sound would play at vector_origin / 0, 0, 0…

If you show us your code, we can show you how to incorporate it properly; also, let us know when the sound should play.

Have you ever killed a Metrocop or two in sandbox? Sometimes the dispatcher will use voice lines after the Metrocop has been killed:

Death noise* radio garble* “Lost Biosignal for protection team unit, X-ray 6” Radio gargle

something like that?
in this case, the NPC strings together 6 different voice lines back to back, without them overlapping

i’m making a Metrocop Nextbot, and i’m trying to mimic this.

i’m attempting this in my OnKilled Function:


function ENT:OnKilled( damageinfo )
local cpdeaths = {"npc/metropolice/die1.wav", "npc/metropolice/die2.wav","npc/metropolice/die3.wav","npc/metropolice/die4.wav"}
local ded = cpdeaths[math.random(#cpdeaths)]
local DispNums = {"npc/overwatch/radiovoice/one.wav", "npc/overwatch/radiovoice/zero.wav", "npc/overwatch/radiovoice/two.wav", "npc/overwatch/radiovoice/three.wav", "npc/overwatch/radiovoice/four.wav","npc/overwatch/radiovoice/five.wav",}
local RanNum = DispNums[math.random(#DispNums)]


local call = Sound("npc/overwatch/radiovoice/on3.wav")
local calling = CreateSound(self, call)
local talk = CreateSound(self, Sound("npc/overwatch/radiovoice/lostbiosignalforunit.wav"))
local patrol = CreateSound(self, Sound("npc/overwatch/radiovoice/patrol.wav"))
local desig = CreateSound(self, Sound(RanNum))
function disp()
calling:Play()
end
function disp2()
talk:Play()
end

	
	
	

	self:EmitSound(ded)
	len = SoundDuration(ded)
	len2 = SoundDuration("npc/overwatch/radiovoice/on3.wav") +len
	len3 = SoundDuration("npc/overwatch/radiovoice/lostbiosignalforunit.wav") +len2
	len4 = SoundDuration("npc/overwatch/radiovoice/patrol.wav") + len3
	
	timer.Simple(len, function() disp() end)
	timer.Simple(len2, function() disp2() end)
	timer.Simple(len3, function() patrol:Play() end)
	timer.Simple(len4, function() desig:Play() end)
	
	
	
	
	
	
	

	self:BecomeRagdoll( damageinfo )
	
	print("ded")
	self:Remove()

end

apologies if it looks messy.

But yeah, with the code above, every sound except the one called by “EmitSound” seems to play from the middle of the map, or the worldspawn, as you said, and i need them to come from my Bot.

was my code so ugly that it scared everyone away? :C

i’d kinda like an answer here…

It’s probably because the sounds are being played after the entity dies, so since the entity becomes invalid and the sound was linked to the entity, it plays from the center of the map.

i figured that after some thought.
I’m wondering if there is a workaround here.
I’m thinking i could have my bot create an entity on death that says the death lines and then removes itself. but i don’t really want to do that if i don’t have to.

Use EmitSound for voice lines and sound effects. CreateSound is only usable for looping sounds really.

In the timer with the play sound shit, do a IsValid check on the nextbot, break the timer if it isn’t valid