[L]ua - Friendly fire help

Anything wrong with this script ?



ANTI_TEAMKILL_TEAMS_TABLE = ANTI_TEAMKILL_TEAMS_TABLE || { };

hook.Add( "InitPostEntity", "ParseTableAtRightTime", function( )
    ANTI_TEAMKILL_TEAMS_TABLE = {

        // Team 1
		[ TEAM_CITIZEN ] = 3;
        [ TEAM_AM ] = 3;
        [ TEAM_AR ] = 3;
        [ TEAM_AS ]  = 3;
		[ TEAM_ASP ] = 3;
		[ TEAM_ASG ] = 3;
		[ TEAM_AHG ] = 3;
		[ TEAM_AMN ] = 3;
		[ TEAM_AG ] = 3;

        // Team 2
		[ TEAM_CITIZEN ] = 10;
        [ TEAM_GM ] = 10;
        [ TEAM_GR ] = 10;
        [ TEAM_GS ] = 10;
		[ TEAM_GSP ] = 10;
		[ TEAM_GSG ] = 10;
		[ TEAM_GHG ] = 10;
		[ TEAM_GMN ] = 10;
		[ TEAM_GG ] = 10;
    };
end );

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( ) ] ) then
            return false;
        end
    end
end );


when i use it, noone can damage . its like godmode .

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

You don’t need something that complicated for anti-teamkill. That’s like 2x the amount of code it should take. Or maybe it’s the comments and underscores that make it look bad.

let me cut the comments

What game-mode are you running? If you use print( TEAM_ASP ); what prints out?

Also, you’re overwriting the TEAM_CITIZEN index, first setting to 3, then to 10. It can only be one, not both.

It isn’t a “complicated” script; it sets the table after DarkRP or whichever game-mode has set up the teams. ( Not all game-modes use the actual hook for setting up teams )… It just compares the team id of the attacker vs victim, if they’re the same then they’re on the same team. Because of how DarkRP and similar game-modes set up teams, where each “job”, even related ones, is a new team, this kind of logic is necessary to prevent team damage.

The only way god mode would occur, is if the TEAM_* values aren’t set up by InitPostEntity… Because nil can be a valid table index, and when a valid identifier is applied where none are then victim == attacker because both will report nil because the TEAM_* values aren’t there.

Make sure you copy from the .lua file. Replace the script with this:

https://dl.dropboxusercontent.com/u/26074909/work/debugging/anti_team_damage.lua

… Look in your server console, if CreateTeams isn’t called, there won’t be green text saying initialized. Red text will appear every 5 seconds if TEAM_CITIZEN never gets set up. I don’t know what game-mode you’re running, if it is custom, or what was done to it which is why I am using a “hack” solution.

If you add me on Steam, I can help you get it running; I do have the exact script above running on quite a few DarkRP servers which is why I’d like to look into why yours isn’t working.

what

no

Previous log: http://pastebin.com/4WvpzgLK

New: 7:15 PM - Thalexs: ace
7:15 PM - Thalexs: [ERROR] lua/autorun/server/antikill.lua:33: table index is nil

  1. InitAntiTeamKillTable - lua/autorun/server/antikill.lua:33
  2. unknown - lua/autorun/server/antikill.lua:61

[ERROR] lua/autorun/server/antikill.lua:33: table index is nil

  1. InitAntiTeamKillTable - lua/autorun/server/antikill.lua:33
  2. unknown - lua/autorun/server/antikill.lua:61

Timer Failed! [InitAntiTeamKillTable][@lua/autorun/server/antikill.lua (line 60)]

from: https://dl.dropboxusercontent.com/u/26074909/work/debugging/antikill.lua

Meaning TEAM_ASG is not set.

Looking through the console.log on pastebin, there are a lot of errors on your server. Messaging here as he went offline on Steam. I’ll take care of fixing the errors for you although I have no clue what Corrupt Entity means, I’ll look at “element max” to see if I can figure that out…