[Plugin] AreaSwitch

AreaSwitcher automatically adjusts the training area to ‘MOBS’
for characters with predefined names upon joining the game, initiating the bot after a 20-second delay designed for use on unstable servers or for users who faces multiple disconnects hope it helps someone

from phBot import *
from threading import Timer

# Generate the list of character names
character_names = ['PhBot_v2_' + str(i) for i in range(1, 41)]

def set_area_plugin(args):
    set_training_area(args)
    log('[' + plugin_name + '] Script area changed to [' + args + ']')
    Timer(25.0, start_bot).start()  # Start bot after 25 seconds
    return 0

# Function called when the user successfully selects a character
def joined_game():
    # Get the character name
    character_name = get_character_data()['name']
    
    # Check if the character name is in the list
    if character_name in character_names:
        log('[' + plugin_name + '] Character [' + character_name + '] joined. Setting area to MOBS with a delay of 20 seconds.')
        Timer(20.0, set_area_plugin, args=['MOBS']).start()  # Set area to MOBS after 20 seconds
    else:
        log('[' + plugin_name + '] Character [' + character_name + '] joined. Bot start skipped.')
    
    return 0

# Plugin name
plugin_name = 'AreaSwitch'

# Plugin loaded message
log('[' + plugin_name + '] Plugin loaded.')

# Start the bot immediately upon loading the plugin only for specific characters
character_name = get_character_data()['name']
if character_name in character_names:
    joined_game()
else:
    log('[' + plugin_name + '] Character [' + character_name + '] loaded. Bot start skipped.')