Player team isn't cleared after rejoin

EDIT:
Please read the posts on the bottom.

Well, you haven’t been that descriptive about your issue.
What gamemode are you running? Or is it custom?
Also, you could try using the PlayerInitialSpawn hook to set the user’s team to whatever ‘spectator’ like team you have.

I believe the first step when indicating you have an error is to give us the error code, and even possibly the code where the error says it is coming from.

After we have the code, then we can properly diagnose your problem and help you resolve it.

It’s a custom gamemode I’m working on ( https://github.com/Newbrict/ObjHunt )

I actually DO have the player set to TEAM_SPECTATOR in the PlayerInitialSpawn hook… with or without it, there is no change.

The errors are caused by the team being incorrect, I set up certain things on team change which prevent the errors.

the problem is that when I join my team is the team I was prior to leaving, for a few moments…

[editline]14th July 2014[/editline]

Update:
This is what my PlayerInitialSpawn looks like now



function GM:PlayerInitialSpawn( ply )
	print( "Start PlayerInitialSpawnHook, player's team:" )
	print( ply:Team() )
	player_manager.SetPlayerClass( ply, "player_spectator" )
	print( "End PlayerInitialSpawnHook, player's team:" )
	print( ply:Team() )
end


Both times it prints 0 for the team, which is for unconnect.
After both of those prints It seems that the player’s team switches for a moment and then back to spectator…

So I’m still pulling my eyeballs out with this issue. Here’s what I’ve since discovered

On a server restart and join, there are NO errors.

When I join and reconnect, there are NO errors.

When I join, then switch team to any non spectator team, then rejoin:
the players team gets properly changed to the spectator team, then goes to the team the player was prior to leaving for JUST A FEW SERVER TICKS, then goes back to the spectator team…

during those few ticks, I get a few errors due to the player having not properly switched teams and initializing some vars for that team.

I tried messing around with some of the network messages I do, shouldn’t be causing this.

Anyone have ideas why the team would quickly change to your last team for a few ticks then back on rejoin?

[editline]15th July 2014[/editline]

I’ve been stripping the game mode down into only the parts that I need, and the bug is STILL happening…

It’s so barren right now you could read through all the code in a 2 minutes, but the same bug still happens.

https://github.com/Newbrict/ObjHunt/tree/teambug

The only thing I can possibly think of is I’m somehow setting the team incorrectly…
It’s a client sided issue since I checked per server tick to see if the player hops teams but they do not.
however the player things they do for those few frames.

turning into a team, leaving, joining a different server, then joining back doesn’t alleviate the issue either…

https://github.com/Newbrict/ObjHunt/tree/teambug

Post step-by-step way to reproduce your “bug”.
Explain what exactly the bug is.

I went through the code, and the issue which seems nonexistent.

The issue is explained as the local player team is the same as props on re connect if disconnect and reconnect. This is not the case.

The error on the stripped gm points to


local function getViewEnt(ply)
	local trace = {}
	trace.start = ply.viewOrigin

meaning that variable isn’t set. I got the error on stripped but not master. I advised to add || Vector( 0, 0, 0 ) to the end of the trace.start line which resolved the error on the stripped gm version.

Additionally, I advised to add if ( !IsValid( LocalPlayer( ) ) ) then return; end to all hooks which run or may run before the player is fully in game.

Additionally, I noticed on the stripped gm that the SHARED file which declares the team values which relates to the stack calling:


if( LocalPlayer():Team() != TEAM_PROPS ) then return end

because TEAM_PROPS is not set to 1 until the shared file is loaded.

The file was LAST in line to be included, I told New that any CONSTs / Enumerations should always be loaded first, because the claim that the LocalPlayer( ):Team( ) is the same as the TEAM_PROPS story may be true ( or in the case of the logic the LocalPlayer( ):Team( ) != nil causing the code which caused the error to run ).

Didn’t seem to apply any of the logic and kept insisting I join his server even though I could not replicate the error on the master copy of his GM, and on the stripped copy I found a viable solution ( || Vector( 0, 0, 0 ) ). Kept insisting the error was the LocalPlayer Team was the same as TEAM_PROPS for a few ticks when the player joins, saying the error wasn’t with the viewOrigin, then saying it was the error… Confusing to work with, not clear with questions, runs in circles. Tried using Steam Call feature after I refused to join server.

I tried guiding Acecool through the steps to test the problem but he refused to listen to what the issue was and instead picked at other pieces of code unrelated to the issue.

Here is how to replicate the issue.
1.Download https://github.com/Newbrict/ObjHunt/tree/teambug and put it in your gamemodes folder

2.Start a local server on ObjHunt

3.Connect to the server

4.Press F1 ( At this point you will get errors, they are not important, I stripped out a lot of code to simplify the problem as much as possible. the errors are because the players on TEAM_PROPS need to have a bunch of vars set to initialize them properly, which happens on the non-stripped version of the code )

  1. Reconnect
    ******* This is the step where the bug is seen ********
    Most of the time, after reconnect I will get a few errors like this:


[ERROR] gamemodes/objhunt/gamemode/client/views.lua:34: bad argument #1 to '__add' (Vector expected, got nil)
  1. __add - [C]:-1
   2. getViewEnt - gamemodes/objhunt/gamemode/client/views.lua:34
    3. v - gamemodes/objhunt/gamemode/client/views.lua:44
     4. Run - lua/includes/modules/hook.lua:84
      5. v - lua/includes/modules/halo.lua:163
       6. unknown - lua/includes/modules/hook.lua:84


These errors should not happen because views.lua:34 is in my getViewEnt function
which is ONLY called in this piece of code



hook.Add( "PreDrawHalos", "Selectable Prop Halos", function()
	if ( !IsValid( LocalPlayer( ) ) ) then return; end
	if( LocalPlayer():Team() != TEAM_PROPS ) then return end
	local prop = getViewEnt( LocalPlayer() )
	local sColor = stencilColor( LocalPlayer(), prop ) 
	if( !sColor ) then return end
	halo.Add( {prop}, sColor, 3, 3, 1 )
end )


as you can see, since the player upon rejoining should be on TEAM_SPECTATOR it should NEVER pass through the first line of that hook.

HOWEVER, the client thinks that it’s on TEAM_PROPS for just a few ticks which produces the few errors I see on reconnect.

Caveats
If I join as and rejoin, there are no errors ( sans F1 )

If I join and press F1 ( switches to TEAM_PROPS ) then restart the server and rejoin there is no error

If I join, press F1, then connect to a different server, then connect back to my server there ARE errors.

I hope this describes the issue thoroughly

I reproduced your error, and got the it as soon as I pressed F1. I then tried Acecool’s solution, and it works now.

The error is not the problem ( directly ) the problem is the error should not occur because the code is UNREACHABLE unless the player is on TEAM_PROPS

you need to follow through to step 5 to get the error(bug) I’m talking about.

I’ve been doing steps one to five about 10 times. Also you mention a local server, as in, listen? Or a locally hosted dedicated server? I’m doing my testing on the latter.

The latter is correct.
Could you add me on steam http://steamcommunity.com/id/Newbrict
or connect to gmod.dimit.me

so I can figure out what you’re doing.

[editline]16th July 2014[/editline]

I am tired of dealing with this, I gave in and decided to add the redundant checks.