Author Topic: [BROKEN] UMotd Revived - Motd and OTHER informational screens.  (Read 61563 times)

0 Members and 1 Guest are viewing this topic.

Reiko

  • Guest
Re: UMotd Revived - Motd and OTHER informational screens.
« Reply #75 on: September 29, 2008, 08:03:12 PM »
That's great! I'll have a fiddle around with it myself then.

Thanks for the hint!

Offline Reiko

  • Newbie
  • *
  • Posts: 12
  • Karma: 2
  • Wheee!
    • VorixNet
Re: UMotd Revived - Motd and OTHER informational screens.
« Reply #76 on: September 29, 2008, 08:54:24 PM »
Sorry for the double post. I decided to grab myself an account since I modify guest posts.

I've changed a bit of "Umotd_client.lua" to;
Code: [Select]
if UMotd.command == "radio" then
Ubutton:SetText( "Hide" )
Ubutton.DoClick = function() Uwindow:SetVisible( false ) end
else
Ubutton:SetText( "Close" )
Ubutton.DoClick = function() Uwindow:Close() end
end

Which works a dream, which in itself is amazing because I know no LUA. However, I've come across another problem. Although this works well now, you can open up multiple radio windows at once because the old window just stays hidden, I was wondering if someone could tell me if there is any way to have the previous radio window close upon a new radio window opening? And if not, if there was a way to just make every window (hidden or not) close whenever a new window is opened so that there can only ever be one window open at once.

Thanks for all the help!
« Last Edit: September 29, 2008, 08:56:15 PM by Reiko »
So there! D=<

Offline JamminR

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 8096
  • Karma: 390
  • Sertafide Ulysses Jenius
    • Team Ulysses [ULib/ULX, other fine releases]
Re: UMotd Revived - Motd and OTHER informational screens.
« Reply #77 on: September 29, 2008, 10:14:55 PM »
My guess, untested...
At the very top of the function before Uwindow gets set, check if it is nil and command = radio.
If it isn't nil and command = radio, Uwindow:Close() (Radio was shown already, close it)
If it is nil, do nothing. (Radio wasn't shown, this is first time)
Uwindow should stay the same in memory, and be able to be closed later before being reset in the function.
"Though a program be but three lines long, someday it will have to be maintained." -- The Tao of Programming

Offline Reiko

  • Newbie
  • *
  • Posts: 12
  • Karma: 2
  • Wheee!
    • VorixNet
Re: UMotd Revived - Motd and OTHER informational screens.
« Reply #78 on: September 30, 2008, 02:36:12 AM »
I currently have it set up like this;

Code: [Select]
function UMotd.showUMotd()

        if Uwindow != nil then
                Uwindow:Close()
        end

local Uwindow = vgui.Create( "DFrame" )
if ScrW() > 640 then -- Make it larger if we can.
Uwindow:SetSize( ScrW()*0.9, ScrH()*0.9 )
else
Uwindow:SetSize( 640, 480 )
end
Uwindow:Center()
Uwindow:SetTitle( "UMotd v" .. UMotd.version .." - Viewing the " .. UMotd.command .. " screen." )
Uwindow:SetVisible( true )
Uwindow:MakePopup()

        etc...

I've also tried every variation of the;
Code: [Select]
if Uwindow != nil then
        Uwindow:Close()
        end
That I can think of and sometimes I would get this error;
Quote
Couldn't include file 'Umotd/umotd_client.lua' (File not found)
So basiclly the server refused to send it, and every other time there were no errors, but nothing happened.
It behaved exactly as I described before.

Any ideas?

So there! D=<

Offline JamminR

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 8096
  • Karma: 390
  • Sertafide Ulysses Jenius
    • Team Ulysses [ULib/ULX, other fine releases]
Re: UMotd Revived - Motd and OTHER informational screens.
« Reply #79 on: September 30, 2008, 03:06:14 PM »
Try removing 'local' from in front of the Uwindow = vgui... line.
I forgot about that.
Up near the top of the client file,
Code: [Select]
local HTML = { }
local UMotd = { }
Add "local Uwindow"
(Lua lesson for you, 'local' inside a function makes the variable local to the function only)

I'm thinking that may cause other issues, but we'll go from there.
"Though a program be but three lines long, someday it will have to be maintained." -- The Tao of Programming

Offline Reiko

  • Newbie
  • *
  • Posts: 12
  • Karma: 2
  • Wheee!
    • VorixNet
Re: UMotd Revived - Motd and OTHER informational screens.
« Reply #80 on: September 30, 2008, 08:56:10 PM »
Sorry about posting this unfinished. I accidentilly hit tab, then space and the form submitted. Editing it now.
Code: [Select]
local HTML = { }
local UMotd = { }
local UWindow = { }

--local UMotd_sc
local UMotd_sstart

for k, v in ipairs ( UMotd_sounds ) do
    util.PrecacheSound( v )
    UMotd_sc = k
end

function HTML:StatusChanged( text )
end

function HTML:ProgressChanged( progress )
end

function HTML:FinishedURL( url )
end

function HTML:OpeningURL( url, target )
end

vgui.Register( "UMotd", HTML, "HTML" )

function UMotd.showUMotd()

if Uwindow != nil then
Uwindow:Close()
end

Uwindow = vgui.Create( "DFrame" )
if ScrW() > 640 then -- Make it larger if we can.
Uwindow:SetSize( ScrW()*0.9, ScrH()*0.9 )
else
Uwindow:SetSize( 640, 480 )
end
Uwindow:Center()
Uwindow:SetTitle( "UMotd v" .. UMotd.version .." - Viewing the " .. UMotd.command .. " screen." )
Uwindow:SetVisible( true )
Uwindow:MakePopup()
       
Right, this is a lot closer. Now; the first time you open up a radio (hiding) window the window opens up fine, then the next time, the old one closes first. However, upon using the "X" button at the top of the window or using a different window such as !motd and closing we get an error;
Quote
Umotd/umotd_client.lua:56: attempt to call method 'Close' (a nil value)
Which I thought the if was suppost to take of. Any ideas?

Thanks again for all the help
« Last Edit: September 30, 2008, 09:00:14 PM by Reiko »
So there! D=<

Offline JamminR

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 8096
  • Karma: 390
  • Sertafide Ulysses Jenius
    • Team Ulysses [ULib/ULX, other fine releases]
Re: UMotd Revived - Motd and OTHER informational screens.
« Reply #81 on: October 01, 2008, 12:06:24 PM »
Lua is case sensitive. And you've tried to convert Uwindow to a table.
At the top, you have
Code: [Select]
local HTML = { }
local UMotd = { }
local UWindow = { }
Change that to
Code: [Select]
local HTML = { }
local UMotd = { }
local Uwindow
I simply changed W to w. And I changed it from the assignment you were doing that declared a table to just a local variable.
"Though a program be but three lines long, someday it will have to be maintained." -- The Tao of Programming

Offline Reiko

  • Newbie
  • *
  • Posts: 12
  • Karma: 2
  • Wheee!
    • VorixNet
Re: UMotd Revived - Motd and OTHER informational screens.
« Reply #82 on: October 01, 2008, 08:00:19 PM »
Code: [Select]
MsgN( Uwindow )
if Uwindow != nil then
Uwindow:Close()
end

Uwindow = vgui.Create( "DFrame" )
MsgN( Uwindow )
if ScrW() > 640 then -- Make it larger if we can.
Uwindow:SetSize( ScrW()*0.9, ScrH()*0.9 )
else
Uwindow:SetSize( 640, 480 )
end
Uwindow:Center()
Uwindow:SetTitle( "UMotd v" .. UMotd.version .." - Viewing the " .. UMotd.command .. " screen." )
Uwindow:SetVisible( true )
Uwindow:MakePopup()

local html = vgui.Create( "UMotd", Uwindow )

local Ubutton = vgui.Create( "DButton", Uwindow )

if UMotd.command:lower() == "radio" then
Ubutton:SetText( "Hide" )
Ubutton.DoClick = function() Uwindow:SetVisible( false ) end
else
Ubutton:SetText( "Close" )
Ubutton.DoClick = function() Uwindow:Close() Uwindow = nil MsgN( Uwindow ) end
end
This helped a lot, didn't realize I was making it a table however, using MsgN as debug I found that even after the panel is closed, the variable keep's it... ID (or whatever that code was) so to get around that, after I noticed that the button was in a function, I added in that once the close button had been pushed, it set Uwindow to nil. Now it works perfectly UNLESS you press the "X" button up in the corner. Is there any way to register when that has been pressed or just when the panel has been closed in general?
So there! D=<

Offline JamminR

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 8096
  • Karma: 390
  • Sertafide Ulysses Jenius
    • Team Ulysses [ULib/ULX, other fine releases]
Re: UMotd Revived - Motd and OTHER informational screens.
« Reply #83 on: October 01, 2008, 08:33:39 PM »
I found that even after the panel is closed, the variable keep's it... ID
<clip>
 Is there any way to register when that has been pressed or just when the panel has been closed in general?
Ah, sorry about that. I forgot to tell you to account for the fact that Uwindow wasn't local to the function anymore, just the script.
When it's local to a function, it gets set back to nil after the function is over. When we removed it from the function and declared it local to the script, we have to manipulate it ourselves. Though we didn't want it to be nil at the beginning if the radio was playing, we do want it to go nil if the radio is stopped.
Glad to see you learned how to account and fix it yourself now though.
Wow, you seem to be learning quite nicely.

As for the X button, yes, there's a way to detect it. Unfortunately, I cant' find it on the Gmod wiki at the moment.
You know about the Gmod Lua wiki, right? Lots of insight to GLua can be found there to tinker with for various projects and ideas.
Several tutorals too.
Anyway, I found this that could be used to now show the X. Perhaps that would work for you.

[Edit] Oh, that 'id' as you call it by the way is I believe a memory address where the object is stored. One of my fellow team mates can correct me on this, or elaborate if I'm close. It's not a string variable, so it doesn't get printed as a 'readable' string.
« Last Edit: October 01, 2008, 08:38:33 PM by JamminR »
"Though a program be but three lines long, someday it will have to be maintained." -- The Tao of Programming

Offline Reiko

  • Newbie
  • *
  • Posts: 12
  • Karma: 2
  • Wheee!
    • VorixNet
Re: UMotd Revived - Motd and OTHER informational screens.
« Reply #84 on: October 01, 2008, 08:43:37 PM »
Anyway, I found this that could be used to now show the X. Perhaps that would work for you.
That's perfect! It's now fool proof.

[Edit] Oh, that 'id' as you call it by the way is I believe a memory address where the object is stored. One of my fellow team mates can correct me on this, or elaborate if I'm close. It's not a string variable, so it doesn't get printed as a 'readable' string.
That makes sense.

Great! It's working perfectly now. Thanks so much for all your help!
So there! D=<

Offline JamminR

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 8096
  • Karma: 390
  • Sertafide Ulysses Jenius
    • Team Ulysses [ULib/ULX, other fine releases]
Re: UMotd Revived - Motd and OTHER informational screens.
« Reply #85 on: October 01, 2008, 08:59:43 PM »
Great! It's working perfectly now. Thanks so much for all your help!

And thank you for the inspiration and practice.
It's been months since I've done any hobby coding I could enjoy.
Now that we've helped each other debug, I'll know what not to do when I incorporate streaming radio into UMotd.

If you ever have ideas or projects you need help with now that you've dabbled in Lua, please feel free to visit our Developer's corner forum.
I personally don't always know the direct answer, but I like learning from our community and my team.

"Though a program be but three lines long, someday it will have to be maintained." -- The Tao of Programming

Offline Frostyfrog

  • Newbie
  • *
  • Posts: 7
  • Karma: 0
Re: UMotd Revived - Motd and OTHER informational screens.
« Reply #86 on: October 07, 2008, 05:23:29 PM »
The MOTD on player spawn thing won't work :(
I think somewhere here is the problem:
Code: [Select]
function Umotd_help(ply, cmd, argv, args)
         ULib.console(ply, "[Umotd] - The following are available; help(this context), " .. string.Implode( ", ", Ucmds ) )
end
--ULib.concommand( "Umotd", Umotd_help )
ULib.begin_subconcommand( "Umotd", Umotd_help, nil, ULib.ACCESS_ALL  )

  Umotd_content = { }
  for Umotd_cmd, Ufile in pairs( Umotd_command_files ) do
      Umotd_content[Umotd_cmd] = { }
      Umotd_content[Umotd_cmd].cmd_name = Umotd_cmd

      if Ufile:lower():find("http:", 1, true) then
         Umotd_content[Umotd_cmd].path = Ufile -- It's a URL!
      else
         Umotd_content[Umotd_cmd].path = Umotd_LoadDir .. Ufile
      end

      if string.lower( Umotd_cmd ) == "motd" then
        if not Umotd_content[Umotd_cmd].path:lower():find("http:", 1, true) then

           local motdpath = "../" .. GetConVarString( "motdfile" )
           if file.Exists( motdpath )
           and not file.Read( motdpath ):find( "Welcome to Team Fortress 2", 1, true ) then
               Umotd_content[Umotd_cmd] = { path = motdpath } --Use motdfile variable if it exists, otherwise use config.
           end
        end
      end

      if file.Exists( Umotd_content[Umotd_cmd].path ) or Umotd_content[Umotd_cmd].path:lower():find("http:", 1, true) then
         Umotd_funcname = Umotd_cmd
         table.insert( Ucmds, Umotd_cmd )

         function Umotd_funcname(ply)
                 if not ply:IsValid() then
                    ULib.console(ply, "[Umotd] - You can't see the "..Umotd_cmd.." from the console.\n" )
                    return
                 end
                  UshowMotd( ply, Umotd_cmd, Umotd_content[Umotd_cmd].path )
         end
         Umotd_content[Umotd_cmd].func = Umotd_funcname
--print("Created ".. Umotd_cmd .." and passing ".. Umotd_content[Umotd_cmd].path )

         ULib.add_subconcommand( "Umotd", Umotd_cmd, Umotd_funcname, ULib.ACCESS_ALL )
         ULib.addSayCommand( Uchat_prefix .. Umotd_cmd, Umotd_funcname, "Umotd " .. Umotd_cmd )

      else
         Msg("[Umotd] Error - I can't create function \"" .. Umotd_cmd .. "\", file\URL " .. Umotd_content.Umotd_cmd.path .. " couldn't be found/understood.\n" )
         Msg("[Umotd] Error - Function \"" .. Umotd_cmd.. "\" not created\n" )
         --       Don't create functions.
      end
  end

  function UShow_motd(ply)
           if util.tobool( GetConVarString( "ulx_showMotd" ) ) then -- If ULX is loaded, attempt to disable its motd.
              game.ConsoleCommand( "ulx showMotd 0\n" )
           end
           ply:ConCommand("Umotd "..Umotd_SpawnCommand .."\n")
  end

local function Umotdinit()
                 if util.tobool(Umotd_ShowatPlayerSpawn) then
                    hook.Add( "PlayerInitialSpawn", "Umotd_Spawner", UShow_motd)
                 end
                 Umotd_map_starttime = os.time()
        end
hook.Add( "Initialize", "UmotdInitialize", Umotdinit )

--[[ ToDo
--table.HasValue - look it up ]]--

end -- UmotdLoaded
end -- Server

My configuration file:
Code: [Select]
Umotd_LoadDir = "Umotd/"
Uchat_prefix = "!"
Umotd_SpawnCommand = "listaddons"
Umotd_ShowatPlayerSpawn = "true"
Umotd_command_files = {
                    ["motd"] = "motd_template.txt",
                    ["rules"] = "rules.txt",
                    ["helpme"] = "help.txt",
                    ["serverinfo"] = "info_template.txt",
                    ["ulysses"] = "http://www.ulyssesmod.net/",
["donations"] = "donations.txt",
["listaddons"] = "addons.txt",
["website"] = "http://www.pawspubserver.co.uk/",
                      }
Umotd_dynvar = true
Umotd_AddOnSep1 = ", <br>" -- this sets what to use as separator if you use %addon_long%
Umotd_AddOnSep2 = ", " -- this sets what to use as separator if you use %addon_short%

Offline JamminR

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 8096
  • Karma: 390
  • Sertafide Ulysses Jenius
    • Team Ulysses [ULib/ULX, other fine releases]
Re: UMotd Revived - Motd and OTHER informational screens.
« Reply #87 on: October 07, 2008, 05:35:06 PM »
Any errors at server startup? Any errors when you join your server? When other people join your server?
"Though a program be but three lines long, someday it will have to be maintained." -- The Tao of Programming

Offline Frostyfrog

  • Newbie
  • *
  • Posts: 7
  • Karma: 0
Re: UMotd Revived - Motd and OTHER informational screens.
« Reply #88 on: October 10, 2008, 08:39:03 PM »
nope, no errors. then again, not really my server. I'm just the Lua guy for it. When I have this, it works: Umotd_ShowatPlayerSpawn = "false"
I shows the default (which isn't what we want)...

Offline angrykid

  • Newbie
  • *
  • Posts: 18
  • Karma: 0
Re: UMotd Revived - Motd and OTHER informational screens.
« Reply #89 on: October 12, 2008, 01:05:43 AM »
nope, no errors. then again, not really my server. I'm just the Lua guy for it. When I have this, it works: Umotd_ShowatPlayerSpawn = "false"
I shows the default (which isn't what we want)...

It's not showing up for me either. I don't really care, though, since nobody ever visits my server. :P


Oh, non-inline CSS works now! Kickass!
Now all I need for it to do is not lag so badly when trying to make a post on my forums... :P
« Last Edit: October 12, 2008, 01:11:53 AM by angrykid »