how to get team by TEAM_ name?

i have been messing around with this for almost 4 hours trying different ways and i cant seem to figure it out,

for example i would like to get the number of TEAM_SPECTATOR (1002 is returned by ply:Team() )

i want to look for a team by its name not by its number (i dont know the number of the teams i am looking for and i dont want to have to figure out the number every time

something like ply:teamnametoid(TEAM_RED) that returns 1
where this ply:teamnametoid(TEAM_BLUE) would return 2

umm i am confused…
TEAM_BLUE is just a key in the global table that has a value of whatever you put, probably your team number.
you can literally do print(TEAM_BLUE)

that returns the stringname “Deathmatch Red”

Re read my post. I edited it since I was confused.

and its getting the name with the number i need to get the number with the name

do print(TEAM_BLUE)

TEAM_BLUE is actually a number

ok wtf… lol i swear i did this… let me play around with my code some more and il try to figure out the real issue.

thank you

[editline]28th February 2015[/editline]

yep i feel like an idiot that worked perfectly, sometimes things that should be SO SIMPLE take me hours lol

[editline]28th February 2015[/editline]

stupid overthinking things XD

[editline]28th February 2015[/editline]

think my issue was trying to pull TEAM_DMBLUE from a table that was defined higher up, will just not try to table it

[editline]28th February 2015[/editline]

[lua]
team1 = TEAM_DMRED
team2 = TEAM_DMBLUE
team1color = Color(255,0,0,255) --Red (default: Color(255,0,0,255) ) set to Color(255,255,255,255) to disable colouring teams
team2color = Color(0,0,255,255) --Blue (default: Color(0,0,255,255) ) set to Color(255,255,255,255) to disable colouring teams


– Do not edit below this line unless you know what you are doing –

– (ply:Team() == 21 or ply:Team() == 20)
hook.Add(“PlayerSpawn”, “Playerspawn”, function(ply)
if IsValid(ply) and ((ply:Team() == team1) or (ply:Team() == team2)) then
timer.Simple( 0, function()
ply:StripWeapons()
for k, v in pairs(spawnweapons) do
ply:Give(v)
end
end)
end
end)
[/lua]

[editline]28th February 2015[/editline]

my issue seems to be trying to define team1 as TEAM_DMRED

its just ignoring this bit of code and raping my whole setup

[editline]28th February 2015[/editline]

but if i set ply:Team() == team1 to ply:Team() == TEAM_DMRED

It works just fine…

[editline]28th February 2015[/editline]

i really need that variable bc i call team1 in about 20 different spots

Snpe

Still cant figure this out…

Post your whole code so we can see what you’ve done wrong. We can’t really do much other than make assumptions.

that is all you should need, the variable is defined and being called yet its not being assigned TEAM_DMBLUE or red

[editline]28th February 2015[/editline]

if you want me to post 500 lines of code so you can fiddle with it then add me on steam otherwise its a waste of everyones time

so: team.GetName( ply:Team( ) ); will return the name such as Spectators.

Make sure you’re creating your teams in a SHARED file, preferably in the GM:CreateTeams hook.

get name returns the string name i need the variable TEAM_ name. or would prefer it

ply:Team( ) gives you the enumeration value / team key used in the team.* functions.

if you print ply:Team() you get the team number not the TEAM_ i need to be able to set a variable as TEAM_DMRED and have it return the team number




TEAM_BLAH = 2
team.SetUp(TEAM_BLAH, "Crep team", Color(255, 0, 0))



Not sure if thats what you mean, but you can do it like that if you want to

Why do you need to return the string version of TEAM_* ???

Enumeration means to give value to the NAME of the variable, not the value. So, if you need to check if something is on a team or to compare it, you use [ TEAM_* ] in tables to set up a table that it can use, not TEAM_* = because then it’d be the string and then you’d need to write a work-around just to get the string value.

I’d recommend re-thinking the problem, or telling us the end-goal for what you’re trying to accomplish. There is likely a far easier / more-efficient method of doing it.

i am telling exactly what i am trying to do thats the thing,
with that code

team1 should = the same value as TEAM_DMRED
yet when i try to compair its value to anything (team1) it doesnt return anything

[editline]28th February 2015[/editline]

i do not want to return the string version i want to set a variable to TEAM_DMRED and then call that variable

Even though all the posts in this thread are saying about the same thing, I’ll give my own explanation.

In the beginning, gamemodes set a variable, usually starting with TEAM_ to a number. This number is rarely used, but it allows you to use this TEAM_ variable instead of a number which is easier to remember. Then, the gamemode calls team.SetUp using that variable as the index, filling in the name, color, etc. which associates the data with the TEAM_ variable (number). Calling ply:Team() returns the team index (the value of the TEAM_ variable) of the player. Calling team.GetColor or team.GetName will return the data you filled in with team.SetUp or team.SetWhatever.

For example:
Say we have a team variable, TEAM_MYTEAM. team.SetUp using that index so we can set a player to it.
We call player1:SetTeam(TEAM_MYTEAM) and player1’s team data is now that of TEAM_MYTEAM.
If we call print(player1:GetTeam()) it will return whatever we set TEAM_MYTEAM to (number).
So if we do print(player1:GetTeam() == TEAM_MYTEAM) that will return true.

okay, have you tried doing that?

[lua]TEAM_DMRED = 123[/lua]

simple as that

Teams should be created in a shared file, in GM:CreateTeams…

Example:


TEAM_X = 1;

function GM:CreateTeams( )
	// team.SetUp( number teamIndex, string teamName, table teamColor, boolean isJoinable=true ) 
	team.SetUp( TEAM_X, "Team X, color_white );
end

Because TEAM_X is global, it can be referenced / used in ANY file or function. The trick is, if a file uses local x = TEAM_X; and tries referencing it PRIOR to the shared teams file being included, then TEAM_X will NOT exist to be assigned to x meaning x == nil. If you use TEAM_X in a hook / function, chances are it will have been set and loaded and you should have absolutely no errors.

There are some notes… ADDONS/ are loaded PRIOR to game-modes. If you use TEAM_ variables in an addon, it won’t work without a work-around, see my anti team-damage code: https://dl.dropboxusercontent.com/u/26074909/tutoring/_systems/simple_antI_teamkill_system/anti_teamkill_system_with_failsafe.lua.html

It adds a hook, and in that hook it checks to see if the rest of the data this addon needs has been set up. If not, it creates the table ( whereby, in that moment that it creates the table, TEAM_* will have been already loaded so they will be valid to be used )…

Older versions were plagued with problems because I didn’t realize how early addons were being loaded; and a few stupid mistakes such as hook.Add is called prior to GM:… meaning these were set up to fail: https://dl.dropboxusercontent.com/u/26074909/tutoring/_systems/anti_teamkill_system.lua.html