Lua !Donate Command Question

Hey guys. I’m new to lua, and I didn’t make this code, but I am trying to learn as I go. I have this code


function donateCommand( pl, text, teamonly )
		    if (text == "!donate") then 
			    pl:SendLua([[gui.OpenURL("mydonationpageurl")]]) -- Change ADDRESS to your chosen page.
			    for k, v in pairs(player.GetAll()) do v:ChatPrint( "Player " .. pl:Nick() .. " has viewed our donation page!" )

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

It starts up fine with the server but when I type !donate it throws this my way:


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

What’s your donation page url?

I’m no LUA coder, but as mentioned above: Your donation URL?
pl:SendLua([[gui.OpenURL(“mydonationpageurl”)]]) – Change ADDRESS to your chosen page.

Try this:

[LUA]
hook.Add( “PlayerSay”, “dcommand”, function( pl, text, teamonly)
if text == “!donate” then
pl:SendLua([[gui.OpenURL(“mydonationpageurl”)]])
for k, v in pairs(player.GetAll()) do
v:ChatPrint( “Player " … pl:Nick() … " has viewed our donation page!” )
end
end
end)
[/LUA]

That is exactly the same as what the OP posted.


function donateCommand( pl, text, teamonly )
		    if (text == "!donate") then 
			    pl:SendLua([[gui.OpenURL("mydonationpageurl")]]) -- Change ADDRESS to your chosen page.
			    for k, v in pairs(player.GetAll()) do v:ChatPrint( "Player " .. pl:Nick() .. " has viewed our donation page!" )

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

whenever I get that shit, it means I have one ‘end’ too many

edit: this code worked for me


function DonateCommand()
	DonateFrame = vgui.Create( "DFrame" )
		DonateFrame:SetPos( 50,50 )
DonateFrame:SetSize(ScrW() - 90, ScrH() - 90)
		DonateFrame:SetTitle( "Donate Command" )
		DonateFrame:SetVisible( true )
		DonateFrame:SetDraggable( true )
		DonateFrame:ShowCloseButton( true )
		DonateFrame:MakePopup()
HTMLTest = vgui.Create("HTML", DonateFrame)
HTMLTest:SetPos(50,50)
HTMLTest:SetSize(ScrW() - 100, ScrH() - 100)
HTMLTest:OpenURL("http://www.wopk.org/site/donate")
end
concommand.Add("donate", DonateCommand)

hook.Add( "OnPlayerChat", "HitCommand1", function( ePlayer, sText )
    if ( ePlayer ~= LocalPlayer() ) then
        return -- Stop right here if it's not us speaking.
    end
    if ( string.StartWith( string.lower( sText ), "/donate" ) ) then
        DonateCommand()
end

But now it is missing an end…

You stated that it threw the error ‘your way,’ so I assume it is a clientside error. But the only clientside code is in the sendlua function, so try commenting out or removing the line

pl:SendLua([[gui.OpenURL(“mydonationpageurl”)]])

then see if you get the error.

I know the chat command is useless now but this is just for debugging the error.

[lua]local function donateCommand( pl, text, teamonly )
if text == “!donate” then
pl:SendLua( [[ gui.OpenURL( “mydonationpageurl” ) ]] ) – Change ADDRESS to your chosen page.

	PrintMessage( HUD_PRINTTALK, "Player " .. pl:Nick() .. " has viewed our donation page!" )
end

end
hook.Add( “PlayerSay”, “dcommand”, donateCommand )[/lua]

Again, this has -nothing- to do with the actual error he posted.
The error is to do with the code that is sent to the client through SendLua, which is why the error occurs in LuaCmd.

I kept my donation URL out of the code because since I’m new I wasn’t sure if those links were allowed. but the complete code wit it would be:


function donateCommand( pl, text, teamonly )
		    if (text == "!donate") then 
			    pl:SendLua([[gui.OpenURL("http://twistitkillit.wix.com/a-twiztid-playhouse#!donations/cnry")]]) -- Change ADDRESS to your chosen page.
			    for k, v in pairs(player.GetAll()) do v:ChatPrint( "Player " .. pl:Nick() .. " has viewed our donation page!" )

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

For Havejack and MakeR, the code jack posted does seem to differ a bit as his lacks this line:


hook.Add( "PlayerSay", "dcommand", donateCommand )

unless of course thatpiece of code isn’t relevant.

For Pazda, I will have to try out that code you suggested. :slight_smile:
For IceTea, I actually forgot to check server console for an error when I got the error… But yeah,I’m sure it’s clientside.
Also on a final note, if anyone could tell me how you guys do you fancy qoutes on here,that would be great. It seems to help things be much more organized.
I will trying out Pazdas Code and be back with results in a few hours as My fiancee is playing Sims 3…
Thank You Everyone
EDIT: The error shows up in server console as well.

Why dont you try this instead

[lua]pl:SendLua(‘gui.OpenURL(“http://twistitkillit.wix.com/a-twiztid-playhouse#!donations/cnry”)’)[/lua]

Equivalent.

There is no reason for that code to error, unless the OP is posting the wrong code.

I know, but what you posted will not fix it.

[editline]4th April 2013[/editline]

because it is equivalent

I tried Pazda’s code:


function DonateCommand()
	DonateFrame = vgui.Create( "DFrame" )
		DonateFrame:SetPos( 50,50 )
DonateFrame:SetSize(ScrW() - 90, ScrH() - 90)
		DonateFrame:SetTitle( "Donate Command" )
		DonateFrame:SetVisible( true )
		DonateFrame:SetDraggable( true )
		DonateFrame:ShowCloseButton( true )
		DonateFrame:MakePopup()
HTMLTest = vgui.Create("HTML", DonateFrame)
HTMLTest:SetPos(50,50)
HTMLTest:SetSize(ScrW() - 100, ScrH() - 100)
HTMLTest:OpenURL("http://www.wopk.org/site/donate")
end
concommand.Add("donate", DonateCommand)

hook.Add( "OnPlayerChat", "HitCommand1", function( ePlayer, sText )
    if ( ePlayer ~= LocalPlayer() ) then
        return -- Stop right here if it's not us speaking.
    end
    if ( string.StartWith( string.lower( sText ), "/donate" ) ) then
        DonateCommand()
end

and I got this


[ERROR] lua/autorun/mhm.lua:23: 'end' expected (to close 'function' at line 17) near '<eof>'
 1. unknown - lua/autorun/mhm.lua:0

Ruzza and MakeR You guys are suggesting this code right?


function donateCommand( pl, text, teamonly )
		    if (text == "!donate") then 
			    pl:SendLua('gui.OpenURL("http://twistitkillit.wix.com/a-twiztid-playhouse#!donations/cnry")')
			    for k, v in pairs(player.GetAll()) do v:ChatPrint( "Player " .. pl:Nick() .. " has viewed our donation page!" )

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

This is the original code modified with the code you suggested I replace, but It looks the same to me.
Am I getting this wrong?

[editline]4th April 2013[/editline]

Ohh, I get it. They are the same, which is what equivalent meant. I’m sorry, I took that wrong.

The original code you posted works fine for me.

[lua]
function donateCommand( pl, text, teamonly )
if (text == “!donate”) then
pl:SendLua([[gui.OpenURL(“http://twistitkillit.wix.com/a-twiztid-playhouse#!donations/cnry”)]]) – Change ADDRESS to your chosen page.
for k, v in pairs(player.GetAll()) do v:ChatPrint( “Player " … pl:Nick() … " has viewed our donation page!” )
end
end
end
hook.Add( “PlayerSay”, “dcommand”, donateCommand )
[/lua]

Maybe you have another addon that is obstructing it?

[editline]5th April 2013[/editline]

Where are you placing this code, is it inside garrysmod/lua/autorun/server/ ?

Actually, I was just placing it inside of the autorun folder per instructions I found in different thread. I will try with it inside server itself and post results. Maybe you have saved me :slight_smile:

I placed the file inside of the autorun folder like you suggested, and it still tossed the error. My main addons are , ULX, ACF, Wiremod, and SProps.
Could any of those cause this?

I put your code into my garrysmod/lua/autorun/server and it worked 100% fine, no idea whats wrong