Author Topic: How do I make clients see text (in a box) from the server, like ulx !motd  (Read 174 times)

0 Members and 1 Guest are viewing this topic.

Offline APNxRPG24

  • Newbie
  • *
  • Posts: 8
  • Karma: 0
My addon has a command, i.e. !open_textbox, that will open a textbox for the client and display some text. The problem is that it will only display the text if the client has the file locally. But I want it to be like the !motd command, so the text displayed in the (motd) box is obtained from the server (the ulx_motd.txt file on the server).

I looked in the "menus.lua" file found in "addons\ulx\lua\ulx\modules\sh" and the "motdmenu.lua" file found in "addons\ulx\lua\ulx\modules\cl" for reference but didn't have much luck.
I understand that the ulx addon is much more complicated than what I'm trying to do, but I hope there's some simple LUA code that can accomplish this as I don't know much about LUA.

My addon's "open_textbox.lua" file is in autorun/client and contains these lines:

Code: [Select]
...
text:SetTextColor(Color(255, 255, 255))
text:SetDisabled(true)
text:SetMultiline(true)
text:SetVerticalScrollbarEnabled(true)
text:SetText(file.Read("textbox_contents.txt", "GAME"))

end)

The key here being the "SetText" line, this only reads the text in "textbox_contents.txt" if the client has that file. How can I make it read the server's custom text like in the !motd command?
« Last Edit: July 15, 2018, 06:23:34 PM by APNxRPG24 »

Offline JamminR

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 7906
  • Karma: 372
  • Sertafide Ulysses Jenius
    • Team Ulysses [ULib/ULX, other fine releases]
The cl/motdmenu.lua writes text to a local /data file on the client side.
You can't easily display client side text from a server file without writing to one first using client side lua.

There are other ways, but that is the least complicated and usually less resource intensive.

The price one pays for pursuing any profession or calling is an intimate knowledge of its ugly side. - James Baldwin

Offline APNxRPG24

  • Newbie
  • *
  • Posts: 8
  • Karma: 0
The cl/motdmenu.lua writes text to a local /data file on the client side.
You can't easily display client side text from a server file without writing to one first using client side lua.

There are other ways, but that is the least complicated and usually less resource intensive.

Wouldn't there also be sort of a "FastDL" method as well? By this I mean the client grabbing text from a web page.

Anyways, after extensive research I found my solution using "file.Write" in the clientside lua file. Thanks for the reply.

Offline JamminR

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 7906
  • Karma: 372
  • Sertafide Ulysses Jenius
    • Team Ulysses [ULib/ULX, other fine releases]
Wouldn't there also be sort of a "FastDL" method as well? By this I mean the client grabbing text from a web page.
I'm pretty sure due to security implications you can only display a web page, not grab text from a server.

EDIT -
Ok, I'm likely wrong, you maybe could grab a text file using http.Fetch, then file.Write it locally.
More advanced, could use https://wiki.garrysmod.com/page/Structures/HTTPRequest
« Last Edit: July 16, 2018, 03:55:56 PM by JamminR »
The price one pays for pursuing any profession or calling is an intimate knowledge of its ugly side. - James Baldwin