I'm writing a datapack for a server I play on, and want to implement a feature like Xisumavoid's AFK datapack. What it does is it changes any AFK player's nametag to gray color in the tab menu, presumably by adding them to an AFK team. Unfortunately, my server already has teams on it, so I need to store the team that a player is on to put them back on it when they are no longer AFK. I have thought of a numeric method for accomplishing this, so am asking here simply to find if there is a simpler or easier way to do it other than my way, and to provide a method for doing this for future command users.
First, I give each team on the server a numeric, hard-coded integer value, from 1...n where n is the number of teams (0 can be unaffiliated/no team, and there is no number for the AFK team). Secondly, I set up a scoreboard which keeps track of a player's current team. Thirdly, in a tick function, I execute as all players on team one, setting their score in the scoreboard to 1. Same procedure for teams 2 through n. Finally, if a player has been still for long enough to be "AFK" I remove them from their team and add them to the afk team. When they move again I remove them from the AFK team and, depending on their score in the scoreboard, add them to the appropriate team (if their score is 1, they will be added to team one, same for teams 2 through n).
Is there a simpler way? If there is not I will add my function(s) here in an edit later.