• Print

Author Topic: How to add a chat tag to ulx advert  (Read 7375 times)

0 Members and 1 Guest are viewing this topic.

Offline sir snifflebutt

  • Newbie
  • *
  • Posts: 7
  • Karma: 0
How to add a chat tag to ulx advert
« on: April 16, 2017, 12:31:09 pm »
How do you add a chat tag to ulx so like (Server Announcement) advert


Offline BlueNova

  • Full Member
  • ***
  • Posts: 113
  • Karma: 13
  • The most powerful force in the universe.
Re: How to add a chat tag to ulx advert
« Reply #1 on: April 16, 2017, 04:14:53 pm »
You could do something like a PlayerSay hook.

Here's an example

Code: Lua
  1. hook.Add( "PlayerSay", "AdvertExample", function( ply, text, team )
  2.         if ( string.sub( text, 1, 4 ) == "/ad" ) then
  3.                 return "[Admin Advert] " .. string.sub( text, 5 )
  4.         end
  5. end )

This is a copy of the example from the Garry's Mod Wiki.
Here's the link
GM:PlayerSay

Could also do something similar to
Code: Lua
  1. for _, v in ipairs( player.GetAll() ) do
  2.         v:PrintMessage( HUD_PRINTTALK, "[Admin Advert] " .. ply:Nick() .. message ) //Another example
  3. end

There are several things you could do of course.
« Last Edit: April 16, 2017, 04:17:43 pm by BlueNova »

Offline sir snifflebutt

  • Newbie
  • *
  • Posts: 7
  • Karma: 0
Re: How to add a chat tag to ulx advert
« Reply #2 on: April 16, 2017, 04:41:24 pm »
where would i add that?

Offline BlueNova

  • Full Member
  • ***
  • Posts: 113
  • Karma: 13
  • The most powerful force in the universe.
Re: How to add a chat tag to ulx advert
« Reply #3 on: April 16, 2017, 04:52:46 pm »
The PlayerSay hook I would personally stick in the /lua/autorun folder of your server. Not entirely sure if there's any where else to put it.

As for the for loop I have there can just be stuck in the code of a command your making.

For example:

Code: Lua
  1. function hi()
  2.  
  3.         for _, v in ipairs( player.GetAll() ) do
  4.                 v:PrintMessage( HUD_PRINTTALK, "Hi" )
  5.         end
  6.  
  7. end

Of course I almost forgot that ULX had a thing for this (:P) but there's a little handy function called ULib.tsayColor that you can use for fancier echos.

Code: Lua
  1. ULib.tsayColor( calling_ply, Color( 255, 0, 0 ), ply:Nick() .. Color( x, x, x ) .. msg, affected_plys ) --I used a bunch of x's because I forgot the RGB color combo for default gmod text.
« Last Edit: April 16, 2017, 05:01:52 pm by BlueNova »

Offline JamminR

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 8096
  • Karma: 390
  • Sertafide Ulysses Jenius
    • Team Ulysses [ULib/ULX, other fine releases]
Re: How to add a chat tag to ulx advert
« Reply #4 on: April 16, 2017, 06:41:18 pm »
Easier than editing code, you could just use XGUI to edit all the adverts and place whatever you want in front of them.
No need to edit code.
Or are you wanting a live saying?
You could still say something in front of your chat/whatever you are typing.
"Though a program be but three lines long, someday it will have to be maintained." -- The Tao of Programming

Offline BlueNova

  • Full Member
  • ***
  • Posts: 113
  • Karma: 13
  • The most powerful force in the universe.
Re: How to add a chat tag to ulx advert
« Reply #5 on: April 16, 2017, 06:47:23 pm »
Easier than editing code, you could just use XGUI to edit all the adverts and place whatever you want in front of them.
No need to edit code.
Or are you wanting a live saying?
You could still say something in front of your chat/whatever you are typing.

Editing code is the fun part though, may not be practical but is still fun :)

  • Print