• Print

Author Topic: Admin Message  (Read 4365 times)

0 Members and 1 Guest are viewing this topic.

Offline lampman13

  • Jr. Member
  • **
  • Posts: 71
  • Karma: -10
Admin Message
« on: May 13, 2014, 01:50:16 pm »
I know i had this on here a long time ago but i still need help im doing better with lua. last time i posted this everyone was like "Use net messages" or "This isnt how you code" and "maybe you should try something easier because your really bad". but i did it didnt I? i just cant do it so it works on a server and every one makes it sound easy so i dont think it is that hard to explain to me how you do net messages so my first code is this this is client side:
Code: Lua
  1. function UCast( ply )
  2.         local ply = LocalPlayer()
  3.         local BackGround = vgui.Create( "DFrame" )
  4.         BackGround:SetSize( 400,100 )
  5.         BackGround:SetPos( (ScrW()/2)-BackGround:GetWide(),(ScrH()/2)-BackGround:GetTall() )
  6.         BackGround:SetTitle( "Admin Menu - Type Your Message To The Server Here" )
  7.         BackGround:SetVisible( true )
  8.         BackGround:SetDraggable( true )
  9.         BackGround:ShowCloseButton( true )
  10.         BackGround:MakePopup()
  11.         BackGround.Paint = function()
  12.                 draw.RoundedBox(4, 0, 0, BackGround:GetWide(), BackGround:GetTall(), Color(100, 100, 100, 255))
  13.                 draw.RoundedBox(2, 2, 2, BackGround:GetWide()-4, 21, Color(50, 50, 50, 255))
  14.         end
  15.        
  16.         local TextEntry = vgui.Create( "DTextEntry", BackGround )
  17.         TextEntry:SetPos( 20,40 )
  18.         TextEntry:SetTall( 20 )
  19.         TextEntry:SetWide( 360 )
  20.         TextEntry:SetEnterAllowed( true )
  21.         TextEntry.OnEnter = netMessage()
  22.                 net.Receive( 'adminMsg', function()
  23.                 chat.AddText(Color(0, 0, 0), "[", Color(255, 0, 0), "ADMIN MESSAGE", Color(0, 0, 0), "]", Color(0, 255, 0), TextEntry:GetText() )
  24.         end )
  25.                 BackGround:SetVisible()
  26.         end
  27. end
  28. concommand.Add("broadcast_chat",UCast)
  29.  

and my server side:

Code: Lua
  1. include( "client/cl.lua" )
  2.         util.AddNetworkString( 'adminMsg' )
  3. function netMessage( pl )
  4.     net.Start( 'adminMsg' )
  5.     net.Broadcast()
  6.   end )





sorry for being kinda bad but i need help and this is where i get it also can someone direct me to where i can learn how to integrate this with ULX? please.
« Last Edit: May 13, 2014, 01:52:09 pm by lampman13 »

Offline MrPresident

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 2727
  • Karma: 430
    • |G4P| Gman4President
Re: Admin Message
« Reply #1 on: May 13, 2014, 02:28:27 pm »
I'm glad you tried and are learning, but this is not how you use net messages at all.

First of all, what are you sending? It looks like you want to send the contents of a text box to the server to be resent to all connected clients as an admin message.

To do that, you'll first need to do a client to server net message to send the text. Then you'll need to do another net message to broadcast the message to the clients to display.

Something like this:

Server:
Code: Lua
  1. util.AddNetworkString( "toServer" )
  2. util.AddNetworkString( "toClients" )
  3.  
  4. net.Receive( "toServer", function( len, pl )
  5.         net.Start( "toClients" )
  6.         net.WriteString( net.ReadString() )
  7.         net.Broadcast()
  8. ent )
  9.  

Client:
Code: Lua
  1. --In your onEnter function
  2. TextEntry.OnEnter = function()
  3.                 net.Start( "toServer" )
  4.                 net.WriteString( TextEntry:GetText() )
  5.                 net.SendToServer()
  6.                 BackGround:SetVisible()
  7.         end )
  8.  
  9. net.Receive( "toClients", function( len )
  10.         local message = net.ReadString()
  11.         chat.AddText(Color(0, 0, 0), "[", Color(255, 0, 0), "ADMIN MESSAGE", Color(0, 0, 0), "]", Color(0, 255, 0), message )
  12. end )
  13.  

Offline lampman13

  • Jr. Member
  • **
  • Posts: 71
  • Karma: -10
Re: Admin Message
« Reply #2 on: May 13, 2014, 02:33:13 pm »
alright i will try it thanks so much i dont know if you were on here when i first put this on here but you seem so much nicer than everyone else that tries to help me and it seems like no one does anything for me but tell me you cant code go find someone to help you then i fell like wait i came here for that reason ... but thanks i will try this now

Offline lampman13

  • Jr. Member
  • **
  • Posts: 71
  • Karma: -10
Re: Admin Message
« Reply #3 on: May 14, 2014, 01:43:08 pm »
hmm didnt seem to work i will try to debug it
« Last Edit: May 14, 2014, 02:26:27 pm by lampman13 »

  • Print