I need to get a line of code that sets the next time the sound emits is one second, other wise it spams heavy 'NO'! 'NIET!' and 'IS NOT POSSIBLE' sounds.
Thanks in Advance, if code is needed just ask.
Code is always needed. It helps get a better idea of what you're trying to do. I could just guess but I have no way to know for sure.
If got a simple use function for an talking vending machine I'm making.
I also have a on damage function which is smaller so here it is.
[code]
function ENT:OnTakeDamage( dmginfo )
self.Entity:TakePhysicsDamage( dmginfo )
self:EmitSound("vo/heavy_paincrticialdeath0" .. math.random(1,3) .. ".wav", 500, 100)
local Physboom = ents.Create("env_physexplosion")
Physboom:SetPos(self.Entity:GetPos())
Physboom:SetParent(self.Entity)
Physboom:SetKeyValue("magnitude", 700)
Physboom:SetKeyValue("radius", 200)
Physboom:SetKeyValue("spawnflags", "1")
Physboom:Spawn()
Physboom:Fire("Explode", "", 0)
Physboom:Fire("kill", "", 5)
local vPoint = self.Entity:GetPos()
local effectdata = EffectData()
effectdata:SetStart( vPoint )
effectdata:SetOrigin( vPoint )
effectdata:SetScale( 3 )
util.Effect( "StriderBlood", effectdata )
end [/code]
Quickly need halp the Heavy voice spam burns, yet is strangely amusing.
try this
[PHP]local NextPlay = os.time()
function ENT:OnTakeDamage( dmginfo )
self.Entity:TakePhysicsDamage( dmginfo )
Time = os.time()
if NextPlay > Time then
self:EmitSound("vo/heavy_paincrticialdeath0" .. math.random(1,3) .. ".wav", 500, 100)
NextPlay = os.time()+5
end
local Physboom = ents.Create("env_physexplosion")
Physboom:SetPos(self.Entity:GetPos())
Physboom:SetParent(self.Entity)
Physboom:SetKeyValue("magnitude", 700)
Physboom:SetKeyValue("radius", 200)
Physboom:SetKeyValue("spawnflags", "1")
Physboom:Spawn()
Physboom:Fire("Explode", "", 0)
Physboom:Fire("kill", "", 5)
local vPoint = self.Entity:GetPos()
local effectdata = EffectData()
effectdata:SetStart( vPoint )
effectdata:SetOrigin( vPoint )
effectdata:SetScale( 3 )
util.Effect( "StriderBlood", effectdata )
end[/PHP]
Change the number 5 after NextPlay = os.time()+ to the length of the sound.
Use CurTime() instead of os.time()
[editline]11:40AM[/editline]
Also, that will never play, because NextTime is never going to be greater than Time.
[editline]11:41AM[/editline]
[lua]function ENT:OnTakeDamage( dmginfo )
self.Entity:TakePhysicsDamage( dmginfo )
if (self.NextPlay or math.huge) > CurTime() then
self:EmitSound("vo/heavy_paincrticialdeath0" .. math.random(1,3) .. ".wav", 500, 100)
self.NextPlay = CurTime() + 5
end
local Physboom = ents.Create("env_physexplosion")
Physboom:SetPos(self.Entity:GetPos())
Physboom:SetParent(self.Entity)
Physboom:SetKeyValue("magnitude", 700)
Physboom:SetKeyValue("radius", 200)
Physboom:SetKeyValue("spawnflags", "1")
Physboom:Spawn()
Physboom:Fire("Explode", "", 0)
Physboom:Fire("kill", "", 5)
local vPoint = self.Entity:GetPos()
local effectdata = EffectData()
effectdata:SetStart( vPoint )
effectdata:SetOrigin( vPoint )
effectdata:SetScale( 3 )
util.Effect( "StriderBlood", effectdata )
end[/lua]
@Maker Why?
local NextPlay = os.time()is outside a function so it will just run once.
Right it needs to be self since it may be more than one entity... :wth:
Aha Thanks guys but neither of them worked. @yuriman your code didn't play the sound at all, @Maker your one still spammed Heavy sounds.
Thanks for your swift replies, I'l try learn from your code.
Please describe exactly what you expect your code to do, and when.
All I want it to do is when damaged emit a sound and create a physexplosion and not emit the sound (Or do the function) for another x amount of time. Ty in advance if you try.
Maybe try this?
[lua]function ENT:OnTakeDamage(dmginfo)
hook.Add("Think", "HasTaken", function()
self:EmitSound("vo/heavy_paincrticialdeath0" .. math.random(1,3) .. ".wav", 500, 100)
local Physboom = ents.Create("env_physexplosion")
Physboom:SetPos(self.Entity:GetPos())
Physboom:SetParent(self.Entity)
Physboom:SetKeyValue("magnitude", 700)
Physboom:SetKeyValue("radius", 200)
Physboom:SetKeyValue("spawnflags", "1")
Physboom:Spawn()
Physboom:Fire("Explode", "", 0)
Physboom:Fire("kill", "", 5)
local vPoint = self.Entity:GetPos()
local effectdata = EffectData()
effectdata:SetStart( vPoint )
effectdata:SetOrigin( vPoint )
effectdata:SetScale( 3 )
util.Effect("StriderBlood", effectdata)
hook.Remove("RemoveHasTaken")
end)
end[/lua] Not really sure if it will work, but I hope it does...
[editline]01:45AM[/editline]
If that doesn't work, try this:
[lua]function ENT:OnTakeDamage(dmginfo)
hastaken = false
if hastaken == false then
self:EmitSound("vo/heavy_paincrticialdeath0" .. math.random(1,3) .. ".wav", 500, 100)
local Physboom = ents.Create("env_physexplosion")
Physboom:SetPos(self.Entity:GetPos())
Physboom:SetParent(self.Entity)
Physboom:SetKeyValue("magnitude", 700)
Physboom:SetKeyValue("radius", 200)
Physboom:SetKeyValue("spawnflags", "1")
Physboom:Spawn()
Physboom:Fire("Explode", "", 0)
Physboom:Fire("kill", "", 5)
local vPoint = self.Entity:GetPos()
local effectdata = EffectData()
effectdata:SetStart( vPoint )
effectdata:SetOrigin( vPoint )
effectdata:SetScale( 3 )
util.Effect("StriderBlood", effectdata)
hastaken = true
end
end[/lua] Sorry if it doesn't work...
[editline]01:50AM[/editline]
So, let me make sure... On ENT:OnTakeDamage(dmginfo), you want it to run through that function ONCE, then when it's done, you want it to stop until ENT:OnTakeDamage(dmginfo) is called again, right?
[QUOTE=jeff223;22339033][/QUOTE]
Sorry but nothing in there look like it should work. Maker's code seemed pretty correct and I don't know why it wouldn't work.
Have you tried debugging it with print?
I know, Quebec, that's what I was thinking... Just thought I'd put a few checks in there or something haha.
At jeff223, the first code gave me
Hook 'HasTaken' Failed: lua\includes\modules\hook.lua:59: attempt to index field '?' (a nil value)
And the second one didn't have any delay between sounds. You tried :3
I'll just re-explain what I'm trying to do:
Make a vending machine that does what it does when its hit(Make the sound) but I need a 2 second delay between each time the sound is emitted. I don't mind if it delays the whole function by 2 seconds as long as it wont spam me with Heavy 'AHHH MURDER's And 'OOOO's :P
P.S Was debugging it with print at Jeff? cos I have no idea what that is.
Edited: I think MaKeR's didn't work because the Current time + 5 will always be greater than the Current time and therefore doesn't stop it from emitting the sound any time later.
That's just my noob lua coder thoughts to my understanding. I'm not fully sure.
[QUOTE=Zombie Strider;22340555]Edited: I think MaKeR's didn't work because the Current time + 5 will always be greater than the Current time and therefore doesn't stop it from emitting the sound any time later.
That's just my noob lua coder thoughts to my understanding. I'm not fully sure.[/QUOTE]
Yea, you are right, I accidentally put a > instead of a <=. Change that and it should work.
But then it will never be less or equal to it meaning it will never be called, I think.
Tested and it didn't make any sounds
[lua]function ENT:OnTakeDamage( dmginfo )
self.Entity:TakePhysicsDamage( dmginfo )
if (self.NextPlay or 0) <= CurTime() then
self:EmitSound("vo/heavy_paincrticialdeath0" .. math.random(1,3) .. ".wav", 500, 100)
self.NextPlay = CurTime() + 5
end
local Physboom = ents.Create("env_physexplosion")
Physboom:SetPos(self.Entity:GetPos())
Physboom:SetParent(self.Entity)
Physboom:SetKeyValue("magnitude", 700)
Physboom:SetKeyValue("radius", 200)
Physboom:SetKeyValue("spawnflags", "1")
Physboom:Spawn()
Physboom:Fire("Explode", "", 0)
Physboom:Fire("kill", "", 5)
local vPoint = self.Entity:GetPos()
local effectdata = EffectData()
effectdata:SetStart( vPoint )
effectdata:SetOrigin( vPoint )
effectdata:SetScale( 3 )
util.Effect( "StriderBlood", effectdata )
end[/lua]
The math.huge had to be changed to 0.
Thanks a bunch, Worked perfectly
Hearts to you.
Thanks other guys for trying.
Finished my SENT if anyone is interested
Your in the credits MaKeR without that code it would be really stupid
[url]http://www.garrysmod.org/downloads/?a=view&id=100405[/url]
Sorry, you need to Log In to post a reply to this thread.