I’m trying to make it so that if a player has a certain NetworkedBool, he automatically gets special damage protection. He should take less damage and be impervious to certain types of damage etc.
I put this in a serverside file but it seems to have no effect. Solutions?
[lua]
function GM:ScalePlayerDamage(ply,hitgroup,dmginfo)
if(ply:GetNetworkedBool("hassuit"))then
if(hitgroup==HITGROUP_HEAD)then dmginfo:ScaleDamage(0.1) end
if(hitgroup==HITGROUP_CHEST)then dmginfo:ScaleDamage(0.1) end
if(hitgroup==HITGROUP_STOMACH)then dmginfo:ScaleDamage(0.1) end
if(hitgroup==HITGROUP_LEFTARM)then dmginfo:ScaleDamage(0.1) end
if(hitgroup==HITGROUP_RIGHTARM)then dmginfo:ScaleDamage(0.1) end
if(hitgroup==HITGROUP_LEFTLEG)then dmginfo:ScaleDamage(0.1) end
if(hitgroup==HITGROUP_RIGHTLEG)then dmginfo:ScaleDamage(0.1) end
if(hitgroup==HITGROUP_GEAR)then dmginfo:ScaleDamage(0.1) end
if(hitgroup==HITGROUP_GENERIC)then dmginfo:ScaleDamage(0.1) end
if((dmginfo:IsDamageType(DMG_POISON))or(dmginfo:IsDamageType(DMG_ACID))or(dmginfo:IsDamageType(DMG_RADIATION))or(dmginfo:IsDamageType(DMG_NERVEGAS)))then
dmginfo:SetDamage(0)
end
if(dmginfo:IsDamageType(DMG_DROWN))then
dmginfo:SetDamage(0)
end
end
end
[/lua]
(User was banned for this post ("Wrong section" - mahalis))
I tried making this just an insignificant function and then hooking it to ScalePlayerDamage, but that didn’t do anything either. On the wiki I don’t see in the example any returning… sorry if I’m a noob, by what do you mean? What do I have to do?
[editline]18th December 2010[/editline]
This is the new code. Why isn’t it doing anything?!
[lua]
function ArmorUp(ply,hitgroup,dmginfo)
if(ply:GetNetworkedBool("hassuit"))then
if((dmginfo:IsDamageType(DMG_POISON))or(dmginfo:IsDamageType(DMG_ACID))or(dmginfo:IsDamageType(DMG_RADIATION))or(dmginfo:IsDamageType(DMG_NERVEGAS))or(dmginfo:IsDamageType(DMG_SLASH))or(dmginfo:IsDamageType(DMG_SHOCK))or(dmginfo:IsDamageType(DMG_BURN)))then
dmginfo:SetDamage(0)
end
if((dmginfo:IsDamageType(DMG_CRUSH))or(dmginfo:IsDamageType(DMG_CLUB)))then
dmginfo:ScaleDamage(0.5)
end
if(dmginfo:IsDamageType(DMG_DROWN))then
dmginfo:SetDamage(0)
end
if(dmginfo:IsDamageType(DMG_BULLET))then
dmginfo:ScaleDamage(0.2)
end
if(dmginfo:IsDamageType(DMG_BLAST))then
dmginfo:ScaleDamage(0.3)
end
end
end
hook.Add(“ScalePlayerDamage”,“ArmorUp”,ArmorUp)
[/lua]
Have you tried putting debugging code near the dmginfo:ScaleDamage() functions to see if it executes the code?
Or,remove the first if condition,the ply:GetNetworkedBool(“hassuit”).
[lua]
function ArmorUp(ply,hitgroup,dmginfo)
if((dmginfo:IsDamageType(DMG_POISON))or(dmginfo:IsDamageType(DMG_ACID))or(dmginfo:IsDamageType(DMG_RADIATION))or(dmginfo:IsDamageType(DMG_NERVEGAS))or(dmginfo:IsDamageType(DMG_SLASH))or(dmginfo:IsDamageType(DMG_SHOCK))or(dmginfo:IsDamageType(DMG_BURN)))then
dmginfo:SetDamage(0);print("dmg_protectedwhatever");
end
if((dmginfo:IsDamageType(DMG_CRUSH))or(dmginfo:IsDamageType(DMG_CLUB)))then
dmginfo:ScaleDamage(0.5);print("dmg_club");
end
if(dmginfo:IsDamageType(DMG_DROWN))then
dmginfo:SetDamage(0);print("dmg_drown");
end
if(dmginfo:IsDamageType(DMG_BULLET))then
dmginfo:ScaleDamage(0.2);print("dmg_bullet");
end
if(dmginfo:IsDamageType(DMG_BLAST))then
dmginfo:ScaleDamage(0.3);print("dmg_blast");
end
end
hook.Add(“ScalePlayerDamage”,“ArmorUp”,ArmorUp)
[/lua]
Maybe another addon is conflicting with yours,try it on a vanilla gmod.
I put in some debugging scripts, and it looks like the whole thing ONLY calls when I get hit with bullets… it’s very wierd. The function I made with EntityTakeDamage never ever calls. Isn’t ScalePlayerDamage supposed to call anytime a player gets damaged? That’s what it says on the wiki…
[editline]19th December 2010[/editline]
It calls when I get shot by any NPC, when I shoot myself with a turret, and when I get hit by a hopper explosion. But it doesn’t call when I grenade myself, get whacked by any creatures, or get hit by a prop. This is bad.
Eg;
[lua]function GM:EntityTakeDamage( ent, inflictor, attacker, amount, dmginfo )
if ent:IsPlayer() and dmginfo:GetDamageType() == DMG_CRUSH then --TODO: Check if the attacker is on the other team, if he is, do damage, else, false
dmginfo:ScaleDamage(0)
elseif ent:IsPlayer() then
timer.Create( “HealthTimer”…tostring(ent:UniqueID()), 10, 1, function()
ent:SetHealth( 100 )
end)
end
end[/lua]