• Print

Author Topic: DButton/DFrame Help  (Read 5498 times)

0 Members and 1 Guest are viewing this topic.

Offline Zmaster

  • Full Member
  • ***
  • Posts: 235
  • Karma: 25
DButton/DFrame Help
« on: September 06, 2014, 08:27:59 pm »
Hi

I'm trying to create a DFrame that opens when a player first joins the server. This isn't my problem, though

My problem is I want a button on that DFrame that sets the player's team ( Player:SetTeam ). When I checked, Player:SetTeam is serverside lua, but the place where I set the function of the DButton is in a clientside file...so what would I do?

Here's the code of the file so far
Code: Lua
  1. function PickMyTeamWindow()
  2.         TeamPickW = vgui.Create( "DFrame" )
  3.         TeamPickW:SetSize( 270, 200 )
  4.         TeamPickW:SetPos( ScrW(), ScrH() )
  5.         TeamPickW:SetTitle( "Please select the team you wish to be on." )
  6.         TeamPickW:SetBackgroundBlur( true )
  7.        
  8.         TeamPickWPri = vgui.Create( "DButton", TeamPickW )
  9.         TeamPickWPri:SetText( "Prisoners" )
  10.         TeamPickWPri:SetPos(  )
  11.         TeamPickWPri:SetSize( 100, 30 )
  12.         TeamPickWPri.DoClick = function()
  13.                 ply:SetGamemodeTeam( 0 )
  14.         end
  15. end

Offline Neku

  • Hero Member
  • *****
  • Posts: 549
  • Karma: 27
Re: DButton/DFrame Help
« Reply #1 on: September 07, 2014, 12:13:02 am »
You use the net library.

http://wiki.garrysmod.com/page/Net_Library_Usage

Make it send to the server, then use that command on the server.
Out of the Garry's Mod business.

Offline Zmaster

  • Full Member
  • ***
  • Posts: 235
  • Karma: 25
Re: DButton/DFrame Help
« Reply #2 on: September 07, 2014, 10:07:02 pm »
Okay
Looking at the clientside example, it tells me to use net.WriteString, which I know I won't be using, since I want the server to run code, not read a string...so what do I use instead of net.WriteString?

Using what you gave me, I did this for serverside:
Code: Lua
  1. util.AddNetworkString( "ChoiceIsPrisoner" )

and this for clientside:
Code: Lua
  1. function PickMyTeamWindow()
  2.         TeamPickW = vgui.Create( "DFrame" )
  3.         TeamPickW:SetSize( ScrW(), ScrH() )
  4.         TeamPickW:SetPos( ( ScrW() / 2 ), ( ScrH() / 2 ) )
  5.         TeamPickW:SetTitle( "Please select the team you wish to be on." )
  6.         TeamPickW:SetBackgroundBlur( true )
  7.        
  8.         TeamPickWPri = vgui.Create( "DButton", TeamPickW )
  9.         TeamPickWPri:SetText( "Prisoners" )
  10.         TeamPickWPri:SetPos(  )
  11.         TeamPickWPri:SetSize( 100, 30 )
  12.         TeamPickWPri.DoClick = function()
  13.                 net.Start("ChoiceIsPrisoner")
  14.                         net.
  15.         end
  16. end

Offline Neku

  • Hero Member
  • *****
  • Posts: 549
  • Karma: 27
Re: DButton/DFrame Help
« Reply #3 on: September 07, 2014, 10:47:02 pm »
You'd do
Code: Lua
  1. net.WriteEntity( LocalPlayer() )

Then, on serverside, do
Code: Lua
  1. net.Receive( "ChoiceIsPrisoner", function( len, ply )
  2.      net.ReadEntity:SetGamemodeTeam( 0 ) -- Or whatever goes here.
  3. end )

Out of the Garry's Mod business.

Offline Zmaster

  • Full Member
  • ***
  • Posts: 235
  • Karma: 25
Re: DButton/DFrame Help
« Reply #4 on: September 08, 2014, 12:12:10 pm »
Thanks for the help so far, Neku

However, I'm getting an error on the net.ReadEntity:SetGamemodeTeam( 0 )

Here's the code on the serverside file
Code: Lua
  1. function OpenTeamPickWindow( ply )
  2.         ply:ConCommand( "jb_onstart_pickteamwindow" )
  3. end
  4. hook.Add( "ShowTeam", "OpenTeamPickWindowKey", OpenTeamPickWindow )
  5.  
  6. util.AddNetworkString( "ChoiceIsPrisoner" )
  7.  
  8. net.Receive( "ChoiceIsPrisoner", function( len, ply )
  9.         net.ReadEntity:SetGamemodeTeam( 0 )
  10. end )

and here's my clientside code (again)
Code: Lua
  1. function PickMyTeamWindow()
  2.         TeamPickW = vgui.Create( "DFrame" )
  3.         TeamPickW:SetSize( ScrW(), ScrH() )
  4.         TeamPickW:SetPos( ( ScrW() / 2 ), ( ScrH() / 2 ) )
  5.         TeamPickW:SetTitle( "Please select the team you wish to be on." )
  6.         TeamPickW:SetBackgroundBlur( true )
  7.        
  8.         TeamPickWPri = vgui.Create( "DButton", TeamPickW )
  9.         TeamPickWPri:SetText( "Prisoners" )
  10.         TeamPickWPri:SetPos( ( ScrW() / 3 ), ( ScrH() / 3 ) )
  11.         TeamPickWPri:SetSize( 200, 50 )
  12.         TeamPickWPri.DoClick = function()
  13.                 net.Start("ChoiceIsPrisoner")
  14.                         net.WriteEntity( LocalPlayer() )
  15.                 net.SendToServer()
  16.         end
  17. end

Here's the error

Offline Decicus

  • Hero Member
  • *****
  • Posts: 552
  • Karma: 81
    • Alex Thomassen
Re: DButton/DFrame Help
« Reply #5 on: September 08, 2014, 12:26:32 pm »
Here's the error


Try:
Code: [Select]
net.ReadEntity():SetGamemodeTeam( 0 )instead of
Code: [Select]
net.ReadEntity:SetGamemodeTeam( 0 )
Contact information:
E-mail: alex@thomassen.xyz.
You can also send a PM.

Offline Zmaster

  • Full Member
  • ***
  • Posts: 235
  • Karma: 25
Re: DButton/DFrame Help
« Reply #6 on: September 13, 2014, 10:01:26 pm »
Sorry for the delay, I've been busy

Thanks for the help, both of you
The button works now :)

  • Print