• ScalePlayerDamage
    3 replies, posted
Hey guys, Im trying to manipulate the damage dealt to players if the attacker is an NPC. This code doesnt seem to work, I would appreciate it if someone helped me out with this. thanks. [CODE]function GM:ScalePlayerDamage( ply, hitgroup, dmginfo ) if dmginfo:GetAttacker():IsNPC() then dmginfo:SetDamage(100) end end[/CODE]
You likely need to check if the attacker is valid first, [code]if IsValid(dmginfo:GetAttacker()) and dmginfo:GetAttacker():IsNPC() then[/code] It might also be helpful if you could post the Lua error you're receiving.
The above code doesnt work and Im not getting any errors.
Here is a scale damage code I put together for my gamemode. All you would have to do is add in if it is a NPC or not. You won't learn if I do all the work for you. [CODE] /*--------------------------------------------------------------------------------------- Scales the players damage based on where shot. ---------------------------------------------------------------------------------------*/ function GM:ScalePlayerDamage(ply, hitgroup, dmginfo) if (hitgroup == HITGROUP_HEAD) then dmginfo:ScaleDamage(1.5) elseif (hitgroup == HITGROUP_CHEST) then dmginfo:ScaleDamage(1) elseif (hitgroup == HITGROUP_STOMACH) then dmginfo:ScaleDamage(0.8) elseif (hitgroup == HITGROUP_LEFTARM || hitgroup == HITGROUP_RIGHTARM) then dmginfo:ScaleDamage(0.35) elseif (hitgroup == HITGROUP_LEFTLEG || hitgroup == HITGROUP_RIGHTLEG) then dmginfo:ScaleDamage(0.65) ply:SetWalkSpeed(125) ply:SetRunSpeed(250) timer.Simple(3, function() ply:SetWalkSpeed(250) ply:SetRunSpeed(500) end) end end [/CODE]
Sorry, you need to Log In to post a reply to this thread.