• Print

Author Topic: Trying (and failing) to add motd-like donation menu.  (Read 6976 times)

0 Members and 1 Guest are viewing this topic.

Offline RalphORama

  • Newbie
  • *
  • Posts: 17
  • Karma: 0
Trying (and failing) to add motd-like donation menu.
« on: February 06, 2014, 08:37:41 pm »
Brief explanation everything because I'm hella tired:
I want players to be able to type '!donate' in chat and be rewarded with a popup window like that of the standard MOTD, but instead directed towards the donation page.

Here's what I have (patched together from multiple threads):
Code: Lua
  1. -- in addons/ulx/lua/ulx/modules/sh/donate.lua
  2. CATEGORY_NAME = "Community Links"
  3.  
  4. --donate menu
  5. function ulx.donate( ply )
  6.         local isUrl             --everything from here to 'end' is pretty much ripped straight from motdmenu.lua
  7.         local url
  8.         local window = vgui.Create( "DFrame" )
  9.        
  10.         if ScrW() > 640 then -- Make it larger if we can.
  11.                 window:SetSize( ScrW()*0.9, ScrH()*0.9 )
  12.         else
  13.                 window:SetSize( 640, 480 )
  14.         end
  15.         window:Center()
  16.         window:SetTitle( "Donate to the Server!" )
  17.         window:SetVisible( true )
  18.         window:SetDraggable( false )
  19.         window:ShowCloseButton( false )
  20.         window:MakePopup()
  21.  
  22.         local html = vgui.Create( "HTML", window )
  23.  
  24.         local button = vgui.Create( "DButton", window )
  25.         button:SetText( "Close" )
  26.         button.DoClick = function() window:Close() end
  27.         button:SetSize( 100, 40 )
  28.         button:SetPos( (window:GetWide() - button:GetWide()) / 2, window:GetTall() - button:GetTall() - 10 )
  29.  
  30.         html:SetSize( window:GetWide() - 20, window:GetTall() - button:GetTall() - 50 )
  31.         html:SetPos( 10, 30 )
  32.         html:OpenURL( "https://sq10.net/don8/" )        -- the url for the window to open
  33. end
  34.  
  35. local donate = ulx.command( CATEGORY_NAME, "ulx donate", ulx.donate, "!donate" )                --add the command
  36. donate:defaultAccess( ULib.ACCESS_ALL )
  37. donate:help( "Donate $10 for VIP commands and access to pointshop!" )

When I join my server and type '!donate' in chat or 'ulx donate' in console, I get no error about missing a command (like I would if I typed 'ulx asdaf' in console), but no window appears and fills me with glee. How do I fix this?

Offline Neku

  • Hero Member
  • *****
  • Posts: 549
  • Karma: 27
Re: Trying (and failing) to add motd-like donation menu.
« Reply #1 on: February 06, 2014, 09:07:41 pm »
Hm, are you sure it's actually creating the window?

I've never edited anything major in this part of ulx, so I can only be of small help.
Out of the Garry's Mod business.

Offline RalphORama

  • Newbie
  • *
  • Posts: 17
  • Karma: 0
Re: Trying (and failing) to add motd-like donation menu.
« Reply #2 on: February 07, 2014, 04:40:59 am »
Hm, are you sure it's actually creating the window?

I've never edited anything major in this part of ulx, so I can only be of small help.

One thought I had whilst trying to debug this was that since this is in modules/sh instead of modules/cl (where motdmenu.lua is), there might be something going wonky when it tries to create the DFrame, etc. Not sure how to fix this though, maybe add another script with the function in it, drop that in modules/cl, and have this script execute it?
I'll try that.

Edit: new code:
Code: Lua
  1. function ulx.donate( ply )
  2.         ply:SendLua([[
  3.                 local isUrl             --everything from here to 'end' is pretty much ripped straight from motdmenu.lua
  4.                 local url
  5.                 local window = vgui.Create( "DFrame" )
  6.          
  7.                 if ScrW() > 640 then -- Make it larger if we can.
  8.                         window:SetSize( ScrW()*0.9, ScrH()*0.9 )
  9.                 else
  10.                         window:SetSize( 640, 480 )
  11.                 end
  12.                 window:Center()
  13.                 window:SetTitle( "Donate to the Server!" )
  14.                 window:SetVisible( true )
  15.                 window:SetDraggable( false )
  16.                 window:ShowCloseButton( false )
  17.                 window:MakePopup()
  18.          
  19.                 local html = vgui.Create( "HTML", window )
  20.          
  21.                 local button = vgui.Create( "DButton", window )
  22.                 button:SetText( "Close" )
  23.                 button.DoClick = function() window:Close() end
  24.                 button:SetSize( 100, 40 )
  25.                 button:SetPos( (window:GetWide() - button:GetWide()) / 2, window:GetTall() - button:GetTall() - 10 )
  26.          
  27.                 html:SetSize( window:GetWide() - 20, window:GetTall() - button:GetTall() - 50 )
  28.                 html:SetPos( 10, 30 )
  29.                 html:OpenURL( "https://sq10.net/don8/" )
  30.         ]])
  31. end
  32. local donate = ulx.command( CATEGORY_NAME, "ulx donate", ulx.donate, "!donate" )
  33. donate:defaultAccess( ULib.ACCESS_ALL )
  34. donate:help( "Donate $10 for VIP commands and access to pointshop!" )

It gives me this error (through the server console, not locally) when I type '!donate' in chat:
DLL_MessageEnd:  Refusing to send user message LuaCmd of 256 bytes to client, user message size limit is 255 bytes


The actual filesize is 1,252 bytes, according to filezilla.
« Last Edit: February 07, 2014, 04:52:44 am by RalphORama »

Offline Bytewave

  • Respected Community Member
  • Hero Member
  • *****
  • Posts: 718
  • Karma: 116
  • :)
    • My Homepage
Re: Trying (and failing) to add motd-like donation menu.
« Reply #3 on: February 07, 2014, 05:19:48 am »
Code: Lua
  1. -- in addons/ulx/lua/ulx/modules/sh/donate.lua
  2. CATEGORY_NAME = "Community Links"
  3.  
  4. --donate menu
  5. function ulx.donate( ply )
  6.         if CLIENT then
  7.         local isUrl             --everything from here to 'end' is pretty much ripped straight from motdmenu.lua
  8.         local url
  9.         local window = vgui.Create( "DFrame" )
  10.  
  11.         if ScrW() > 640 then -- Make it larger if we can.
  12.                 window:SetSize( ScrW()*0.9, ScrH()*0.9 )
  13.         else
  14.                 window:SetSize( 640, 480 )
  15.         end
  16.         window:Center()
  17.         window:SetTitle( "Donate to the Server!" )
  18.         window:SetVisible( true )
  19.         window:SetDraggable( false )
  20.         window:ShowCloseButton( false )
  21.         window:MakePopup()
  22.  
  23.         local html = vgui.Create( "HTML", window )
  24.  
  25.         local button = vgui.Create( "DButton", window )
  26.         button:SetText( "Close" )
  27.         button.DoClick = function() window:Close() end
  28.         button:SetSize( 100, 40 )
  29.         button:SetPos( (window:GetWide() - button:GetWide()) / 2, window:GetTall() - button:GetTall() - 10 )
  30.  
  31.         html:SetSize( window:GetWide() - 20, window:GetTall() - button:GetTall() - 50 )
  32.         html:SetPos( 10, 30 )
  33.         html:OpenURL( "https://sq10.net/don8/" )        -- the url for the window to open
  34.         elseif SERVER then
  35.              AddCSLuaFile( "lua/ulx/modules/sh/donate.lua" )
  36.         else
  37.              error( "i be in ur codez, messin' dem upz" )
  38.         end
  39. end
  40.  
  41. local donate = ulx.command( CATEGORY_NAME, "ulx donate", ulx.donate, "!donate" )                --add the command
  42. donate:defaultAccess( ULib.ACCESS_ALL )
  43. donate:help( "Donate $10 for VIP commands and access to pointshop!" )
Try that out for size..?
bw81@ulysses-forums ~ % whoami
Homepage

Offline RalphORama

  • Newbie
  • *
  • Posts: 17
  • Karma: 0
Re: Trying (and failing) to add motd-like donation menu.
« Reply #4 on: February 07, 2014, 05:59:44 am »
Try that out for size..?

Nope, same thing as earlier. No window, but no errors either.

Offline Cobalt

  • Full Member
  • ***
  • Posts: 216
  • Karma: 44
  • http://steamcommunity.com/id/__yvl/
Re: Trying (and failing) to add motd-like donation menu.
« Reply #5 on: February 07, 2014, 09:12:50 am »
You can't use all of those functions in shared like that. Use umsg to call a function on the client side that creates the menu.

  • Print