Alright, so here's my predicament.
I have a SafeZone script installed on a Server I co-own with a buddy of mine to attempt to prevent spawn killing.
Works alright if both players are inside the SafeZone
Though if only the attacker is standing inside it shooting at someone standing outside of it.. well.. basically they can avoid getting damaged while killing other players..
Here's the hook that gets called when damage is taken.
[code]
hook.Add( "EntityTakeDamage", "RSP.stopDamage", function( targ, dmg )
if ( RSP:InsideSafeZone( targ:GetPos() ) ) then
dmg:SetDamage( 0 )
end
end )
[/code]
As you can see it only checks if the player activily getting shot at is inside the "safe zone" x,y,z. Yet, doesn't check if the attacker is aswell..
Any help is greatly appreciated. Thank you, have a great day!
[QUOTE=AwfulRanger;52359961][img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/CTakeDamageInfo/GetAttacker]CTakeDamageInfo:GetAttacker[/url][/QUOTE]
...Although that's the right answer I'm still confused.
Basically check if the attacker is in the safezone also, if they are scale their damage to 0, or you could refuse to let them pull out a weapon.
[code]
hook.Add( "EntityTakeDamage", "RSP.stopDamage", function( targ, dmg )
local attacker = dmg:GetAttacker()
if ( RSP:InsideSafeZone( targ:GetPos() ) or IsValid(attacker) and RSP:InsideSafeZone (attacker:GetPos() ) ) then
dmg:SetDamage( 0 )
end
end )
[/code]
[CODE]hook.Add( "EntityTakeDamage", "RSP.stopDamage", function( targ, dmg )
if ( RSP:InsideSafeZone( targ:GetPos() ) && RSP:InsideSafeZone( dmg:GetAttacker():GetPos() ) ) then
dmg:SetDamage( 0 )
end
end )[/CODE]
[QUOTE=chikkenslayer;52360209][CODE]hook.Add( "EntityTakeDamage", "RSP.stopDamage", function( targ, dmg )
if ( RSP:InsideSafeZone( targ:GetPos() ) && RSP:InsideSafeZone( dmg:GetAttacker():GetPos() ) ) then
dmg:SetDamage( 0 )
end
end )[/CODE][/QUOTE]
GetAttacker() is not guaranteed to be set. Your code will error with badly coded addons that do damage.
[editline]15th June 2017[/editline]
Your code is also completely wrong, since if a player is outside the zone they can be damaged by players inside the zone and damage players inside the zone.
[QUOTE=chikkenslayer;52360209][CODE]hook.Add( "EntityTakeDamage", "RSP.stopDamage", function( targ, dmg )
if ( RSP:InsideSafeZone( targ:GetPos() ) && RSP:InsideSafeZone( dmg:GetAttacker():GetPos() ) ) then
dmg:SetDamage( 0 )
end
end )[/CODE][/QUOTE]
Wouldn't that need to be an 'or' instead of 'and'?
[QUOTE=chikkenslayer;52360209][CODE]hook.Add( "EntityTakeDamage", "RSP.stopDamage", function( targ, dmg )
if ( RSP:InsideSafeZone( targ:GetPos() ) && RSP:InsideSafeZone( dmg:GetAttacker():GetPos() ) ) then
dmg:SetDamage( 0 )
end
end )[/CODE][/QUOTE]
yep, the attacker might be an NPC, or just some rocket or whatever that is still in air (perhaps granade) - and if player disconnected during shooting, he might be invalid when the entity takes damage.
lol i messed up and meant or, i wasn't giving him functional code but an example to fix his. My code isn't completely wrong it has two errors.
Sorry, you need to Log In to post a reply to this thread.