Get Started - Learn How To Make Your Bot!

Guides

Code Snippets

Get methods

Post methods

Web API

Useful links

List of all currently Free Items

List of Emotes

Highrise Bot SDK Changelog


Concept

This is a simple code to Teleport a given player to a given coordinate.

Highrise 2023-07-23 22-21-45.mp4

Required Libraries

Code

The code includes comments on how the code works and what it’s doing

from highrise import *
from highrise.models import *

class Bot(BaseBot):
    async def on_start(self, SessionMetadata: SessionMetadata)-> None:
        print (f"Starting: {SessionMetadata}")
        
    async def on_chat(self, user: User, message: str)-> None:
        print (f"Received: {message} from {user.username}")
        if message.startswith("/teleport "):
            await self.teleport(message)
        
        
    async def teleport(self, message: str)-> None:
        """
            Teleports the user to the specified user or coordinate
            Usage: /teleport <username> <x,y,z>
                                                                """
        #separates the message into parts
        #part 1 is the command "/teleport"
        #part 2 is the name of the user to teleport to (if it exists)
        #part 3 is the coordinates to teleport to (if it exists)
        try:
            command, username, coordinate = message.split(" ")
        except:
            await self.highrise.chat("Incorrect format, please use /teleport <username> <x,y,z>")
            return
        
        #checks if the user is in the room
        room_users = (await self.highrise.get_room_users()).content
        for user in room_users:
            if user[0].username.lower() == username.lower():
                user_id = user[0].id
                break
        #if the user_id isn't defined, the user isn't in the room
        if "user_id" not in locals():
            await self.highrise.chat("User not found, please specify a valid user and coordinate")
            return
            
        #checks if the coordinate is in the correct format (x,y,z)
        try:
            x, y, z = coordinate.split(",")
        except:
            await self.highrise.chat("Coordinate not found or incorrect format, please use x,y,z")
            return
        
        #teleports the user to the specified coordinate
        await self.highrise.teleport(user_id = user_id, dest = Position(float(x), float(y), float(z)))