OpenUrl Server steam group on player spawn

I need lua help with a script,
on player spawn on my server open my steam group url, and if player already joined on group don’t open

THANKS :stuck_out_tongue:

Can you show your code so far?


function gui.OpenURL(url, bool)
	local DFrame = vgui.Create("DFrame")
	DFrame:SetPos(0, 0)
	DFrame:SetSize(ScrW(), ScrH())
	DFrame:SetTitle(url)
	DFrame:SetSizable(false)
	DFrame:SetDraggable(false)
	DFrame:SetMouseInputEnabled(true)
	DFrame:SetKeyBoardInputEnabled(true)
	DFrame:MakePopup()
	DFrame.btnMaxim.Paint = function() end
	DFrame.btnMinim.Paint = function() end
	
	if !bool then
		DFrame.btnClose:MoveToFront()
	else
		DFrame.btnClose.Paint = function() end
	end
	
	local DHTML = vgui.Create("DHTML", DFrame)
	DHTML:SetPos(0, 25)
	DHTML:SetSize(DFrame:GetWide(), DFrame:GetTall() - 25)
	DHTML.ConsoleMessage = function() end
	DHTML:OpenURL(tostring(url))
end

hook.Add("PlayerConnect", "SteamGroup", function()
	if !SteamGroup then
		gui.OpenURL("https://steamcommunity.com/groups/HavocGamers", false)
		SteamGroup = true
	end
end)



local plyMeta = FindMetaTable("Player");

function plyMeta:InGroup(group)
	assert(isstring(group), ("bad argument #%i (string expected, got %s)"):format(1, type(group)));
	
	local inGroup;
	
	http.Fetch("https://control.pococraft.org/inDevelWorkingDir/xmltojson.php?xml=http://steamcommunity.com/groups/" .. group .. "/memberslistxml/?xml=1",
		function(body)
			local tbl = util.JSONToTable(body);
			if !(tbl) then return; end
			local steamid = tbl.memberList.members.steamID64;
			
			for i, id in ipairs(steamid) do
				if (id == self:SteamID64()) then
					inGroup = true;
					break;
				end
			end
		end,
		
		function()
		end
	);
	
	return inGroup;
end

if (LocalPlayer():InGroup("Valve")) then
	chat.AddText("You're in the Valve group!");
end


Credits to pococraft for the xml to json parser. Haven’t checked the URL to see if it still works but this code use to work well for me.

Thanks everbody :slight_smile:

[editline]1st February 2017[/editline]

i will test

[editline]1st February 2017[/editline]

I will try a more simple code,
i need just run this code on player spawn on server



SendLua([[gui.OpenURL("http://steamcommunity.com/sharedfiles/filedetails/?id=853157947")]])


Run it in an autorun clientside file. You should do it clientside instead of using ply:SendLua when they spawn.

FOUND
my first script :smiley: i so happy

i make a .lua file in
server\gmodds\garrysmod\lua\autorun



local function spawn( ply )
	ply:SendLua([[gui.OpenURL("http://steamcommunity.com/groups/pyth0nn/discussions/0/135507855751347359/")]])
end
hook.Add( "PlayerSpawn", "SendLua", spawn )


You don’t need to use ply:SendLua, you could just do ‘gui.OpenURL("…")’.

PlayerSpawn is a server side hook, see here next time:

GM:PlayerSpawn

Well obviously he could just call the gui.OpenURL directly instead of having it in a function inside a hook.