• [Lua] Send link
    7 replies, posted
So today I was bored and tried to make a menu for a server I play on. you open the menu with a console command as of right now and it opens up a menu with a checkbox list of every play on the server. check the boxes for the people you want to send it to. here is where I am stuck. I want it to say who sent it. and what the url is from. then have them type -accept to open it. to protect people against spam and such. (even though its used by admins only) here is the code. [code] if(SERVER)then util.AddNetworkString( "browserlist" ) end function Playerpicker( ply, cmd, link ) if(CLIENT)then local Frame = vgui.Create( "DFrame" ) Frame:SetTitle( "Link sender" ) Frame:SetSize( 420, 470 ) Frame:Center() Frame:MakePopup() Frame.Paint = function( self, w, h ) draw.RoundedBox( 0, 0, 0, w, h, Color( 192, 68, 45, 220 ) ) end local Bg = vgui.Create( "DPanel", Frame ) Bg:SetSize( 410, 440 ) Bg:Center() Bg:SetPos( 5, 25 ) Bg.Paint = function( self, w, h ) draw.RoundedBox( 0, 0, 0, w, h, Color( 48, 48, 48, 150 ) ) end local Text = vgui.Create( "DTextEntry", Bg ) Text:SetPos( 25, 10 ) Text:SetSize( 290, 25 ) Text.OnChange = function( self ) local urltext = "" urltext = Text:GetText() if(string.StartWith( Text:GetText(), "http://" ))then urltext = string.sub( Text:GetText(), 8 ) Text:SetText( urltext ) end if(string.StartWith( Text:GetText(), "https://" ))then urltext = string.sub( Text:GetText(), 9 ) Text:SetText( urltext ) end end floofs = 0 for k, v in pairs(player.GetAll()) do floofs = floofs + 1 v.box = vgui.Create( "DCheckBoxLabel", Bg ) v.box:SetPos( 25, 30+(20* floofs) ) v.box:SetSize( 290, 25 ) v.box:SetText( v:Name() ) Frame:SetSize( 430, 100+(20* floofs) ) Bg:SetSize( 420, 70+(20* floofs) ) end local Button = vgui.Create( "DButton", Frame ) Button:SetText( "Send" ) Button:SetTextColor( Color( 255, 255, 255 ) ) Button:SetPos( 330, 35 ) Button:SetSize( 80, 25 ) Button.Paint = function( self, w, h ) draw.RoundedBox( 0, 0, 0, w, h, Color( 128, 128, 128, 250 ) ) end Button.DoClick = function() surface.PlaySound( "ui/item_acquired.wav" ) print(Text:GetText()) local applied = {} local floof = 0 for k, v in pairs(player.GetAll()) do if(v.box:GetChecked()==true)then floof = floof + 1 print( v:Name().." checked") applied[floof] = v end end net.Start( "browserlist" ) net.WriteString( Text:GetText() ) net.WriteTable( applied ) net.SendToServer() end end end concommand.Add( "BrowserSend", Playerpicker ) function BrowserOpen( ply, cmd, link ) if(CLIENT)then local url = link[1] print( "url :"..url ) local browser = vgui.Create( "DFrame" ) browser:SetTitle( "browser" ) browser:SetSize( ScrW() * 0.75, ScrH() * 0.75 ) browser:Center() browser:MakePopup() browser.Paint = function( self, w, h ) draw.RoundedBox( 0, 0, 0, w, h, Color( 152, 68, 45, 220 ) ) end local html = vgui.Create( "HTML", browser ) html:Dock( FILL ) html:OpenURL( url ) surface.PlaySound( "ui/item_acquired.wav" ) end end concommand.Add( "Browser", BrowserOpen ) if(SERVER) then local url = "" local play = {} net.Receive( "browserlist", function( len, ply ) if ( IsValid( ply ) and ply:IsPlayer() and ply:IsAdmin() ) then url = net.ReadString() play = net.ReadTable() for k, v in pairs(play) do if( IsValid( v ) )then MsgAll( v:Nick() .. " was checked" ) v:ConCommand( "Browser "..url ) end end end end ) end if(SERVER)then function chatCommand( ply, text, public ) if (string.sub(text, 1, 9) == "-browser") then ply:ConCommand( "BrowserSend" ) return end end hook.Add( "PlayerSay", "chatCommand", chatCommand ); end [/code]
the player [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/net/WriteEntity]net.WriteEntity[/url] the url [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/net/WriteString]net.WriteString[/url]
[QUOTE=DiscoKnight;49306430]the player [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/net/WriteEntity]net.WriteEntity[/url] the url [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/net/WriteString]net.WriteString[/url][/QUOTE] well the url is kinda already taken care of I would just need the player's name.
[QUOTE=DiscoKnight;49306430]the player [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/net/WriteEntity]net.WriteEntity[/url] the url [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/net/WriteString]net.WriteString[/url][/QUOTE] Never send LocalPlayer() through WriteEntity. net.Receive has a function callback for that specific reason (length,player) [code] net.Receive("URL",function(length,player) print(player:Nick().." chose "..net.ReadString().."!") end) [/code]
[QUOTE=Kevlon;49306446]Never send LocalPlayer() through WriteEntity. net.Receive has a function callback for that specific reason (length,player) [code] net.Receive("URL",function(length,player) print(player:Nick().." chose "..net.ReadString().."!") end) [/code][/QUOTE] How would I use v:ChatPrint() to display who sent then the link. example : Ari sent you a link to google.com. type -accept to open.
[QUOTE=Ari_Draconia;49306472]How would I use v:ChatPrint() to display who sent then the link. example : Ari sent you a link to google.com. type -accept to open.[/QUOTE] use net.WriteTable to send the list of players (as entities), and net.WriteString for the URL [code] net.Receive("URLSend",function(len,ply) -- check if the player is admin local players = net.ReadTable() local url = net.ReadString() for k,v in pairs(players) do v.urlsendto = url v:ChatPrint(ply:Nick().." sent you a referall to "..url.." type -accept to accept!") end end) hook.Add("PlayerSay","-accept thing",function(ply,txt) if txt:lower():match("^-accept$") and ply.urlsendto then net.Start("OpenURL") -- Add this clientside as a receiver net.WriteString(ply.urlsendto) -- Don't use sendlua to open the url on the player, that is insecure. net.Send(ply) ply.urlsendto = nil return "" end end) [/code]
:snip: nvm
[QUOTE=Kevlon;49306490]use net.WriteTable to send the list of players (as entities), and net.WriteString for the URL [code] net.Receive("URLSend",function(len,ply) -- check if the player is admin local players = net.ReadTable() local url = net.ReadString() for k,v in pairs(players) do v.urlsendto = url v:ChatPrint(ply:Nick().." sent you a referall to "..url.." type -accept to accept!") end end) hook.Add("PlayerSay","-accept thing",function(ply,txt) if txt:lower():match("^-accept$") and ply.urlsendto then net.Start("OpenURL") -- Add this clientside as a receiver net.WriteString(ply.urlsendto) -- Don't use sendlua to open the url on the player, that is insecure. net.Send(ply) ply.urlsendto = nil return "" end end) [/code][/QUOTE] right now I am just running a console command on them to open the browser with the url. Sorry if I ask some stupid question by the way I'm still learning. Edit: Alright I got it working. now to do the chat commands. Thanks for the help. Edit: I can't get the -accept to work correctly. it just does not open the window, no errors.
Sorry, you need to Log In to post a reply to this thread.