disable teamkilling

 function GM:PlayerHurt( player, attacker )
 if player:Team() == TEAM_ARECRUIT  and attacker:Team() == TEAM_ARECRUIT then
	return false
	end
	end

why wont it work?

//Thanks :slight_smile:

try this

[lua]
function GM:PlayerHurt( player, attacker )
if attacker:IsPlayer() && player:Team() == attacker:Team() then
return false
end
end
[/lua]

also if this is not inside a gamemode but a external script do this
[lua]
function AntiFriendlyFire( player, attacker )
if attacker:IsPlayer() && player:Team() == attacker:Team() then
return false
end
end
hook.Add(“PlayerHurt”, “FriendlyFire”, AntiFriendlyFire).
[/lua]

Also depending on your gamemode

mp_friendlyfire = 0 may just work

Try this.

[lua]function NoTeamDamage( ply, atk, hr, dd )
if ( ply:Team() == YOURTEAM && atk:IsPlayer() && atk:Team() == YOURTEAM ) then
ply.SetHealth(hr + dd)
end
end

hook.Add( “PlayerHurt”, “NoTeamDamage”, NoTeamDamage )[/lua]

Untested but should work.

what if i have multiple teams? , i mean i have 3 different teams in 1 team, like “sniper” “rifleman” etc…

Mine should work fine if you think it doesn’t. I don’t think you can return false on PlayerHurt to take no damage at all.

but you can shoot your friend while a enemy doo it because your friends health will restore all the time, if im right.

No. When the person is damaged by a team member, it takes the health remaining, and the health that was inflicted, and adds it together, and sets that player’s health.

People can’t use it to cheat.

okay, i will try it :slight_smile: Thanks.

[editline]10:38PM[/editline]

dang it, it did not work :confused:
and it doesnt show any errors.

I’m not sure then. Try looking at this **[Gamemode.EntityTakeDamage

http://wiki.garrysmod.com/favicon.ico](wiki.garrysmod.com/?title=Gamemode.EntityTakeDamage)**.

And try scaling the damage to 0 if they are on the same team.

Oh, come on. At least post the right hooks. All of the above are called after dealing damage.

**[Gamemode.PlayerShouldTakeDamage

http://wiki.garrysmod.com/favicon.ico](wiki.garrysmod.com/?title=Gamemode.PlayerShouldTakeDamage)**

That would make a lot of statements then

PS flapjack is right

I was looking for a hook like this but I couldn’t find it XD.

ty