• Print

Author Topic: ______  (Read 9312 times)

0 Members and 1 Guest are viewing this topic.

Offline rexorator

  • Newbie
  • *
  • Posts: 1
  • Karma: 0
______
« on: December 02, 2017, 06:07:11 pm »
______
« Last Edit: October 24, 2020, 06:15:35 am by rexorator »

Offline iViscosity

  • Respected Community Member
  • Hero Member
  • *****
  • Posts: 803
  • Karma: 58
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 PM.

Offline iViscosity

  • Respected Community Member
  • Hero Member
  • *****
  • Posts: 803
  • Karma: 58
Re: ULX Chat Links
« Reply #2 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 PM.

Offline iViscosity

  • Respected Community Member
  • Hero Member
  • *****
  • Posts: 803
  • Karma: 58
Re: ULX Chat Links
« Reply #3 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 PM.

Offline iViscosity

  • Respected Community Member
  • Hero Member
  • *****
  • Posts: 803
  • Karma: 58
Re: ULX Chat Links
« Reply #4 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 PM.

Offline MrPresident

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

-_-

Offline iViscosity

  • Respected Community Member
  • Hero Member
  • *****
  • Posts: 803
  • Karma: 58
Re: ULX Chat Links
« Reply #6 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 PM.

Offline iViscosity

  • Respected Community Member
  • Hero Member
  • *****
  • Posts: 803
  • Karma: 58
Re: ULX Chat Links
« Reply #7 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 PM.

  • Print