print("Superstepa's enhanced damage addon initialized") --[[ Code is a ness, gotta fix Todo: Make the sounds a single function, decrapify the model check. Also stop having the same piece of code multiple times, thats a bad practice ]]-- if CLIENT then print("Superstepa's enhanced damage addon initialized on client. You should be able to change your voice now") CreateClientConVar("enhanceddamage_cl_voice","Default","1",true) else RUNSPEED = nil WALKSPEED = nil function Damage(ply,hitgroup,dmginfo) --Gotta separate this into more functions if (GetConVar("enhanceddamage_enabled"):GetBool()) then if (ConVarExists("sandboxteams_npcdamage") and ply:Team() != 1 ) then return end --Pseudo support for my sandbox teams addon local dmgpos = dmginfo:GetDamagePosition() local PelvisIndx = ply:LookupBone("ValveBiped.Bip01_Pelvis") if (PelvisIndx == nil) then return dmginfo end --Maybe Hitgroup still works, need testing local PelvisPos = ply:GetBonePosition( PelvisIndx ) local NutsDistance = dmgpos:Distance(PelvisPos) local LHandIndex = ply:LookupBone("ValveBiped.Bip01_L_Hand") local LHandPos = ply:GetBonePosition( LHandIndex ) local LHandDistance = dmgpos:Distance(LHandPos) local RHandIndex = ply:LookupBone("ValveBiped.Bip01_R_Hand") local RHandPos = ply:GetBonePosition(RHandIndex) local RHandDistance = dmgpos:Distance(RHandPos) if (NutsDistance <= 7 && NutsDistance >= 5) then hitgroup = "HITGROUP_NUTS" elseif (LHandDistance < 6 || RHandDistance < 6 ) then hitgroup = "HITGROUP_HAND" end if (hitgroup == HITGROUP_HEAD) then dmginfo:ScaleDamage(GetConVar("enhanceddamage_headdamagescale"):GetFloat()) GenericHurtSound(ply) elseif (hitgroup == HITGROUP_LEFTARM || hitgroup == HITGROUP_RIGHTARM) then ArmHurtSound(ply) dmginfo:ScaleDamage(GetConVar("enhanceddamage_armdamagescale"):GetFloat()) DropWeapon(ply,100 - GetConVar("enhanceddamage_armdropchance"):GetInt(),dmginfo:GetAttacker()) elseif (hitgroup == HITGROUP_LEFTLEG || hitgroup == HITGROUP_RIGHTLEG) then dmginfo:ScaleDamage(GetConVar("enhanceddamage_legdamagescale"):GetFloat()) if (ply:IsPlayer()) then BreakLeg(ply,5) end elseif (hitgroup == HITGROUP_CHEST) then GenericHurtSound(ply) dmginfo:ScaleDamage(GetConVar("enhanceddamage_chestdamagescale"):GetFloat()) elseif (hitgroup == HITGROUP_STOMACH) then StomachHurtSound(ply) dmginfo:ScaleDamage(GetConVar("enhanceddamage_stomachdamagescale"):GetFloat()) elseif (hitgroup == "HITGROUP_NUTS") then local SoundsEnabled = GetConVar("enhanceddamage_enablesounds"):GetBool() if (!isFemale(ply) and SoundsEnabled) then dmginfo:ScaleDamage(GetConVar("enhanceddamage_nutsdamagescale"):GetFloat()) local sound = Sound("vo/npc/male01/ow01.wav") ply:EmitSound(sound,500,125) end elseif(hitgroup == "HITGROUP_HAND") then ArmHurtSound(ply) dmginfo:ScaleDamage(GetConVar("enhanceddamage_handdamagescale"):GetFloat()) DropWeapon(ply,100 - GetConVar("enhanceddamage_armdropchance"):GetInt(),dmginfo:GetAttacker()) else GenericHurtSound(ply) end ply.hurttimer = true timer.Simple(0.5, function() ply.hurttimer = false end) end end function FallDamage(ply,speed) if GetConVar("enhanceddamage_falldamage"):GetBool() then local damage = speed / 10 if (damage > ply:Health() / 2) then BreakLeg(ply,10) end return damage else --Default valve falldamage calculations if GetConVarNumber("mp_falldamage") == 1 then speed = speed - 580 return speed * (100/(1024-580)) end return 10 end end function BreakLeg(ply,duration) if RUNSPEED == nil or WALKSPEED == nil then --Getting the default speed RUNSPEED = ply:GetRunSpeed() WALKSPEED = ply:GetWalkSpeed() end if !ply.legshot then LegHurtSound(ply) ply.legshot = true ply:SetRunSpeed(RUNSPEED/2) ply:SetWalkSpeed(WALKSPEED/2) timer.Simple(duration,function() ply:SetRunSpeed(RUNSPEED) ply:SetWalkSpeed(WALKSPEED) ply.legshot = false end) end end function DropWeapon(ply,chance,attacker) local chnc = math.random(1,100) if (chnc > chance) then if (ply:IsPlayer()) then if (table.HasValue(weaponblacklist,ply:GetActiveWeapon():GetClass() )) then return end --Exclude the blacklist stuff ply:ConCommand("-zoom") ply:DropWeapon(ply:GetActiveWeapon()) else --if it's an npc if GetConVar("enhanceddamage_npcweapondrop"):GetBool() then local weapon = ply:GetActiveWeapon() if IsValid(weapon) then weapon:Remove() ply:ClearEnemyMemory( ) ply:SetNPCState(2) ply:AddEntityRelationship(attacker, 2, 99) -- Attempt to make it run away end end end end end function GenericHurtSound(ply) local SoundsEnabled = GetConVar("enhanceddamage_enablesounds"):GetBool() if !ply.hurttimer and SoundsEnabled then if isFemale(ply) then local sound = table.Random(femalepainsounds) ply:EmitSound(sound) elseif isZombie(ply) then local sound = table.Random(zombiepainsounds) ply:EmitSound(sound) else local sound = table.Random(malepainsounds) ply:EmitSound(sound) end end end function ArmHurtSound(ply) local SoundsEnabled = GetConVar("enhanceddamage_enablesounds"):GetBool() if !ply.hurttimer and SoundsEnabled then if isFemale(ply) then local sound = table.Random(femalearmsounds) ply:EmitSound(sound) elseif isZombie(ply) then local sound = table.Random(zombiepainsounds) ply:EmitSound(sound) else local sound = table.Random(malearmsounds) ply:EmitSound(sound) end end end function LegHurtSound(ply) local SoundsEnabled = GetConVar("enhanceddamage_enablesounds"):GetBool() if !ply.hurttimer and SoundsEnabled then if isFemale(ply) then local sound = table.Random(femalelegsounds) ply:EmitSound(sound) elseif isZombie(ply) then local sound = table.Random(zombiepainsounds) ply:EmitSound(sound) else local sound = table.Random(malelegsounds) ply:EmitSound(sound) end end end function StomachHurtSound(ply) local SoundsEnabled = GetConVar("enhanceddamage_enablesounds"):GetBool() if !ply.hurttimer and SoundsEnabled then if isFemale(ply) then local sound = Sound("vo/npc/female01/mygut02.wav") ply:EmitSound(sound) else local sound = Sound("vo/npc/male01/mygut02.wav") ply:EmitSound(sound) end end end function isFemale(ply) if (ply:IsPlayer()) then local clientvar = string.lower(ply:GetInfo("enhanceddamage_cl_voice")) if (clientvar == "female") then return true elseif (clientvar == "male") or (clientvar == "zombie") then return false end end if table.HasValue(femalemodels,ply:GetModel()) then return true else if string.match(ply:GetModel(),"female") || string.match(ply:GetModel(),"alyx") || string.match(ply:GetModel(),"mossman") then return true else return false end end end function isZombie(ply) if (ply:IsPlayer()) then local clientvar = string.lower(ply:GetInfo("enhanceddamage_cl_voice")) if (clientvar == "zombie") then return true elseif (clientvar == "male") or (clientvar == "female") then return false end end if table.HasValue(zombiemodels,ply:GetModel()) then return true else if string.match(ply:GetModel(),"zombie") then return true else return false end end end weaponblacklist = {"gmod_tool","weapon_physgun","gmod_camera","arrest_stick","keys","pocket","weapon_ttt_unarmed","weapon_fists","weapon_keypadchecker"} malearmsounds = {Sound("vo/npc/male01/myarm01.wav"),Sound("vo/npc/male01/myarm02.wav")} femalearmsounds = {Sound("vo/npc/female01/myarm01.wav"),Sound("vo/npc/female01/myarm02.wav")} malelegsounds = {Sound("vo/npc/male01/myleg01.wav"),Sound("vo/npc/male01/myleg02.wav")} femalelegsounds = {Sound("vo/npc/female01/myleg01.wav"),Sound("vo/npc/female01/myleg02.wav")} malepainsounds = {Sound("vo/npc/male01/pain01.wav"), Sound("vo/npc/male01/pain02.wav"), Sound("vo/npc/male01/pain03.wav"), Sound("vo/npc/male01/pain04.wav"), Sound("vo/npc/male01/pain05.wav"), Sound("vo/npc/male01/pain06.wav"), Sound("vo/npc/male01/pain07.wav"), Sound("vo/npc/male01/pain08.wav"), Sound("vo/npc/male01/pain09.wav"), Sound("vo/ravenholm/monk_pain01"), Sound("vo/ravenholm/monk_pain02"), Sound("vo/ravenholm/monk_pain03"), Sound("vo/ravenholm/monk_pain04"), Sound("vo/ravenholm/monk_pain05"), Sound("vo/ravenholm/monk_pain06"), Sound("vo/ravenholm/monk_pain07"), Sound("vo/ravenholm/monk_pain08"), Sound("vo/ravenholm/monk_pain09"), Sound("vo/ravenholm/monk_pain10"), Sound("vo/ravenholm/monk_pain12"), } zombiepainsounds = {Sound("npc/zombie/pain1"), Sound("npc/zombie/pain2"), Sound("npc/zombie/pain3"), Sound("npc/zombie/pain4"), Sound("npc/zombie/pain5"), Sound("npc/zombie/pain6"), Sound("npc/zombie/die1"), Sound("npc/zombie/die2"), Sound("npc/zombie/die3"), Sound("npc/zombie_poison/pz_pain1"), Sound("npc/zombie_poison/pz_pain2"), Sound("npc/zombie_poison/pz_pain3"), Sound("npc/zombie_poison/pz_die3"),} femalepainsounds = {Sound("vo/npc/female01/pain01.wav"), Sound("vo/npc/female01/pain02.wav"), Sound("vo/npc/female01/pain03.wav"), Sound("vo/npc/female01/pain04.wav"), Sound("vo/npc/female01/pain05.wav"), Sound("vo/npc/female01/pain06.wav"), Sound("vo/npc/female01/pain07.wav"), Sound("vo/npc/female01/pain08.wav"), Sound("vo/npc/female01/pain09.wav")} femalemodels = { "models/player/group01/female_01.mdl", "models/player/group01/female_02.mdl", "models/player/group01/female_03.mdl", "models/player/group01/female_04.mdl", "models/player/group01/female_05.mdl", "models/player/group01/female_06.mdl", "models/player/group01/female_07.mdl", "models/player/group03/female_01.mdl", "models/player/group03/female_02.mdl", "models/player/group03/female_03.mdl", "models/player/group03/female_04.mdl", "models/player/group03/female_05.mdl", "models/player/group03/female_06.mdl", "models/player/group03/female_07.mdl", "models/player/alyx.mdl", "models/player/mossman.mdl", "models/Humans/alyx.mdl", "models/Humans/mossman.mdl", } zombiemodels = { "models/player/classic.mdl", "models/player/zombiefast.mdl", "models/player/zombie_soldier.mdl", "models/player/Charple01.mdl", "models/player/corpse1.mdl" } CreateConVar("enhanceddamage_enabled", 1, {FCVAR_SERVER_CAN_EXECUTE},"Enable enhanced damage") CreateConVar("enhanceddamage_headdamagescale", 2, {FCVAR_SERVER_CAN_EXECUTE},"Change the scale for this bodypart") CreateConVar("enhanceddamage_armdamagescale", 0.50, {FCVAR_SERVER_CAN_EXECUTE},"Change the scale for this bodypart") CreateConVar("enhanceddamage_legdamagescale",0.50, {FCVAR_SERVER_CAN_EXECUTE},"Change the scale for this bodypart") CreateConVar("enhanceddamage_chestdamagescale", 1.25, {FCVAR_SERVER_CAN_EXECUTE},"Change the scale for this bodypart") CreateConVar("enhanceddamage_stomachdamagescale",0.75, {FCVAR_SERVER_CAN_EXECUTE},"Change the scale for this bodypart") CreateConVar("enhanceddamage_nutsdamagescale", 2, {FCVAR_SERVER_CAN_EXECUTE},"Change the scale for this bodypart") CreateConVar("enhanceddamage_handdamagescale", 0.25, {FCVAR_SERVER_CAN_EXECUTE},"Change the scale for this bodypart") CreateConVar("enhanceddamage_armdropchance",20, {FCVAR_SERVER_CAN_EXECUTE},"The weapon drop chance for ") CreateConVar("enhanceddamage_handdropchance", 40, {FCVAR_SERVER_CAN_EXECUTE},"Change the scale for this bodypart") CreateConVar("enhanceddamage_enablesounds", 1, {FCVAR_SERVER_CAN_EXECUTE},"Enable the sounds when hurt ") CreateConVar("enhanceddamage_npcweapondrop",1,{FCVAR_SERVER_CAN_EXECUTE},"Enable weapon dropping for npcs (Really buggy)") CreateConVar("enhanceddamage_falldamage",1,{FCVAR_SERVER_CAN_EXECUTE},"Enable enhanced falldamage (Much more 'realistic' and breaks your bones)") hook.Add("ScalePlayerDamage","EnhancedPlayerDamage",Damage) hook.Add("ScaleNPCDamage","EnhancedNPCDamage",Damage) hook.Add("GetFallDamage","EnhancedFallDamage",FallDamage) end