Scripting on the RME

EdMignari

Veteran OT User
Joined
Jan 8, 2011
Messages
193
Best answers
0
Reaction score
338
OT world has a lot of skilled Lua programmers. This will enable them to implement new features like procedural map generation, custom area selection and move, custom item replacement, etc.

Already implemented functions:

Code:
g_gui.newMap()
g_gui.loadMap(path)
g_gui.shouldSaveCurrentMap()
g_gui.saveCurrentMap()
g_gui.canUndo()
g_gui.canRedo()
g_gui.doUndo()
g_gui.doRedo()
g_gui.getEditorAt(index)
g_gui.getCurrentEditor()
g_gui.setCurrentEditor(editor)
g_gui.setCurrentEditor(index)
g_gui.getCurrentFloor()
g_gui.setCurrentFloor(z)
g_gui.getCenterPosition()
g_gui.setCenterPosition(position)
g_gui.setSelectionMode()
g_gui.setDrawingMode()
g_gui.setStatusText(text)
g_gui.showTextBox(title, text)
g_gui.getExecDirectory()
g_gui.getDataDirectory()
g_gui.getLocalDataDirectory()
g_gui.getLocalDirectory()
g_gui.getExtensionsDirectory()

Editor(index)
editor:getMapDescription()
editor:setMapDescription(newDescription)
editor:getMapWidth()
editor:setMapWidth(newWidth)
editor:getMapHeight()
editor:setMapHeight(newHeight)
editor:getTile(x, y, z)
editor:getTile(position)
editor:createSelection(start, end)
editor:selectTiles(tiles)
editor:getSelection()

Tile(x, y, z)
Tile(position)
tile:getPosition()
tile:isHouse()
tile:isHouseExit()
tile:isPvP()
tile:isNoPvP()
tile:isNoLogout()
tile:isPZ()
tile:isBlocking()
tile:isSelected()
tile:isModified()
tile:setPvP(enable)
tile:setNoPvP(enable)
tile:setNoLogout(enable)
tile:setPZ(enable)

Selection(editor, start, end)
selection:getTiles()
selection:getTileCount()
selection:getMinPosition()
selection:getMaxPosition()
selection:move(position)
selection:offset(x[, y = 0[, z = 0]])
selection:borderize()
selection:randomize()
selection:saveAsMinimap(directory, fileName)
selection:destroy()









Examples:


Code:
local startPos = {x = 231, y = 215, z = 7}
local endPos = {x = 252, y = 227, z = 7}

local editor = Editor(0) -- Gets the editor at tab 0.
if editor then
  local selection = editor:createSelection(startPos, endPos) -- Creates a rectangular selection.
  if selection  then
    local tiles = selection:getTiles()
    for _,tile in pairs(tiles) do
      tile:setPZ(false)
    end
  end
end

Code:
local startPos = {x = 231, y = 215, z = 7}
local endPos = {x = 252, y = 227, z = 7}
local destination = {x = 1000, y = 1035, z = 7}

local editor = Editor(0) -- Gets the editor at tab 0.
if editor then
  local selection = editor:createSelection(startPos, endPos) -- Creates a rectangular selection.
  if selection  then
    selection:move(destination)
  end
end

Code:
local startPos = {x = 199, y = 187, z = 7}
local endPos = {x = 278, y = 237, z = 0}
local directory = "C:/Users/Mignari/Documents/output"
local filename = "test"

local editor = Editor(0) -- Gets the editor at tab 0.
if editor then
  local selection = editor:createSelection(startPos, endPos) -- Creates a rectangular selection.
  if selection  then
    selection:saveAsMinimap(directory, filename)
  end
end

Discussion:
https://github.com/hjnilsson/rme/issues/131

Follow the development:
https://github.com/hjnilsson/rme/tree/lua_scripting

Nightly builder (Win):
https://www.dropbox.com/sh/auqhbsiqdk33gm8/AACKIsP_Z5ZeCPdWkh8ougPTa?dl=0

NOTE: this is a development version! Use it only for testing and exploring new features.
 
Last edited:

strutZ

Australian OT Member {AKA Beastn}
Joined
Nov 16, 2014
Messages
1,341
Best answers
6
Reaction score
477
This looks cool man! Perfect time for me as i'm i'm starting to map hahaha thanks!
 

Peonso

Godly Member
Joined
Jan 14, 2008
Messages
1,517
Best answers
24
Reaction score
1,014
I'm glad I inspired you!
 

whitevo

Feeling good, thats what I do.
Joined
Jan 2, 2015
Messages
3,449
Best answers
1
Reaction score
602
Location
Estonia
so it adds itemID's to position with Lua scripts?
 

Marcelo Druida

Intermediate OT User
Joined
Nov 17, 2014
Messages
423
Best answers
1
Reaction score
122
cool
i'm willing to add a system called route waypoint
i was about to start coding it entirely in C++ but i'd for sure utilize the scripting interface
 

Yamaken

Pro OpenTibia Developer
Premium User
Joined
Jul 27, 2013
Messages
464
Best answers
3
Reaction score
334
I think scripting on RME is cool but there is other things that bother me more like otbm format. Otbm format is binary and is not merge friend, two mappers can't work together on the same map which is so bad.
 
OP
EdMignari

EdMignari

Veteran OT User
Joined
Jan 8, 2011
Messages
193
Best answers
0
Reaction score
338
I think scripting on RME is cool but there is other things that bother me more like otbm format. Otbm format is binary and is not merge friend, two mappers can't work together on the same map which is so bad.
It's really that difficult to find someone who wants to do this. Changing the format without maintaining backward compatibility is a pain for us.
So the otbm format is sufficient for me.
 

Yamaken

Pro OpenTibia Developer
Premium User
Joined
Jul 27, 2013
Messages
464
Best answers
3
Reaction score
334
It's really that difficult to find someone who wants to do this. Changing the format without maintaining backward compatibility is a pain for us.
So the otbm format is sufficient for me.
What about a small hack in the otbm format? Like lock areas? I lock a certain area, commit it(Ex: git) and the other mapper can't edit that area. Then we need a tool to merge both maps. Even if we change the format, how the merging would happen? I think we would need a tool to merge anyway.
 

whitevo

Feeling good, thats what I do.
Joined
Jan 2, 2015
Messages
3,449
Best answers
1
Reaction score
602
Location
Estonia
Btw, can you add map markers on RME or something similar?
I prefer if map markers look like arrows.
Would be nice if I can add text to map markers too.

I'm currently marking my map like this:


These flags are removed on server start up.
About these flags, the annoying part is that it replaces some other item, so I have to put them down nearby and kinda spam them to make me understand where is the position I am using in my scripts.
Also to understand what corner is this marker, I sometimes have to draw a corner with flags too.
 
OP
EdMignari

EdMignari

Veteran OT User
Joined
Jan 8, 2011
Messages
193
Best answers
0
Reaction score
338
please guys let's not make this topic as feature requests for RME.
 

Kuzyn

Premium User
Premium User
Joined
Dec 19, 2009
Messages
1,351
Best answers
1
Reaction score
355
Location
Gdansk, Poland.
Btw, can you add map markers on RME or something similar?
I prefer if map markers look like arrows.
Would be nice if I can add text to map markers too.

I'm currently marking my map like this:


These flags are removed on server start up.
About these flags, the annoying part is that it replaces some other item, so I have to put them down nearby and kinda spam them to make me understand where is the position I am using in my scripts.
Also to understand what corner is this marker, I sometimes have to draw a corner with flags too.
https://github.com/hjnilsson/rme/issues/128
 

Printer

if Printer then print("LUA") end
Premium User
Joined
Dec 27, 2009
Messages
5,733
Best answers
21
Reaction score
2,020
Location
Sweden?
This is just awesome. Thank you for this!
 

Marcelo Druida

Intermediate OT User
Joined
Nov 17, 2014
Messages
423
Best answers
1
Reaction score
122
Btw, can you add map markers on RME or something similar?
I prefer if map markers look like arrows.
Would be nice if I can add text to map markers too.

I'm currently marking my map like this:


These flags are removed on server start up.
About these flags, the annoying part is that it replaces some other item, so I have to put them down nearby and kinda spam them to make me understand where is the position I am using in my scripts.
Also to understand what corner is this marker, I sometimes have to draw a corner with flags too.
I've already done something like that but I used tile flags (and on server startup I seek for these flags on the tiles)
also I did not placed items but colors like spawn/house/pz
despite of this I'm very interested in improving this to work similar as you intend
 
OP
EdMignari

EdMignari

Veteran OT User
Joined
Jan 8, 2011
Messages
193
Best answers
0
Reaction score
338
Bump!


A new useful function was added to the building:
selection:saveAsMinimap(directory, fileName)

Now is possible to export just a piece of the map as minimap(PNG). A code example was added in the topic.

Also:
editor:getMapDescription()
editor:setMapDescription(newDescription)
editor:getMapWidth()
editor:setMapWidth(newWidth)
editor:getMapHeight()
editor:setMapHeight(newHeight)
 

jockzor

IDGAF
Joined
Jul 21, 2007
Messages
45
Best answers
0
Reaction score
0
I think scripting on RME is cool but there is other things that bother me more like otbm format. Otbm format is binary and is not merge friend, two mappers can't work together on the same map which is so bad.
OTBM is an object tree structure, I don't see why you wouldn't be able to make your own representation in a text-based format and just convert between the two if you're into that sort of thing.

Personally I'd go for a server-based solution where a centralized party tells each client "draw a tree at 45,56,7" when one of the clients draws a tree there. Seems like it'd be easier to implement. If EdMignari's Lua implementation supports event listeners you could probably get a prototype up and running with the scripting feature this thread is about.
 
Top