Ulysses
General => Developers Corner => Topic started by: Wully616 on April 29, 2013, 07:24:08 AM
-
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?
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
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 (http://www.wullysgamers.co.uk/loading_background/index.php?steamid=76561197989877834&mapname=gm_flatgrass_revolution)
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
Would the above function work? Or is there any easier way to do this?
-
First off, that number is not a regular steamid, but a 64-bit steamid. You'd use this function (http://wiki.garrysmod.com/page/Player/SteamID64) 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.
-
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?
[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
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
(http://gyazo.com/80aa710efd4679fc6ffac794eac3e122.png)
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.
-
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.
-
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.
-
Ah I see, thanks again for the info!
I think letting the player spawn, begin to move then stopping them with the MOTD a few seconds later might annoy them.
I tried this sort of delay (My lua isn't great but finding scripts online to do the job works too). The delay function didn't work when joining the server, only when the client executed !motd it froze their client for 10 seconds, then opened the MOTD, oops :-[ .
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
delay_s(10)
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 delay_s(delay)
delay = delay or 1
local time_to = os.time() + delay
while os.time() < time_to do end
end
Is it possible to check if the player is created, before calling the function? So it may not have the players SteamID when they initially join, but open opening it later the function would work?
I tried:
if LocalPlayer()~=nil then
steamid = LocalPlayer():SteamID64() //get the players steam ID
else
steamid = "NOID"
end
This still tried to call LocalPlayer():SteamID64() when the player joined the server. I'm lost now as to what I can do.
Otherwise, how could I get the server to inform the player their steamID?
-
Try "if IsValid( LocalPlayer() ) then"
-
I agree with Megiddo, I would also try putting the above in a timer with a delay of 1.5 (more or less) seconds, so that it can give the server a little bit more time to think.
-
Woohoo that did it!
Thank you very much gents and for being patient with my lack of knowledge.
(http://gyazo.com/f466adbda37fed201c3511a0736a42a8.png)
I also got it to grab other info with GetConVarString( "hostname" ); and GetConVarString( "ip" );
My hope is to make it detect which of my servers it is being loaded on, then loads the appropiete rules for that server :)
Thanks again for the help!
-
No problem, glad you were able to get it to work satisfactorily!
-
*sigh*
Oh how I miss the time I had for UMotd and Umotd revived.