?login_element?

Subversion Repositories NedoOS

Rev

Blame | Last modification | View Log | Download

  1. -- Find block in map
  2.  
  3. function main ()
  4.  local w = mappy.getValue(mappy.MAPWIDTH)
  5.  local h = mappy.getValue(mappy.MAPHEIGHT)
  6.  
  7.  if (w == 0) then
  8.   mappy.msgBox ("Find block in map", "You need to load or create a map first", mappy.MMB_OK, mappy.MMB_ICONINFO)
  9.  else
  10.  
  11.   mappy.msgBox ("Find block in map", "This will go to the next occurence of the currently selected block or anim", mappy.MMB_OK, mappy.MMB_ICONINFO)
  12.     local blk = mappy.getValue (mappy.CURANIM)
  13.     if (blk == -1) then
  14.      blk = mappy.getValue (mappy.CURBLOCK)
  15.     else
  16. -- setBlock need anims in the format below (ie: anim 1 should be a value of -2)
  17.      blk = -(blk+1)
  18.     end
  19.  
  20.     local y = mappy.getValue (mappy.YMAPOFFSET)
  21.     while y < h do
  22.      local x = 0
  23.      if (y == mappy.getValue (mappy.YMAPOFFSET)) then
  24.       x = mappy.getValue (mappy.XMAPOFFSET) + 1
  25.      end
  26.      while x < w do
  27.       if (mappy.getBlock (x, y) == blk) then
  28.        mappy.msgBox ("Found block "..blk, "At "..x..", "..y, mappy.MMB_OK, mappy.MMB_ICONINFO)
  29.        mappy.setValue (mappy.XMAPOFFSET, x)
  30.        mappy.setValue (mappy.YMAPOFFSET, y)
  31.        mappy.updateScreen()
  32.        return
  33.       end
  34.       x = x + 1
  35.      end
  36.      y = y + 1
  37.     end
  38.  
  39.     mappy.msgBox ("Find block in map", "No more blocks found, try moving to the top left of the map.", mappy.MMB_OK, mappy.MMB_ICONINFO)
  40.     mappy.updateScreen()
  41.  
  42.  end
  43. end
  44.  
  45. test, errormsg = pcall( main )
  46. if not test then
  47.     mappy.msgBox("Error ...", errormsg, mappy.MMB_OK, mappy.MMB_ICONEXCLAMATION)
  48. end
  49.