• ScalePlayerDamage hook isn't calling
    5 replies, posted
I'm having issues with this hook, I added the following in my sandbox player.lua so if you have any ideas on how to fix the following, please shoot them my way. [lua] -- -- Mine too -- EVO = {}; EVO.Sound = { Source = "Human/hurt/", Breath = {1}, Death = { DieSuit = {0,1,2,3}, DieNormal = {1,2,3,4,5,6,7} }, Reactions = { DMG_GENERIC = {--Generic: 0 HitType = {1,2,3,4,5,6,7}, Hit = {1,2,3,4,5,6,7}, Pain = {1,2,3,4,5,6,7,8} }, DMG_BULLET = {--Bullet: 2 HitType = {1,2,3,4}, Hit = {1,2,3,4}, Pain = {1,2,3} } } }; PrintTable(EVO); hook.Add("ScalePlayerDamage", function( ply, hitgroup, dmginfo ) local DamageInfo = dmginfo; //play our hit sound local SoundInfo = (EVO.Sound.Reactions.DMG_GENERIC); local Translate; local type; local RandomItem; print("TakeDamage: "..SoundInfo); if SoundInfo then Translate = "hurt"; if (SoundInfo == 2) then Translate = "bullet_hit_"; SoundInfo = (EVO.Sound.Reactions.DMG_BULLET) end print("Translate: "..Translate); if SoundInfo.HitType then RandomItem = tostring(table.Random(SoundInfo.HitType)); print("Found hit type: "..RandomItem); type = Sound(EVO.Sound.Source..Translate..RandomItem..".wav"); type.Add({name = (Translate..v),sound = (EVO.Sound.Source..Translate..RandomItem..".wav")}) type:Play(); type = {}; if (ply:Health() - DamageInfo:GetDamage() < 0) then RandomItem = tostring(table.Random(SoundInfo.DieNormal)); print("Die: "..RandomItem); type = Sound(EVO.Sound.Source..Translate..RandomItem..".wav"); type.Add({name = (Translate..v),sound = (EVO.Sound.Source..Translate..RandomItem..".wav")}); type:Play(); type = nil; return; end end // we die end it here with a death sound if (hitgroup == HITGROUP_HEAD) then RandomItem = tostring(table.Random(SoundInfo.DieNormal)); print("Headshot: "..RandomItem); ply:Kill(); if (ply:Health() - DamageInfo:GetDamage() < 0) then type = Sound(EVO.Sound.Source..Translate..RandomItem..".wav"); type.Add({name = (Translate..v),sound = (EVO.Sound.Source..Translate..RandomItem..".wav")}); type:Play(); type = nil;--No more use for this, SEND IT TO THE GARBAGE. return; end //play death sound return; end if (SoundInfo.Hit) then RandomItem = tostring(table.Random(SoundInfo.Hit)); print("Found reaction: "..RandomItem); ply.Sound = Sound(EVO.Sound.Source..Translate..RandomItem..".wav"); ply.Sound.Add({name = (Translate..v),sound = (EVO.Sound.Source..Translate..RandomItem..".wav")}) ply.Sound:Play(); ply.Sound = {}; //play a reaction sound end end end); [/lua]
Are you running it serverside?
yeh [editline]12th December 2013[/editline] I'm sorry... I was going to add the sounds through a loop but thought this way would be easier to code. I removed Translate from the function and added a damage type sound source, I then noticed that I left the v from the start of the loop I was going to add the sounds with earlier. I then noticed that it's 4 AM and it's probably a good idea to stop coding since I'm too tired to test it, night. [lua] -- -- Mine too -- EVO = {}; EVO.Sound = { Source = "Human/hurt/", Breath = {1}, Death = { DieSuit = {0,1,2,3}, DieNormal = {1,2,3,4,5,6,7} }, Reactions = { DMG_GENERIC = {--Generic: 0 Source = "hurt",--This is the actual filename (besides the numbers) HitType = {1,2,3,4,5,6,7}, Hit = {1,2,3,4,5,6,7}, Pain = {1,2,3,4,5,6,7,8} }, DMG_BULLET = {--Bullet: 2 Source = "bullet_hit_", HitType = {1,2,3,4}, Hit = {1,2,3,4}, Pain = {1,2,3} } } }; PrintTable(EVO); hook.Add("ScalePlayerDamage", function( ply, hitgroup, dmginfo ) local DamageInfo = dmginfo; //play our hit sound local SoundInfo = (EVO.Sound.Reactions.DMG_GENERIC); local Translate; local type; local RandomItem; print("TakeDamage: "..SoundInfo); if SoundInfo then if (SoundInfo == 2) then SoundInfo = (EVO.Sound.Reactions.DMG_BULLET) end print("Translate: "..SoundInfo.Source); if SoundInfo.HitType then RandomItem = tostring(table.Random(SoundInfo.HitType)); print("Found hit type: "..RandomItem); type = Sound(EVO.Sound.Source..SoundInfo.Source..RandomItem..".wav"); type.Add({name = (SoundInfo.Source..RandomItem),sound = (EVO.Sound.Source..SoundInfo.Source..RandomItem..".wav")}) type:Play(); type = {}; if (ply:Health() - DamageInfo:GetDamage() < 0) then RandomItem = tostring(table.Random(SoundInfo.DieNormal)); print("Die: "..RandomItem); type = Sound(EVO.Sound.Source..SoundInfo.Source..RandomItem..".wav"); type.Add({name = (SoundInfo.Source..RandomItem),sound = (EVO.Sound.Source..SoundInfo.Source..RandomItem..".wav")}); type:Play(); type = nil; return; end end // we die end it here with a death sound if (hitgroup == HITGROUP_HEAD) then RandomItem = tostring(table.Random(SoundInfo.DieNormal)); print("Headshot: "..RandomItem); ply:Kill(); if (ply:Health() - DamageInfo:GetDamage() < 0) then type = Sound(EVO.Sound.Source..SoundInfo.Source..RandomItem..".wav"); type.Add({name = (SoundInfo.Source..RandomItem),sound = (EVO.Sound.Source..SoundInfo.Source..RandomItem..".wav")}); type:Play(); type = nil;--No more use for this, SEND IT TO THE GARBAGE. return; end //play death sound return; end if (SoundInfo.Hit) then RandomItem = tostring(table.Random(SoundInfo.Hit)); print("Found reaction: "..RandomItem); ply.Sound = Sound(EVO.Sound.Source..SoundInfo.Source..RandomItem..".wav"); ply.Sound.Add({name = (SoundInfo.Source..RandomItem),sound = (EVO.Sound.Source..SoundInfo.Source..RandomItem..".wav")}) ply.Sound:Play(); ply.Sound = {}; //play a reaction sound end end end); [/lua] [editline]12th December 2013[/editline] It still isn't fixed btw. :yarr: [editline]12th December 2013[/editline] I'm getting spammed by these: CSoundEmitterSystemBase::AddSound( 'pkm_shoot.single', 'scripts/sounds/lua.txt', ... ), script file not list in manifest 'scripts/game_sounds_manifest.txt' I think this error spam is related to addons DL'd through workshop, though I'm not sure. So I'm not even sure if I'm getting an error telling me how to fix the issue.
ScalePlayerDamage only works with bullets shot from guns. You need to use EntityTakeDamage.
Additionally, the way you define your table; the enums aren't being activated/used. You're defining STRING keys in that sounds table. If you want to use the literal value of an enum, you need to surround said enum with [ ]'s
[QUOTE=JetBoom;43156798]ScalePlayerDamage only works with bullets shot from guns. You need to use EntityTakeDamage.[/QUOTE] I can't get EntityTakeDamage to print either. [QUOTE=Acecool;43160520]Additionally, the way you define your table; the enums aren't being activated/used. You're defining STRING keys in that sounds table. If you want to use the literal value of an enum, you need to surround said enum with [ ]'s[/QUOTE] I'm using this method and JetBooms method and neither helped fixed the issue. (I'm still calling the table with [])
Sorry, you need to Log In to post a reply to this thread.