Hey there, I’ve looked at about 5 other posts related to this, but couldn’t find anything related quite exactly to what I want.
PROBLEM
I have about 8 teams in my game
local friends = {"US Military","Marines","Spec Ops","Secret Service","[DOS] Department of State","Congress","Military Police","Homeland Security","Department of Justice","[MED] Military Education Dept."}
The issue being, every way I’ve tried to approach this - it doesn’t seem to work.
if plr1.Team == Teams[friends] and Player.Team == Teams[friends] then
end
Those are the lines of codes relevant to this anti-teamkill script. Maybe I’ve been working on this so long I’m frankly braindead and just making things worst? This was implemented, we tested - and now nobody can be damaged.
GOAL:
“Friendly” teams cannot damage each other, but may damage raiders.
Raiders may damage “friendly” teams.
You can use table.find
local friends = {"US Military","Marines","Spec Ops","Secret Service","[DOS] Department of State","Congress","Military Police","Homeland Security","Department of Justice","[MED] Military Education Dept."}
if table.find(friends, plr1.Team.Name) and table.find(friends, Player.Team.Name) then
print("friendly fire!")
end
2 Likes
Tried both, essentially what I’m trying to do is make it so that if they shoot each other, it won’t kill the other player.
Tried it as plr1.Team.Name and plr1.Team - both failed to stop the teamkill - while allowing raiders to still kill allied teams.
What exactly are the variables Teams
, friends
, and plr1
/Player
?
Heres a basic framework
-- have a table of friendly teams
-- inside hit/damage function:
local canDamage = true
for _, team in friendlyTeams do
if (playerThatGotHit.Team == team) then
canDamage = false
end
end
if (canDamage) then
-- damage
end
basically, just have a table of friendly teams, and iterate through it to see if the person you hit is one of those teams. If so, then don’t damage them.
ok so, I really do apologize - I truly did overcomplicate things. I’m not sure if anybody can relate to that when you’ve been in studio too long.
This is what I ended up needing, and it works now:
local allied = false
if table.find(friends, plr1.Team.Name) and table.find(friends, Player.Team.Name) then
allied = true
end
if plr1.Team ~= Player.Team and allied == false then
(damage dealing code)
end
thank you @CodedJack for helping w my lack of education w/ tables. Marked you as solution, because you truly guided me in the right direction here.
1 Like
Ahh just seen this, thank you as well!