General > Developers Corner

Passing Player Data to MOTD

(1/3) > >>

Wully616:
Hello,

Is there any way to pass player or server  data from the MOTD to the URL which it loads, much in the same way the sv_loadingurl can grab the players steamID and the map name?


--- Code: ---If you run sv_loadingurl "http://mywebsite.com/loadingpage.php?steamid=%s&mapname=%m" then the following $_GET values are available to PHP.

    $_GET["steamid"] is the player's steam community id.
    $_GET["mapname"] is the current map name. EX: gm_construct

--- End code ---

My lua is more or less non existent so please forgive me, now that uni's nearly over I'm hoping to learn though.

I've looked through the documentation for ulib/ulx and the gmod wiki, I've seen like the getUser, game.GetMap() ply:SteamID() functions and stuff but in all honestly I'm not 100% what I'm looking for.
I need a function to grab the players steamID  when they execute the command "ulx motd", save it to a variable so it may be appended to the motd URL.
Which PHP should be able to grab and I can do whatever with as I've done for my loading screen.

http://www.wullysgamers.co.uk/loading_background/index.php?steamid=76561197989877834&mapname=gm_flatgrass_revolution




--- Code: ---function ulx.showMotdMenu()
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( "HTML", window )

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" ) )
else
local mapname = game.GetMap() //Get the map name
local steamid = ply:SteamID() //get the players steam ID
html:OpenURL( url.."?steamid="..steamid.."&mapname="..mapname) //append data onto URL for php to grab
end
end
--- End code ---

Would the above function work? Or is there any easier way to do this?

Megiddo:
First off, that number is not a regular steamid, but a 64-bit steamid. You'd use this function to get that. Also there is no "ply" object in the code to grab the ID from. So you should be using "LocalPlayer():SteamID64()". Other than that it looks like it should work.

Wully616:
Thanks Megiddo!
One problem I'm having with it now though is that it doesn't get the localPlayers steamID64 when first joining the server and the motd opens. I would guess this is because it isn't the player thats technically executing the command?


--- Code: ---[ERROR] addons/ulx/lua/ulx/modules/cl/motdmenu.lua:32: attempt to call method 'SteamID64' (a nil value)
  1. fn - addons/ulx/lua/ulx/modules/cl/motdmenu.lua:32
   2. func - addons/ulib/lua/ulib/client/cl_util.lua:22
    3. unknown - lua/includes/modules/net.lua:31

--- End code ---


--- Code: ---ulx.motdmenu_exists = true

local isUrl
local url

function ulx.showMotdMenu()
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( "HTML", window )

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" ) )
else
local mapname = game.GetMap() //Get the map name
local steamid = LocalPlayer():SteamID64() //get the players steam ID
html:OpenURL( url.."?steamid="..steamid.."&mapname="..mapname) //append data onto URL for php to grab
end
end

function ulx.rcvMotd( isUrl_, text )
isUrl = isUrl_
if not isUrl then
file.Write( "ulx_motd.txt", text )
else
if text:find( "://", 1, true ) then
url = text
else
url = "http://" .. text
end
end
end

--- End code ---



Other than that, once the player types !motd in chat or ulx motd it opens and passes the steamID64 over perfectly.
I can change the steam64ID into the nicer looking one with a script that's no problem.

Megiddo:
Okay, so it's calling the function before the player is created, probably. To fix that you'd need to wait to bring up the MOTD until the player is created, but that's not a simple modification. Another (less robust) idea would be bringing the MOTD up ten seconds after a player joins.

Megiddo:
Another idea is having the server inform the player what their steamid is. It seems silly to need to do that, but it would work.

Navigation

[0] Message Index

[#] Next page

Go to full version