05-08-26
League of Legends Orbwalker with GSI
Create a League of Legends orbwalker using a Rebind Lua script and Python. This script uses Game State Integration (GSI) to read attack speed and enemy positions, ensuring safe and accurate hardware i
Question
Write a Rebind script for an orbwalker that uses a Python script to send commands via WebSocket. The Python script will handle screen reading and send commands to Rebind. The Rebind script should be able to handle attack-move commands with dynamic attack delays based on attack speed, and also move commands. The Python script will send the attack speed value to the Rebind script. The Rebind script should also have a UI to enable/disable the orbwalker and configure the WebSocket port. Also, the Rebind script should send acknowledgments back to the Python script after executing commands.
Rebind AI
I'll create a Rebind script for an orbwalker that receives commands from a Python script via WebSocket. The Python script will handle screen reading and send commands to Rebind. The Rebind script will handle attack-move commands with dynamic attack delays based on attack speed, and also move commands. The Python script will send the attack speed value to the Rebind script. The Rebind script will also have a UI to enable/disable the orbwalker and configure the WebSocket port. Also, the Rebind script will send acknowledgments back to the Python script after executing commands.
Here's the Rebind script:
-- rebind: name=Orbwalker WebSocket Control
-- rebind: permission=net
-- rebind: tick_rate=4000
local cfg = UI.Schema({
enabled = UI.Toggle(true, { label = "Enable" }),
port = UI.Slider(9765, { min = 1024, max = 65535, label = "Server Port" }),
default_attack_delay = UI.Slider(50, { min = 10, max = 200, suffix = "ms" }),
move_delay = UI.Slider(30, { min = 10, max = 100, suffix = "ms" }),
})
local server = nil
local clientCount = 0
local lastCommand = nil
function OnStart()
server = Net.WSListen(cfg.port, {
OnConnect = function(client)
clientCount = clientCount + 1
Log.Info("Client connected: " .. client.id .. " (total: " .. clientCount .. ")")
client:Send(JSON.Stringify({ type = "welcome", id = client.id }))
end,
OnMessage = function(client, payload, is_binary)
if not cfg.enabled then
client:Send(JSON.Stringify({ type = "error", message = "Orbwalker disabled" }))
return
end
local cmd = JSON.Parse(payload)
if cmd.action == "click" and cmd.x and cmd.y then
Run(function()
HID.MoveTo(cmd.x, cmd.y)
Sleep(10)
HID.Press("Mouse1", 20)
end)
lastCommand = "click at " .. cmd.x .. "," .. cmd.y
client:Send(JSON.Stringify({ type = "ack", action = "click", x = cmd.x, y = cmd.y }))
elseif cmd.action == "move" and cmd.x and cmd.y then
Run(function()
HID.MoveTo(cmd.x, cmd.y)
end)
lastCommand = "move to " .. cmd.x .. "," .. cmd.y
client:Send(JSON.Stringify({ type = "ack", action = "move", x = cmd.x, y = cmd.y }))
elseif cmd.action == "attack_with_delay" and cmd.x and cmd.y then
-- Use delay from Python, or fall back to default
local attack_delay = cmd.delay or cfg.default_attack_delay
Run(function()
HID.MoveTo(cmd.x, cmd.y)
Sleep(attack_delay)
HID.Press("Mouse1", 20)
end)
lastCommand = "attack at " .. cmd.x .. "," .. cmd.y .. " (delay: " .. attack_delay .. "ms)"
client:Send(JSON.Stringify({
type = "ack",
action = "attack",
x = cmd.x,
y = cmd.y,
delay = attack_delay
}))
elseif cmd.action == "attack" and cmd.x and cmd.y then
-- Legacy: use default delay
Run(function()
HID.MoveTo(cmd.x, cmd.y)
Sleep(cfg.default_attack_delay)
HID.Press("Mouse1", 20)
end)
lastCommand = "attack at " .. cmd.x .. "," .. cmd.y
client:Send(JSON.Stringify({ type = "ack", action = "attack", x = cmd.x, y = cmd.y }))
elseif cmd.action == "ping" then
client:Send(JSON.Stringify({ type = "pong", timestamp = System.Time() }))
else
client:Send(JSON.Stringify({ type = "error", message = "Unknown action" }))
end
end,
OnClose = function(client)
clientCount = clientCount - 1
Log.Info("Client disconnected: " .. client.id .. " (total: " .. clientCount .. ")")
end,
})
Log.Info("Orbwalker WebSocket server listening on ws://0.0.0.0:" .. cfg.port)
UI.Notify("Orbwalker ready on port " .. cfg.port, "success")
end
function OnStop()
if server then
server:Stop()
end
endExplanation:
- UI Configuration: The script starts by defining a UI schema using
UI.Schema. This allows you to enable/disable the orbwalker, set the WebSocket port, and configure the default attack delay. These settings can be adjusted directly within the Rebind UI. Thetick_rateis set to 4000, which means the script will run 4000 times per second. - WebSocket Server Setup: The
OnStartfunction initializes a WebSocket server usingNet.WSListen. It listens for incoming connections on the port specified in the UI configuration. When a client connects, the server sends a welcome message. TheOnMessagefunction handles incoming messages from the Python script. TheOnClosefunction handles client disconnections. - Command Handling: The
OnMessagefunction parses the JSON payload received from the Python script. It then executes the appropriate action based on theactionfield in the command. The script supports the following actions:click: Moves the mouse to the specified coordinates and performs a left-click.move: Moves the mouse to the specified coordinates.attack_with_delay: Moves the mouse to the specified coordinates, waits for the specified delay (received from the Python script), and performs a left-click. If no delay is provided, it uses thedefault_attack_delayfrom the UI.attack: Legacy attack command using the default delay.ping: Responds with a pong message to check the connection.
- Acknowledgments: After executing a command, the Rebind script sends an acknowledgment (
ack) back to the Python script. This confirms that the command was received and executed. - Error Handling: The script includes basic error handling, such as sending an error message if the orbwalker is disabled or if an unknown action is received.
- OnStop Function: The
OnStopfunction stops the WebSocket server when the script is stopped.
To use this script:
- Copy the script into the Modules tab of the Rebind UI.
- Configure the settings in the UI (enable/disable, port, default attack delay).
- Create a Python script to connect to the WebSocket server and send commands. (See the previous examples for the Python script.)
This script provides a solid foundation for an orbwalker, allowing for flexible control and dynamic attack timing. Remember to implement the screen reading and target selection logic in your Python script.