• Print

Author Topic: Chat Triggers  (Read 10731 times)

0 Members and 1 Guest are viewing this topic.

Offline Decicus

  • Hero Member
  • *****
  • Posts: 552
  • Karma: 81
    • Alex Thomassen
Re: Chat Triggers
« Reply #15 on: July 22, 2013, 04:30:03 pm »
Well, long story, but I basically moved the script from normal lua/autorun/server into it's own addons folder. You can take a look at the code here, it wasn't originally created by me, but I have done some modifications.

Code: Lua
  1.     if admin then
  2.         for k,v in ipairs(player.GetAll()) do
  3.             v:SendLua("surface.PlaySound(\""..admin.Sound.."\")")
  4.             ULib.tsayColor(v, Color( 204, 204, 0 ), "[Admin] ", Color( 255, 255, 255 ) ..ply:Nick().. Color( 100, 255, 200 ), " has joined the game!")
  5.         end

(There is more code below, other elseif statements, so I did not forget an "end", it's just not in the example code)
Originally, where ULib.tsayColor is now, there was v:ChatPrint (I might also have messed up with the colors before + after ply:Nick()). This isn't the full code, there are some tables and such, but this should(?) be enough to try and explain what I'm trying to do. ply:Nick() doesn't work, while it did before, so I don't know what I have done wrong. Obviously something that isn't supported with ULib.tsayColor when it's set up like this. This is also the only thing I've modified, everything else is intact.
« Last Edit: July 22, 2013, 04:33:46 pm by Decicus »
Contact information:
E-mail: alex@thomassen.xyz.
You can also send a PM.

Offline JamminR

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 8096
  • Karma: 390
  • Sertafide Ulysses Jenius
    • Team Ulysses [ULib/ULX, other fine releases]
Re: Chat Triggers
« Reply #16 on: July 22, 2013, 04:41:58 pm »
ply isn't your player object in that loop.
v is.
:)
"Though a program be but three lines long, someday it will have to be maintained." -- The Tao of Programming

Offline Decicus

  • Hero Member
  • *****
  • Posts: 552
  • Karma: 81
    • Alex Thomassen
Re: Chat Triggers
« Reply #17 on: July 22, 2013, 04:47:03 pm »
I can't believe I didn't notice that, thanks (I feel like a dumb-dumb now).
Contact information:
E-mail: alex@thomassen.xyz.
You can also send a PM.

Offline Decicus

  • Hero Member
  • *****
  • Posts: 552
  • Karma: 81
    • Alex Thomassen
Re: Chat Triggers
« Reply #18 on: July 22, 2013, 05:06:24 pm »
I'll post the whole code, because removing the ply:Nick() didn't work (I replaced it with v). In fact, in the main function "Intro" the "player object" is in fact ply. Although, you wouldn't until I post this (which you would realize now, I guess)

Code: Lua
  1. function Intro(ply)
  2.     local admin = Admins[ply:SteamID()]
  3.     if admin then
  4.         for k,v in ipairs(player.GetAll()) do
  5.             v:SendLua("surface.PlaySound(\""..admin.Sound.."\")")
  6.             ULib.tsayColor(nil, Color( 204, 204, 0 ), "[FADW-Admin] ", Color( 255, 255, 255 ) ..ply:Nick().. Color( 100, 255, 200 ), " has joined the game!")
  7.         end
  8.     end
  9.  

The table is set up like this:
Code: Lua
  1. local Admins = {
  2.     ["STEAM_0:0:00000000"] = {Sound = "sound/directory"},
  3. }
  4.  

It plays the sound, but doesn't print a message. The error said something about trying to "Attempting to concatenate table on line *whatever ply:Nick() is on*" or something like that, then showed an error in ulib's shared/hook.lua:183 (I checked line 183, didn't understand anything).

I'm sort of confused now, because I can't even re-create the error (and I forgot to add a log to my local server). I'll attempt to re-create with the full error.

EDIT: Here's the error.

Code: Lua
  1. [ERROR] addons/intros/lua/ulib/modules/intros.lua:81: attempt to concatenate a table value
  2.   1. fn - addons/intros/lua/ulib/modules/intros.lua:81
  3.    2. unknown - addons/ulib/lua/ulib/shared/hook.lua:183
  4.  
« Last Edit: July 22, 2013, 05:08:32 pm by Decicus »
Contact information:
E-mail: alex@thomassen.xyz.
You can also send a PM.

Offline MrPresident

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 2727
  • Karma: 430
    • |G4P| Gman4President
Re: Chat Triggers
« Reply #19 on: July 22, 2013, 05:41:48 pm »
ply is your player object.

v is the player object of the player you are sending the message to.

The reason your code isn't working is because you still need to separate each parameter of tsaycolor with commas.


Code: [Select]
ULib.tsayColor(nil, Color( 204, 204, 0 ), "[FADW-Admin] ", Color( 255, 255, 255 ), ply:Nick(), Color( 100, 255, 200 ), " has joined the game!")

Offline Decicus

  • Hero Member
  • *****
  • Posts: 552
  • Karma: 81
    • Alex Thomassen
Re: Chat Triggers
« Reply #20 on: July 23, 2013, 01:34:16 am »
Thank you so much! I actually tested that at first, but when it said that "unexpected object '..'...." and so on, it sort of confused me. I figured it out by removing those dots. Now this should be my final question, because it's the only thing that doesn't properly work.

When trying to color the first part "[Admin]", even though I've added a custom RGB code, it still stays at the default/blue-ish ULX text. Is there any workaround to that?

Scratch that, I just added the "wait" parameter, and it worked fine. Again, thanks for all the help you've given me, I've learned a lot from it!
« Last Edit: July 23, 2013, 01:39:49 am by Decicus »
Contact information:
E-mail: alex@thomassen.xyz.
You can also send a PM.

Offline MrPresident

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 2727
  • Karma: 430
    • |G4P| Gman4President
Re: Chat Triggers
« Reply #21 on: July 23, 2013, 02:56:38 am »
No worries. The reason the .. didn't work is because in lua:

.. is how you combine strings. Similar to . in php.


"this" .. "and" .. "that" = "thisandthat"

Offline Decicus

  • Hero Member
  • *****
  • Posts: 552
  • Karma: 81
    • Alex Thomassen
Re: Chat Triggers
« Reply #22 on: July 23, 2013, 03:12:52 am »
I figured it was something like that, I guess ChatPrint required that.
Contact information:
E-mail: alex@thomassen.xyz.
You can also send a PM.

  • Print