Author Topic: Tags  (Read 5919 times)

0 Members and 1 Guest are viewing this topic.

Offline easer7

  • Newbie
  • *
  • Posts: 24
  • Karma: 1
Re: Tags
« Reply #15 on: January 08, 2013, 04:14:21 PM »
Quick question about the else/if part though.


if (SERVER) then
        AddCSLuaFile("autorun/tags.lua")
end
 
if (CLIENT) then
function Insert( pl, msg )
                local tab = {}
        if pl:IsUserGroup("headmanagement") then
                table.insert( tab, Color( 255, 0, 0, 255 ) )
                        table.insert( tab, "[Head Management] " )
                table.insert( tab, Color( 255, 255, 255, 255 ) )
                        table.insert( tab, pl:Nick() )
                        table.insert( tab, ": " )
                table.insert( tab, msg )
        elseif pl:IsUserGroup("leadmanagement") then
                table.insert( tab, Color( 255, 0, 0, 255 ) )
                        table.insert( tab, "[Lead Management] " )
                table.insert( tab, Color( 255, 255, 255, 255 ) )
                        table.insert( tab, pl:Nick() )
                        table.insert( tab, ": " )
                table.insert( tab, msg )
        elseif pl:IsUserGroup("management") then
                table.insert( tab, Color( 255, 0, 0, 255 ) )
                        table.insert( tab, "[Management] " )
                table.insert( tab, Color( 255, 255, 255, 255 ) )
                        table.insert( tab, pl:Nick() )
                        table.insert( tab, ": " )
                table.insert( tab, msg )
        elseif pl:IsUserGroup("leadmoderator") then
                table.insert( tab, Color( 33, 110, 252, 255 ) )
                        table.insert( tab, "[Lead Moderator] " )
                table.insert( tab, Color( 255, 255, 255, 255 ) )
                        table.insert( tab, pl:Nick() )
                        table.insert( tab, ": " )
                table.insert( tab, msg )
        elseif pl:IsUserGroup("moderator") then
                table.insert( tab, Color( 33, 110, 252, 255 ) )
                        table.insert( tab, "[Moderator] " )
                table.insert( tab, Color( 255, 255, 255, 255 ) )
                        table.insert( tab, pl:Nick() )
                        table.insert( tab, ": " )
                table.insert( tab, msg )
        elseif pl:IsUserGroup("premium") then
                table.insert( tab, Color( 245, 226, 20, 255 ) )
                        table.insert( tab, "[Premium] " )
                table.insert( tab, Color( 255, 255, 255, 255 ) )
                        table.insert( tab, pl:Nick() )
                        table.insert( tab, ": " )
                table.insert( tab, msg )
        elseif pl:IsUserGroup("trusted") then
                table.insert( tab, Color( 194, 19, 153, 255 ) )
                        table.insert( tab, "[Trusted] " )
                table.insert( tab, Color( 255, 255, 255, 255 ) )
                        table.insert( tab, pl:Nick() )
                        table.insert( tab, ": " )
                table.insert( tab, msg )
        elseif pl:IsUserGroup("supporter") then
                table.insert( tab, Color( 86, 185, 80, 255 ) )
                        table.insert( tab, "[Supporter] " )
                table.insert( tab, Color( 255, 255, 255, 255 ) )
                        table.insert( tab, pl:Nick() )
                        table.insert( tab, ": " )
                table.insert( tab, msg )
        else
                table.insert( tab, Color( 86, 185, 80, 255 ) )
                        table.insert( tab, "[User] " )
                table.insert( tab, Color( 255, 255, 255, 255 ) )
                        table.insert( tab, pl:Nick() )
                        table.insert( tab, ": " )                     
                table.insert( tab, msg )
        end
chat.AddText( unpack(tab) )
return true
        end
end
hook.Add("OnPlayerChat", "InsertTags", Insert)


I'm getting the error: /tags.lua.lua:0
[ERROR] lua/autorun/tags.lua.lua:8: unfinished string near '"headmanagement) then'  1. unknown - lua/autorun/tags.
What is this?

Offline MrPresident

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 2728
  • Karma: 430
    • |G4P| Gman4President
Re: Tags
« Reply #16 on: January 08, 2013, 04:40:05 PM »
Try this...

btw.. do you use something like Notepad++ to edit your lua? Your tabulation is atrocious. lol

Code: [Select]
if (SERVER) then
AddCSLuaFile("autorun/tags.lua")
end

if (CLIENT) then
function Insert( pl, msg )
local tab = {}
if pl:IsUserGroup("headmanagement") then
table.insert( tab, Color( 255, 0, 0, 255 ) )
table.insert( tab, "[Head Management] " )
table.insert( tab, Color( 255, 255, 255, 255 ) )
table.insert( tab, pl:Nick() )
table.insert( tab, ": " )
table.insert( tab, msg )
elseif pl:IsUserGroup("leadmanagement") then
table.insert( tab, Color( 255, 0, 0, 255 ) )
table.insert( tab, "[Lead Management] " )
table.insert( tab, Color( 255, 255, 255, 255 ) )
table.insert( tab, pl:Nick() )
table.insert( tab, ": " )
table.insert( tab, msg )
elseif pl:IsUserGroup("management") then
table.insert( tab, Color( 255, 0, 0, 255 ) )
table.insert( tab, "[Management] " )
table.insert( tab, Color( 255, 255, 255, 255 ) )
table.insert( tab, pl:Nick() )
table.insert( tab, ": " )
table.insert( tab, msg )
elseif pl:IsUserGroup("leadmoderator") then
table.insert( tab, Color( 33, 110, 252, 255 ) )
table.insert( tab, "[Lead Moderator] " )
table.insert( tab, Color( 255, 255, 255, 255 ) )
table.insert( tab, pl:Nick() )
table.insert( tab, ": " )
table.insert( tab, msg )
elseif pl:IsUserGroup("moderator") then
table.insert( tab, Color( 33, 110, 252, 255 ) )
table.insert( tab, "[Moderator] " )
table.insert( tab, Color( 255, 255, 255, 255 ) )
table.insert( tab, pl:Nick() )
table.insert( tab, ": " )
table.insert( tab, msg )
elseif pl:IsUserGroup("premium") then
table.insert( tab, Color( 245, 226, 20, 255 ) )
table.insert( tab, "[Premium] " )
table.insert( tab, Color( 255, 255, 255, 255 ) )
table.insert( tab, pl:Nick() )
table.insert( tab, ": " )
table.insert( tab, msg )
elseif pl:IsUserGroup("trusted") then
table.insert( tab, Color( 194, 19, 153, 255 ) )
table.insert( tab, "[Trusted] " )
table.insert( tab, Color( 255, 255, 255, 255 ) )
table.insert( tab, pl:Nick() )
table.insert( tab, ": " )
table.insert( tab, msg )
elseif pl:IsUserGroup("supporter") then
table.insert( tab, Color( 86, 185, 80, 255 ) )
table.insert( tab, "[Supporter] " )
table.insert( tab, Color( 255, 255, 255, 255 ) )
table.insert( tab, pl:Nick() )
table.insert( tab, ": " )
table.insert( tab, msg )
else
table.insert( tab, Color( 86, 185, 80, 255 ) )
table.insert( tab, "[User] " )
table.insert( tab, Color( 255, 255, 255, 255 ) )
table.insert( tab, pl:Nick() )
table.insert( tab, ": " )                     
table.insert( tab, msg )
end
chat.AddText( unpack(tab) )
return true
end
hook.Add("OnPlayerChat", "InsertTags", Insert)
end

Offline easer7

  • Newbie
  • *
  • Posts: 24
  • Karma: 1
Re: Tags
« Reply #17 on: January 08, 2013, 05:04:37 PM »
I do use notepad++ =( I thought notepad++ was of the highest quality, what should I use?

Offline JamminR

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 8096
  • Karma: 390
  • Sertafide Ulysses Jenius
    • Team Ulysses [ULib/ULX, other fine releases]
Re: Tags
« Reply #18 on: January 08, 2013, 08:12:07 PM »
I do use notepad++ =( I thought notepad++ was of the highest quality, what should I use?
Notepad++ is fine. Just keep your lines together.
Also, in case you missed what MrPresident did, from your error, your missing the closing quotation mark.
'"headmanagement) then' should have been  '"headmanagement") then'
Also, why use so many table.inserts?
Table manipulation is time consuming (for any programming language, even Lua).
It would be better, optimization wise, to use this ...
Code: [Select]
elseif pl:IsUserGroup("management") then
table.insert( tab, Color( 255, 0, 0, 255 ) .. "[Management] " .. Color( 255, 255, 255, 255 ) .. pl:Nick() .. ": " .. msg )
elseif ...
than what you're doing currently.
Look up "lua concatenation".
Those ".." bring together many string items.
"Though a program be but three lines long, someday it will have to be maintained." -- The Tao of Programming

Offline Megiddo

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 6214
  • Karma: 394
  • Project Lead
Re: Tags
« Reply #19 on: January 09, 2013, 09:15:10 AM »
Also, why use so many table.inserts?
Table manipulation is time consuming (for any programming language, even Lua).
It would be better, optimization wise, to use this ...
Code: [Select]
elseif pl:IsUserGroup("management") then
table.insert( tab, Color( 255, 0, 0, 255 ) .. "[Management] " .. Color( 255, 255, 255, 255 ) .. pl:Nick() .. ": " .. msg )
elseif ...
than what you're doing currently.
Look up "lua concatenation".
Those ".." bring together many string items.

It's necessary to do it the way he currently is. The color objects are not strings, and chat.AddText wants a list of string or color objects.
Experiencing God's grace one day at a time.

Offline easer7

  • Newbie
  • *
  • Posts: 24
  • Karma: 1
Re: Tags
« Reply #20 on: January 09, 2013, 04:58:30 PM »
Sorry I'm very new to this.  I've been going through the tutorials but im not done yet! :) Also, how do I get it to say |TEAM| when they talk in team chat and |DEAD| When dead players are talking? Would this work?


                if ( pl:Alive == false ) then
      table.insert( tab, Color( 255, 30, 40 ) )
      table.insert( tab, "|DEAD| " )
      end
      
      if ( bTeamOnly ) then
      table.insert( tab, Color( 30, 160, 40 ) )
      table.insert( tab, "|TEAM|" )
      end