• Hail, we're RedGuides. We want you to play several EverQuest characters at once. We have scripts and a friendly community to help, please join our playstyle and say hello! 👋

Lua - Old Man Roran: Randomizer

Roran

Member
This is a script that will make you more inefficient, but it will also make your characters behave more human like and thereby reducing/removing some of the "benefits" MQ gives that are not "needed" if you are using MQ as disability support software.

This simple Lua will randomize any command you want on a character. Simply run the script and then choose the random amount of time in seconds, you want a character to wait before the command is executed.

Examples for EQBC:

//This will tell all characters in your group to hail an NPC with their own random delay between 0 and 10 seconds.
/bcg //rd 10 /keypress h

//This will tell everyone in your raid to say ready with their own random delay between 0 and 20 seconds.
/bcaa //rd 20 /say ready

Randomizer.lua
Lua:
local mq = require("mq")

-- Variables for script status and help
local ScriptActive = true

-- Function to convert a string (character name) to a seed number
local function stringToSeed(str)
    local seed = 0
    for i = 1, #str do
        local c = str:byte(i)
        seed = seed + c
    end
    return seed
end

-- Function to execute a command with a random delay up to the specified maximum
local function executeWithRandomDelay(maxDelayInSeconds, command)
    -- Generate a random delay between 0 and maxDelayInSeconds
    local delayInSeconds = math.random(0, maxDelayInSeconds)
    local delayInMilliseconds = delayInSeconds * 1000
    mq.delay(delayInMilliseconds)
    mq.cmd(command)
end

-- Function to show help text
local function showHelp()
    print("Random Delay (/rd) Command Help:")
    print("/rd [max delay in seconds] [command] - Executes the specified command after a random delay up to the specified number of seconds.")
    print("Example: /rd 10 /cast 1 - This will cast the spell in slot 1 after a random delay of up to 10 seconds.")
    print("/rd help - Shows this help text.")
    print("/rd active - Toggles the script active or inactive.")
end

-- Function to parse and process input commands
local function processRDCommand(...)
    local args = {...}
    if not ScriptActive then return end
    if args[1] == 'help' then
        showHelp()
    elseif args[1] == 'active' then
        ScriptActive = not ScriptActive
        local status = ScriptActive and 'active' or 'inactive'
        print(string.format("Random Delay (/rd) script is now %s.", status))
    else
        local maxDelayInSeconds = tonumber(args[1])
        local commandToRun = table.concat(args, " ", 2)
        if maxDelayInSeconds and commandToRun and commandToRun ~= "" then
            executeWithRandomDelay(maxDelayInSeconds, commandToRun)
        else
            print("Invalid command format. Type '/rd help' for usage information.")
        end
    end
end

-- Initialize random seed with character name
local charName = mq.TLO.Me.Name()
math.randomseed(stringToSeed(charName))

-- Binding the /rd command to the processRDCommand function
mq.bind('/rd', processRDCommand)

-- Main loop to keep the script running
while true do
    mq.delay(100) -- Small delay to prevent the script from hogging CPU resources
end
 
Last edited:
Nice tool.
If I understand the structure of the system well, a "doevents()" in the main loop shall make it more responsive to events triggered by other tools running like:
Doevents
Code:
-- Main loop to keep the script running
while true do
    doevents()
    mq.delay(100) -- Small delay to prevent the script from hogging CPU resources
end

can anyone confirm, that I understand it right?
 
can anyone confirm, that I understand it right?

Shouldn't be needed since they are using mq.bind()

Per the wiki
Binds are very similar to events (and even use the same backend code) with a couple of important differences. Instead of capturing arbitrary text, it will pass arguments specified by the user, and it will execute at the beginning of the next frame always (no need to call mq.doevents()). When you set up a bind, you call mq.bind('/command', callback).
 
This described functionality, as I understand it, describes how the bind assures, that the code is executed and that mq.doevents() is not needed to activate it for the next frame.
My thoughts are more about releasing ressources for the other processes running.
The infinite loop:
Loop
Code:
-- Main loop to keep the script running
while true do
    mq.delay(100) -- Small delay to prevent the script from hogging CPU resources
end
Without "doevents()" may dedicate the whole frame to this process, which tends to make the ui feel irresponsive to the user's input. A "doevents()" within this loop shall check, if any user action should result in triggering other processes events.

I am not certain about my view of event-handling and really want to understand/learn if it works like I think it does.
 
Lua:
    if args[1] == 'help' then
        if not ScriptActive then return end  -- Move the check inside specific commands, except for 'active'
        showHelp()
    elseif args[1] == 'active' then
        ScriptActive = not ScriptActive
        local status = ScriptActive and 'active' or 'inactive'
        print(string.format("Random Delay (/rd) script is now %s.", status))
    else
        if not ScriptActive then return end  -- Apply the check here as well for other commands
        local maxDelayInSeconds = tonumber(args[1])
        local commandToRun = table.concat(args, " ", 2)
        if maxDelayInSeconds and commandToRun and commandToRun ~= "" then
            executeWithRandomDelay(maxDelayInSeconds, commandToRun)
        else
            print("Invalid command format. Type '/rd help' for usage information.")
        end
    end
end
 
Lua - Old Man Roran: Randomizer

Users who are viewing this thread

Back
Top
Cart