ULX

Author Topic: Get a team's Color  (Read 8686 times)

0 Members and 1 Guest are viewing this topic.

Offline ahref

  • Jr. Member
  • **
  • Posts: 62
  • Karma: 4
Get a team's Color
« on: March 09, 2009, 09:07:03 AM »
I've got everything working for a custom ulx command ive been writing except that im trying to get the players team color(Im using UTeam so it thought this would be easy :()

Im using the usual code i see in all the other commands where multiple users can be used:
Code: [Select]
if #argv < 1 then
ULib.tsay( ply, ulx.LOW_ARGS )
return
end

local targets, err = ULib.getUsers( argv[ 1 ], _, true, ply ) -- Enable keywords
if not targets then
ULib.tsay( ply, err )
return
end

for _, v in ipairs( targets ) do
ULib.tsay(ply,v:Team():GetColor())
        end

The code does nothing and appears to not even load. How do i get the players team color? thanks

Offline Megiddo

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 6214
  • Karma: 394
  • Project Lead
Re: Get a team's Color
« Reply #1 on: March 09, 2009, 12:12:06 PM »
Where are you saving this code to?
Experiencing God's grace one day at a time.

Offline ahref

  • Jr. Member
  • **
  • Posts: 62
  • Karma: 4
Re: Get a team's Color
« Reply #2 on: March 09, 2009, 01:20:05 PM »
its within a function thats in a file thats in the modules directory :P.

Offline JamminR

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 8096
  • Karma: 390
  • Sertafide Ulysses Jenius
    • Team Ulysses [ULib/ULX, other fine releases]
Re: Get a team's Color
« Reply #3 on: March 09, 2009, 02:50:07 PM »
According to GetColor, the value is returned as separate integers. Not even a table (I consider that odd, but, meh)
Not too sure how tsay would see that.
Perhaps try the example shown in GetColor to save to local r,g,b,a variables, then display those variables using TSay?

As for the (seemingly) not loading, perhaps add a MsgN at the bottom of your file below the functions. Basically, if the module loads correctly within ULX, your MsgN will show a message, then ULX will say it loaded (as a filename) during SP game or server startup.


« Last Edit: March 09, 2009, 02:57:10 PM by JamminR »
"Though a program be but three lines long, someday it will have to be maintained." -- The Tao of Programming

Offline ahref

  • Jr. Member
  • **
  • Posts: 62
  • Karma: 4
Re: Get a team's Color
« Reply #4 on: March 09, 2009, 03:03:43 PM »
thanks it loads correctly if that line is removed. The rest of the function works its just getting the color. ive tried doing this:

Code: [Select]
local r,g,b,a = v:Team():GetColor()
ULib.tsay(ply,"Color: (" .. r .. ", " .. g .. ", " .. b .. ", " .. a .. ")");

this also breaks the module.

Ill try the table method

Offline JamminR

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 8096
  • Karma: 390
  • Sertafide Ulysses Jenius
    • Team Ulysses [ULib/ULX, other fine releases]
Re: Get a team's Color
« Reply #5 on: March 09, 2009, 04:26:44 PM »
Try;
Code: [Select]
local r,g,b,a = v:Team():GetColor()
local ThisTeamColor = string.format( "Color: R=%i G=%i B=%i A=%i" , r, g, b, a )
ULib.tsay(ply, ThisTeamColor )
Though concatenation (using periods to separate strings and lua variables .. var .. var ..) is fine for quick little tests, I suggest reading a tutorial explaining the different string.format functions.

"Though a program be but three lines long, someday it will have to be maintained." -- The Tao of Programming

Offline ahref

  • Jr. Member
  • **
  • Posts: 62
  • Karma: 4
Re: Get a team's Color
« Reply #6 on: March 09, 2009, 04:34:29 PM »
nope still not working. Ive moved this function into its own file and everything :(

EDIT: just tried:
Code: [Select]
ULib.tsay(ply, "hello" )
local r,g,b,a = v:Team():GetColor()
ULib.tsay(ply, "hello2" )
the module gets registered etc. I see the first hello message but nothing runs past the line that uses GetColor(). hello2 is not displayed
« Last Edit: March 09, 2009, 04:38:58 PM by ahref »

Offline JamminR

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 8096
  • Karma: 390
  • Sertafide Ulysses Jenius
    • Team Ulysses [ULib/ULX, other fine releases]
Re: Get a team's Color
« Reply #7 on: March 09, 2009, 08:17:30 PM »
There should be errors in console, most likely the server, after that function is run.
If you remove GetColor and try to tsay or Print v:Team(), what are the results?
"Though a program be but three lines long, someday it will have to be maintained." -- The Tao of Programming

Offline ahref

  • Jr. Member
  • **
  • Posts: 62
  • Karma: 4
Re: Get a team's Color
« Reply #8 on: March 10, 2009, 08:52:53 AM »
Code: [Select]
local T = v:Team()
local r,g,b,a = team.GetColor(T)
local ThisTeamColor = string.format( "Color: R=%i G=%i B=%i A=%i" , r, g, b, a )

just tried this :( still nothing

also finally got a simple error message:
Code: [Select]
local r,g,b,a = v:Team():GetColor()
ulx/modules/test.lua:20: attempt to index a number value
« Last Edit: March 10, 2009, 09:13:48 AM by ahref »

Offline JamminR

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 8096
  • Karma: 390
  • Sertafide Ulysses Jenius
    • Team Ulysses [ULib/ULX, other fine releases]
Re: Get a team's Color
« Reply #9 on: March 10, 2009, 03:15:55 PM »
I know I'm throwing out wild guesses, try team.GetColor( v:Team() )
v:Team():GetColor() should work as far as I know, but apparently its not.

NOTE: Actually, before making this post, I poked around sui_scoreboard to see how it did team colors for it's rows.
Though the above was a educated guess, ... sui_scoreboard uses it to set a variable.
tcolor = team.GetColor( self.Player:Team()  )
And tcolor.r tcolor.g and tcolor.b are used to later set a color.
What I find confusing is the fact those are used like a table (tablename.key), but, the Gmod wiki says they aren't a table.
I may have missed a conversion function though.


"Though a program be but three lines long, someday it will have to be maintained." -- The Tao of Programming

Offline ahref

  • Jr. Member
  • **
  • Posts: 62
  • Karma: 4
Re: Get a team's Color
« Reply #10 on: March 10, 2009, 03:20:54 PM »
yes it was outputing tables at one point.

Seems a bit odd. ill try the sui method


sui method works fine. Ill release the function tomorrow. Its basically the Assmod rocket but in ulx with uteam colors as a smoke trail :P. looks great if one person from every rank is online
« Last Edit: March 10, 2009, 04:08:19 PM by ahref »

Offline JamminR

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 8096
  • Karma: 390
  • Sertafide Ulysses Jenius
    • Team Ulysses [ULib/ULX, other fine releases]
Re: Get a team's Color
« Reply #11 on: March 10, 2009, 06:31:14 PM »
Nice. I've never seen ASSMod's rocket, but I've seen it requested in another recent discussion here.
One time with Gmod9, a community member (Golden Death) created a fun pack for ULX 1.
Perhaps you could continue with some more creative ideas.

If you can, write in 'generics' if the person using it doesn't have UTeam.
I have no idea what the 'default' teams are when a person joins if they aren't running some sort of team script.
If they're bland, wouldn't be too difficult to test for and change colors. :)
« Last Edit: March 10, 2009, 06:33:17 PM by JamminR »
"Though a program be but three lines long, someday it will have to be maintained." -- The Tao of Programming

Offline ahref

  • Jr. Member
  • **
  • Posts: 62
  • Karma: 4
Re: Get a team's Color
« Reply #12 on: March 11, 2009, 01:38:44 AM »
i could make it just do grey if uteam isnt being used. perhaps another color for admins or something :D

Offline JamminR

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 8096
  • Karma: 390
  • Sertafide Ulysses Jenius
    • Team Ulysses [ULib/ULX, other fine releases]
Re: Get a team's Color
« Reply #13 on: March 11, 2009, 05:12:35 PM »
Thats a good idea. Perhaps just for defaults, use Garry's original scoreboard colors ranked by groups.
The green for super, the blue for non-super, etc. I've never actually looked at it, but presume its not far off from sui (or I should say, sui prob isn't far off from original Gmod scorboard. :)
"Though a program be but three lines long, someday it will have to be maintained." -- The Tao of Programming