If I could get just a bit more help I'd appreciate it.
So now we're dealing with X and Y coordinates. I figured I could just cut everything involved Z out of the script but I was wrong.
Mud output:
Current Coordinates: 20, 8
Ammo: (8, 10), (6, 4), (6, 7), (13, 5), (9, 4), (16, 1), (10, 7), (20, 1), (18, 6), and (4, 2)
I must admit I've read through the code a bunch and it's made me realize how much I don't quite understand.
I'm going to paste the code I'm using but keep in mind it's me literally going in and cutting out anything related to the Z coordinate so I'm sure I messed it up.
Trigger that finds my current location.
<triggers>
<trigger
enabled="y"
group="mapammo"
ignore_case="y"
keep_evaluating="y"
match="Current Coordinates: *, *"
name="curco"
send_to="12"
sequence="100"
>
<send>
me = { x = %1, y = %2 }
mobs = mobs or { } -- in case no mobs
-- find closest
closest_distance = nil
closest_mob = nil
for k, v in ipairs (mobs) do
-- calculate distance to me
distance = math.sqrt ((me.x - v.x)^2 + (me.y - v.y)^2)
if not closest_distance then
-- first time
closest_distance = distance
closest_mob = v
else
-- record this if it is closer
if distance < closest_distance then
closest_distance = distance
closest_mob = v
end -- if
end -- if
print (string.format ("%%s is %%0.1f km away", v.name, distance))
end -- for
if closest_mob then
print (string.format ("Closest is %%s at (%%i, %%i)",
closest_mob.name, closest_mob.x, closest_mob.y))
else
print ("No aircraft nearby")
end -- if
</send>
</trigger>
</triggers>
Ammo trigger to populate the table:
<triggers>
<trigger
group="mapammo"
keep_evaluating="y"
match="Ammo: *"
name="ammoco"
omit_from_output="y"
send_to="12"
sequence="100"
>
<send>mobs = { } -- table of mobs
function processMob (name, x, y)
-- get rid of comma from previous mob
name = string.gsub (name, "^, ", "")
-- insert into table
table.insert (mobs, { name = name, x = x, y = y } )
end -- processMob
-- split wildcard into individual mobs
string.gsub ("%1", "(.-) %((%d+), (%d+), ", processMob)
</send>
</trigger>
</triggers>
Again any help is greatly appreciated and I'm sorry for failing to grasp this concept. |