• EntityTakeDamage does not work as it should?
    4 replies, posted
Or did I just not understand how it works? I wanted to make a safezone, and for that I wanted to use this hook, so that when an attacker is looking or attacked in a zone, then the attacked person would not suffer damage. I wrote something like: hook.Add("EntityTakeDamage","HyperCheck", function(target, dmginfo) if target:GetPos():WithinAABox(Vector(495,-1024,-150),Vector(-1024,-1918,240))  then  return true end end) But instead of getting only damage outside the zone, bots after one shot in the zone became unkillable, although as I checked the hook really works, and if the player is not in the zone does not return true. It seems to me that I am doing something wrong ...
Instead of returning if the target's position is within a box, call SetDamage(0) on the dmginfo object. hook.Add("EntityTakeDamage", "HyperCheck", function(target, dmginfo) if target:GetPos():WithinAABox(Vector(495,-1024,-150),Vector(-1024,-1918,240)) then dmginfo:SetDamage(0) end end)
I tried it with ScaleDamage (0), but the result was the same
Hmm. What map are you trying this hook on? What realm are you running the hook on (server,shared or client)?
full code: if SERVER then hook.Add("PlayerSpawn","SpawnTeleport", function (ply) ply:SetPos(Vector(-246.5+math.Rand(-720,720),-1471+math.Rand(-430,430),-80)) ply:GodEnable()  end) hook.Add("EntityTakeDamage", "HyperCheck", function(target, dmginfo) if target:GetPos():WithinAABox(Vector(495,-1024,-150),Vector(-1024,-1918,240))  then         dmginfo:SetDamage(0)     end     end) end map is "gm_construct" I run my script through autorun.
Sorry, you need to Log In to post a reply to this thread.