• Code issue
    4 replies, posted
I've been working on a command that opens a webpage on a person's screen with both the link and the amount of time being specified by the person using the command. So far, all is well but I've been trying to edit the command so that it takes the ID of youtube videos and inserts them into another link instead to fullscreen them with other options. The videos instead open normally on a normal page. [lua]local CATEGORY_NAME = "Abuse" if (CLIENT) then net.Receive("ShowSite", function(link, openlink) local linkpart1 = string.Explode(".", link) local linkpart2 = string.Explode("=", link) seconds = net.ReadInt(32) link = net.ReadString() showsitepanel = vgui.Create("HTML") showsitepanel:SetPos(50,50) showsitepanel:SetSize(ScrW() - 100, ScrH() - 100) if linkpart1[2] == "youtube" or linkpart1[2] == "youtu" then openlink = "https://www.youtube.com/embed/"..linkpart2[2].."?autoplay=1&controls=0&loop=1&showinfo=0&modestbranding=1&disablekb=1" else openlink = link end showsitepanel:OpenURL(openlink) timer.Simple(seconds, function() showsitepanel:Remove() end ) LocalPlayer():ChatPrint(link) LocalPlayer():ChatPrint(openlink) LocalPlayer():ChatPrint(seconds) PrintTable(linkpart1) PrintTable(linkpart2) end) else util.AddNetworkString("ShowSite") end function ulx.showsite(calling_ply, target_plys, seconds, link) ulx.fancyLogAdmin(calling_ply, "#A gave #s seconds of a link to #T", seconds, target_plys) for i=1, #target_plys do local v = target_plys[ i ] net.Start("ShowSite") net.WriteInt( tonumber(seconds), 32 ) net.WriteString( link ) net.Send( v ) end end local showsite = ulx.command( CATEGORY_NAME, "ulx showsite", ulx.showsite, "!showsite" ) showsite:addParam{ type=ULib.cmds.PlayersArg } showsite:addParam{ type=ULib.cmds.NumArg, min=0, default=10, hint="seconds", ULib.cmds.optional, ULib.cmds.round } showsite:addParam{ type=ULib.cmds.StringArg, hint= "Enter your URL here!" } showsite:addParam{ type=ULib.cmds.BoolArg, invisible=true } showsite:defaultAccess( ULib.ACCESS_SUPERADMIN ) showsite:help( "Torture an innocent soul!" )[/lua] When the data for each varibale is printed using: [code] LocalPlayer():ChatPrint(link) LocalPlayer():ChatPrint(openlink) LocalPlayer():ChatPrint(seconds) PrintTable(linkpart1) PrintTable(linkpart2) [/code] this is given: [code] www.youtube.com/watch?v=BA0TMOf9ibQ www.youtube.com/watch?v=BA0TMOf9ibQ 5 1 = 320 1 = 320 [/code] A number is being printed instead of the table being printed and I've spent a while trying to figure out to no avail. I'd greatly appreaciate any help. Thanks in advance :)
link is 320 because net.Receive has one arg (len) which is the size of the message, so your link arg is being set to the size. Read more on the net library.
I've resolved that and done a bit more editing and seem to have encountered another error. I've played with it for about an hour and I don't seem to have made any progress My current code is: [lua]local CATEGORY_NAME = "Abuse" if (CLIENT) then net.Receive("ShowSite", function(len) local linkpart1 = string.Explode(".", link) local linkpart2 = string.Explode("=", link) seconds = net.ReadInt(32) link = net.ReadString() showsitepanel = vgui.Create("HTML") showsitepanel:SetPos(50,50) showsitepanel:SetSize(ScrW() - 100, ScrH() - 100) if linkpart1[2] == "youtube" then showsitepanel:OpenURL("https://www.youtube.com/embed/"..linkpart2[2].."?autoplay=1&controls=0&loop=1&showinfo=0&modestbranding=1&disablekb=1") else showsitepanel:OpenURL(link) end timer.Simple(seconds, function() showsitepanel:Remove() end ) LocalPlayer():ChatPrint(link) LocalPlayer():ChatPrint(seconds) PrintTable(linkpart1) PrintTable(linkpart2) end) else util.AddNetworkString("ShowSite") end function ulx.showsite(calling_ply, target_plys, seconds, link) ulx.fancyLogAdmin(calling_ply, "#A gave #s seconds of a link to #T", seconds, target_plys) for i=1, #target_plys do local v = target_plys[ i ] net.Start("ShowSite") net.WriteInt( tonumber(seconds), 32 ) net.WriteString( link ) net.Send( v ) end end local showsite = ulx.command( CATEGORY_NAME, "ulx showsite", ulx.showsite, "!showsite" ) showsite:addParam{ type=ULib.cmds.PlayersArg } showsite:addParam{ type=ULib.cmds.NumArg, min=0, default=10, hint="seconds", ULib.cmds.optional, ULib.cmds.round } showsite:addParam{ type=ULib.cmds.StringArg, hint= "Enter your URL here!" } showsite:addParam{ type=ULib.cmds.BoolArg, invisible=true } showsite:defaultAccess( ULib.ACCESS_SUPERADMIN ) showsite:help( "Torture an innocent soul!" )[/lua] and the error is: [code] [ERROR] lua/includes/extensions/string.lua:91: bad argument #1 to 'string_gmatch' (string expected, got nil) 1. string_gmatch - [C]:-1 2. Explode - lua/includes/extensions/string.lua:91 3. func - addons/ulx_addons/lua/ulx/modules/sh/showsite.lua:4 4. unknown - lua/includes/modules/net.lua:32[/code] I don't want to seem like I'm just reporting any issue I have here, I've looked for a solution for a while now and I can't seem to find one. Thanks in advance for any help :)
[QUOTE=Baron von Hax;47528643]I've resolved that and done a bit more editing and seem to have encountered another error. I've played with it for about an hour and I don't seem to have made any progress My current code is: [lua]local CATEGORY_NAME = "Abuse" if (CLIENT) then net.Receive("ShowSite", function(len) local linkpart1 = string.Explode(".", link) local linkpart2 = string.Explode("=", link) seconds = net.ReadInt(32) link = net.ReadString() showsitepanel = vgui.Create("HTML") showsitepanel:SetPos(50,50) showsitepanel:SetSize(ScrW() - 100, ScrH() - 100) if linkpart1[2] == "youtube" then showsitepanel:OpenURL("https://www.youtube.com/embed/"..linkpart2[2].."?autoplay=1&controls=0&loop=1&showinfo=0&modestbranding=1&disablekb=1") else showsitepanel:OpenURL(link) end timer.Simple(seconds, function() showsitepanel:Remove() end ) LocalPlayer():ChatPrint(link) LocalPlayer():ChatPrint(seconds) PrintTable(linkpart1) PrintTable(linkpart2) end) else util.AddNetworkString("ShowSite") end function ulx.showsite(calling_ply, target_plys, seconds, link) ulx.fancyLogAdmin(calling_ply, "#A gave #s seconds of a link to #T", seconds, target_plys) for i=1, #target_plys do local v = target_plys[ i ] net.Start("ShowSite") net.WriteInt( tonumber(seconds), 32 ) net.WriteString( link ) net.Send( v ) end end local showsite = ulx.command( CATEGORY_NAME, "ulx showsite", ulx.showsite, "!showsite" ) showsite:addParam{ type=ULib.cmds.PlayersArg } showsite:addParam{ type=ULib.cmds.NumArg, min=0, default=10, hint="seconds", ULib.cmds.optional, ULib.cmds.round } showsite:addParam{ type=ULib.cmds.StringArg, hint= "Enter your URL here!" } showsite:addParam{ type=ULib.cmds.BoolArg, invisible=true } showsite:defaultAccess( ULib.ACCESS_SUPERADMIN ) showsite:help( "Torture an innocent soul!" )[/lua] and the error is: [code] [ERROR] lua/includes/extensions/string.lua:91: bad argument #1 to 'string_gmatch' (string expected, got nil) 1. string_gmatch - [C]:-1 2. Explode - lua/includes/extensions/string.lua:91 3. func - addons/ulx_addons/lua/ulx/modules/sh/showsite.lua:4 4. unknown - lua/includes/modules/net.lua:32[/code] I don't want to seem like I'm just reporting any issue I have here, I've looked for a solution for a while now and I can't seem to find one. Thanks in advance for any help :)[/QUOTE] Link is undefined on line 4. Move the definition to before you use it.
You are trying to use the string before it's been read. Make sure link is put before linkpart1 and linkpart2. [editline]n[/editline] Bloody ninja's..
Sorry, you need to Log In to post a reply to this thread.