# Multiple Team Friendly Fire

Currently I want 3 different teams (Team_v1, Team_v2, Team_v3) to not be able to kill eachother, but to be able to kill teams (Team_A1, Team_A2 and Team A3). And Vice Versa.
I have tried for the last hour but sadly I have came to no avail.

Any help would be appreciated. Thanks!

I did use that hook. I think my use of it was broken as it means no damage is done to any team or you can damage both teams:
[lua]
function FriendlyFire(victim, killer )
if (killer:Team() == (TEAM_V1 or TEAM_V2 or TEAM_V3)) and (victim:Team() == (TEAM_A1 or TEAM_A2 or TEAM_A3)) then
return true
else
return false
end
end

[/lua]

This is a gamemode? If so

function GM:PlayerShouldTakeDamage(victim, killer)

Edit:

Here’s my gamemodes.

[lua]-- Stop friendly fire –
function GM:PlayerShouldTakeDamage(ply, attacker)
if attacker:IsPlayer() and attacker:Team() == ply:Team() or self:GetRound() != ROUND_ACTIVE then
return false
end

``````return true
``````

end[/lua]

No, it is a darkrp edit. Sorry. I forgot to add a hook for it in the comment. Fixing now.

Your if statement logic is flawed, you can’t do
[lua]killer:Team() == (TEAM_V1 or TEAM_V2 or TEAM_V3)[/lua]
you have to do
[lua]
(killer:Team() == TEAM_V1 or killer:Team() == TEAM_V2 or killer:Team() == TEAM_V3)[/lua]

Because your parenthetical statement with the teams is doing this in psuedocode:
find first valid value of TEAM_V1, TEAM_V2, and TEAM_V3 and if it equals the killer’s team then do X
So essentially you are just checking against TEAM_V1 and continuing.

Your hook would look like this:
[lua]function FriendlyFire(victim, killer)
if not killer:IsPlayer() then return end
local team1, team2 = killer:Team(), victim:Team()
if (team1 == TEAM_V1 or team1 == TEAM_V2 or team1 == TEAM_V3) and (team2 == TEAM_V1 or team2 == TEAM_V2 or team2 == TEAM_V3)) then
return false
end
end

You also want to return FALSE to see if these sets of teams should not take damage, not true. If you return true then other take-damage hooks don’t get a chance to run.

You guys are doing it in a way that will make adding more teams a mess.

``````
local map = { }

function TeamCanDamageTeam( a, b )
if not map[ a ] then
return false
end

return map[ a ][ b ]
end

local function SetEnemyTeams( t, ... )
local _, v

map[ t ] = map[ t ] or { }

for _, v in ipairs{ ... } do
map[ t ][ v ] = true
map[ v ] = map[ v ] or { }
map[ v ][ t ] = true
end
end

SetEnemyTeams( TEAM_V1, TEAM_A1, TEAM_A2, TEAM_A3 )
SetEnemyTeams( TEAM_V2, TEAM_A1, TEAM_A2, TEAM_A3 )
SetEnemyTeams( TEAM_V3, TEAM_A1, TEAM_A2, TEAM_A3 )

function FriendlyFire( victim, killer )
return TeamCanDamageTeam( victim:Team( ), killer:Team( ) )
end

``````

This leaves it very open - if you add TEAM_V4, you’d just do this:

``````

SetEnemyTeams( TEAM_V4, TEAM_A1, TEAM_A2, TEAM_A3 )

``````

And then it automatically makes TEAM_A# able to damage _V4 in addition to _V4 being able to damage all of them.

This is one alternate to having a sprawling if statement to determine the same thing.

Thanks for your help! The code you have given me is more than I expected!

Thanks again!