Jump to content
Frequently Asked Questions
  • Are you not able to open the client? Try following our getting started guide
  • Still not working? Try downloading and running JarFix
  • Help! My bot doesn't do anything! Enable fresh start in client settings and restart the client
  • How to purchase with PayPal/OSRS/Crypto gold? You can purchase vouchers from other users
  • Live Scripting w/ Lua


    GhostData

    Recommended Posts

    Live Scripting w/ Lua

    Write scripts with lua using LuaJ

    Wanted to write something where i can see the results immediately. Please post any errors here or on the Github. Thanks!

     

    xFoCkcy.pngBO4jsHl.png

    oPPBoyA.png

    Spoiler

    836309559_Screenshot2022-07-25033015.thumb.png.d5817dd960e5480ca2928114156df1e5.png1174904828_Screenshot2022-07-25033151.png.d012dbf29cbb55862e2a7f5c2a8e92fc.png

     

    Source: https://github.com/GhostDataIsDreaming/GhostIsDreamingScripts/tree/main/LiveScripting

    Download Link: https://github.com/GhostDataIsDreaming/GhostIsDreamingScripts/releases

    VirusTotal: https://www.virustotal.com/gui/file/7ef83bd0e0880409ecd78c65a971f9d5f6f7752fe0ab7537f89e74a3964d7d32?nocache=1

    Edited by GhostData
    fix broken links
    Link to comment
    Share on other sites

    Samples

    WoodcutAnywhere (Source - Most Recent)

    Spoiler
    --[[
        Simple Wookcutting Script written in Lua
    
        Notes:
            1. [Important] This entire script is iterated on every onLoop
            2. Adjust frequency of script with Executing Interval to make it faster or slower
            3. Can be ran anywhere. Will chop trees nearby until inventory is full or is in combat
                    and will run to closest bank if either criteria is met
            4. No Antiban present. Figure that shit out yourselves.
    --]]
    local Players = luajava.bindClass("org.dreambot.api.methods.interactive.Players")
    local Walking = luajava.bindClass("org.dreambot.api.methods.walking.impl.Walking")
    local MethodProvider = luajava.bindClass("org.dreambot.api.methods.MethodProvider")
    local NPCs = luajava.bindClass("org.dreambot.api.methods.interactive.NPCs")
    local Inventory = luajava.bindClass("org.dreambot.api.methods.container.impl.Inventory")
    local Bank = luajava.bindClass("org.dreambot.api.methods.container.impl.bank.Bank")
    local GameObjects = luajava.bindClass("org.dreambot.api.methods.interactive.GameObjects")
    local Calculations = luajava.bindClass("org.dreambot.api.methods.Calculations")
    
    --[[
        Lets setup Main Variables to adjust script
    --]]
    local bankers = { "Banker" }
    local maxRadius = 10; -- Max Travel distance around starting tile
    local trees = { "Tree", "Oak Tree", "Willow" } -- Trees to Cut Down
    local logs = { "Logs", "Oak logs", "Willow logs" } -- Logs to deposit in bank
    
    --[[
        Variables for script, Do not modify. Script uses them
    --]]
    local startingArea = nil
    local bankLocation = nil
    local bankArea = nil
    
    --[[
        Define functions script can use
    --]]
    function isAtBank()
        if not bankLocation or not bankArea then
            bankLocation = Bank:getClosestBankLocation()
            bankArea = bankLocation:getArea(2)
        end
    
        if not NPCs:closest(bankers) then return false end
        return true
    end
    
    function isAtStartingArea()
        if not startingArea then
            startingArea = Players:localPlayer():getTile():getArea(maxRadius)
        end
    
        if not startingArea:contains(Players:localPlayer():getTile()) then return false end
        return true
    end
    
    --[[
        Actual Script
    --]]
    script.onStart(function()
        -- Grab Variables onStart
        isAtStartingArea()
        isAtBank()
    end)
    
    script.onLoop(function()
        local min = Calculations:random(100, 1000)
        local max = Calculations:random(1001, 5000)
    
        --MethodProvider:log("Waiting between " .. min .. " and " .. max);
        --MethodProvider:log("Inventory Full: " .. tostring(Inventory:isFull()));
        --MethodProvider:log("Is at Bank (" .. bankLocation:name() .. ")? " .. tostring(isAtBank()));
        --MethodProvider:log("Is at Starting Area? " .. tostring(isAtStartingArea()));
    
        if Inventory:isFull() then
            if (isAtBank()) then
                local banker = NPCs:closest(trees)
    
                if not Bank:isOpen() then
                    Bank:open()
                    MethodProvider:sleep(100, 1000)
                end
    
                for _, item in ipairs(logs) do
                    Bank:depositAll(item)
                    MethodProvider:sleep(25, 500)
                end
    
                Bank:close()
            else
                --MethodProvider:log("Walking to Bank Area");
                Walking:walk(bankArea:getRandomTile())
            end
        else if isAtStartingArea() then
            local me = Players:localPlayer()
    
            --MethodProvider:log("Is Interacted With? " .. tostring(me:isInteractedWith()));
            --MethodProvider:log("Is Animating? " .. tostring(me:isAnimating()));
            --MethodProvider:log("Animating = " .. tostring(me:getAnimation()));
    
            if me:getAnimation() == -1 then
                --MethodProvider:log("Pick Tree");
                local treeObject = GameObjects:closest(trees)
    
                if (treeObject) then
                    treeObject:interact("Chop down")
                end
            end
        else
            --MethodProvider:log("Walking to Starting Area");
            Walking:walk(startingArea:getRandomTile())
        end
        end
    
        return Calculations:random(min, max)
    end)

     

    MineAnywhere (Source - Most Recent)

    Spoiler
    --[[
        Simple Mining Script written in Lua identical to the woodcutting one
    
        Notes:
            1. [Important] This entire script is iterated on every onLoop
            2. Adjust frequency of script with Executing Interval to make it faster or slower
            3. Can be ran anywhere. Will chop trees nearby until inventory is full or is in combat
                    and will run to closest bank if either criteria is met
            4. No Antiban present. Figure that shit out yourselves.
    --]]
    local Players = luajava.bindClass("org.dreambot.api.methods.interactive.Players")
    local Walking = luajava.bindClass("org.dreambot.api.methods.walking.impl.Walking")
    local MethodProvider = luajava.bindClass("org.dreambot.api.methods.MethodProvider")
    local NPCs = luajava.bindClass("org.dreambot.api.methods.interactive.NPCs")
    local Inventory = luajava.bindClass("org.dreambot.api.methods.container.impl.Inventory")
    local Bank = luajava.bindClass("org.dreambot.api.methods.container.impl.bank.Bank")
    local GameObjects = luajava.bindClass("org.dreambot.api.methods.interactive.GameObjects")
    local Calculations = luajava.bindClass("org.dreambot.api.methods.Calculations")
    
    --[[
        Lets setup Main Variables to adjust script
    --]]
    local bankers = { "Banker" }
    local maxRadius = 10; -- Max Travel distance around starting tile
    local deposits = { 11362, 113611, 11360, 10943, 11161 } -- Low Level ore deposits.. Clay, Tin, Copper ids
    local items = { "Clay", "Tin ore", "Copper ore" } -- Ores to deposit in bank
    
    --[[
        Variables for script, Do not modify. Script uses them
    --]]
    local startingArea = nil
    local bankLocation = nil
    local bankArea = nil
    
    --[[
        Define functions script can use
    --]]
    function isAtBank()
        if not bankLocation or not bankArea then
            bankLocation = Bank:getClosestBankLocation()
            bankArea = bankLocation:getArea(2)
        end
    
        if not NPCs:closest(bankers) then return false end
        return true
    end
    
    function isAtStartingArea()
        if not startingArea then
            startingArea = Players:localPlayer():getTile():getArea(maxRadius)
        end
    
        if not startingArea:contains(Players:localPlayer():getTile()) then return false end
        return true
    end
    
    --[[
        Actual Script
    --]]
    script.onStart(function()
        -- Grab Variables onStart
        isAtStartingArea()
        isAtBank()
    end)
    
    script.onLoop(function()
        local min = Calculations:random(100, 1000)
        local max = Calculations:random(1001, 5000)
    
        --MethodProvider:log("Waiting between " .. min .. " and " .. max);
        --MethodProvider:log("Inventory Full: " .. tostring(Inventory:isFull()));
        --MethodProvider:log("Is at Bank (" .. bankLocation:name() .. ")? " .. tostring(isAtBank()));
        --MethodProvider:log("Is at Starting Area? " .. tostring(isAtStartingArea()));
    
        if Inventory:isFull() then
            if (isAtBank()) then
                local banker = NPCs:closest(deposits)
    
                if not Bank:isOpen() then
                    Bank:open()
                    MethodProvider:sleep(100, 1000)
                end
    
                for _, item in ipairs(items) do
                    Bank:depositAll(item)
                    MethodProvider:sleep(25, 500)
                end
    
                Bank:close()
            else
                --MethodProvider:log("Walking to Bank Area");
                Walking:walk(bankArea:getRandomTile())
            end
        else if isAtStartingArea() then
            local me = Players:localPlayer()
    
            --MethodProvider:log("Is Interacted With? " .. tostring(me:isInteractedWith()));
            --MethodProvider:log("Is Animating? " .. tostring(me:isAnimating()));
            --MethodProvider:log("Animating = " .. tostring(me:getAnimation()));
    
            if me:getAnimation() == -1 then
                --MethodProvider:log("Mine");
                local depsotiObject = GameObjects:closest(deposits)
    
                if (depsotiObject) then
                    depsotiObject:interact("Mine")
                end
            end
        else
            --MethodProvider:log("Walking to Starting Area");
            Walking:walk(startingArea:getRandomTile())
        end
        end
    
        return Calculations:random(min, max)
    end)

     

    Edited by GhostData
    Added MineAnywhere
    Link to comment
    Share on other sites

    Update to v2.2 - Direct Download

    ChangeLog

    • Revamped the menus. Now includes 3 distinct menues. Loader, Editor, Settings
    • Rewrote the Script Loading, Handling, Executing
      -- Start your Lua Scripts with (script.)
      --Supports onStart, onLoop, onExit, onResume, onPaint
      --Supports onLoop calling even if not present, treats entire script as onLoop
    • Rewrote the sample WoodcutAnywhere. Start that shit anywhere and when your inventory is full it will walk to bank, deposit and then walk back
    • Option to choose samples from the Load Menu. Automatically run them when chose.
    Edited by GhostData
    Link to comment
    Share on other sites

    • 3 weeks later...

    Update to v2.4 - Direct Download

    ChangeLog

    • Added functions to be able to create guis inside of the lua scripts using wrapped swing components
    • Added function `newInstance` to create new instances of classes
    • Added function `require_local` to import local lua dependencies
    • Updated `import` function
    • Updated way that we load scripts. Works whether we run from SDN or as local.
    • Created `MineAnywhere.lua` -- Based on `WoodcutAnywhere.lua`
    • Fix bug related to New Empty Script
    • Removed unnecessary logging to console
    • Fixed bug for script.kill() & script.stop()
    Edited by GhostData
    Link to comment
    Share on other sites

    Create an account or sign in to comment

    You need to be a member in order to leave a comment

    Create an account

    Sign up for a new account in our community. It's easy!

    Register a new account

    Sign in

    Already have an account? Sign in here.

    Sign In Now
    ×
    ×
    • Create New...

    Important Information

    We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.