Only 1 Hotspot Id Can Login Together - MikroTik Script RouterOS

Make Sure that only 1 hotspot ID can log in together, if there are 2 IDs that are logged in, it will automatically turn off the first ID (note: not for multi shared users). This script is also great if we want to switch logins to other devices without having to log out and wait for the session timeout on the previous device.
Before it is installed, at least we don't understand the concept of the work of the script, don't just take it out and paste it, instead the hotspot error :)

Please install it directly on the IP -> hotspot -> User Profile -> select the profile name -> Script -> On Login

Hotspot Profile On Login

# Local Variables Section
:local uname $user;
:local usercount 0;
:local usertime "00:00:00";
# Variable for previously logged in users
:local kickable;
# Variable for max user allowed sessions, if 2 means only one session is allowed at a time
:local maxuser 2;
# Loads all active users on the hotspot
:foreach i in=[/ip hotspot active find user=$uname] do= {
# UPTIME loads for all users and for later matches
:local curup [/ip hotspot active get $i uptime];
# If the same user was previously matched using UPTIME [above then 0] then assign global variables to break
:if ( $curup > $usertime ) do={
:set usertime $curup;
:set kickable $i;
}
:set usercount ($usercount+1);
}
# IF Function Function for logged in users,
:if ($usercount = $maxuser) do={
:log info "Login user: $uname ($usercount/$maxuser) - Oldest $usertime will be logout!";
# Kick the previous login user (if the ID is the same)
/ip hotspot active remove numbers=$kickable;
# If not, do nothing, just log in, you can modify this function too
} else {
:log info "Login user: $uname ($usercount/$maxuser)";
Credit: www.o-om.com