team killing, custom gamemode

hi, im wondering why this code isnt working

function GM:PlayerShouldTakeDamage( ply, att )
	if ply:Team() == att:Team then
		return false
	att:PrintMessage( ply:Nick() .. " Is On Your Team!" )
	att:PrintMessage( "Stop Shooting!" )

for my no team kill script, and if anyone could help me make one?

i was given this one by .Author but it doesnt work and doesnt let team 0 kill team 1

function GM:PlayerShouldTakeDamage( victim, killer )
	if victim:Team() == killer:Team() then
		return false

function GM:PlayerShouldTakeDamage( victim, killer )
	if victim:Team() == killer:Team() then
		return false
return true

Try that.

That shouldn’t change anything as it’s basically set to do true if nothing is returned.

Do you get no errors at script startup or when it’s run? Are the teams set?

  1. Make sure that you are running it server side.
  2. Try and print the teams, see if they are actually the same.
    Basically just debug it…

That looks like it should work. Are you sure that the players are actually being set to the same team?

except the message to the player won’t be printed.

Code is fine, the coding boss just doesn’t know what he’s doing and has integrated it wrong.
If only there were some kind of boss of the codes to help him.

Acecool helped me with this one.


hook.Add( “InitPostEntity”, “ParseTableAtRightTime”, function( )

 	[ TEAM_1 ] = 1;
            --Team 2
	[ TEAM_2 ] = 2;

end );

hook.Add(“PlayerShouldTakeDamage”, “PlayerShouldTakeDamage:AvoidTeamDamage”, function( _victim, _attacker )
if ( IsValid( _victim ) && IsValid( _attacker ) && _victim:IsPlayer( ) && _attacker:IsPlayer( ) ) then
if (ANTI_TEAMKILL_TEAMS_TABLE[ _victim:Team( ) ] == 1 && ANTI_TEAMKILL_TEAMS_TABLE[ _attacker:Team( ) ] == 1) then
return true;
elseif (ANTI_TEAMKILL_TEAMS_TABLE[ _victim:Team( ) ] == 2 && ANTI_TEAMKILL_TEAMS_TABLE[ _attacker:Team( ) ] == 2) then
return true;
elseif (ANTI_TEAMKILL_TEAMS_TABLE[ _victim:Team( ) ] == 7 && ANTI_TEAMKILL_TEAMS_TABLE[ _attacker:Team( ) ] == 7) then
return true;
if ( ANTI_TEAMKILL_TEAMS_TABLE[ _victim:Team( ) ] == ANTI_TEAMKILL_TEAMS_TABLE[ _attacker:Team( ) ] ) then
return false;
end );

This will prevent team damage all together.

thanks man your a life saver!

Here’s a newer version of that script:

[ NOTE ] Remove .html to view / copy .Lua …

my eyes literally bleed trying to read this

Why are you making it so advanced? Friendly fire can be disabled just like this as well.

[lua]hook.Add(“PlayerShouldTakeDamage”, “Anti-FF”, function( victim, attacker )
if IsValid( attacker ) and attacker:IsPlayer() and IsValid( victim ) then
if ( victim:Team() == attacker:Team() ) then
– attacker:ChatPrint(“Don’t fire at your own team.”)
return false
Sorry for tabbing wrote on my phone.

Mine allows you to set TEAM_POLICE, TEAM_POLICE_CHIEF, etc… as common ids, ie group teams together. The one you posted means that common “teams” will not be considered “friendly”…

I’m not a fan of how many people use the team system to create many “teams” instead of creating a simple role system, but because it is how almost everyone handles teams ( Even TTT has 3 teams, Detective, Terrorist, and Good Guy Traitors; where Terrorist and Detective would be able to damage each other using the code you posted [ even though they’re considered “Roles”, they still use the team system ] )…

I’m rewriting the entire team module which will build all of this in with options for all of it, plus rewrite how spawn systems will work… It’ll be, for the most part, stand-alone ( Except it uses one of my custom hooks for when it should create the team assignments [ called after CreateTeams ] which is easy enough to change ) for those that want to use the features:

He never mentioned anything with different teams that work together, etc? From the latest threads the OP has made, it looks like he is trying to create a team death match gamemode themed off of Advanced Warfare from scratch, which I am very certain don’t need anything related to roles or different teams that would be friendly together.