[Home] [Downloads] [Search] [Help/forum]


Register forum user name Search FAQ

Gammon Forum

Notice: Any messages purporting to come from this site telling you that your password has expired, or that you need to "verify" your details, making threats, or asking for money, are spam. We do not email users with any such messages. If you have lost your password you can obtain a new one by using the password reset link.
 Entire forum ➜ MUSHclient ➜ General ➜ changing variables with new data

changing variables with new data

It is now over 60 days since the last post. This thread is closed.     Refresh page


Pages: 1  2 

Posted by Zack   (23 posts)  Bio
Date Reply #15 on Thu 03 Mar 2022 07:38 AM (UTC)

Amended on Thu 03 Mar 2022 07:57 PM (UTC) by Nick Gammon

Message
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 &lt; 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.
Top

Posted by Nick Gammon   Australia  (23,046 posts)  Bio   Forum Administrator
Date Reply #16 on Thu 03 Mar 2022 07:58 PM (UTC)
Message
You haven't said what is wrong. Is there an error message? If so what is it? Is it doing something wrong? If so, what?

- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

The dates and times for posts above are shown in Universal Co-ordinated Time (UTC).

To show them in your local time you can join the forum, and then set the 'time correction' field in your profile to the number of hours difference between your location and UTC time.


28,236 views.

This is page 2, subject is 2 pages long:  [Previous page]  1  2 

It is now over 60 days since the last post. This thread is closed.     Refresh page

Go to topic:           Search the forum


[Go to top] top

Quick links: MUSHclient. MUSHclient help. Forum shortcuts. Posting templates. Lua modules. Lua documentation.

Information and images on this site are licensed under the Creative Commons Attribution 3.0 Australia License unless stated otherwise.

[Home]