ULX

Author Topic: Creating a force MOTD command, however I need some help.  (Read 2938 times)

0 Members and 2 Guests are viewing this topic.

Offline feldma

  • Newbie
  • *
  • Posts: 47
  • Karma: 5
  • 5696 hours in Gmod and counting!
    • Mega-Strike Network
Creating a force MOTD command, however I need some help.
« on: February 21, 2016, 04:49:11 PM »
I'm creating a "ForceMOTD" command, however I do not want players to be able to close it instantly.

I looked at the motdmenu.lua file (or whatever it's called), however I'm not sure if copying the file would work.

If I changed
Code: [Select]
local isUrl
local url

function ulx.showMotdMenu( steamid )
local window = vgui.Create( "DFrame" )
if ScrW() > 640 then -- Make it larger if we can.
window:SetSize( ScrW()*0.9, ScrH()*0.9 )
else
window:SetSize( 640, 480 )
end
window:Center()
window:SetTitle( "ULX MOTD" )
window:SetVisible( true )
window:MakePopup()

local html = vgui.Create( "DHTML", window )
--html:SetAllowLua( true ) -- Too much of a security risk for us to enable. Feel free to uncomment if you know what you're doing.

local button = vgui.Create( "DButton", window )
button:SetText( "Close" )
button.DoClick = function() window:Close() end
button:SetSize( 100, 40 )
button:SetPos( (window:GetWide() - button:GetWide()) / 2, window:GetTall() - button:GetTall() - 10 )

html:SetSize( window:GetWide() - 20, window:GetTall() - button:GetTall() - 50 )
html:SetPos( 10, 30 )
if not isUrl then
html:SetHTML( ULib.fileRead( "data/ulx_motd.txt" ) or "" )
else
url = string.gsub( url, "%%curmap%%", game.GetMap() )
url = string.gsub( url, "%%steamid%%", steamid )
html:OpenURL( url )
end
end
to
Code: [Select]
local isUrl
local url

function ulx.showMotdMenu( steamid )
local window = vgui.Create( "DFrame" )
if ScrW() > 640 then -- Make it larger if we can.
window:SetSize( ScrW()*0.9, ScrH()*0.9 )
else
window:SetSize( 640, 480 )
end
window:Center()
window:SetTitle( "ULX MOTD" )
window:SetVisible( true )
window:MakePopup()

local html = vgui.Create( "DHTML", window )
--html:SetAllowLua( true ) -- Too much of a security risk for us to enable. Feel free to uncomment if you know what you're doing.
       
        timer.Simple(60, function()
local button = vgui.Create( "DButton", window )
button:SetText( "Close" )
button.DoClick = function() window:Close() end
button:SetSize( 100, 40 )
button:SetPos( (window:GetWide() - button:GetWide()) / 2, window:GetTall() - button:GetTall() - 10 )
        end)

html:SetSize( window:GetWide() - 20, window:GetTall() - button:GetTall() - 50 )
html:SetPos( 10, 30 )
if not isUrl then
html:SetHTML( ULib.fileRead( "data/ulx_motd.txt" ) or "" )
else
url = string.gsub( url, "%%curmap%%", game.GetMap() )
url = string.gsub( url, "%%steamid%%", steamid )
html:OpenURL( url )
end
end

Would that work?
I'm not talking about the function name, just wondering if the motd would actually appear + would the timer on the close button work.

Thanks. I would test but at school.

EDIT: Just realised, even if I called this, it would open on the calling player. How would I make it open on the target_ply?
« Last Edit: February 21, 2016, 04:57:45 PM by feldma »
Solving 50% of people's questions by searching it up on google.

Trying to think of a cool idea to code, so I can inspire myself to code. If you want something done, please message me!

Offline Bytewave

  • Respected Community Member
  • Hero Member
  • *****
  • Posts: 718
  • Karma: 116
  • :)
    • My Homepage
Re: Creating a force MOTD command, however I need some help.
« Reply #1 on: February 21, 2016, 04:59:24 PM »
Couldn't you just...

Code: [Select]
RunConsoleCommand("ulx", "cexec", target_ply:Nick(), "ulx motd")?

Or, , bypass the command entirely and just use cexec?
bw81@ulysses-forums ~ % whoami
Homepage

Offline feldma

  • Newbie
  • *
  • Posts: 47
  • Karma: 5
  • 5696 hours in Gmod and counting!
    • Mega-Strike Network
Re: Creating a force MOTD command, however I need some help.
« Reply #2 on: February 21, 2016, 05:00:30 PM »
Couldn't you just...

Code: [Select]
RunConsoleCommand("ulx", "cexec", target_ply:Nick(), "ulx motd")?

Or, <censor>, bypass the command entirely and just use cexec?

Yes, we have been using cexec, but I need a command that forces the MOTD and makes the player unable to close it for a minute.
Solving 50% of people's questions by searching it up on google.

Trying to think of a cool idea to code, so I can inspire myself to code. If you want something done, please message me!

Offline Bytewave

  • Respected Community Member
  • Hero Member
  • *****
  • Posts: 718
  • Karma: 116
  • :)
    • My Homepage
Re: Creating a force MOTD command, however I need some help.
« Reply #3 on: February 21, 2016, 05:03:26 PM »
Yes, we have been using cexec, but I need a command that forces the MOTD and makes the player unable to close it for a minute.
Ah, I'm sorry, didn't see that part.
Still, though. There's a hack for making it not closable for a few seconds on one of these threads here. Why not just make that the default? Continue using cexec and save yourself the trouble?
bw81@ulysses-forums ~ % whoami
Homepage

Offline JamminR

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 8096
  • Karma: 390
  • Sertafide Ulysses Jenius
    • Team Ulysses [ULib/ULX, other fine releases]
Re: Creating a force MOTD command, however I need some help.
« Reply #4 on: February 21, 2016, 06:00:37 PM »
Search this developers corner section of the forum for 'motd', or 'motd close'
I'm sure there has been discussion of someone wanting this before.
"Though a program be but three lines long, someday it will have to be maintained." -- The Tao of Programming

Offline feldma

  • Newbie
  • *
  • Posts: 47
  • Karma: 5
  • 5696 hours in Gmod and counting!
    • Mega-Strike Network
Re: Creating a force MOTD command, however I need some help.
« Reply #5 on: February 21, 2016, 07:55:01 PM »
Yes, I saw those threads.

The problem is I don't want the default one to be timed.
Solving 50% of people's questions by searching it up on google.

Trying to think of a cool idea to code, so I can inspire myself to code. If you want something done, please message me!

Offline JamminR

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 8096
  • Karma: 390
  • Sertafide Ulysses Jenius
    • Team Ulysses [ULib/ULX, other fine releases]
Re: Creating a force MOTD command, however I need some help.
« Reply #6 on: February 21, 2016, 08:30:30 PM »
The problem is I don't want the default one to be timed.
I'm not saying edit the default one.
I'm saying use one of the others as example of how to do it.
Read one of the other ones, rename the command object and any vars that would conflict, and then add the timer as shown in examples.
"Though a program be but three lines long, someday it will have to be maintained." -- The Tao of Programming

Offline feldma

  • Newbie
  • *
  • Posts: 47
  • Karma: 5
  • 5696 hours in Gmod and counting!
    • Mega-Strike Network
Re: Creating a force MOTD command, however I need some help.
« Reply #7 on: February 21, 2016, 11:09:35 PM »
Hmm, I'll give that a try.

Thanks for helping.
Solving 50% of people's questions by searching it up on google.

Trying to think of a cool idea to code, so I can inspire myself to code. If you want something done, please message me!