I recently added a pointshop to my TTT server that gives or takes points when you kill enemies and allies respectively. I've run into some problems though. When the round ends, every surviving player tries to kill everyone else. Unfortunately, when you kill allies, you lose points. How can I change this so that it only gives/takes points when there is an active round?
[CODE]hook.Add("DoPlayerDeath", "ShowKiller", function(victim, attacker)
if attacker:IsPlayer() then
victim:PrintMessage(HUD_PRINTTALK, "You have been killed by "..attacker:Nick()..". He was a "..attacker:GetRoleString()..".")
elseif not attacker:IsPlayer() then
victim:PrintMessage(HUD_PRINTTALK, "You were killed by some entity!")
end
if victim:IsPlayer() and attacker:IsPlayer() then
if attacker:GetRoleString() == "traitor" and victim:GetRoleString() ~= "traitor" then
attacker:PS_GivePoints(10)
attacker:PS_Notify("You've been given ", 10, " for killing "..victim:Nick().."!")
elseif attacker:GetRoleString() ~= "traitor" and victim:GetRoleString() == "traitor" then
attacker:PS_GivePoints(15)
attacker:PS_Notify("You've been given ", 15, " for killing "..victim:Nick().."!")
elseif attacker:GetRoleString() ~= "traitor" and victim:GetRoleString() ~= "traitor" and attacker:Nick() ~= victim:Nick() then
attacker:PS_GivePoints(-15)
attacker:PS_Notify("You've lost ", 15, " for killing "..victim:Nick().."!")
elseif attacker:GetRoleString() == "traitor" and victim:GetRoleString() == "traitor" and attacker:Nick() ~= victim:Nick() then
attacker:PS_GivePoints(-20)
attacker:PS_Notify("You've lost ", 20, " for killing "..victim:Nick().."!")
end
end
end)
[/CODE]
thanks.
If GetRoundState() is not equal to ROUND_ACTIVE then return end
[CODE]hook.Add("DoPlayerDeath", "ShowKiller", function(victim, attacker)
if GetRoundState() ~= "ROUND_ACTIVE" then return false end
if attacker:IsPlayer() then
victim:PrintMessage(HUD_PRINTTALK, "You have been killed by "..attacker:Nick()..". He was a "..attacker:GetRoleString()..".")
elseif not attacker:IsPlayer() then
victim:PrintMessage(HUD_PRINTTALK, "You were killed by some entity!")
end
if victim:IsPlayer() and attacker:IsPlayer() then
if attacker:GetRoleString() == "traitor" and victim:GetRoleString() ~= "traitor" then
attacker:PS_GivePoints(10)
attacker:PS_Notify("You've been given ", 10, " for killing "..victim:Nick().."!")
elseif attacker:GetRoleString() ~= "traitor" and victim:GetRoleString() == "traitor" then
attacker:PS_GivePoints(15)
attacker:PS_Notify("You've been given ", 15, " for killing "..victim:Nick().."!")
elseif attacker:GetRoleString() ~= "traitor" and victim:GetRoleString() ~= "traitor" and attacker:Nick() ~= victim:Nick() then
attacker:PS_GivePoints(-15)
attacker:PS_Notify("You've lost ", 15, " for killing "..victim:Nick().."!")
elseif attacker:GetRoleString() == "traitor" and victim:GetRoleString() == "traitor" and attacker:Nick() ~= victim:Nick() then
attacker:PS_GivePoints(-20)
attacker:PS_Notify("You've lost ", 20, " for killing "..victim:Nick().."!")
end
end
end)[/CODE]
Try that
well, it ended up making us stuck in spectator mode with weapons and no arms, but I changed it around a bit, and it worked. Thanks guys.
[QUOTE=ChemicalCat;41259233]well, it ended up making us stuck in spectator mode with weapons and no arms, but I changed it around a bit, and it worked. Thanks guys.[/QUOTE]
The nice thing to do is to post how you solved it so anyone who stumbles upon this in the future knows what to do :)
GetRoundState() doesn't return a string, it returns a integer.
ROUND_ACTIVE is just a ENUM that returns a integer.
[lua]
if GetRoundState() ~= ROUND_ACTIVE then return false end
[/lua]
[QUOTE]The nice thing to do is to post how you solved it so anyone who stumbles upon this in the future knows what to do :)[/QUOTE]
I was gonna say the same thing lol ;]
Oh, apologies.
[CODE]hook.Add("DoPlayerDeath", "ShowKiller", function(victim, attacker)
if attacker:IsPlayer() and GetRoundState() == "ROUND_ACTIVE" then
victim:PrintMessage(HUD_PRINTTALK, "You have been killed by "..attacker:Nick()..". He was a "..attacker:GetRoleString()..".")
elseif not attacker:IsPlayer() then
victim:PrintMessage(HUD_PRINTTALK, "You were killed by some entity!")
end
if victim:IsPlayer() and attacker:IsPlayer() and GetRoundState() == "ROUND_ACTIVE" then
if attacker:GetRoleString() == "traitor" and victim:GetRoleString() ~= "traitor" then
attacker:PS_GivePoints(10)
attacker:PS_Notify("You've been given ", 10, " for killing "..victim:Nick().."!")
elseif attacker:GetRoleString() ~= "traitor" and victim:GetRoleString() == "traitor" then
attacker:PS_GivePoints(15)
attacker:PS_Notify("You've been given ", 15, " for killing "..victim:Nick().."!")
elseif attacker:GetRoleString() ~= "traitor" and victim:GetRoleString() ~= "traitor" and attacker:Nick() ~= victim:Nick() then
attacker:PS_GivePoints(-15)
attacker:PS_Notify("You've lost ", 15, " for killing "..victim:Nick().."!")
elseif attacker:GetRoleString() == "traitor" and victim:GetRoleString() == "traitor" and attacker:Nick() ~= victim:Nick() then
attacker:PS_GivePoints(-20)
attacker:PS_Notify("You've lost ", 20, " for killing "..victim:Nick().."!")
end
end
end)
[/CODE]
Sorry, you need to Log In to post a reply to this thread.