Friendly Fire [OFF]

So, I’m trying to create a Military themed RP server, using DarkRP 2.5 as a base. I’ve been trying to turn off friendly fire for awhile, meaning to where people in the same teamset can’t kill each other, any help would be much appreciated.

I’ve come up with this so far.
[lua]function GM:PlayerShouldTakeDamage( ply, victim )
if ply:IsPlayer() then
if ply:Team() == victim:Team() then
return false
end
end
return true
end [/lua]

This should work, under the terms that the players have the same teams. Have you tested it; are there any issues?

Your ply:IsPlayer() check is dumb, change it to victim:IsPlayer()

other then that, what is your problem? Looks fine.

DarkRP uses a team for each job, so the team check won’t work. This will ( set up the teams starting from 1 and going to whatever number of teams you have, pair them together, you’ll need to use the [ TEAM_BLAH ] = 1; instead of TEAM_BLAH = 1; so the team id will be set as index to the table ): https://dl.dropboxusercontent.com/u/26074909/tutoring/_systems/anti_teamkill_system.lua.html

It still allows the players of the same team to kill each other, that’s the problem.

Thank you, very much Acecool.

If you set the table like this:


local ANTI_TEAMKILL_TEAMS_TABLE = {
	// Team 1
	[ TEAM_POLICE ] 	= 1;
	[ TEAM_SWAT ] 	= 1;
	[ TEAM_JUDGE ] 	= 1;
	
	// Team 2
	[ TEAM_GANGSTER ] 	= 2;
	[ TEAM_GANG_SUPPLIER ] 	= 2;
	[ TEAM_GANG_BOSS ] 	= 2;
};

it’ll work fine, just add the teams together like that, and it will prevent damage. Unless you have ULX and ulx has done something with PlayerScaleDamage…

[lua]local ANTI_TEAMKILL_TEAMS_TABLE = {

// Team 1
 [ TEAM_USMC1 ]     = 1;
 [ TEAM_USMC2 ]     = 1;
 [ TEAM_CITIZEN ]    = 1;
// Team 2
 [ TEAM_CUBAN1 ]    = 2;
 [ TEAM_CUBAN2 ]    = 2;
 [ TEAM_CITIZEN ]    = 2;
// Team 3
 [ TEAM_RUSSIAN1 ]    = 3;
 [ TEAM_RUSSIAN2 ]    = 3;
 [ TEAM_CITIZEN ]    = 3;

}; [/lua]
http://i.imgur.com/IodJRH4.png How it looks in N++

Thats how I have it setup, it doesn’t want to work :confused:

Edit:
[lua]local ANTI_TEAMKILL_TEAMS_TABLE = {
// Team 1
[ TEAM_CITIZEN ] = 1;
[ TEAM_USMC1 ] = 1;
[ TEAM_USMC2 ] = 1;

// Team 2
[ TEAM_CITIZEN ] 	= 2;
[ TEAM_CUBAN1 ] 	= 2;
[ TEAM_CUBAN2 ] 	= 2;

// Team 3
[ TEAM_CITIZEN ] 	= 3;
[ TEAM_RUSSIAN1 ] 	= 3;
[ TEAM_RUSSIAN2 ] 	= 3;

};[/lua]

I copied the exact one you posted, and it didnt work.

The issue is TEAM_CITIZEN will continue to overwrite itself, therefore you’ll only be left with TEAM_CITIZEN is on team 3.

I’d say, take TEAM_CITIZEN OUT, and simply add an || _victim:Team( ) == TEAM_CITIZEN to the return false; portion of the code.

https://dl.dropboxusercontent.com/u/26074909/tutoring/_systems/anti_teamkill_system.lua.html


//
// Perform the action that prevents team-damage between like-teams
//
hook.Add("PlayerShouldTakeDamage", "PlayerShouldTakeDamage:AvoidTeamDamage", function( _victim, _attacker )
	// Make sure both victim and attacker are valid entities and that they're both player entities -- The victim can be assumed a player because of the hook. We're just calling it to remain uniform.
	if ( IsValid( _victim ) && IsValid( _attacker ) && _victim:IsPlayer( ) && _attacker:IsPlayer( ) ) then 
		// If both victim and attacker team data matches, don't allow damage. This is the ONLY test we need to perform.
		if ( ANTI_TEAMKILL_TEAMS_TABLE[ _victim:Team( ) ] == ANTI_TEAMKILL_TEAMS_TABLE[ _attacker:Team( ) ] || _victim:Team( ) == TEAM_CITIZEN ) then
			return false;
		end
	end
end );

It just means that citizens won’t ever be damaged.

Yeah, it still doesn’t work :confused:

Give DarkRP time to initialize teams…


ANTI_TEAMKILL_TEAMS_TABLE = ANTI_TEAMKILL_TEAMS_TABLE || { };
hook.Add( "InitPostEntity", "SetupTeamIDS", function( )
	ANTI_TEAMKILL_TEAMS_TABLE = {
		// Team 1
		[ TEAM_CITIZEN ] 	= 1;
		[ TEAM_USMC1 ] 	= 1;
		[ TEAM_USMC2 ] 	= 1;
	
		// Team 2
		[ TEAM_CITIZEN ] 	= 2;
		[ TEAM_CUBAN1 ] 	= 2;
		[ TEAM_CUBAN2 ] 	= 2;
	
		// Team 3
		[ TEAM_CITIZEN ] 	= 3;
		[ TEAM_RUSSIAN1 ] 	= 3;
		[ TEAM_RUSSIAN2 ] 	= 3;
	};
end );