Ulysses
General => Developers Corner => Topic started by: ahref 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:
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
-
Where are you saving this code to?
-
its within a function thats in a file thats in the modules directory :P.
-
According to GetColor (http://wiki.garrysmod.com/wiki/?title=Entity.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.
-
thanks it loads correctly if that line is removed. The rest of the function works its just getting the color. ive tried doing this:
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
-
Try;
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.
-
nope still not working. Ive moved this function into its own file and everything :(
EDIT: just tried:
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
-
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?
-
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:
local r,g,b,a = v:Team():GetColor()
ulx/modules/test.lua:20: attempt to index a number value
-
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.
-
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
-
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. :)
-
i could make it just do grey if uteam isnt being used. perhaps another color for admins or something :D
-
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. :)