• 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

Question - First lua and first lua question

Soandso2

Well-known member
Joined
Mar 13, 2023
RedCents
937¢
Alright, so after having uploaded my bam.mac, people kept telling me to "DO'ET IN Lua INSTEAD, DOOOO EEEEEET, FOOL!"

So I thought I would convert bam.mac to bam.Lua. I read up on Lua a bit, looked at a few examples and I decided to start out small and carefully. But since I am not 100% familiar with the documentation yet, I struggle to find the solution to the first major issue.

(I think) I know what the problem is, just not how to correct it.

[CODE lang="Lua" title="bam.Lua"]mq = require('mq')

print('Running Bam.Lua')

local terminate = false
mq.bind('/bamend', function() terminate = true end)

local function doShortDiscs(discName,targetDist)
local shortDisc = mq.TLO.Spell(discName).RankName
if mq.TLO.Me.CombatAbilityReady(shortDisc) and mq.TLO.Target.Distance() < targetDist then
mq.cmd('/doability '..shortDisc)
print(shortDisc)
mq.delay(3)
end
end

while not terminate do
if mq.TLO.Me.Combat() and mq.TLO.Target.ID() then
doShortDiscs('Vigorous Shuriken',175)
end
end[/CODE]

The error occurs in line 11: mq.cmd('/doability '..shortDisc) and I presume it has to do with the fact that shortDisc in this case contains a space. I also tried to use mq.cmdf('/doability %s',shortDisc) but then I got something along the lines of "you dont seem to have that ability: vigorous" (again, just taking the first word of the string).
I have also seen mq.cmd.doability() ... what is the difference and which way is the prefered way?

EDIT: I just found this in LeRouge lua
start = function() mq.cmdf('/useitem "%s"', mq.TLO.FindItem(name).Name()) end

I guess I just answered my own question. Sorry for taking up your time, folks.
 
Last edited:
A few new things now confuse me.

Lua:
local function useShortDisc(discName,targetDist)
  local shortDisc = mq.TLO.Spell(discName).RankName
  print(mq.TLO.Me.CombatAbilityReady(shortDisc))
  if mq.TLO.Me.CombatAbilityReady(shortDisc) and mq.TLO.Target.Distance() < targetDist then
    mq.cmdf('/doability "%s"',shortDisc)
    print(string.format('useShortDisc: "%s"',shortDisc))
    mq.delay(300)
  else
        print(string.format('useShortDisc: "%s" not ready',shortDisc))
  end
end

local function useShortDiscs()
  local discs={ ["vigorous shuriken"]=175, ["Curse of Sixteen Shadows"]=50, ["Bloodwalker's Synergy"]=50, ["Buffeting of Fists"]=50, ["Zlexak's Fang"]=50, ["Bloodwalker's Precision Strike"]=200, ["Dragons's Poise"]=50, ["Ecliptic Form"]=50, ["Heron Stance"]=50}
  for disc,range in pairs(discs) do
    useShortDisc(disc,range)
  end
end

while not terminate do
  if mq.TLO.Me.Combat() and mq.TLO.Target.ID() then
    useShortDiscs()
    if long then
      useLongDiscs()
    end
  end
end

Line 3 correctly prints TRUE or FALSE depending on the readyness of the combat ability. Still, lines5-7 always run. I never end up in the else-part of the code (line 9)
Also, I sometimes "NULL" values when looping through the array. Why is this?
 

try putting some stuff into here and it might clear it up (userdata vs string/number/boolean etc)

hint: ()
Hmm ok I still dont get it. I tested the eval Lua and :
1) mq.TLO.Me.CombatAbilityReady("Vigorous Shuriken Rk. II") evaluates to true or false, depending on if it is ready or not, or if I have the ability or not. Surely I can use a variable name (shortDisc) instead of a hard coded string there?
2) Also I see that mq.TLO.Target.Distance() gives me a number like 6.96576764675 but mq.TLO.Target.Distance gives 6.97

Edit: AAAAHA. I see now. Thanks! mq.TLO.Me.CombatAbilityReady(shortDisc)() looked too wierd to even be something to consider.
 
Last edited:
something that helped me with seeing that issue, is the "type()" command, so in your print if you put it inside that type, it will tell you userdata or after you added () will say string.
because there can be times you want userdata too.
 
something that helped me with seeing that issue, is the "type()" command, so in your print if you put it inside that type, it will tell you userdata or after you added () will say string.
because there can be times you want userdata too.
I see. Good advice. Thanks! :)
 
Another thing that am a bit uncertain of, but currently unable to test is how to use if not properly.
This is PHP and
PHP:
$bool1 = false;
$bool2 = true;

if (!$bool1 && $bool2)
    echo "yep this happened";

In Lua, would this be? Does not refer to the first variable only (just like the ! in php), or to the whole if sequence?

Lua:
if not bool1 and bool2 then
  print("yes this happened")

EDIT: never mind, I realised that there are online Lua sandboxes where I can test these things without actually having EQ and Macroquest running. Sorry for the spam. :(
 
Last edited:
At the beginning there is a decent learning curve to understand the right syntax. Had similar issues when I started to do stuff with Lua. But soon I got the feeling, that Lua is much faster in running the code and it became fun to achieve what I wanted.
 
Question - First lua and first lua question

Users who are viewing this thread

Back
Top
Cart