[TFS 1.1] Lua map generator (beta)

Discussion in 'Mods & Lua Functions' started by zbizu, Mar 27, 2015.

  1. nowayrlz

    nowayrlz New Member

    Joined:
    Nov 10, 2011
    Messages:
    19
    Likes Received:
    0
    Best Answers:
    0
    Is there any way to make it compatible with Otserv 0.6.3 (8.60) ?
    I got it to generate some tiles, but always a big crap with no borders
     
  2. zbizu

    zbizu ‌‌Luakami

    Joined:
    Nov 22, 2010
    Messages:
    2,437
    Likes Received:
    1,328
    Best Answers:
    0
  3. nowayrlz

    nowayrlz New Member

    Joined:
    Nov 10, 2011
    Messages:
    19
    Likes Received:
    0
    Best Answers:
    0
    Got a bunch of Item not found when created, of course cause it uses some items that do not exist in 8.6.
    Curious thing is that even if I remove every Id that not exist in 8.6 it keeps getting me those Item not found messages.
    I managed to translate the tile:getGround():getId() to getThingFromPos(pos), what would be the function to replace tile:getGround()?
     
  4. zbizu

    zbizu ‌‌Luakami

    Joined:
    Nov 22, 2010
    Messages:
    2,437
    Likes Received:
    1,328
    Best Answers:
    0
    same function I guess, just with stackpos 0
    {x = pos.x, y = pos.y, z = pos.z, stackpos = 0}
     
  5. nowayrlz

    nowayrlz New Member

    Joined:
    Nov 10, 2011
    Messages:
    19
    Likes Received:
    0
    Best Answers:
    0
    The transform thing would be doTransformItem then?
     
  6. zbizu

    zbizu ‌‌Luakami

    Joined:
    Nov 22, 2010
    Messages:
    2,437
    Likes Received:
    1,328
    Best Answers:
    0
    test before asking, otherwise you will never learn
     
  7. nowayrlz

    nowayrlz New Member

    Joined:
    Nov 10, 2011
    Messages:
    19
    Likes Received:
    0
    Best Answers:
    0
    I got no errors at all with these classes, but it only creates dirt and water tiles.
    Any help would be appreciated.
    Code (Text):
    1. Creature = {}
    2. Player = {}
    3. Monster = {}
    4. Npc = {}
    5. Game = {}
    6. Condition = {}
    7. Combat = {}
    8. Position = {}
    9. Tile = {}
    10.  
    11. function createClass(class, inheritance)
    12.    setmetatable(class, {
    13.    __index = inheritance and inheritance or nil,
    14.    __call =
    15.    function(self, cid)
    16.      if not cid then
    17.        self = {__index = class}
    18.        setmetatable(self, self)
    19.        return self
    20.      end
    21.      local cid = type(cid) == "number" and cid or type(cid) == "string" and getPlayerByNameWildcard(cid)
    22.      if cid then
    23.        if not self[cid] then
    24.          self[cid] = {__index = class}
    25.          setmetatable(self[cid], self[cid])
    26.          self[cid].cid = cid
    27.          return self[cid]
    28.        else
    29.          return self[cid]
    30.        end
    31.      else
    32.        return nil
    33.      end
    34.    end
    35.    })
    36. end
    37.  
    38. function createClass2(class, inheritance)
    39.    setmetatable(class, {
    40.    __index = inheritance and inheritance or nil,
    41.    __call =
    42.    function(self, pos)
    43.      if not pos then
    44.        self = {__index = class}
    45.        setmetatable(self, self)
    46.        return self
    47.      end
    48.      local pos = type(pos) == "table" and getThingFromPos(pos)
    49.      if pos then
    50.        if not self[pos] then
    51.          self[pos] = {__index = class}
    52.          setmetatable(self[pos], self[pos])
    53.          self[pos].type = pos.type
    54.          self[pos].itemid = pos.itemid
    55.          self[pos].actionid = pos.actionid
    56.          self[pos].pos = getThingPos(pos.uid)
    57.          return self[pos]
    58.        else
    59.          return self[pos]
    60.        end
    61.      else
    62.        return nil
    63.      end
    64.    end
    65.    })
    66. end
    67.  
    68. function createClass3(class, inheritance)
    69.    setmetatable(class, {
    70.    __index = inheritance and inheritance or nil,
    71.    __call =
    72.    function(self, pos)
    73.      if not pos then
    74.        self = {__index = class}
    75.        setmetatable(self, self)
    76.        return self
    77.      end
    78.      local pos = type(pos) == "table" and pos
    79.      if pos then
    80.        if not self[pos] then
    81.          self[pos] = {__index = class}
    82.          setmetatable(self[pos], self[pos])
    83.          self[pos].x = pos.x
    84.          self[pos].y = pos.y
    85.          self[pos].z = pos.z
    86.          self[pos].stackpos = pos.stackpos
    87.          return self[pos]
    88.        else
    89.          return self[pos]
    90.        end
    91.      else
    92.        return nil
    93.      end
    94.    end
    95.    })
    96. end
    97.  
    98. createClass(Creature)
    99. createClass(Player, Creature)
    100. createClass(Monster, Creature)
    101. createClass(Npc, Creature)
    102. createClass(Game)
    103. createClass(Condition)
    104. createClass(Combat)
    105. createClass3(Position)
    106. createClass2(Tile)
    107.  
    108. -- access metatable functions from creature
    109. function Creature:getPlayer() return Player(self.cid) end
    110. function Creature:getMonster() return Monster(self.cid) end
    111. function Creature:getNpc() return Npc(self.cid) end
    112.  
    113. -- Creature
    114. -- Creature get functions
    115. function Creature:getId() return self.cid end
    116. function Creature:getName() return getCreatureName(self.cid) end
    117. function Creature:getHealth() return getCreatureHealth(self.cid) end
    118. function Creature:getMaxHealth() return getCreatureMaxHealth(self.cid) end
    119. function Creature:getMana() return getCreatureMana(self.cid) end
    120. function Creature:getMaxMana() return getCreatureMaxMana(self.cid) end
    121. function Creature:getStorageValue(id) return getCreatureStorageValue(self.cid, id) end
    122. function Creature:getHiddenHealth() return getCreatureHideHealth(self.cid) end
    123. function Creature:getSpeakType() return getCreatureSpeakType(self.cid) end
    124. function Creature:getLookDirection() return getCreatureLookDirection(self.cid) end
    125.  
    126. -- Creature set functions
    127. function Creature:setMaxHealth(health) return setCreatureMaxHealth(self.cid, health) end
    128. function Creature:setMaxMana(mana) return setCreatureMaxMana(self.cid, mana) end
    129. function Creature:setStorageValue(storage, value) return setCreatureStorageValue(self.cid, storage, value) end
    130. function Creature:setHiddenHealth(hide) doCreatureSetHideHealth(self.cid, hide) end
    131. function Creature:setSpeakType(type) doCreatureSetSpeakType(self.cid, type) end
    132.  
    133. -- Creature misc. functions
    134. function Creature:teleportTo(newpos, pushmove) doTeleportThing(self.cid, newpos, pushmove or false) end
    135. function Creature:addHealth(health, hitEffect, hitColor, force) doCreatureAddHealth(self.cid, health, hitEffect, hitColor, force) end
    136. function Creature:addMana(mana) doCreatureAddMana(self.cid, mana) end
    137. function Creature:say(text, type, ghost, cid, pos) doCreatureSay(self.cid, text, type or SPEAK_SAY, ghost or false, cid or 0, pos) end
    138. function Creature:addCondition(condition) doAddCondition(self.cid, condition) end
    139. function Creature:removeCondition(onlyPersistent, type, subId) if onlyPersistent then doRemoveConditions(self.cid, onlyPersistent) else doRemoveCondition(self.cid, type, subId) end end
    140. function Creature:moveCreature(direction) doMoveCreature(self.cid, direction) end
    141. function Creature:isCreature() return isCreature(self.cid) end
    142. function Creature:isPlayer() return isPlayer(self.cid) end
    143. function Creature:isMonster() return isMonster(self.cid) end
    144. function Creature:isNpc() return isNpc(self.cid) end
    145. function Creature:remove(forceLogout) doRemoveCreature(self.cid, forceLogout or true) end
    146.  
    147. -- Player
    148. -- Player get functions
    149. function Player:getLevel() return getPlayerLevel(self.cid) end
    150. function Player:getExperience() return getPlayerExperience(self.cid) end
    151. function Player:getMagicLevel(ignoreBuffs) return getPlayerMagLevel(self.cid, ignoreBuffs) end
    152. function Player:getManaSpent() return getPlayerSpentMana(self.cid) end
    153. function Player:getFood() return getPlayerFood(self.cid) end
    154. function Player:getAccess() return getPlayerAccess(self.cid) end
    155. function Player:getGhostAccess() return getPlayerGhostAccess(self.cid) end
    156. function Player:getSkillLevel(skillid) return getPlayerSkillLevel(self.cid, skillid) end
    157. function Player:getSkillTries(skillid) return getPlayerSkillTries(self.cid, skillid) end
    158. function Player:getTown() return getPlayerTown(self.cid) end
    159. function Player:getVocation() return getPlayerVocation(self.cid) end
    160. function Player:getBaseVocation() local vocation = self:getVocation(); return vocation > 4 and vocation - 4 or vocation end
    161. function Player:getIp() return getPlayerIp(self.cid) end
    162. function Player:getRequiredMana(magicLevel) return getPlayerRequiredMana(self.cid, magicLevel) end
    163. function Player:getRequiredSkillTries(skillId, skillLevel) return getPlayerRequiredSkillTries(self.cid, skillId, skillLevel) end
    164. function Player:getItemCount(itemid, subType) return getPlayerItemCount(self.cid, itemid, subType or -1) end
    165. function Player:getMoney() return getPlayerMoney(self.cid) end
    166. function Player:getSoul() return getPlayerSoul(self.cid) end
    167. function Player:getCap() return getPlayerFreeCap(self.cid) end
    168. function Player:getLight() return getPlayerLight(self.cid) end
    169. function Player:getSlotItem(slot) return getPlayerSlotItem(self.cid, slot) end
    170.  
    171. -- Player set functions
    172. function Player:setMaxCap(cap) doPlayerSetMaxCapacity(self.cid, cap) end
    173. function Player:setTown(townid) doPlayerSetTown(self.cid, townid) end
    174. function Player:setVocation(vocation) doPlayerSetVocation(self.cid, vocation) end
    175.  
    176.  
    177. -- Player send functions
    178. function Player:sendCancelMsg(text) doPlayerSendCancel(self.cid, text) end
    179. function Player:sendDefaultCancelMsg(ReturnValue) doPlayerSendDefaultCancel(self.cid, ReturnValue) end
    180. function Player:sendTextMessage(MessageClasses, message) doPlayerSendTextMessage(self.cid, MessageClasses, message) end
    181. function Player:sendChannelMessage(author, message, SpeakClasses, channel) doPlayerSendChannelMessage(self.cid, author, message, SpeakClasses, channel) end
    182. function Player:sendToChannel(targetId, SpeakClasses, message, channel, time) doPlayerSendToChannel(self.cid, targetId, SpeakClasses, message, channel, time) end
    183. function Player:addMoney(money) doPlayerAddMoney(self.cid, money) end
    184. function Player:removeMoney(money) doPlayerRemoveMoney(self.cid, money) end
    185. function Player:transferMoney(target, money) doPlayerTransferMoneyTo(self.cid, target, money) end
    186. function Player:showTextDialog(itemid, text) doShowTextDialog(self.cid, itemid, text) end
    187. function Player:addSkillTries(skillid, n, useMultiplier) doPlayerAddSkillTry(self.cid, skillid, n, useMultiplier or false) end
    188.  
    189. -- Player misc. functions
    190. function Player:feed(food) doPlayerFeed(self.cid, food) end
    191. function Player:addSpentMana(amount, useMultiplier) doPlayerAddSpentMana(self.cid, amount, useMultiplier) end
    192. function Player:addSoul(soul) doPlayerAddSoul(self.cid, soul) end
    193. function Player:addItem(itemid, count, canDropOnMap, subtype) return doPlayerAddItem(self.cid, itemid, count, canDropOnMap, subtype) end
    194. function Player:addItemEx(uid, canDropOnMap) return doPlayerAddItemEx(self.cid, uid, canDropOnMap or false) end
    195. function Player:addExperience(amount) doPlayerAddExperience(self.cid, amount) end
    196. function Player:savePlayer(shallow) doPlayerSave(self.cid, shallow or false) end
    197. function Player:isPzLocked() return isPlayerPzLocked(self.cid) end
    198.  
    199. -- Game
    200. function Game.getStorageValue(key) return getGlobalStorageValue(key) end
    201. function Game.setStorageValue(key, value) setGlobalStorageValue(key, value) end
    202. function Game.getChannelUsers(channelId) return getChannelUsers(channelId) end
    203. function Game.setWorldType(type) return setWorldType(type) end
    204. function Game.getWorldType() return getWorldType() end
    205. function Game.getSpectators(centerPos, rangex, rangey, multifloor) return getSpecators(centerPos, rangex, rangey, multifloor or false) end
    206. function Game.getPlayers() return getPlayersOnline() end
    207. function Game.getExperienceStage(level) return getExperienceStage(level) end
    208. function Game.getGameState() return getGameState() end
    209. function Game.setGameState(state) return doSetGameState(state) end
    210. function Game.startRaid(raid) return doExecuteRaid(raid) end
    211. function Game.createItem(itemId, count, position) return doCreateItem(itemId, count, position) end
    212. function Game.createTile(itemId, position) return doCreateItem(itemId, 1, position) end
    213. function Game.createMonster(name, pos, extend, force, displayError) return doCreateMonster(name, pos, extend or false, force or false, displayError or true) end
    214. function Game.createNpc(name, pos, displayError) return doCreateNpc(name, pos, displayError or true) end
    215.  
    216. -- Condition
    217. --
    218.  
    219. -- Combat
    220. --
    221.  
    222. -- Position
    223. function Position:new(pos)
    224.     return {x = pos.x, y = pos.y, z = pos.z}
    225. end
    226.  
    227. function Position:iterateArea(topos, func)
    228.     for z = self.z, topos.z do
    229.     for y = self.y, topos.y do
    230.     for x = self.x, topos.x do
    231.         func({x = x, y = y, z = z})
    232.     end
    233.     end
    234.     end
    235. end
    236.  
    237. -- Tile
    238.  
    239.  
    240. --[[function Tile(pos)
    241.     print("deu")
    242.     --print(getThingFromPos(pos))
    243.     return getThingFromPos(pos)
    244. end]]--
    245.  
    246. function Tile:getGround()
    247.  
    248.     return getThingFromPos(self.pos)
    249. end
    250.  
    251. function Tile:getItemById(id)
    252.     return getTileItemById(self.pos,id)
    253. end
    254.  
    255.  
    256. function Tile:getTileInfo(pos)
    257.     return getTileInfo(pos and pos or self:getPosition())
    258. end
    EDIT:
    Nvm, got it to work...
    Does it adds furniture like the other one of evorpg?
     
    Last edited: Jun 26, 2016
  8. Mock

    Mock Mock the bear (MTB)

    Joined:
    Jul 29, 2008
    Messages:
    619
    Likes Received:
    90
    Best Answers:
    0
    Sometimes in the year i login to see if there is something good. Most of times, nope.

    This one... holy shit! <3

    im impressed.

    <edit>

    Have you tought about creating some kind of instances? Like using the same map area, but multiple players cannot see or interact with each other.

    Will be an kind of revolution to OTservers. Creating map areas proceduraly. Each area only exist for one player or others in party. Creating an stuff PoE (path of exile) like. Players only meet at city.

    I am willing to work again in ots to try this c:
     
    SN4KY and silveralol like this.
  9. zbizu

    zbizu ‌‌Luakami

    Joined:
    Nov 22, 2010
    Messages:
    2,437
    Likes Received:
    1,328
    Best Answers:
    0
    You are alive :O
    Thank you for your contribution to otland. Your scripts taught me a lot.

    I could design a system which would duplicate a certain area, but it would be a waste of resources.
    I believe there is a better way to achieve this with source edits.

    Anyway, I'm working on more advanced generator than this one (see link in my signature).
    If someone implement working instances system I could make my generator support them easily.
     
    hellboy likes this.
  10. kito2

    kito2 mtibia-global.com Just a noob

    Joined:
    Mar 9, 2009
    Messages:
    3,307
    Likes Received:
    72
    Best Answers:
    0
    Wow! Totally amazing!

    I have a question: It can create random caves without ground tiles? For example you designate an area range and it creates a random cave with random monsters.

    Totally amazing! Great job!
     
  11. jmarkos

    jmarkos Member

    Joined:
    Dec 11, 2008
    Messages:
    31
    Likes Received:
    0
    Best Answers:
    0
    Thanks for the contribuition bro.
     
  12. zbizu

    zbizu ‌‌Luakami

    Joined:
    Nov 22, 2010
    Messages:
    2,437
    Likes Received:
    1,328
    Best Answers:
    0
    Working on it in the new version (no ETA at this time).
     
  13. chiitus

    chiitus Member

    Joined:
    Jun 1, 2009
    Messages:
    201
    Likes Received:
    10
    Best Answers:
    0
    Oh Mock, btw, thanks for your contribution in OTSERVER evolution.
    This feature will be nice, but this system will not consume too much memory/CPU?

    @TOPIC
    Man, any doubt or helpneed feel free to post here, we will be glad to help.
    Thanks for this amazing feature.
     

Share This Page

Loading...