Guest User

Untitled

a guest
Jan 24th, 2018
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.88 KB | None | 0 0
  1. Script name: showMap
  2. EventHandlers: gmcp.Room.Info
  3.  
  4. -------------------------------------------------
  5. --         Put your Lua functions here.        --
  6. --                                             --
  7. -- Note that you can also use external Scripts --
  8. -------------------------------------------------
  9. function showMap()
  10.  
  11. local function set_exit(x, y, exit, dir)
  12.  
  13.   if exit~=nil then
  14.     map[x][y][dir] = true
  15.   end
  16.  
  17. end
  18.  
  19. local function set_all_exits(roomnum, x, y)
  20.  
  21.     local exits = getRoomExits(roomnum)
  22.  
  23.     -- East, southeast, south. (current element)
  24.     set_exit(x,y, exits["east"], "east")
  25.     set_exit(x,y, exits["southeast"], "southeast")
  26.     set_exit(x,y, exits["south"], "south")
  27.  
  28.     -- Northwest. (northwest element)
  29.     if (x~=0 and y~=0) then
  30.         set_exit(x-1,y-1, exits["northwest"], "southeast")
  31.     end
  32.  
  33.     -- North, northeast. (north element)
  34.     if (y~=0) then
  35.         set_exit(x, y-1, exits["north"], "south")
  36.         set_exit(x, y-1, exits["northeast"], "southeast_rev")
  37.     end
  38.  
  39.     -- West, southwest. (west element)
  40.     if (x~=0) then
  41.         set_exit(x-1, y, exits["west"], "east")
  42.         set_exit(x-1, y, exits["southwest"], "southeast_rev")
  43.     end
  44.  
  45.     -- In, out.
  46.     map[x][y].in_out = exits["in"] and true or (exits["out"] and true or false)
  47.     map[x][y].up = exits["up"] and true or false
  48.     map[x][y].down = exits["down"] and true or false
  49.  
  50. end
  51.  
  52. local function fill_map(roomnum,x,y, level)
  53.   local xi = { 0, 1, 1, 1, 0, -1, -1, -1, 2, 2, 2, 2, 2 }
  54.   local yi = { -1, -1, 0, 1, 1, 1, 0, -1, 2, 2, 2, 2, 2 }
  55.   local directions = {"north", "northeast", "east", "southeast", "south", "southwest", "west", "northwest", "up", "down", "in", "out"}
  56.  
  57.   if mapped_rooms[roomnum] then
  58.     return
  59.   end
  60.   if x < 0 or x >= 18 or y < 0 or y >= 14 then
  61.     return
  62.   end
  63.   if current_area ~= getRoomArea(roomnum) then
  64.     return
  65.   end
  66.  
  67. --  if level == 13 then
  68. --    return
  69. --  end
  70.  
  71.   mapped_rooms[roomnum] = true
  72.  
  73.   map[x][y].room = roomnum
  74.  
  75.   set_all_exits(roomnum, x, y)
  76.  
  77.   local exits = getRoomExits(roomnum)
  78.  
  79.   for num, name in ipairs(directions) do
  80.     if exits[name] and roomExists(exits[name]) then
  81.        local xn,yn,zn = getRoomCoordinates(exits[name])
  82.        local xo,yo,zo = getRoomCoordinates(roomnum)
  83.        local lengthx, lengthy = xo-xn, yn-yo
  84.        if xi[num]~=2 and yi[num]~=2 then
  85.          fill_map(exits[name], x - lengthx, y - lengthy, level+1)
  86.        end
  87.     end
  88.   end
  89. end
  90.  
  91.  map = {}
  92. mapped_rooms = {}
  93.  current_area = getRoomArea(gmcp.Room.Info.num)
  94. for i=0, 18 do
  95.   map[i] = {}
  96.   for j = 0, 14 do
  97.     map[i][j] = {}
  98.   end
  99. end
  100.  
  101. fill_map(gmcp.Room.Info.num, 9, 7, 0)
  102. for y = 0, 14 do
  103.   local line = ""
  104.   for x = 0, 18 do
  105.     if map[x][y].room then
  106.       line = line .. "["
  107.       if x == 9 and y == 7 then
  108.         line = line .. "+"
  109.       elseif map[x][y].in_out then
  110.         line = line .. "o"
  111.       elseif map[x][y].up and map[x][y].down then
  112.         line = line .. "X"
  113.       elseif map[x][y].up then
  114.         line = line .. "^"
  115.       elseif map[x][y].down then
  116.         line = line .. "v"
  117.       else
  118.         line = line .. " "
  119.       end
  120.       line = line .. "]"
  121.     else
  122.       line = line .. "   "
  123.     end
  124.     if map[x][y].east then
  125.       line = line .. "-"
  126.     else
  127.       line = line .. " "
  128.     end
  129.   end
  130.   line = line .. "\n"
  131.   echo(line)
  132.  
  133.   line = ""
  134.   for x = 0, 18 do
  135.     if map[x][y].south then
  136.       line = line .. " | "
  137.     else
  138.       line = line .. "   "
  139.     end
  140.     if map[x][y].southeast and not map[x][y].southeast_rev then
  141.       line = line .. "\\"
  142.     elseif map[x][y].southeast and map[x][y].southeast_rev then
  143.       line = line .. "X"
  144.     elseif not map[x][y].southeast and map[x][y].southeast_rev then
  145.       line = line .. "/"
  146.     else
  147.       line = line .. " "
  148.     end
  149.   end
  150.   line = line .. "\n"
  151.   echo(line)
  152. end
  153. --display(map)
  154. --centerview(7695)
  155. end
Add Comment
Please, Sign In to add comment