Hello guys,
i tried to code an lua script for my server so traitors get PS Points for winning. They should get different amounts of points depending on if the are alive or not, but unfortunately it isnt working. I hope you can help me.
Here is the code:
[CODE]
-- Pointshop Hook
if SERVER then
hook.Add("TTTEndRound", "tttendroundpoints", function( win )
--chat.AddText("HALLO")
for k, v in pairs( player.GetAll() ) do
if pl:IsTerror() then
if win == WIN_TRAITOR then
if v:IsActiveTraitor() then
v:PS_GivePoints(1337)
end
else
if v:IsActiveTraitor() then
v:PS_GivePoints(5)
end
end
end
end
end)
end
[/CODE]
[QUOTE=Pustekuchen98;52308297]Hello guys,
i tried to code an lua script for my server so traitors get PS Points for winning. They should get different amounts of points depending on if the are alive or not, but unfortunately it isnt working. I hope you can help me.
Here is the code:
[CODE]
-- Pointshop Hook
if SERVER then
hook.Add("TTTEndRound", "tttendroundpoints", function( win )
--chat.AddText("HALLO")
for k, v in pairs( player.GetAll() ) do
if pl:IsTerror() then
if win == WIN_TRAITOR then
if v:IsActiveTraitor() then
v:PS_GivePoints(1337)
end
else
if v:IsActiveTraitor() then
v:PS_GivePoints(5)
end
end
end
end
end)
end
[/CODE][/QUOTE]
pl is nil, replace pl:IsTerror() with v:IsTerror()
You're right, but its still not working :( Any other idea? The File is located in the autorun folder (TTT-Test-Server\garrysmod\lua\autorun\server)
You're checking if the player is a terrorist and a traitor at the same time, which isn't possible. Remove the IsTerror() check and it should work.
Still not workin'.
Here is the updated code:
[CODE]-- Pointshop Hook
if SERVER then
hook.Add("TTTEndRound", "tttendroundpoints", function( win )
--chat.AddText("HALLO")
for k, v in pairs( player.GetAll() ) do
if win == WIN_TRAITOR then
if v:IsActiveTraitor() then
v:PS_GivePoints(1337)
end
else
if v:IsActiveTraitor() then
v:PS_GivePoints(5)
end
end
end
end)
end[/CODE]
Try adding some prints to see if the hook is called, which team won and if the player is a traitor.
OUTPUT: HOOK CALLED
T WIN
T WIN
T WIN
I think the problem is that i check for an alive traitor but after the round end he isnt a traitor anymore. So i would have to check if hes alive and not a t.
EDIT: Its was the problem, now im checking for v:Alive() and it works :)
Thank you very much for your help.
[editline]3rd June 2017[/editline]
Okay, i got one more problem. Now everyone is getting the points if the traitors win, but only the traitors should get the points if the wincause is a traitor win. Any idea?
Your problem is simply that you're not using the correct function
[lua]if SERVER then
hook.Add( "TTTEndRound", "tttendroundpoints", function( win )
--chat.AddText("HALLO")
for k, v in ipairs( player.GetAll() ) do
if v:GetTraitor() --[[and v:IsTerror()]] then -- Remove the comment to only give points for living traitors
if win == WIN_TRAITOR then
v:PS_GivePoints(1337)
else
v:PS_GivePoints(5)
end
end
end
end )
end[/lua]
Try v:IsTraitor() instead of v:IsActiveTraitor() ( or now v:Alive() )
[editline]3rd June 2017[/editline]
what he said
Its working. Thank you both.
Sorry, you need to Log In to post a reply to this thread.