i'm a newbie LUA programmer and need help this script.
the function ITEM:OnBuy is is working but RoundRemoverbuy(ply,roundsbuy) is not.
[IMG]http://i.imgur.com/Y3rad1m.png?1[/IMG]
[CODE]
ITEM.Name = "Traitor"
ITEM.Price = 1000
ITEM.Material = "VGUI/ttt/sprite_traitor.vmt"
ITEM.NoPreview = true
ITEM.SingleUse = true
ITEM.AllowedUserGroups = { } --change this after
function ITEM:OnBuy(ply)
if((ply.roundsbuy == 0) or (ply.roundsbuy == nil)) then
RunConsoleCommand("ulx", "forcenr", ply:Nick(), "traitor")
math.randomseed (os.time())
ply.roundsbuy = math.random(2, 4)
RunConsoleCommand("ulx", "psay", ply:Nick(), "Nice, you bought a traitor round. Now, you can only buy in ",ply.roundsbuy," rounds")
else
RunConsoleCommand("ulx", "psay", ply:Nick(), "You cant but traitor now . There are still ",ply.roundsbuy," rounds to buy again ")
end
return ply.roundsbuy
end
function RoundRemoverbuy(ply,roundsbuy)
if(ply.roundsbuy > 0) then
ply.roundsbuy = ply.roundsbuy - 1
RunConsoleCommand("ulx", "psay", ply:Nick(), "[VIP]You can buy traitor in ",ply.roundsbuy," rounds")
else
RunConsoleCommand("ulx", "psay", ply:Nick(), "[VIP]Buying Traitor is available in this round")
end
return ply.roundsbuy
end
hook.Add( "TTTEndRound", "roundremover", RoundRemoverbuy )
[/CODE][T][T][/T][/T]
[QUOTE=Nargarath;46847918]i'm a newbie LUA programmer and need help this script.
the function ITEM:OnBuy is is working but RoundRemoverbuy(ply,roundsbuy) is not.
[IMG]http://i.imgur.com/Y3rad1m.png?1[/IMG]
[CODE][/CODE][T][T][/T][/T][/QUOTE]
Line 32 is blank. There are also issues with the tabbing.
The error says that somewhere along the line ply is a number instead of a player object. You are trying to access table elements on ply but since it is a number it can't do it.
Do you know, what TTTEndRound hook gives as arguments?
hook.Call("TTTEndRound", GAMEMODE, type)
GAMEMODE is number.
You can view all ttt only hooks here [url]http://ttt.badking.net/guides/hooks[/url]
TTTendround doesn't Return a player argument only the result. So that's why your player is nil ( a number)
[QUOTE=TheRedKorsar;46848188]Do you know, what TTTEndRound hook gives as arguments?
hook.Call("TTTEndRound", GAMEMODE, type)
GAMEMODE is number.[/QUOTE]
no it doesnt? Read your documentation of hook.Call
[img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/hook/Call]hook.Call[/url]
Second argument is gamemode table, then after that are the hooks arguments
EndRound returns a number based on which role won the match
what i can do to solve it? .-.
[QUOTE=Nargarath;46848351]what i can do to solve it? .-.[/QUOTE]
You could loop through every player on the server or make a table that contains only the players that purchased it either way.
With every player you'd use the same hook, Just sort out the arguments properly and do
for _, ply in pairs(player.GetAll()) do
--Your code to check if they have one and do your messages here
end
[QUOTE=keensta;46848585]You could loop through every player on the server or make a table that contains only the players that purchased it either way.
With every player you'd use the same hook, Just sort out the arguments properly and do
for _, ply in pairs(player.GetAll()) do
--Your code to check if they have one and do your messages here
end[/QUOTE]
Thanks :D
Sorry, you need to Log In to post a reply to this thread.