[B]I want to make this button:[/B]
[I]local button = vgui.Create("DButton" , frame)
button:SetText("Россия")
button:SetSize(980,200)
button:SetPos(10, 270)
button:SetColor(Color(0,0,0))
button.Paint = function(s,w,h)
draw.RoundedBox(5,0,0,w,h,Color(255,0,0))
end
function button.DoClick()
SelectRusia()
end [/I]
[B]will select a team to the player:[/B]
[I]
team.SetUp(1,Rusia,Color(255, 0, 0), true )
function SelectRusia()
ply:SetTeam(1)
print("you sellected russia")
end[/I]
[B]
and i´m getting this error:[/B]
[I]
[ERROR] gamemodes/territory/gamemode/teams.lua:11: attempt to call method 'SetTeam' (a nil value)
1. SelectRusia - gamemodes/territory/gamemode/teams.lua:11
2. DoClick - gamemodes/territory/gamemode/cl_dermateam.lua:31
3. unknown - lua/vgui/dlabel.lua:218
[/I]
[B]What I have to do?[/B]
PD: Sorry for my bad english, yo soy de argentina y me gusta comer empanadas
You can't change teams in client realm, you have to send a network message in DoClick, receive it in server and then change team
replace
[code]ply:SetTeam(1)
print("you sellected russia")[/code]
by
[code]net.Start("setrussia")
net.SendToServer()
print("you sellected russia")[/code]
and on the serverside part do this :
[code]util.AddNetworkString( "setrussia" )
net.Receive( "setrussia", function( len, ply )
ply:SetTeam(1)
end )[/code]
ply:SetTeam is serverside so you have to do an net.Start to ask the server to change team.
[url]https://wiki.garrysmod.com/page/Net_Library_Usage[/url]
Thanks guys!
Sorry, you need to Log In to post a reply to this thread.