General > Developers Corner

Custom command to open a webpage

(1/4) > >>

Prentice:
Hey,
I was wondering how I could set it so that if someone typed "!donate" for example it would open "http://myurl.com/donate" in a motd type window?
Any support would be appreciated...
Thanks!

MrPresident:

--- Code: ---function DonateMOTD( ply, text, _ )

    if ( string.sub( string.lower( text ), 1, 7 ) == "!donate" ) then
local url = "\"http://www.google.com\""
ply:ConCommand( "ulx motd " .. url )
return false
    end

end
hook.Add( "PlayerSay", "DonateMOTD", DonateMOTD )

--- End code ---




^^
Not tested.. but it should work?

You could put this in a file and drop it in your garrysmod/lua/autorun/server folder.

Prentice:
That code just opens my motd :(

bender180:

--- 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 ---

Like MrPresident said,
You could put this in a file and drop it in your garrysmod/lua/autorun/server folder.

Deemony07:
When i did that. I typed !donate and it didnt open the url. It just said Deemoney07 donated.

Navigation

[0] Message Index

[#] Next page

Go to full version