• You've discovered RedGuides, an EverQuest multi-boxing and scripting community 🧙‍♀️⚙️. We want you to play several EQ characters at once, come join us and say hello! 👋

  • A TLP without truebox has thawed (Very Vanilla ready)
    Frostreaver

Lua - Lua Snips and discussion

You shouldn’t assume that you are the only script that is running. It may be confusing to try and know all the commands for your script.

it’s better to create one command and read the arguments and provide good help text too

edit: some of these might also overlap with existing commands, or look like existing commands, or he confused with existing commands etc.
 
type characters in selected box

Code:
local function type_chars(p_chars)
    for i = 1, string.len(p_chars) do
        print(string.sub(p_chars, i, i))
        local str = string.sub(p_chars, i, i)
        if str == " " then
            mq.cmd('/squelch /keypress space chat')
        else
            mq.cmd('/squelch /keypress ' .. str .. ' chat')
            mq.delay(100)
        end
    end
end
 
I have often wondered when it says you learned a new recipe, it allows you to search for it in the tradeskill UI, but is there a way to look up that recipe ID information? I mean look it up using MQ not eqtc..
 
So.. if you were wondering how to pick up an item by ID and put it in a static container.. Here is one way...

zz=13069 this is an item ID
ev=1 this is the environment variable for the static container

Code:
mq.cmd('/ctrl /itemnotify "${FindItem["'..zz..'"]}" leftmouseup')
mq.delay(300)
mq.cmd('/nomodkey /itemnotify enviro"'..ev..'" leftmouseup')

doesn't work :(


this works for me.. but I am unable to pick up anything by ID any other way.. it picks up the first match even when I put the specific ID in there..

Code:
local id = 8500
local slot2 =  mq.TLO.FindItem(id).ItemSlot2()+1
if slot2 ==  0 then
    -- not in bag
       local slot1 = mq.TLO.FindItem(id).ItemSlot()
    mq.cmd('/ctrl /itemnotify '..slot1..' leftmouseup')
  
else
    -- in bag
    local slot1 = mq.TLO.FindItem(id).ItemSlot()-22
    mq.cmd('/ctrl /itemnotify in pack'..slot1..' '..slot2..' leftmouseup')
end
 
> doesn't work :(

no, of course it doesn't. You're writing Lua, not a macro.

did you try

INI:
mq.cmdf('/ctrl /itemnotify "%s" leftmouseup', mq.TLO.FindItem(zz)())
 
No I wasted my time on this :(

Code:
function library.GrabItemID(p_id, p_count)
    local l_id = p_id
    local l_count = p_count
    local slot2 = mq.TLO.FindItem(l_id).ItemSlot2() + 1
    if slot2 == 0 then
        -- Not in bag
        local slot1 = mq.TLO.FindItem(l_id).ItemSlot()
        if l_count == 1 then
            mq.cmd('/ctrl /itemnotify ' .. slot1 .. ' leftmouseup')
            mq.delay(500)
        end
        if l_count == -1 then
            mq.cmd('/shift /itemnotify ' .. slot1 .. ' leftmouseup')
            mq.delay(500)
        end
        if l_count > 1 then
            mq.cmd('/itemnotify ' .. slot1 .. ' leftmouseup')
            mq.delay(500)
            mq.cmd('/notify QuantityWnd QTYW_slider newvalue', l_count)
            mq.delay(500)
            mq.cmd(
                '/nomodkey /notify QuantityWnd QTYW_Accept_Button leftmouseup')
            mq.delay(500)
        end
    else
        -- In bag
        local pack = mq.TLO.FindItem(l_id).ItemSlot() - 22
        if l_count == 1 then
            mq.cmd('/ctrl /itemnotify in pack' .. pack .. ' ' .. slot2 ..
                       ' leftmouseup')
            mq.delay(500)
        end
        if l_count == -1 then
            mq.cmd('/shift /itemnotify in pack' .. pack .. ' ' .. slot2 ..
                       ' leftmouseup')
            mq.delay(500)
        end
        if l_count > 1 then
            mq.cmd('/itemnotify in pack' .. pack .. ' ' .. slot2 ..
                       ' leftmouseup')
            mq.delay(500)
            mq.cmd('/notify QuantityWnd QTYW_slider newvalue', l_count)
            mq.delay(500)
            mq.cmd(
                '/nomodkey /notify QuantityWnd QTYW_Accept_Button leftmouseup')
            mq.delay(500)
        end
    end
    return
end
 
Last edited:
> doesn't work :(

no, of course it doesn't. You're writing lua, not a macro.

did you try

INI:
mq.cmdf('/ctrl /itemnotify "%s" leftmouseup', mq.TLO.FindItem(zz)())

local l_item_id =8572

mq.cmdf('/shift /itemnotify "%s" leftmouseup', mq.TLO.FindItem(l_item_id)())
mq.delay(1000)


it is picking up item 8500 instead
 
Its working for me ..

This is all I have for code..

Code:
local mq = require('mq')
local l_item_id = 8572
mq.delay(1000)
mq.cmdf('/shift /itemnotify "%s" leftmouseup',mq.TLO.FindItem(l_item_id)())
mq.delay(1000)

brand new Lua file
 
oh its because they all have the same name.. great.

item notify via slot has been broken for a while, or so I'm told. I haven't used it.
 
oh its because they all have the same name.. great.

item notify via slot has been broken for a while, or so I'm told. I haven't used it.

Well it looks like my grabitemid() does the trick for the time being..

provided I open the bag if it is in a bag.. for quantity selection
 
having serious trouble here. We've established I know squat about how to properly implement doevents, what am I doing wrong here?
I have tried various delays but it only triggers the messages after it leaves the loop

Code:
                while true do
                    mq.delay(1500)
                    -- Destroy by ID option
                    if DESTROY_ID ~= 0 then
                        --     item_destroy(DESTROY_ID)
                    end
                    mq.doevents()
                    -- sell -- flag = 4?  -- 350   ---skill up
                    local l_inv = mq.TLO.FindItemCount(l_recipe_item_id)()
                    -- Check Make Count Completion
                    if l_inv >= l_make_count then
                        mq.delay(500)
                        mq.cmd('/cleanup')
                        --  tsui_disable_make_all()
                        print(msg, "TCN_Craft goal complete UI testing")
                        outer_flag = 1
                        break
                    end
                    -- Click auto-inventory button as needed
                    --   tsui_click_auto_inv()
                    local check = 0
                    component_check(p_id, a_craft_item_normal)
                    if check == 0 then
                        print(msg, "Out of materials")
                        -- tsui_disable_make_all()
                        -- os.exit()
                        mq.cmd('/cleanup')
                        --   tsui_disable_make_all()
                        outer_flag = 2
                        break
                    end
                end

this is the second do while in this routine

meaning:
while do
while do
end
end

and is run from the main driver Lua in it's own do while
 
Last edited:
my solution when using the tradeskill_ui and I can't do do events.. because.. reasons..

I ensure the cursor is clean before doing a component check

Code:
repeat mq.delay(1000) until mq.TLO.Cursor.ID() == nil
 
my solution when using the tradeskill_ui and I can't do do events.. because.. reasons..

I ensure the cursor is clean before doing a component check

Code:
repeat mq.delay(1000) until mq.TLO.Cursor.ID() == nil


If I assert:

assert(loadfile("\\MQNext\\Lua\\TCN\\God.Lua"))(1) it does the mq.events just fine.. it is just when I am using require that I have issues..
 
If I assert:

assert(loadfile("\\MQNext\\Lua\\TCN\\God.lua"))(1) it does the mq.events just fine.. it is just when I am using require that I have issues..

my dreams of code silos are fading!

Basically the thing that I require is a little bit more than just a library and it does stuff..

Why do I do this, I want a light weight feeder to do all the other things..

my next option is to parse eqlog.txt for events and toggle logging on and off :P

options

A) put everything all together and call it TCSNextAssist
B) Assert
C) eq log parsing
D) not on the menu
E) someone has a better option
F) run a separate Lua that just sends values
G) global event function
H) opinions or non-sequitur speech
I) Fix your code - Winner!
 
Last edited:
I like to say we are the architects of our own destruction..

1632800205988.png


So, pro-tip..

don't run stuff from the bind, run it from within the do while.. :)
 
My take on navigating to a known path and trying to get unstuck

Code:
local function movement_path(p_nav)
    local counter = 0
    local attempts = 0
    -- Current distance to NAV
    local PathLengthCurrent = mq.TLO.Nav.PathLength('loc ' .. p_nav)()
    -- Start loop
    while mq.TLO.Nav.Active() do
        PathLengthCurrent = mq.TLO.Nav.PathLength('loc ' .. p_nav)()
        mq.delay(1)
        local NextLengthLast = mq.TLO.Nav.PathLength('loc ' .. p_nav)()
        -- Distance has not changed
        if NextLengthLast == PathLengthCurrent then
            counter = counter + 1
            -- Try to get unstuck by ducking
            if counter == 200 then
                mq.cmd('/keypress duck')
                mq.delay(3000)
                mq.cmd('/keypress duck')
                counter = 0
                attempts = attempts + 1
                if attempts > 5 then
                    print "we tried 5 times, giving up!"
                    os.exit()
                end
            end
        else
            counter = 0
        end
        mq.delay(1)
    end
        return
end

local nav = "-316 846 -94"
mq.cmd('/squelch /nav locyxz ' .. nav .. ' |log=off')

-- Usage
movement_path(nav)[/code]
 
good to know, I was trying to have some MQless Luas.. I suppose I could call the mq.exit() as a function but is there really a point other than to look clean..
I do this in write. You just need to check for mq and choose one or the other. But you can keep it as they mentioned.
 
IMO, don't use exit() at all (in either form). Let your control flow exit the script. It's cleaner, you can do any script exit cleanup, and people (like future you) won't get lost trying to track when the control flow breaks.
 
IMO, don't use exit() at all (in either form). Let your control flow exit the script. It's cleaner, you can do any script exit cleanup, and people (like future you) won't get lost trying to track when the control flow breaks.

from a clean perspective you are right.. let's say I am trying to buy something and I am out of platinum and I visited the bank before but didn't have enough.. I go to buy it.. I can

local a = buy.item("tacos",1) get the return flag I set and then break out or return from the calling function, but the laziness comes when I don't feel like break and return all over the place and can just

mq.exit() and say you broke, which means you cannot continue doing what you want to do..
 
from a clean perspective you are right.. let's say I am trying to buy something and I am out of platinum and I visited the bank before but didn't have enough.. I go to buy it.. I can

local a = buy.item("tacos",1) get the return flag I set and then break out or return from the calling function, but the laziness comes when I don't feel like break and return all over the place and can just

mq.exit() and say you broke, which means you cannot continue doing what you want to do..

I use a lot of mq.exit for nil errors currently..

I suppose I should look into Lua error facility
 
While we are at it I have been looking for the Lua equivalent of OnExit.. but have come up empty..

So if you type /Lua stop I want the code to do something or clean up stuff..
 
While we are at it I have been looking for the Lua equivalent of OnExit.. but have come up empty..

So if you type /lua stop I want the code to do something or clean up stuff..

not possible to do it this way in Lua, unfortunately. I would recommend adding a command and using it to gracefully exit.
 
Because why would we want to figure out if we need to destroy it, sell it ,keep it, or bank it..

1632969237345.png
 


the way I accomplished this:

Code:
  for x = 0 ,#max_table do
    for y = #max_table,0  ,-1 do
        for z = 0 , #recid do
               if recid[z] == max_table[x] and subid[z]==max_table[y] then
                           local  string = subid[z]..","..recid[z]
                          writetofile(string)
                  print ("Primary: ",recid[z], "Secondary: ",subid[z])
            dd =dd +1
            end
          end
      end

I ran the max aug table against the max aug table against a recipe ID table it took about 2 hours but it churned out every associated recipe that is used to max the aug.

could have been easier if I just compared them against each other and added the names so I wouldn't have to reference the component table
 
Last edited:
my infamous restacker...

-- picks up every occurrence of a stackable item and turns it into a single stack..


Code:
function library.restack_items(p_id)
    local l_stack_count = mq.TLO.FindItem(p_id).Stacks()
    if l_stack_count < 2 then return end
    print("\atTCSNeXt] \aw[Auto-Restack]")
    for c = 0, l_stack_count do
        library.GrabItemID(p_id, -1)
        library.ClearCursor()
    end
    return
end
 
So, when I made all the data.. there were quite a few eqtc recipes that were bugged or unknown but I added the recipe id to the db anyways..

well when it goes through list it will blow up because there are no associated components..

enter...

Code:
-- bugged recipes list return
function library.bugged_recipes()
    local m = {}
    local counter = 0
    for r in db:nrows(
                 "SELECT RecipeID FROM MasterCompTable WHERE ItemID = 0 and MItemID = 0") do
        m[counter] = r.RecipeID
        counter = counter + 1
    end
    return m
end

Not too flashy but it dumps a list of unknown/bugged recipes.. which can then be compared to the recipe id of what you are trying to make and it will just skip it!

Because one day that recipe will be there, all we have is hope..
 
Lua - Lua Snips and discussion

Users who are viewing this thread

Back
Top
Cart