Author Topic: ULX Chat Links  (Read 237 times)

0 Members and 1 Guest are viewing this topic.

Offline rexorator

  • Newbie
  • *
  • Posts: 7
  • Karma: 0
    • View Profile
ULX Chat Links
« on: December 02, 2017, 06:07:11 PM »
I am having trouble creating chat links on my server I fund a forum post with several examples to no avail. Here is the link to the forum post: https://forums.ulyssesmod.net/index.php?topic=5883.0

Whenever i copy and pasted the code into a text file in the appropriate folder and filled in the placeholder text in the code it never worked when I typed !donate. I just want to be able to set up chat links for downloading assets and bring up the MOTD. I couldn't find any other source for the problem like a youtube video or other forum post, so a link to some sources of helpful in depth information on setting up stuff like this would be appreciated. Thanks.

ULX version:
3.73

Game mode(s) I am having this problem on:
sandbox

Offline iViscosity

  • Hero Member
  • *****
  • Posts: 698
  • Karma: 39
    • View Profile
    • iViscosity Gaming
Re: ULX Chat Links
« Reply #1 on: December 02, 2017, 06:19:04 PM »
What do you mean you put it "into a text file"?
I'm iViscosity. I like gaming and programming. Need some help? Shoot me a PM or Join my Discord!.
--==[ Links ]==--
Steam
YouTube
Steam Group (feel free to join!)
Forums
Public Discord

Quote from: Steve Jobs
Your work is going to fill a large part of your life, and the only way to be truly satisfied is to do what you believe is great work. And the only way to do great work is to love what you do. If you haven't found it yet, keep looking. Don't settle. As with all matters of the heart, you'll know when you find it. And, like any great relationship, it just gets better and better as the years roll on. So keep looking until you find it. Don't settle.

Offline rexorator

  • Newbie
  • *
  • Posts: 7
  • Karma: 0
    • View Profile
Re: ULX Chat Links
« Reply #2 on: December 02, 2017, 06:47:06 PM »
I pasted the code in garrysmod/lua/autorun/server folder in a new text file with .lua at the end

Offline iViscosity

  • Hero Member
  • *****
  • Posts: 698
  • Karma: 39
    • View Profile
    • iViscosity Gaming
Re: ULX Chat Links
« Reply #3 on: December 02, 2017, 07:15:46 PM »
Did you restart the server/change the map?
I'm iViscosity. I like gaming and programming. Need some help? Shoot me a PM or Join my Discord!.
--==[ Links ]==--
Steam
YouTube
Steam Group (feel free to join!)
Forums
Public Discord

Quote from: Steve Jobs
Your work is going to fill a large part of your life, and the only way to be truly satisfied is to do what you believe is great work. And the only way to do great work is to love what you do. If you haven't found it yet, keep looking. Don't settle. As with all matters of the heart, you'll know when you find it. And, like any great relationship, it just gets better and better as the years roll on. So keep looking until you find it. Don't settle.

Offline rexorator

  • Newbie
  • *
  • Posts: 7
  • Karma: 0
    • View Profile
Re: ULX Chat Links
« Reply #4 on: December 02, 2017, 07:52:54 PM »
I add the file while the server was offline and then started it up and tested it by typing !donate and it didn't work and i didn't change the map

Offline rexorator

  • Newbie
  • *
  • Posts: 7
  • Karma: 0
    • View Profile
Re: ULX Chat Links
« Reply #5 on: December 02, 2017, 08:05:01 PM »
Here is an example of one of the codes I used

https://imgur.com/gallery/HBaM1


Offline iViscosity

  • Hero Member
  • *****
  • Posts: 698
  • Karma: 39
    • View Profile
    • iViscosity Gaming
Re: ULX Chat Links
« Reply #6 on: December 02, 2017, 08:13:36 PM »
Okay... so "ulx motd" is going to open the motd on their end. You're then trying to add on a url to it.

So basically, you're making the client perform a console command "ulx motd "http://www.google.com"" which doesn't exist.

If you looked farther down the thread, you'd see one that uses ply:SendLua( blahblah stuff in here ); this is the one you want to use.

So, for example, if you wanted them to open google, you'd have this code:
Code: Lua
  1. local URL = "http://www.google.com" -- This is the URL you want them to open.
  2. function openGoogle( ply, text ) -- This can be named anything, but the parameters must match the parameters for the hook you want to use ( PlayerSay )
  3.     if ( string.sub( text, 1, 7 ) == "!google" ) then -- This will check the first 7 characters of the given string ( text, indexes 1 through 7 ) and check if it matches this.
  4.         ply:SendLua( [[ gui.OpenURL( \"" .. URL .. "\" ) ]] ) -- If it does, it will open the URL you specified above.
  5.         return "" -- This prevents the message from showing ( you can remove this if you like )
  6.     end
  7. end
  8. hook.Add( "PlayerSay", "Open Google", openGoogle ) -- This actually makes the game call this function when this hook is triggered ( whenever someones sends a message in chat ).
I'm iViscosity. I like gaming and programming. Need some help? Shoot me a PM or Join my Discord!.
--==[ Links ]==--
Steam
YouTube
Steam Group (feel free to join!)
Forums
Public Discord

Quote from: Steve Jobs
Your work is going to fill a large part of your life, and the only way to be truly satisfied is to do what you believe is great work. And the only way to do great work is to love what you do. If you haven't found it yet, keep looking. Don't settle. As with all matters of the heart, you'll know when you find it. And, like any great relationship, it just gets better and better as the years roll on. So keep looking until you find it. Don't settle.

Offline rexorator

  • Newbie
  • *
  • Posts: 7
  • Karma: 0
    • View Profile
Re: ULX Chat Links
« Reply #7 on: December 02, 2017, 08:43:58 PM »
Okay... I think im getting there, do i need to replace all the red text?

Also on line two you said

"function openGoogle( ply, text ) -- This can be named anything but the parameters must match the parameters for the hook you want to use ( PlayerSay )

What can be named anything and is playerSay the parameter?

Is !google on line 3 what the player would have to type to open the MOTD?

thanks again

Offline iViscosity

  • Hero Member
  • *****
  • Posts: 698
  • Karma: 39
    • View Profile
    • iViscosity Gaming
Re: ULX Chat Links
« Reply #8 on: December 02, 2017, 09:26:05 PM »
I'll give you a little introduction to hooks.

Hooks are what Garry's Mod lets scripters use to "hook into" game events. It allows us to perform certain actions when an event happens in the game. The GM:PlayerSay hook lets us do something when someone sends a message in the chat. There are three parameters to PlayerSay: The Player that sent the message, the String that holds the text inside the message, and a Boolean (true/false) variable that says whether or not the message was sent to only the person's team or not. Since we don't care if it's team chat or not, we can ignore it in our parameter list ( everything inside of the parentheses ).

So when I said "this can be named anything" I mean the function name ( in this case, "openGoogle" ) can be named anything. If you wanted
Code: Lua
  1. function thisIsStupid( ply, text )
that would work just as well, but you'd have to edit it in the hook.Add statement at the bottom. The parameters, again, are anything inside of the parentheses. We want something that is distinguishable as a Player, so we use ply ( again, though, this can be anything, but we use 'ply' or 'calling_ply' as a standard in gLua to make code easier to read ). The next thing PlayerSay wants us to provide is a variable for the message. On the wiki page ( GM:PlayerSay) the parameter is "text", so we generally use "text" as our variable.

The "!google" on line 3 is the text that our script is checking. If the message that the person sent starts with "!google", our script will be performed ( if not, nothing will happen, at least in our script ) and the webpage "google" will be opened in their browser.

If you wanted to use this example, all you have to change is the string ( anything inside quotes [ "" ] ) next to where it says "local URL = "
For example, if you wanted to link to your donation website, you would need to change where it says "http://www.google.com" to whatever your donation link is. You will also need to change the command you want to open this. Line 2 says
Code: Lua
  1. if ( string.sub( text, 1, 7 ) == "!google" ) then
  2.  

What this is checking is if the substring ( a part of a string ) if the message sent is equal to "!google", then whatever is inside this if statement ( anything before the next "end" ) will be executed.


I see you're fairly new to Lua, so here are some links that might help:

How to use hooks: http://wiki.garrysmod.com/page/Hook_Library_Usage
Lua String library: https://www.lua.org/pil/20.html
What are functions?: https://www.lua.org/pil/5.html


Let me know if anything in here was confusing; I tried to break it down for you.
I'm iViscosity. I like gaming and programming. Need some help? Shoot me a PM or Join my Discord!.
--==[ Links ]==--
Steam
YouTube
Steam Group (feel free to join!)
Forums
Public Discord

Quote from: Steve Jobs
Your work is going to fill a large part of your life, and the only way to be truly satisfied is to do what you believe is great work. And the only way to do great work is to love what you do. If you haven't found it yet, keep looking. Don't settle. As with all matters of the heart, you'll know when you find it. And, like any great relationship, it just gets better and better as the years roll on. So keep looking until you find it. Don't settle.

Offline MrPresident

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 2568
  • Karma: 395
    • View Profile
    • |G4P| Gman4President
Re: ULX Chat Links
« Reply #9 on: December 03, 2017, 02:06:30 AM »
Also.. unless he fixed it already.. his file is called Chatlinks.lua.txt

-_-

Offline iViscosity

  • Hero Member
  • *****
  • Posts: 698
  • Karma: 39
    • View Profile
    • iViscosity Gaming
Re: ULX Chat Links
« Reply #10 on: December 03, 2017, 06:32:29 AM »
Either way it wouldn't work but yeah. Thought I established it with my first post but maybe not
I'm iViscosity. I like gaming and programming. Need some help? Shoot me a PM or Join my Discord!.
--==[ Links ]==--
Steam
YouTube
Steam Group (feel free to join!)
Forums
Public Discord

Quote from: Steve Jobs
Your work is going to fill a large part of your life, and the only way to be truly satisfied is to do what you believe is great work. And the only way to do great work is to love what you do. If you haven't found it yet, keep looking. Don't settle. As with all matters of the heart, you'll know when you find it. And, like any great relationship, it just gets better and better as the years roll on. So keep looking until you find it. Don't settle.

Offline rexorator

  • Newbie
  • *
  • Posts: 7
  • Karma: 0
    • View Profile
Re: ULX Chat Links
« Reply #11 on: December 03, 2017, 08:05:33 AM »
So progress has been made...

I changed the .txt file into a .lua file and then when i tried typing !google in game it said "something is creating script errors" in the top left.

Link to the Error
https://imgur.com/GuPZGIV

Link to current Script:
https://imgur.com/BgHCFWd

Cant quite figure out what the error is talking about...

Im so close to the answer I can taste it!


Offline iViscosity

  • Hero Member
  • *****
  • Posts: 698
  • Karma: 39
    • View Profile
    • iViscosity Gaming
Re: ULX Chat Links
« Reply #12 on: December 03, 2017, 08:17:31 AM »
Oh right that was something I forgot to change when editing the command. You need to remove both of the \"
I'm iViscosity. I like gaming and programming. Need some help? Shoot me a PM or Join my Discord!.
--==[ Links ]==--
Steam
YouTube
Steam Group (feel free to join!)
Forums
Public Discord

Quote from: Steve Jobs
Your work is going to fill a large part of your life, and the only way to be truly satisfied is to do what you believe is great work. And the only way to do great work is to love what you do. If you haven't found it yet, keep looking. Don't settle. As with all matters of the heart, you'll know when you find it. And, like any great relationship, it just gets better and better as the years roll on. So keep looking until you find it. Don't settle.

Offline rexorator

  • Newbie
  • *
  • Posts: 7
  • Karma: 0
    • View Profile
Re: ULX Chat Links
« Reply #13 on: December 03, 2017, 08:29:37 AM »
OK thanks for everything I finally got it working.  :)