• problems with basic lua
    3 replies, posted
I am trying to make a script where you can open a website on a player, it works fine when using a string inside code, but cannot get it to read from a local. [code] local CATEGORY_NAME = "Other" local urlname = "http://facepunch.com" function ulx.openurl( calling_ply, target_plys, urlstring ) local affected_plys = {} for i=1, #target_plys do local v = target_plys[ i ] v:SendLua([[gui.OpenURL(urlstring)]]) table.insert( affected_plys, v ) end ulx.fancyLogAdmin( calling_ply, "#A opened #s on #T", affected_plys, urlstring ) end local openurl = ulx.command( CATEGORY_NAME, "ulx openurl", ulx.openurl, "!openurl" ) openurl:addParam{ type=ULib.cmds.PlayersArg } openurl:addParam{ type=ULib.cmds.StringArg, hint="www.google.com" } openurl:defaultAccess( ULib.ACCESS_ADMIN ) openurl:help( "Open a url on a player - !openurl" ) [/code] so to execute it: !openurl 'name' google.ca It works fine if I replace v:SendLua([[gui.OpenURL(urlstring)]]) with v:SendLua([[gui.OpenURL("www.google.com")]]), what am I doing wrong here as I want the string from urlstring? I get this error when using the urlstring as a parameter. [code] [ERROR] LuaCmd:1: bad argument #1 to 'OpenURL' (string expected, got nil) 1. OpenURL - [C]:-1 2. unknown - LuaCmd:1 [/code]
Please wrap your code in tags. So we can help you.
-Nevermind-
Try something like this: [code] function ulx.openurl( calling_ply, target_plys, urlstring ) for _, v in ipairs( target_plys ) do v:SendLua( [[gui.OpenURL("]] .. urlstring .. [[")]] ) end ulx.fancyLogAdmin( calling_ply, "#A opened #s on #T", urlstring , target_plys ) end local openurl = ulx.command( CATEGORY_NAME, "ulx openurl", ulx.openurl, "!openurl" ) openurl:addParam{ type=ULib.cmds.PlayersArg } openurl:addParam{ type=ULib.cmds.StringArg, hint="www.google.com" } openurl:defaultAccess( ULib.ACCESS_ADMIN ) openurl:help( "Open a url on a player - !openurl" ) [/code] Also you may want to add ULib.cmds.takeRestOfLine in your second param
Sorry, you need to Log In to post a reply to this thread.