├── .gitignore ├── LICENSE ├── README.md ├── config ├── Agent.py ├── AgentConfig.json ├── appearance.cfg ├── bot.cfg └── requirements.txt ├── index.ts ├── package.json └── pnpm-lock.yaml /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | config/__pycache__ -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright © 2021 Simon Lindgren 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 4 | 5 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 6 | 7 | THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # EasyRLBotExample 2 | 3 | This is a example of RLBot in node.js using the EasyRLBot library. 4 | 5 | ## Setup / Installation 6 | 7 | First make sure you have node.js and npm installed (in your path). Then follow the steps below. 8 | 9 | 1. Clone this repo and cd into it 10 | 2. Install dependencies using npm. (`npm i`) 11 | 3. Add bot.cfg in RLBotGUI 12 | 13 | ## EasyRLBot documentation 14 | 15 | [github.com/RLBot/EasyRLBot/wiki](https://github.com/RLBot/EasyRLBot/wiki) 16 | -------------------------------------------------------------------------------- /config/Agent.py: -------------------------------------------------------------------------------- 1 | # This file is copied from RLBotJS by SuperVK. Some minor changes were made to make it compatible with this codebase. 2 | 3 | import os 4 | import socket 5 | import time 6 | import subprocess 7 | import json 8 | 9 | from rlbot.agents.base_independent_agent import BaseIndependentAgent 10 | from rlbot.botmanager.helper_process_request import HelperProcessRequest 11 | from rlbot.utils.structures import game_interface 12 | 13 | 14 | class BaseJavaScriptAgent(BaseIndependentAgent): 15 | 16 | def __init__(self, name, team, index): 17 | super().__init__(name, team, index) 18 | self.config = self.read_config_from_file() 19 | self.port = self.config["port"] 20 | self.is_retired = False 21 | 22 | self.runner = None 23 | if self.config["autoStart"]: 24 | try: 25 | self.runner = subprocess.Popen(self.config["startCommand"].split(" "), shell=True) 26 | except Exception as e: 27 | self.runner = None 28 | self.logger.error(f"A JavaScript bot with the name of {self.name} will need to be started manually. Error when running startCommand: {str(e)}.") 29 | 30 | def run_independently(self, terminate_request_event): 31 | 32 | while not terminate_request_event.is_set(): 33 | message = f"add\n{self.index}" 34 | 35 | try: 36 | s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) 37 | s.connect(("127.0.0.1", self.port)) 38 | s.send(bytes(message, "ASCII")) 39 | s.close() 40 | except ConnectionRefusedError: 41 | self.logger.warn("Could not connect to server! Searching on port " + str(self.port)) 42 | 43 | time.sleep(1) 44 | else: 45 | self.retire() 46 | 47 | # def get_helper_process_request(self): 48 | # return HelperProcessRequest(python_file_path=None, key=self.name + str(self.port), executable=self.auto_run_path) 49 | 50 | def retire(self): 51 | port = self.port 52 | message = f"remove\n{self.index}" 53 | 54 | try: 55 | s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) 56 | s.connect(("127.0.0.1", port)) 57 | s.send(bytes(message, "ASCII")) 58 | s.close() 59 | except ConnectionRefusedError: 60 | self.logger.warn("Could not connect to server!") 61 | 62 | if self.runner is not None: 63 | self.logger.info(f"Killing auto run process for bot {self.name}...") 64 | try: 65 | self.runner.kill() 66 | self.logger.info("Success!") 67 | except Exception as e: 68 | self.logger.error(f"A JavaScript bot with the name of {self.name} will need to be ended manually. **YOU MAY NEED TO RESTART RLBOT.** Error when running trying to kill the bot manager: {str(e)}.") 69 | else: 70 | self.logger.error(f"A JavaScript bot with the name of {self.name} will need to be ended manually because it was not auto ran.") 71 | 72 | self.is_retired = True 73 | 74 | def read_config_from_file(self): 75 | try: 76 | location = self.get_config_file_path() 77 | 78 | with open(location) as f: 79 | return json.load(f) 80 | 81 | except ValueError: 82 | self.logger.warn("Failed to parse config file!") 83 | raise 84 | 85 | def get_config_file_path(self): 86 | return os.path.realpath(os.path.join(os.getcwd(), os.path.dirname(__file__), './AgentConfig.json')) 87 | -------------------------------------------------------------------------------- /config/AgentConfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "port": 3215, 3 | "autoStart": false, 4 | "startCommand": "npm start" 5 | } 6 | -------------------------------------------------------------------------------- /config/appearance.cfg: -------------------------------------------------------------------------------- 1 | [Bot Loadout] 2 | # Primary Color selection 3 | team_color_id = 35 4 | # Secondary Color selection 5 | custom_color_id = 90 6 | # Car type (Octane, Merc, etc) 7 | car_id = 23 8 | # Type of decal 9 | decal_id = 0 10 | # Wheel selection 11 | wheels_id = 363 12 | # Boost selection 13 | boost_id = 46 14 | # Antenna Selection 15 | antenna_id = 0 16 | # Hat Selection 17 | hat_id = 0 18 | # Paint Type (for first color) 19 | paint_finish_id = 0 20 | # Paint Type (for secondary color) 21 | custom_finish_id = 0 22 | # Engine Audio Selection 23 | engine_audio_id = 0 24 | # Car trail Selection 25 | trails_id = 3220 26 | # Goal Explosion Selection 27 | goal_explosion_id = 0 28 | # Finds the closest primary color swatch based on the provided RGB value like [34, 255, 60] 29 | primary_color_lookup = None 30 | # Finds the closest secondary color swatch based on the provided RGB value like [34, 255, 60] 31 | secondary_color_lookup = None 32 | 33 | [Bot Loadout Orange] 34 | # Primary Color selection 35 | team_color_id = 34 36 | # Secondary Color selection 37 | custom_color_id = 90 38 | # Car type (Octane, Merc, etc) 39 | car_id = 23 40 | # Type of decal 41 | decal_id = 0 42 | # Wheel selection 43 | wheels_id = 363 44 | # Boost selection 45 | boost_id = 46 46 | # Antenna Selection 47 | antenna_id = 0 48 | # Hat Selection 49 | hat_id = 0 50 | # Paint Type (for first color) 51 | paint_finish_id = 0 52 | # Paint Type (for secondary color) 53 | custom_finish_id = 0 54 | # Engine Audio Selection 55 | engine_audio_id = 0 56 | # Car trail Selection 57 | trails_id = 3220 58 | # Goal Explosion Selection 59 | goal_explosion_id = 0 60 | # Finds the closest primary color swatch based on the provided RGB value like [34, 255, 60] 61 | primary_color_lookup = None 62 | # Finds the closest secondary color swatch based on the provided RGB value like [34, 255, 60] 63 | secondary_color_lookup = None 64 | 65 | [Bot Paint Blue] 66 | # car_paint_id 67 | car_paint_id = 12 68 | # decal_paint_id 69 | decal_paint_id = 0 70 | # wheels_paint_id 71 | wheels_paint_id = 3 72 | # boost_paint_id 73 | boost_paint_id = 0 74 | # antenna_paint_id 75 | antenna_paint_id = 0 76 | # hat_paint_id 77 | hat_paint_id = 0 78 | # trails_paint_id 79 | trails_paint_id = 0 80 | # goal_explosion_paint_id 81 | goal_explosion_paint_id = 0 82 | 83 | [Bot Paint Orange] 84 | # car_paint_id 85 | car_paint_id = 12 86 | # decal_paint_id 87 | decal_paint_id = 0 88 | # wheels_paint_id 89 | wheels_paint_id = 3 90 | # boost_paint_id 91 | boost_paint_id = 0 92 | # antenna_paint_id 93 | antenna_paint_id = 0 94 | # hat_paint_id 95 | hat_paint_id = 0 96 | # trails_paint_id 97 | trails_paint_id = 0 98 | # goal_explosion_paint_id 99 | goal_explosion_paint_id = 0 100 | 101 | -------------------------------------------------------------------------------- /config/bot.cfg: -------------------------------------------------------------------------------- 1 | [Locations] 2 | # Path to loadout config. Can use relative path from here. 3 | looks_config = appearance.cfg 4 | 5 | # Path to python file. Can use relative path from here. 6 | python_file = ./Agent.py 7 | 8 | 9 | requirements_file = ./requirements.txt 10 | 11 | # Name of the bot in-game 12 | name = Example bot 13 | 14 | # The maximum number of ticks per second that your bot wishes to receive. 15 | maximum_tick_rate_preference = 120 16 | 17 | # Bot logo 18 | # logo_file = ./Logo.png 19 | 20 | [Details] 21 | # These values are optional but useful metadata for helper programs 22 | # Name of the bot's creator/developer 23 | developer = Unknown 24 | 25 | # Short description of the bot 26 | description = A basic javascript rocket league bot. 27 | 28 | # Fun fact about the bot 29 | fun_fact = This is an example 30 | 31 | # Link to github repository 32 | github = https://github.com/RLBot/EasyRLBotExample 33 | 34 | # Programming language 35 | language = Javascript (Node.js and EasyRLBot) 36 | -------------------------------------------------------------------------------- /config/requirements.txt: -------------------------------------------------------------------------------- 1 | # Include everything the framework requires 2 | # You will automatically get updates for all versions starting with "1.". 3 | rlbot==1.* 4 | -------------------------------------------------------------------------------- /index.ts: -------------------------------------------------------------------------------- 1 | import { 2 | Client, 3 | Manager, 4 | Controller, 5 | GameTickPacketT, 6 | FieldInfoT, 7 | BallPredictionT, 8 | } from "easyrlbot"; 9 | 10 | class ExampleBot extends Client { 11 | constructor(botIndex: number, ...args: any[]) { 12 | super(botIndex, ...args); // Do not change this except if you know what you are doing. 13 | } 14 | getOutput( 15 | gameTickPacket: GameTickPacketT, 16 | fieldInfo: FieldInfoT, 17 | ballPrediction: BallPredictionT 18 | ) { 19 | let controller = new Controller(); // Create a new controller 20 | 21 | if ( 22 | !ballPrediction || 23 | !gameTickPacket.players[this.botIndex] || 24 | !gameTickPacket.ball || 25 | !gameTickPacket.ball.physics?.location 26 | ) 27 | return; // Return if needed information is not provided 28 | 29 | // Define target and car physics 30 | let target = gameTickPacket.ball.physics; // Set targeted location to ball 31 | let car = gameTickPacket.players[this.botIndex].physics; 32 | 33 | if (!target.location || !car?.location || !car.rotation) return; // Return if needed information is not provided 34 | 35 | // Calculate angle 36 | let botToTargetAngle = Math.atan2( 37 | target.location.y - car.location.y, 38 | target.location.x - car.location.x 39 | ); 40 | 41 | // Angle relative to car 42 | let botFrontToTargetAngle = botToTargetAngle - car.rotation.yaw; 43 | 44 | // Correct angle 45 | if (botFrontToTargetAngle > Math.PI) botFrontToTargetAngle -= 2 * Math.PI; 46 | if (botFrontToTargetAngle < -Math.PI) botFrontToTargetAngle += 2 * Math.PI; 47 | 48 | // Calculate distance in 2D between car and ball 49 | let targetDistance2D = Math.round( 50 | Math.sqrt( 51 | Math.pow(target.location.x - car.location.x, 2) + 52 | Math.pow(target.location.y - car.location.y, 2) 53 | ) 54 | ); 55 | 56 | // Steer the car in the targeted direction 57 | if (botFrontToTargetAngle > 0) { 58 | controller.steer = 1; 59 | } else { 60 | controller.steer = -1; 61 | } 62 | 63 | // If distance to target is more than 2500 then boost 64 | if (targetDistance2D > 2500) { 65 | controller.boost = true; 66 | } 67 | 68 | // Drive forward 69 | controller.throttle = 1; 70 | 71 | // Send controller to RLBot 72 | this.controller.sendInput(controller); 73 | } 74 | } 75 | 76 | let manager = new Manager( 77 | ExampleBot, 78 | require("./config/AgentConfig.json").port 79 | ); 80 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "easyrlbotexample", 3 | "version": "0.1.3", 4 | "description": "Example of a Rocket League bot using EasyRLBot", 5 | "main": "index.js", 6 | "scripts": { 7 | "start": "ts-node index && exit" 8 | }, 9 | "author": "Simon Lindgren", 10 | "license": "MIT", 11 | "dependencies": { 12 | "easyrlbot": "^1.0.3", 13 | "ts-node": "^10.9.1", 14 | "typescript": "^4.2.2" 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /pnpm-lock.yaml: -------------------------------------------------------------------------------- 1 | lockfileVersion: '6.0' 2 | 3 | settings: 4 | autoInstallPeers: true 5 | excludeLinksFromLockfile: false 6 | 7 | dependencies: 8 | easyrlbot: 9 | specifier: ^1.0.3 10 | version: 1.0.3 11 | ts-node: 12 | specifier: ^10.9.1 13 | version: 10.9.1(@types/node@20.6.0)(typescript@4.9.5) 14 | typescript: 15 | specifier: ^4.2.2 16 | version: 4.9.5 17 | 18 | packages: 19 | 20 | /@cspotcode/source-map-support@0.8.1: 21 | resolution: {integrity: sha512-IchNf6dN4tHoMFIn/7OE8LWZ19Y6q/67Bmf6vnGREv8RSbBVb9LPJxEcnwrcwX6ixSvaiGoomAUvu4YSxXrVgw==} 22 | engines: {node: '>=12'} 23 | dependencies: 24 | '@jridgewell/trace-mapping': 0.3.9 25 | dev: false 26 | 27 | /@jridgewell/resolve-uri@3.1.1: 28 | resolution: {integrity: sha512-dSYZh7HhCDtCKm4QakX0xFpsRDqjjtZf/kjI/v3T3Nwt5r8/qz/M19F9ySyOqU94SXBmeG9ttTul+YnR4LOxFA==} 29 | engines: {node: '>=6.0.0'} 30 | dev: false 31 | 32 | /@jridgewell/sourcemap-codec@1.4.15: 33 | resolution: {integrity: sha512-eF2rxCRulEKXHTRiDrDy6erMYWqNw4LPdQ8UQA4huuxaQsVeRPFl2oM8oDGxMFhJUWZf9McpLtJasDDZb/Bpeg==} 34 | dev: false 35 | 36 | /@jridgewell/trace-mapping@0.3.9: 37 | resolution: {integrity: sha512-3Belt6tdc8bPgAtbcmdtNJlirVoTmEb5e2gC94PnkwEW9jI6CAHUeoG85tjWP5WquqfavoMtMwiG4P926ZKKuQ==} 38 | dependencies: 39 | '@jridgewell/resolve-uri': 3.1.1 40 | '@jridgewell/sourcemap-codec': 1.4.15 41 | dev: false 42 | 43 | /@tsconfig/node10@1.0.9: 44 | resolution: {integrity: sha512-jNsYVVxU8v5g43Erja32laIDHXeoNvFEpX33OK4d6hljo3jDhCBDhx5dhCCTMWUojscpAagGiRkBKxpdl9fxqA==} 45 | dev: false 46 | 47 | /@tsconfig/node12@1.0.11: 48 | resolution: {integrity: sha512-cqefuRsh12pWyGsIoBKJA9luFu3mRxCA+ORZvA4ktLSzIuCUtWVxGIuXigEwO5/ywWFMZ2QEGKWvkZG1zDMTag==} 49 | dev: false 50 | 51 | /@tsconfig/node14@1.0.3: 52 | resolution: {integrity: sha512-ysT8mhdixWK6Hw3i1V2AeRqZ5WfXg1G43mqoYlM2nc6388Fq5jcXyr5mRsqViLx/GJYdoL0bfXD8nmF+Zn/Iow==} 53 | dev: false 54 | 55 | /@tsconfig/node16@1.0.4: 56 | resolution: {integrity: sha512-vxhUy4J8lyeyinH7Azl1pdd43GJhZH/tP2weN8TntQblOY+A0XbT8DJk1/oCPuOOyg/Ja757rG0CgHcWC8OfMA==} 57 | dev: false 58 | 59 | /@types/node@20.6.0: 60 | resolution: {integrity: sha512-najjVq5KN2vsH2U/xyh2opaSEz6cZMR2SetLIlxlj08nOcmPOemJmUK2o4kUzfLqfrWE0PIrNeE16XhYDd3nqg==} 61 | dev: false 62 | 63 | /acorn-walk@8.2.0: 64 | resolution: {integrity: sha512-k+iyHEuPgSw6SbuDpGQM+06HQUa04DZ3o+F6CSzXMvvI5KMvnaEqXe+YVe555R9nn6GPt404fos4wcgpw12SDA==} 65 | engines: {node: '>=0.4.0'} 66 | dev: false 67 | 68 | /acorn@8.10.0: 69 | resolution: {integrity: sha512-F0SAmZ8iUtS//m8DmCTA0jlh6TDKkHQyK6xc6V4KDTyZKA9dnvX9/3sRTVQrWm79glUAZbnmmNcdYwUIHWVybw==} 70 | engines: {node: '>=0.4.0'} 71 | hasBin: true 72 | dev: false 73 | 74 | /arg@4.1.3: 75 | resolution: {integrity: sha512-58S9QDqG0Xx27YwPSt9fJxivjYl432YCwfDMfZ+71RAqUrZef7LrKQZ3LHLOwCS4FLNBplP533Zx895SeOCHvA==} 76 | dev: false 77 | 78 | /colors@1.4.0: 79 | resolution: {integrity: sha512-a+UqTh4kgZg/SlGvfbzDHpgRu7AAQOmmqRHJnxhRZICKFUT91brVhNNt58CMWU9PsBbv3PDCZUHbVxuDiH2mtA==} 80 | engines: {node: '>=0.1.90'} 81 | dev: false 82 | 83 | /create-require@1.1.1: 84 | resolution: {integrity: sha512-dcKFX3jn0MpIaXjisoRvexIJVEKzaq7z2rZKxf+MSr9TkdmHmsU4m2lcLojrj/FHl8mk5VxMmYA+ftRkP/3oKQ==} 85 | dev: false 86 | 87 | /diff@4.0.2: 88 | resolution: {integrity: sha512-58lmxKSA4BNyLz+HHMUzlOEpg09FV+ev6ZMe3vJihgdxzgcwZ8VoEEPmALCZG9LmqfVoNMMKpttIYTVG6uDY7A==} 89 | engines: {node: '>=0.3.1'} 90 | dev: false 91 | 92 | /easyrlbot@1.0.3: 93 | resolution: {integrity: sha512-yPyqUmNsQp9g739/TMpnEbuazeq6/eNngdl1wF7NBj/z10/7xz3zb+rAw7ED8BAJKbQrYb9pC0scRjKQblFCag==} 94 | dependencies: 95 | colors: 1.4.0 96 | flatbuffers: 2.0.7 97 | dev: false 98 | 99 | /flatbuffers@2.0.7: 100 | resolution: {integrity: sha512-5JulPk3a7zTdb2p2ElkAT8hmw4udmSL8GoRKkDa/y9+qFwKbFrRgAbF4VgSt2oIGTEpBqz9CmsvwCstwJ5D9kg==} 101 | dev: false 102 | 103 | /make-error@1.3.6: 104 | resolution: {integrity: sha512-s8UhlNe7vPKomQhC1qFelMokr/Sc3AgNbso3n74mVPA5LTZwkB9NlXf4XPamLxJE8h0gh73rM94xvwRT2CVInw==} 105 | dev: false 106 | 107 | /ts-node@10.9.1(@types/node@20.6.0)(typescript@4.9.5): 108 | resolution: {integrity: sha512-NtVysVPkxxrwFGUUxGYhfux8k78pQB3JqYBXlLRZgdGUqTO5wU/UyHop5p70iEbGhB7q5KmiZiU0Y3KlJrScEw==} 109 | hasBin: true 110 | peerDependencies: 111 | '@swc/core': '>=1.2.50' 112 | '@swc/wasm': '>=1.2.50' 113 | '@types/node': '*' 114 | typescript: '>=2.7' 115 | peerDependenciesMeta: 116 | '@swc/core': 117 | optional: true 118 | '@swc/wasm': 119 | optional: true 120 | dependencies: 121 | '@cspotcode/source-map-support': 0.8.1 122 | '@tsconfig/node10': 1.0.9 123 | '@tsconfig/node12': 1.0.11 124 | '@tsconfig/node14': 1.0.3 125 | '@tsconfig/node16': 1.0.4 126 | '@types/node': 20.6.0 127 | acorn: 8.10.0 128 | acorn-walk: 8.2.0 129 | arg: 4.1.3 130 | create-require: 1.1.1 131 | diff: 4.0.2 132 | make-error: 1.3.6 133 | typescript: 4.9.5 134 | v8-compile-cache-lib: 3.0.1 135 | yn: 3.1.1 136 | dev: false 137 | 138 | /typescript@4.9.5: 139 | resolution: {integrity: sha512-1FXk9E2Hm+QzZQ7z+McJiHL4NW1F2EzMu9Nq9i3zAaGqibafqYwCVU6WyWAuyQRRzOlxou8xZSyXLEN8oKj24g==} 140 | engines: {node: '>=4.2.0'} 141 | hasBin: true 142 | dev: false 143 | 144 | /v8-compile-cache-lib@3.0.1: 145 | resolution: {integrity: sha512-wa7YjyUGfNZngI/vtK0UHAN+lgDCxBPCylVXGp0zu59Fz5aiGtNXaq3DhIov063MorB+VfufLh3JlF2KdTK3xg==} 146 | dev: false 147 | 148 | /yn@3.1.1: 149 | resolution: {integrity: sha512-Ux4ygGWsu2c7isFWe8Yu1YluJmqVhxqK2cLXNQA5AcC3QfbGNpM7fu0Y8b/z16pXLnFxZYvWhd3fhBY9DLmC6Q==} 150 | engines: {node: '>=6'} 151 | dev: false 152 | --------------------------------------------------------------------------------