?login_element?

Subversion Repositories NedoOS

Rev

Blame | Last modification | View Log | Download | RSS feed

  1. -- Solid rectangle
  2. -- Sets an area of the map to a specified block
  3.  
  4. function main ()
  5.  local w = mappy.getValue(mappy.MAPWIDTH)
  6.  local h = mappy.getValue(mappy.MAPHEIGHT)
  7.  
  8.  if (w == 0) then
  9.   mappy.msgBox ("Solid rectangle", "You need to load or create a map first", mappy.MMB_OK, mappy.MMB_ICONINFO)
  10.  else
  11.  
  12.   local isok,rx,ry,rw,rh = mappy.doDialogue ("Solid rectangle", "Enter x,y,width,height", "0,0,10,10", mappy.MMB_DIALOGUE2)
  13.   if isok == mappy.MMB_OK then
  14.  
  15.    rx = tonumber (rx)
  16.    ry = tonumber (ry)
  17.    rw = tonumber (rw)
  18.    rh = tonumber (rh)
  19.  
  20.    if (rx < 0 or (rx+rw) > w or ry < 0 or (ry+rh) > h) then
  21.     mappy.msgBox ("Solid rectangle", "A value was out of bounds, rectangle not drawn", mappy.MMB_OK, mappy.MMB_ICONINFO)
  22.    else
  23.  
  24.     local blk = mappy.getValue (mappy.CURANIM)
  25.     if (blk == -1) then
  26.      blk = mappy.getValue (mappy.CURBLOCK)
  27.     else
  28. -- setBlock need anims in the format below (ie: anim 1 should be a value of -2)
  29.      blk = -(blk+1)
  30.     end
  31.  
  32.     mappy.copyLayer(mappy.getValue(mappy.CURLAYER),mappy.MPY_UNDO)
  33.  
  34.     local y = ry
  35.     while y < (ry+rh) do
  36.      local x = rx
  37.      while x < (rx+rw) do
  38.       mappy.setBlock (x, y, blk)
  39.       x = x + 1
  40.      end
  41.      y = y + 1
  42.     end
  43.  
  44.     mappy.updateScreen()
  45.  
  46.    end
  47.   end
  48.  end
  49. end
  50.  
  51. test, errormsg = pcall( main )
  52. if not test then
  53.     mappy.msgBox("Error ...", errormsg, mappy.MMB_OK, mappy.MMB_ICONEXCLAMATION)
  54. end
  55.