Okay I have no clue what I'm doing I guess.
So in order to generate the table I need to place it in a trigger that's pulling the coordinates of the enemy right?
I read on the page about tables the table doesn't go in the trigger so how do I populate the table with the info?
Note: I'll clean up the trigger and turn it into a reg-exp once I have it all working.
Trigger is:
<triggers>
<trigger
enabled="y"
group="test"
match="*(*, *, *)*"
send_to="12"
sequence="100"
>
<send>mobs = {} -- create the table (once only)
table.insert (mobs, {x=%2,y=%3,z=%4})
table.insert (mobs, {x=%2,y=%3,z=%4})
table.insert (mobs, {x=%2,y=%3,z=%4})
table.insert (mobs, {x=%2,y=%3,z=%4})
table.insert (mobs, {x=%2,y=%3,z=%4})
table.insert (mobs, {x=%2,y=%3,z=%4})
table.insert (mobs, {x=%2,y=%3,z=%4})
table.insert (mobs, {x=%2,y=%3,z=%4})
print ("There are", #mobs, "enemies")
for k,v in ipairs (mobs) do
print ("Mob number", k, "is at location", v.x, ",", v.y)
end -- for
me = {x=4,y=3}
-- 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 = k
else
-- record this if it is closer
if distance < closest_distance then
closest_distance = distance
closest_mob = k
end -- if
end -- if
print (string.format ("Mob %i is %0.1f away", k, distance))
end -- for
print ("Closest mob is number", closest_mob, "at",
mobs [closest_mob].x, "," , mobs [closest_mob].y)
</send>
</trigger>
</triggers>
So a few problems I'm getting is it generates 8 mobs when there's only 5.
Anytime I try to add a Z value to me it throws up there needs to be a ) error.
It also repeats itself 8 times with all the enemies. Here's a sample of just one. It throws all this out 7 more times.
I understand it's creating 8 mobs because there is 8 table.inserts but if I don't have 8 it only fills the table in with one. So how do I have it fill in with the right amount with out over populating or under populating?
Also the mobs locations aren't exactly right you'll notice that it repeats the same mob at the same coordinates a bunch.
There are 8 enemies
Mob number 1 is at location 10 , 20
Mob number 2 is at location 10 , 20
Mob number 3 is at location 10 , 20
Mob number 4 is at location 10 , 20
Mob number 5 is at location 10 , 20
Mob number 6 is at location 10 , 20
Mob number 7 is at location 10 , 20
Mob number 8 is at location 10 , 20
Mob 1 is aircraft: bomber 1 (10, 20, 18), bomber 2 (6, 20, 20), bomber 3 (3, 12, 15), bomber 4 (2, 10, 13), and bomber 5 (20, 13, 4).1f away
Mob 2 is aircraft: bomber 1 (10, 20, 18), bomber 2 (6, 20, 20), bomber 3 (3, 12, 15), bomber 4 (2, 10, 13), and bomber 5 (20, 13, 4).1f away
Mob 3 is aircraft: bomber 1 (10, 20, 18), bomber 2 (6, 20, 20), bomber 3 (3, 12, 15), bomber 4 (2, 10, 13), and bomber 5 (20, 13, 4).1f away
Mob 4 is aircraft: bomber 1 (10, 20, 18), bomber 2 (6, 20, 20), bomber 3 (3, 12, 15), bomber 4 (2, 10, 13), and bomber 5 (20, 13, 4).1f away
Mob 5 is aircraft: bomber 1 (10, 20, 18), bomber 2 (6, 20, 20), bomber 3 (3, 12, 15), bomber 4 (2, 10, 13), and bomber 5 (20, 13, 4).1f away
Mob 6 is aircraft: bomber 1 (10, 20, 18), bomber 2 (6, 20, 20), bomber 3 (3, 12, 15), bomber 4 (2, 10, 13), and bomber 5 (20, 13, 4).1f away
Mob 7 is aircraft: bomber 1 (10, 20, 18), bomber 2 (6, 20, 20), bomber 3 (3, 12, 15), bomber 4 (2, 10, 13), and bomber 5 (20, 13, 4).1f away
Mob 8 is aircraft: bomber 1 (10, 20, 18), bomber 2 (6, 20, 20), bomber 3 (3, 12, 15), bomber 4 (2, 10, 13), and bomber 5 (20, 13, 4).1f away
Closest mob is number 1 at 10 , 20
aircraft: bomber 1 (10, 20, 18), bomber 2 (6, 20, 20), bomber 3 (3, 12, 15), bomber 4 (2, 10, 13), and bomber 5 (20, 13, 4)
There are 8 enemies
Mob number 1 is at location 3 , 2
Mob number 2 is at location 3 , 2
Mob number 3 is at location 3 , 2
Mob number 4 is at location 3 , 2
Mob number 5 is at location 3 , 2
Mob number 6 is at location 3 , 2
Mob number 7 is at location 3 , 2
Mob number 8 is at location 3 , 2
Mob 1 is Current Coordinates: (3, 2, 13).1f away
Mob 2 is Current Coordinates: (3, 2, 13).1f away
Mob 3 is Current Coordinates: (3, 2, 13).1f away
Mob 4 is Current Coordinates: (3, 2, 13).1f away
Mob 5 is Current Coordinates: (3, 2, 13).1f away
Mob 6 is Current Coordinates: (3, 2, 13).1f away
Mob 7 is Current Coordinates: (3, 2, 13).1f away
Mob 8 is Current Coordinates: (3, 2, 13).1f away
Closest mob is number 1 at 3 , 2 |