• 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 - Looking for a lua expert to help me debug some code

doomzday

Member
Joined
Dec 19, 2011
RedCents
117¢
I am not an expert programmer. I just started really learning recently. I am going crazy trying to code what should be something simple, but I can't get it to work. I started trying to understand tables and I got this to work, but as soon as I introduce any MQ TLO code it fails.

[CODE lang="Lua" title="working function"]local tank_list = {

my_tank = "tank"

}



local function is_tank(table, key)

if table[key] ~= nil then

return true

else

return false

end

end


-- this returns true if I give it the name of my tank and false otherwise as expected
print(is_tank(tank_list, "my_tank"))[/CODE]

[CODE lang="Lua" title="failing function"]local tank_list = {
my_tank == "tank" -- I replace my_tank with the name of my tank I just use variable here so I don't show my character name
}

local function is_tank(table,key)

if table[key] ~= nil then
return true
else
return false
end

end

local tank_key = mq.TLO.Target.AggroHolder --this seems to return a string so should work?
print(is_tank(tank_list, tank_key)) -- it always returns false but it works if I ddon't use any MQ TLO
[/CODE]

Is there a better way to do this? I just want to see if the current mob is targeting my tank and if its not I want him to taunt. I feel like this should be very simple, but its wasted my whole day trying to figure it out.
 
check out the Lua section on docs.macroquest.org

The short version is mq.TLO.Target.AggroHolder is not a string, its an object. you need to add () to the end of any TLO expression to get a Lua value from it.
 
mq.TLO.Target.AggroHolder() is going to return next in line on the aggro list.
Code:
if mq.TLO.Me.TargetOfTarget() ~= mq.TLO.Me.CleanName() then
mq.cmd('/doability Taunt')
end
 
Sorry to trouble you all, but I have another question.

Per this documentation on mq2nav it says

/if ${Navigation.PathExists[target]} { /nav target }

However it doesn't seem to work that way for me. I was testing these commands and shouldn't this navigate to the mob I have targeted? Instead it navigates to the closest mob with the same name?

I set the target first, then I try to navigate to it.

mq.cmd.target(mq.TLO.Me.XTarget(2)()) mq.cmdf("/squelch /nav id %s", mq.TLO.Target.ID())

If I check the target id with /echo ${Me.Xtarget[2].ID} I get the same ID as if I use /echo ${Target.ID}. This really has me stumped.
 
I think I may have figured it out. I think the issue is I am passing /nav an id instead of a string value.

Nope that is not it.
 
Provided you are actually targeting the right mob. Maybe try something like this. Better to post your whole code for a better response to issues. It's hard to decode no code. :)
Code:
local target = mq.TLO.Target.CleanName()
local target_loc = mq.TLO.Target.Loc()
local target_id = mq.TLO.Target(target).ID()
if mq.TLO.Navigation.PathExists(target_loc)() then
mq.cmdf('/nav id %s', target_id)
end
 
Provided you are actually targeting the right mob. Maybe try something like this. Better to post your whole code for a better response to issues. It's hard to decode no code. :)
Code:
local target = mq.TLO.Target.CleanName()
local target_loc = mq.TLO.Target.Loc()
local target_id = mq.TLO.Target(target).ID()
if mq.TLO.Navigation.PathExists(target_loc)() then
mq.cmdf('/nav id %s', target_id)
end
don't do it this way

PathExists accepts the same arguments as /nav. If you want to check if a path exists and then nav to it, use the same arguments.

Code:
local nav_arg = string.format("id %d", mq.TLO.Target.ID())
if mq.TLO.Navigation.PathExists(nav_arg) then
    mq.cmdf("/nav %s", nav_arg)
end

ID is always more accurate than name or loc. No reason to mix them all up. If you have a target, use its ID. Doesn't even need to be your target. can be any spawn's id. like mq.TLO.Me.XTarget(2).ID()
 
This Seems to work.

This is my entire code btw. I am just testing things to learn.

[CODE title="testing code"]mq.cmd.target(mq.TLO.Me.XTarget(2)())
local the_target = mq.TLO.Target.CleanName()
mq.cmdf("/squelch /nav target %s",the_target)[/CODE]
 
don't do it this way

PathExists accepts the same arguments as /nav. If you want to check if a path exists and then nav to it, use the same arguments.

Code:
local nav_arg = string.format("id %d", mq.TLO.Target.ID())
if mq.TLO.Navigation.PathExists(nav_arg) then
    mq.cmdf("/nav %s", nav_arg)
end

ID is always more accurate than name or loc. No reason to mix them all up. If you have a target, use its ID. Doesn't even need to be your target. can be any spawn's id. like mq.TLO.Me.XTarget(2).ID()

Thanks for the heads up about ID being more accurate. I will try to learn from this. Thanks again!
 
This Seems to work.

This is my entire code btw. I am just testing things to learn.

[CODE title="testing code"]mq.cmd.target(mq.TLO.Me.XTarget(2)())
local the_target = mq.TLO.Target.CleanName()
mq.cmdf("/squelch /nav target %s",the_target)[/CODE]

target takes no additional parameters here, so all you are effectively passing is /nav target (but you should use id when possible so that you don't need to suspiciously target things to nav to them first). Also /squelch doesn't really do much to silence nav.
 
I tested your code and it works 100% of the time. That is pretty cool. I am hoping I can put this new knowledge to use.
 
Lua - Looking for a lua expert to help me debug some code

Users who are viewing this thread

Back
Top
Cart