[ANY] How to properly switch team
Introduction:
This snippet is aimed at those not willing to use ChangeClientTeam due to undesired side effects, but still wish to change a player team. And without any crash! How to find out if you're concerned: If you're doing Code:
I was myself doing it and that's how I found how to fix it as well why I'm making this snippet :crab: Here's a list of plugins I can think of that are/were affected by the crash(all from tf2 but I'm sure it's happening on other games): How to fix: Luckily the solution is very simple: Code:
Gamedata (for tf2, I leave you find the correct team entity classname and offsets for other games) Code:
More details on the crash: In source MP games, each team is governed by an entity. Those entities contains an array of CBasePlayer *, of course when ChangeClientTeam is called everything is properly handled and the player pointer is removed from one, and added to the other. However some plugins want to move players to spec team but keep them alive, which is impossible to do with ChangeClientTeam even by changing the player alive state, as they will be forcibly be put in observer mode. So most will do: PHP Code:
Here's a piece code I reversed from TF2 server. Code:
That's all, thanks for reading, hopefully you learned something or you knew already either way my job is done here :bacon: |
Re: [ANY] How to properly switch team
If the undesired affects you are referring to is the suicide, you can avoid that simply by doing something like the following:
PHP Code:
|
Re: [ANY] How to properly switch team
Quote:
Quote:
code reference #1 code reference #2 |
Re: [ANY] How to properly switch team
Benoist3012, tried your code. Works great. Thanks!
|
Re: [ANY] How to properly switch team
Quote:
Code:
if ( iTeamNum == TEAM_UNASSIGNED ) |
Re: [ANY] How to properly switch team
Quote:
|
Re: [ANY] How to properly switch team
Quote:
It's aimed at people who can't use ChangeClientTeam due to undesired side effects. Force death is something you can avoid with the code you sent but it is not enough to avoid forced observer mode or whatever else the game code might have. :nono: |
Re: [ANY] How to properly switch team
Quote:
|
Re: [ANY] How to properly switch team
Quote:
to be frank. :bee: And yeah that's fine, perhaps I should have made the first post clearer. |
Re: [ANY] How to properly switch team
For switch to spectator team, you can just use that :
PHP Code:
If you want to change team but not in spectator, just use this Quote:
|
All times are GMT -4. The time now is 11:14. |
Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.