team kill

Hi!
i want to make a no team kill but my script does not work! can someone help me


function GM:PlayerShouldTakeDamage( victim, killer )
	if Target:Team() == Attacker:Team() then
	print("[GMWarfare] ERROR: " .. Target .. " Tried To Kill " .. Attacker .. "")
	print("[GMWarfare] ERROR: " .. Target .. " And " .. Attacker .. " Are On The Same Team!")
	return false
else
	end
	print("[GMWarfare]" .. Attacker .. " Killed " .. Target .. "")

end

You’re using Target/Attacker in the code but use victim/killer above, in the function

That’s not how lua works; you can’t give random names that sound like what you want and expect the code to automatically figure out what you mean

Errors?

Look at the



else
    **end**


Dont put else if you dont need it, Target:Nick() and Attacker:Nick() for name.

And it is victim and killer.

I was too slow writing.

oh yeah and i want it for logging thanks!

[editline]9th March 2015[/editline]

but now team 1 cant kill team 2

[editline]9th March 2015[/editline]

my code following what you all said still doesnt work


function GM:PlayerShouldTakeDamage( victim, killer )
	if Target:Team() == Attacker:Team() then
	print("[GMWarfare] ERROR: " .. target .. " Tried To Kill " .. attacker .. "")
	print("[GMWarfare] ERROR: " .. target .. " And " .. atacker .. " Are On The Same Team!")
	return false
else
	print("[GMWarfare]" .. attacker:Nick() .. " Killed " .. target:Nick() .. "")
end

end

You can’t use variables that aren’t defined. The variables defined in the function are victim and killer. The victim would be the same as the target, and the killer would be the same as the attacker. But the code won’t know this itself, you have to instruct it to do so. Note that this hook gets ran every time someone gets hurt, not killed. If you want it to get called only when you would die, you would have to add a check that checks wether or not the player will die if he gets hurt. (Basically check if the health is 1 or something)

[lua]function GM:PlayerShouldTakeDamage( victim, killer )
if victim:Team() == killer:Team() then
print("[GMWarfare] ERROR: " … victim … " tried to hurt " … killer )
print("[GMWarfare] ERROR: " … victim … " and " … killer … " are on the same team!")
return false
else
print("[GMWarfare]" … killer:Nick() … “hurted” … victim:Nick() … “”)
end
end[/lua]

Also, you made a post some days ago regarding a smooth health regeneration, and you locked the thread before I was able to reply. I made a lot better thing for you to use for regeneration.

[lua]local meta = FindMetaTable(“Player”)

function meta:Regenerate( amount, rate)
if (not (IsValid(self) and self:IsPlayer())) then return end
if self:Health() < amount then
timer.Create(“regenerate_”… self:SteamID(), 0.1 * rate, 0, function()
self:SetHealth( self:Health() + 1 )

		if self:Health() == amount then
			timer.Destroy("regenerate_".. self:SteamID())
		end
	end)
end

end[/lua]

You use it by doing ply:Regenerate( 100, 0.5 ), which regenerates the players health to 100 with a speed of 0.5, which I found to be a decent speed. I suggest you try out different ones, though.

thank you!

[editline]9th March 2015[/editline]

also does anyone know a auto balance team? ive tried using this


	if ply:Team(1) < ply:Team(0) then
	ply:SetTeam(1)
	else
	ply:SetTeam(0)
	end

but it doesnt work

[editline]9th March 2015[/editline]

never mind madeit