General > Developers Corner

Custom command to open a webpage

<< < (3/4) > >>

Twiztidkiller:
I hate to bump, but this thread seemed lik a good spot to ask this question.
I have the above given lua script installed, but when Me and/or my friends use the !donate command, it tosses this into my console.


--- Code: ---[ERROR] LuaCmd:1: unfinished string near '<eof>'
  1. unknown - LuaCmd:0

--- End code ---

nathan736:
its because you  screwed up the "" so the code cant find the end of the string so it yells <censor>WHAT?!<censor> we cant find the end if this string.... simple error just fix your " "

ps: when ever you get <eof> you 9/10 did something wrong or removed something when your editing existing code like the important things here
 end "string" , -- if for
pss: heres a easier version to work with

local myurl = "http://www.google.com"     -- "http://YOUR-URL.com"
function donateCommand( pl, text, teamonly )
          if (text == "!donate") then
             pl:SendLua([[gui.OpenURL(myurl)]]) -- Change ADDRESS to your chosen page.
             for k, v in pairs(player.GetAll()) do v:ChatPrint( "Player " .. pl:Nick() .. " has donated to the server via !donate" )

      end
   end
end
hook.Add( "PlayerSay", "Chat", donateCommand )

Twiztidkiller:
Ahh, ok. So then, with my current code being this.

--- Code: ---function donateCommand( pl, text, teamonly )
    if (text == "!donate") then
    pl:SendLua([[gui.OpenURL(http://cur.lv/mifq)]]) -- Change ADDRESS to your chosen page.
    for k, v in pairs(player.GetAll()) do v:ChatPrint( "Player " .. pl:Nick() .. " has considered donating $1.00 to the cause!" )

end
end
end
hook.Add( "PlayerSay", "Chat", donateCommand )
--- End code ---

I would instead want this.

--- Code: ---function donateCommand( pl, text, teamonly )
    if (text == "!donate") then
    pl:SendLua([[gui.OpenURL("http://myurl.com/donate")]]) -- Change ADDRESS to your chosen page.
    for k, v in pairs(player.GetAll()) do v:ChatPrint( "Player " .. pl:Nick() .. " has donated to the server via !donate" )

end
end
end
hook.Add( "PlayerSay", "Chat", donateCommand
--- End code ---
)
I notice the bottom *correct* one has both of these "", which I'm guessing makes the difference?

nathan736:
yeah that would fix it  you MUST have the "" or your not  telling it a url(a string) your telling it a var (which im 90% would throw a billion errors anyways)

An Error Has Occurred!

array_keys(): Argument #1 ($array) must be of type array, null given

[0] Board index

Go to full version