setting a variable based off GM:PlayerDeath()

I want to set “killway” to either “killed” or “betrayed” based on the team of the killer player and the team of the victim

the code:
[lua]function GM:PlayerDeath( Victim, Inflictor, Killer )
if Killer:Team() = 2
if Victim:Team() = 1
killway = killed
end
if Killer:Team() = 1
if Victim:Team() = 1
killway = betrayed
end
if Killer:Team() = 1
if Victim:Team() = 2
ply.killway = killed
end
if Killer:Team() = 2
if Victim:Team() = 2
killway = betrayed
end

ply:PrintMessage( HUD_PRINTTALK, “‘victim:GetName()’ has been ‘killway’ by ‘killer:GetName()’ with a ‘Inflictor:GetName()’”
end[/lua]

Thanks!

[lua]local killed;

function GM:PlayerDeath( victim, inflictor, killer )
if killer:Team() == 1 and victim:Team() == 1 or killer:Team() == 2 and victim:Team() == 2 then
killed = “Betrayed”
elseif killer:Team() == 1 and victim:Team() == 2 or killer:Team() == 2 and victim:Team() == 1 then
killed = “Killed”
end

ply:PrintMessage( HUD_PRINTTALK, victim:Nick()…" has been “…killed…” by “…killer:GetName()…” with a "…inflictor:GetName())

end[/lua]

It could just be because I killed myself with the ‘kill’ command in console but…


 [gamemodes\rebelnpcwar\gamemode\init.lua:167] attempt to index global 'ply' (a nil value)(Hook: PlayerDeath)

[lua]local killed;

function GM:PlayerDeath( victim, inflictor, killer )
if killer:Team() == 1 and victim:Team() == 1 or killer:Team() == 2 and victim:Team() == 2 then
killed = “Betrayed”
elseif killer:Team() == 1 and victim:Team() == 2 or killer:Team() == 2 and victim:Team() == 1 then
killed = “Killed”
end

PrintMessage( HUD_PRINTTALK, victim:Nick()…" has been “…killed…” by “…killer:GetName()…” with a "…inflictor:GetName())

end[/lua]
Fixed.

[editline]7th November 2010[/editline]

If you don’t want it to say player has has been betrayed by player with a nothing then just do if killer != victim then…

Could’ve said thanks it works with the copied of end results.

[lua]
local variableA

function GM:PlayerDeath ( victim, inflictor, killer )
if killer:Team() != victim:Team() then variableA = " has been killed by “…killer:GetName()…
elseif killer:Team() == victim:Team() and killer != victim then variableA = " has been betrayed by “…killer:GetName()…
elseif killer == victim then variableA = " has suicided”
end
PrintMessage ( HUD_PRINTTALK, victim:Nick()…variableA…” with a "…inflictor:GetName())
end
[/lua]

I’ve already helped him out no need to post copying my method, if someone has already posted don’t interfere.

That won’t work anyway.

umad

Mad about what, I’m confused?

You’re such an idiot Cubar. Stop trying to help people you obviously don’t know what you’re doing.

Fine i will.

Sorry man I was too busy to respond, also BUMP

I’m still getting this error in singleplayer


[gamemodes\rebelnpcwar\gamemode\init.lua:159] attempt to call method 'Team' (a nil value)(Hook: PlayerDeath)


Check if killer / victim are players before checking which team they are on.

I tried :frowning:
[lua]local killed;

function GM:PlayerDeath( victim, inflictor, killer )
if killer == player and victim == player then

if killer:Team() == 1 and victim:Team() == 1 or killer:Team() == 2 and victim:Team() == 2 then
killed = “Betrayed”

PrintMessage( HUD_PRINTTALK, victim:Nick()…" has been “…killed…” by “…killer:GetName()…” with a "…inflictor:GetName())

elseif killer:Team() == 1 and victim:Team() == 2 or killer:Team() == 2 and victim:Team() == 1 then
killed = “Killed”

PrintMessage( HUD_PRINTTALK, victim:Nick()…" has been “…killed…” by “…killer:GetName()…” with a "…inflictor:GetName())

else

PrintMessage( HUD_PRINTTALK, victim:Nick()…" has been killed by the guardians"())

end
end[/lua]


[gamemodes\rebelnpcwar\gamemode\init.lua:173] ')' expected near '('
[cpp] 

I tried removing the [lua] " [/lua] at the end of [lua] guardians [/lua] but it didn’t do anything

[LUA]

if (killer and victim) and (killer:IsPlayer() and victim:IsPlayer()) then

[/LUA]

[lua]
function KillReason( victim, inflictor, killer )

if !victim:IsPlayer() && !killer:IsPlayer() then
	return ""
end

KT = killer:Team()
VT = victim:Team()

local KR = "Unidentified"

if KT == 2 && VT == 1 then
	KR = "Killed"
elseif KT == 1 && VT == 1 then
	KR = "Betrayed"
elseif KT == 1 && VT == 2 then
	KR = "Killed"
elseif KT == 2 && VT == 2 then
	KR = "Betrayed"
else
	for k,v in pairs(player.GetAll()) do
		k:ChatPrint("The kill reason for "..victim:Nick().." could not be identified.")
		return ''
	end
end

if KR == "Betrayed" then
	victim:ChatPrint('You have betrayed!')
else
	victim:ChatPrint('You were killed!')
end

end
hook.Add(“PlayerDeath”,“KillReason”,KillReason)
[/lua]

You should simplify your logic.

[lua]
function KillReason( victim, inflictor, killer )

if !victim:IsPlayer() && !killer:IsPlayer() then
	return ""
end

local KT = killer:Team()
local VT = victim:Team()

local KR = "Unidentified"

if KT != VT then
	KR = "Killed"
	victim:ChatPrint('You were killed!')
else
	KR = "Betrayed"
	victim:ChatPrint('You were betrayed!')
end

end
[/lua]