Author Topic: Chat command -> Open website not working correctly  (Read 2857 times)

0 Members and 1 Guest are viewing this topic.

Offline nicwillu

  • Newbie
  • *
  • Posts: 5
  • Karma: 1
Chat command -> Open website not working correctly
« on: May 20, 2014, 07:55:46 AM »
Greetings.

I have this piece of lua code working perfectly, basically it opens a recruitment window when typing !joinsgx:
Code: [Select]
function joinsgxCommand( pl, text, teamonly )
    if (text == "!joinsgx") then
    pl:SendLua([[gui.OpenURL("http://sg-x.info/recruitment")]]) -- Change ADDRESS to your chosen page.


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

Now, I want to add another chat command for getting a list of addons the server is using when typing !addons

Code: [Select]
function getaddonsCommand( pl, text, teamonly )
    if (text == "!addons") then
    pl:SendLua([[gui.OpenURL("http://steamcommunity.com/sharedfiles/filedetails/?id=139301267")]]) -- Change ADDRESS to your chosen page.


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

But when I type in !addons nothing happens, why? How come !joinsgx works but not !addons? I changed the function variable (or whatever it is called) so they are not the same.

Excuse my noob-skill in lua coding, I got this code from somewhere else and I edited it to fit my needs. any help appreciated!
« Last Edit: May 20, 2014, 07:58:36 AM by nicwillu »

Offline Neku

  • Hero Member
  • *****
  • Posts: 549
  • Karma: 27
Re: Chat command -> Open website not working correctly
« Reply #1 on: May 20, 2014, 08:03:39 AM »
This isn't a ULX command...but alright.
I don't see anything wrong, so those two are probably just conflicting.

Put both urls in one function instead of two.
Out of the Garry's Mod business.

Offline nicwillu

  • Newbie
  • *
  • Posts: 5
  • Karma: 1
Re: Chat command -> Open website not working correctly
« Reply #2 on: May 20, 2014, 08:28:29 AM »
This isn't a ULX command...but alright.
I don't see anything wrong, so those two are probably just conflicting.

Put both urls in one function instead of two.

How exactly would I do that?

EDIT: Made it work somehow :)
Code: [Select]
function donateCommand( pl, text, teamonly )
    if (text == "!joinsgx") then
    pl:SendLua([[gui.OpenURL("http://sg-x.info/recruitment")]]) -- Change ADDRESS to your chosen page.
end

if (text == "!addons") then
    pl:SendLua([[gui.OpenURL("http://sg-x.infololol/recruitment")]])



end
end

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

Thanks for the help.
« Last Edit: May 20, 2014, 08:45:59 AM by nicwillu »

Offline Neku

  • Hero Member
  • *****
  • Posts: 549
  • Karma: 27
Re: Chat command -> Open website not working correctly
« Reply #3 on: May 20, 2014, 08:44:16 AM »
Code: [Select]
function GetURLCommand( pl, text, teamonly )
    if text == "!addons" then
    pl:SendLua([[gui.OpenURL("http://steamcommunity.com/sharedfiles/filedetails/?id=139301267")]])
                    elseif text == "!joinsgx" then
                            pl:SendLua([[gui.OpenURL("http://sg-x.info/recruitment")]])
                    end
end
hook.Add( "PlayerSay", "Chat", GetURLCommand )

In my honest opinion, you need to learn lua to run a server.
Out of the Garry's Mod business.

Offline nicwillu

  • Newbie
  • *
  • Posts: 5
  • Karma: 1
Re: Chat command -> Open website not working correctly
« Reply #4 on: May 20, 2014, 08:52:28 AM »
Code: [Select]
function GetURLCommand( pl, text, teamonly )
    if text == "!addons" then
    pl:SendLua([[gui.OpenURL("http://steamcommunity.com/sharedfiles/filedetails/?id=139301267")]])
                    elseif text == "!joinsgx" then
                            pl:SendLua([[gui.OpenURL("http://sg-x.info/recruitment")]])
                    end
end
hook.Add( "PlayerSay", "Chat", GetURLCommand )

In my honest opinion, you need to learn lua to run a server.

Why is that? I've hosted servers for years without having to get involved in lua that much. Sure it's good to know, but to say that you need to know lua to run a server... well in my honest opinion I disagree.

Anyway thanks :)

Offline Neku

  • Hero Member
  • *****
  • Posts: 549
  • Karma: 27
Re: Chat command -> Open website not working correctly
« Reply #5 on: May 20, 2014, 09:27:57 AM »
Hold on, I just helped you and gave an opinion, and you complain against me?
That's uncalled for.
« Last Edit: May 20, 2014, 09:33:02 AM by Neku »
Out of the Garry's Mod business.

Offline nicwillu

  • Newbie
  • *
  • Posts: 5
  • Karma: 1
Re: Chat command -> Open website not working correctly
« Reply #6 on: May 20, 2014, 09:45:02 AM »
Hold on, I just helped you and gave an opinion, and you complain against me?
That's uncalled for.

Am I not allowed to give my own opinion to what you said?

I thanked twice! :)

Now, case closed

Offline MrPresident

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 2728
  • Karma: 430
    • |G4P| Gman4President
Re: Chat command -> Open website not working correctly
« Reply #7 on: May 20, 2014, 10:30:18 AM »
Your original problem was that you were giving 2 hooks the same unique name.

hook.Add( "PlayerSay", "Unique Name", function)

If you name 2 hooks the same unique name as you did, one will override the other.

Offline JamminR

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 8096
  • Karma: 390
  • Sertafide Ulysses Jenius
    • Team Ulysses [ULib/ULX, other fine releases]
Re: Chat command -> Open website not working correctly
« Reply #8 on: May 21, 2014, 09:42:48 PM »
What MrPres says!
Additionally Neku, he IS learning lua by asking questions, and, though he did ask in a ULX specific section, simply ask he post in Developers corner next time.
I didn't even fully understand that the original topic had been moved until I saw the MOVED notice after this topic.

Oh, and nicwillu, fyi, the help and support section is intended for ULX related questions.
Feel free to ask lua/other development questions here in the Developers corner section of the forums.
« Last Edit: May 21, 2014, 09:46:24 PM by JamminR »
"Though a program be but three lines long, someday it will have to be maintained." -- The Tao of Programming