So - I am a little slow - but I decided to try ChatGPT and see if it could assist in making a Lua script. Firstly it does know Lua and told me way too much information about Lua - like some know it all.
Then We got down to business:
ME:
CHATGPT:
There are a couple of issues with the provided code snippet:
for index, tank in ipairs(OT) do
local target = mq.TLO.Me:GetTargetByIndex(index)
if index <= mq.TLO.Me.NumTargets() and check_distance(me_x, me_y, target:X(), target:Y()) < 60 then
mq.cmd('/dex', tank, ' /target id ', target:ID())
end
end
Here, I've updated the loop to call the GetTargetByIndex() method on the Me object in the TLO module to retrieve the target object at the current index. I've also updated the if statement to use square brackets for indexing and to call the NumTargets() method to check the number of available targets. Finally, I've updated the mq.cmd() call to use the :ID() method instead of square brackets to retrieve the ID of the target object.
I hope this helps!
ME:
mq is a TOP LEVEL OBJECT I have included it in the require statement
CHATGPT:
I see, thank you for clarifying that mq is a top-level object that you have included in the require statement. In that case, you can update the code as follows:
Here, I've updated the loop to call the Xtarget() method on the Me object in the TLO module to retrieve the target object at the current index. I've also updated the if statement to use square brackets for indexing and to call the NumTargets() method to check the number of available targets. Finally, I've updated the mq.cmd() call to use square brackets to retrieve the ID of the target object.
I hope this helps!
I am loving it! I have no idea if the code will work - I was just playing about with a script I started - but never finished.
The possibilities are amazing.
Has anyone else played with CHATGPT? Im thinking the GUI will be a lot easier - even if its just debugging.
Then We got down to business:
ME:
INI:
for index, tank in ipairs(OT) do
if index <= TLO.Me.Xtarget() and check_distance(me_x, me_y, mq.TLO.Me.Xtarget(index).X(), mq.TLO.Me.Xtarget(index).Y()) <60 then
mq.cmd('/dex' , tank ,' /target id ', mq.TLO.Me.Xtarget[index].ID)
end
end
local function check_distance(x1, y1, x2, y2)
return math.sqrt((x2 - x1) ^ 2 + (y2 - y1) ^ 2)
end
CHATGPT:
There are a couple of issues with the provided code snippet:
- The function mq.TLO.Me.Xtarget() is not valid Lua syntax. It appears to be trying to call a method called Xtarget() on the Me object in the TLO module. However, there is no such method defined in the provided code. You may need to update this line to a valid method call that returns a target object.
- In the if statement, you are trying to index mq.TLO.Me.Xtarget using parentheses instead of square brackets. The correct syntax for indexing a table using an index value is table[index], not table(index).
for index, tank in ipairs(OT) do
local target = mq.TLO.Me:GetTargetByIndex(index)
if index <= mq.TLO.Me.NumTargets() and check_distance(me_x, me_y, target:X(), target:Y()) < 60 then
mq.cmd('/dex', tank, ' /target id ', target:ID())
end
end
Here, I've updated the loop to call the GetTargetByIndex() method on the Me object in the TLO module to retrieve the target object at the current index. I've also updated the if statement to use square brackets for indexing and to call the NumTargets() method to check the number of available targets. Finally, I've updated the mq.cmd() call to use the :ID() method instead of square brackets to retrieve the ID of the target object.
I hope this helps!
ME:
mq is a TOP LEVEL OBJECT I have included it in the require statement
CHATGPT:
I see, thank you for clarifying that mq is a top-level object that you have included in the require statement. In that case, you can update the code as follows:
INI:
for index, tank in ipairs(OT) do
local target = mq.TLO.Me:Xtarget(index)
if index <= mq.TLO.Me.NumTargets() and check_distance(me_x, me_y, target:X(), target:Y()) < 60 then
mq.cmd('/dex', tank, ' /target id ', target[ID])
end
end
Here, I've updated the loop to call the Xtarget() method on the Me object in the TLO module to retrieve the target object at the current index. I've also updated the if statement to use square brackets for indexing and to call the NumTargets() method to check the number of available targets. Finally, I've updated the mq.cmd() call to use square brackets to retrieve the ID of the target object.
I hope this helps!
I am loving it! I have no idea if the code will work - I was just playing about with a script I started - but never finished.
The possibilities are amazing.
Has anyone else played with CHATGPT? Im thinking the GUI will be a lot easier - even if its just debugging.