Lua Dugeon System

Discussion in 'Support' started by zabuzo, Sep 9, 2018.

  1. zabuzo

    zabuzo Member

    Joined:
    Jun 10, 2016
    Messages:
    116
    Likes Received:
    16
    Best Answers:
    0
    I miss dugeon system on OTs.
    I wanna make a server based in dugeon system.
    I made this pseudo code to this dugeon system:

    - 4 sqms (1 per vocation)
    - different IPs
    - a lot dugeons in same script
    - some tasks min/max lvl
    - 24 hours exausted per task (after in)
    - only 1 team per time
    - no logout zone inside task and after 15 min if players dont kill the boss and open the chest, go teleport back to fromPos
    - random rewards

    /lib/dugeon_system.lua
    Code (Text):
    1.  
    2. local dugeonName = "dragons"
    3.  
    4. local fromPos[1] = {x = 952, y = 1039, z = 7},
    5. local fromPos[2] = {x = 953,, y = 1039, z = 7},
    6. local fromPos[3] = {x = 954, y = 1039, z = 7},
    7. local fromPos[4] = {x = 955, y = 1039, z = 7},
    8.  
    9. local toPos[1]    = {x = 952, y = 1039, z = 6},
    10. local toPos[1]    = {x = 953, y = 1039, z = 6},
    11. local toPos[1]    = {x = 954, y = 1039, z = 6},
    12. local toPos[1]    = {x = 955, y = 1039, z = 6},
    13.  
    14. local playerMinimumLevel = 15
    15. local playerMaximumLevel = 30
    16.  
    17. local rewards = {1100, 1101, 1102}
    18.  

    <action actionid="9602" script="dugeonsystem_lever.lua"/>
    Code (Text):
    1.  
    2. -- get a vocation's base vocation
    3. function getBaseVocation(vocation)
    4.     if vocation >= 5 and vocation <= 8 then
    5.         return vocation - 4
    6.     elseif vocation >= 9 and vocation <= 12 then
    7.         return vocation - 8
    8.     end
    9.     return vocation
    10. end
    11.  
    12. function onUse(cid)
    13.     for i = 1, 4 do
    14.         local pid = getTopCreature(p[i].player.position).uid
    15.         if isPlayer(pid) then
    16.             -- MIN / MAX level
    17.             if getPlayerLevel(pid) > playerMinimumLevel then
    18.                 doPlayerSendCancel(cid, getCreatureName(pid) .. ", is not high enough in level, minimum level is " .. playerMinimumLevel .. ".")
    19.                 return false
    20.             end
    21.             if getPlayerLevel(pid) < playerMinimumLevel then
    22.                 doPlayerSendCancel(cid, getCreatureName(pid) .. ", is not low enough in level, maximum level is " .. playerMinimumLevel .. ".")
    23.                 return false
    24.             end
    25.             -- CHECK 1 PER VOCATION (1 knight, 1 paladin, 1 sorcerer, 1 druid)
    26.             if getBaseVocation( getPlayerVocation(pid) ) == X then
    27.             -- CHECK IF EVERY PLAYER HAVE DIFFERENT IP
    28.             if() then
    29.  
    30.             end
    31.             -- everything is working - GO GO GO  
    32.             -- check if have 4 players allowed
    33.             if() then
    34.                 doPlayerSendTextMessage(pid, MESSAGE_INFO_DESCR, "You are inside " .. dugeonName .. "dugeon! You have 15 minutes to finish this dugeon.")
    35.                 doTeleportThing(x, pos)
    36.                 -- add a PLAYER storage and if player do not finish dugeon in 15 minutes teleport back to fromPos
    37.                 -- add a PLAYER storage to set exausted for this task (24 hours)
    38.                 -- add a GLOBAL storage to block dugeon to no other team enter, if there is a team inside
    39.             end
    40.  
    41.     end
    42.     return true
    43. end
    44.  
    <action actionid="9603" script="dugeonsystem_chest.lua"/>
    Code (Text):
    1.  
    2. function onUse(cid, item, fromPosition, itemEx, toPosition)
    3.     -- STORAGE
    4.     local storage = 9603
    5.     -- check if player is in a dugeon (to avoid abuses)
    6.     -- check if player is in a dugeon exausted (to avoid aabuses)
    7.     -- ITEMS
    8.     local rewardid = random rewards
    9.     if getPlayerFreeCap(cid) >= getItemWeightById(rewardid, 1) then
    10.     doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, 'You have found a '..getItemNameById(rewardid)..'. It weighs '..getItemWeightById(rewardid, 1)..'.00 and it is too heavy.')
    11.     return false
    12.     end
    13.     doPlayerAddItem(cid, rewardid, 1)
    14.     -- STOP auto teleport OUT (15 min inside with no complete, teleport out...)
    15.     -- teleport player topos
    16.     return true
    17. end
    18.  
    edit: I'm using 0.4 sources
     
    Last edited: Sep 15, 2018
    supergt likes this.
  2. zabuzo

    zabuzo Member

    Joined:
    Jun 10, 2016
    Messages:
    116
    Likes Received:
    16
    Best Answers:
    0
  3. TheRatazana

    TheRatazana Member

    Joined:
    Feb 5, 2015
    Messages:
    37
    Likes Received:
    29
    Best Answers:
    7
    Hi zabuzo

    I like of your ideia, is really a cool thing to have in a RPG server. And the fact that you create a pseudo code with the schematic of things is really nice. This is not a very small system, although it can be made in a very simple way. For now I don't have time to work on this, but I can contribute with some code sometimes, so maybe we can collaborate on this.

    As an start I offer to you the lib/dungeon_system.lua. This will create a Dungeon element to store all the data about a specific dungeon, and methods to make it work without polluting others scripts. Check this out:


    Code (Lua):
    1. local dungeons = {}
    2.  
    3. function Dungeon(name, minLevel, maxLevel, rewards)
    4.     local this = {
    5.         name = name or "unamed",
    6.         minLevel = minLevel or 1,
    7.         maxLevel = maxLevel or 1,
    8.         rewards = rewards or {},
    9.         druid = nil,
    10.         knight = nil,
    11.         sorcerer = nil,
    12.         paladin = nil
    13.     }
    14.  
    15.     -- Check if all positions are occuped
    16.     function this.isFull(self)
    17.         return self.druid and self.knight and self.sorcerer and self.paladin
    18.     end
    19.  
    20.     -- Start dungeon teleporting the players and setting additional events
    21.     function this.start(self)
    22.         if self:isFull() then
    23.         end
    24.     end
    25.  
    26.     -- Add a player to dungeon
    27.     function this.addPlayer(self, player)
    28.         if player:isPlayer() and not self:isFull() then
    29.             local level = player:getLevel()
    30.             if level > this.maxLevel or level < this.minLevel then
    31.                 player:sendCancelMessage("You can't do this dungeon")
    32.                 return false
    33.             end
    34.  
    35.             local vocation = this.getPlayerBaseVocation(player)
    36.             if vocation:getName() == "knight" and not this.knight then
    37.                 this.knight = player
    38.             elseif vocation:getName() == "druid" and not this.druid then
    39.                 this.druid = player
    40.             elseif vocation:getName() == "paladin" and not this.paladin then
    41.                 this.paladin = player
    42.             elseif vocation:getName() == "sorcerer" and not this.sorcerer then
    43.                 this.sorcerer = player
    44.             end
    45.             return true
    46.         end
    47.         return false
    48.     end
    49.  
    50.     -- Clear the players on dungeon
    51.     function this.clearPlayers(self)
    52.         self.knight = nil
    53.         self.druid = nil
    54.         self.sorcerer = nil
    55.         self.paladin = nil
    56.     end
    57.  
    58.     -- Finish the dungeon giving the prizes
    59.     function this.finish(self)
    60.  
    61.     end
    62.  
    63.     -- This will perform a check in a row style looking for player meeting the requirements
    64.     -- returns true if the isFull, otherwise returns false and clear the players from dungeon obj
    65.     function this.checkRow(self, position)
    66.         for y = position.y, position.y + 4 do
    67.             local tile = Tile(position)
    68.             if tile then
    69.                 local topPlayer = Player(tile:getTopCreature())
    70.                 if topPlayer then
    71.                     if topPlayer:getLevel() >= self.minLevel and topPlayer:getLevel() <= self.maxLevel then
    72.                         this:addPlayer(topPlayer)
    73.                     end
    74.                 end
    75.             end
    76.             -- Lets check next
    77.             position.y = y
    78.         end
    79.  
    80.         if this:isFull() then
    81.             return true
    82.         end
    83.  
    84.         this:clearPlayers()
    85.         return false
    86.     end
    87.  
    88.     -- Teleport all the participantes to the passed destinations
    89.     -- positions is a table of positions = {{x,y,z},{x,y,z}}
    90.     function this.teleportTo(positions)
    91.         if this.isFull() then
    92.             if #positions >=4 then
    93.                 druid:teleportTo(positions[1])
    94.                 knight:teleportTo(positions[2])
    95.                 sorcerer:teleportTo(positions[3])
    96.                 paladin:teleportTo(positions[4])
    97.             elseif #positions == 1 then
    98.                 druid:teleportTo(positions[1])
    99.                 knight:teleportTo(positions[1])
    100.                 sorcerer:teleportTo(positions[1])
    101.                 paladin:teleportTo(positions[1])
    102.             end
    103.         end
    104.     end
    105.  
    106.     -- This return the base vocation from a passed player
    107.     function this.getPlayerBaseVocation(player)
    108.         local vocation = player:getVocation()
    109.         while(vocation:getDemotion()) do
    110.             vocation = vocation:getDemotion()
    111.         end
    112.         return vocation
    113.     end
    114.  
    115.     return this
    116. end
    So you use like this. In somewhere you create a Dungeon(name, minLevel, maxLevel, rewards) obj as global:
    Code (Lua):
    1. g_Dungeons = {
    2.     Dragons = Dungeon("Dragons", 15, 30, {1100, 1101, 1102})
    3. }
    And use in the lever script like:
    Code (Lua):
    1. if g_Dungeons.Dragons:checkRow({x = 952, y = 1039, z = 7}) then
    2.     g_Dungeons.Dragons:teleportTo({{x = 952, y = 1039, z = 6}, {x = 953, y = 1039, z = 6}, {x = 954, y = 1039, z = 6}, {x = 955, y = 1039, z = 6}})
    3.     g_Dungeons.Dragons:start()
    4. end
    And to finish something like:
    Code (Lua):
    1. g_Dungeons.Dragons.teleportTo({{x = 952, y = 1039, z = 7}, {x = 953, y = 1039, z = 7}, {x = 954, y = 1039, z = 7}, {x = 955, y = 1039, z = 7}})
    2. g_Dungeons.Dragons.finish()
    In start and finish we should implement things like add/remove a storage, un/registering a event to check if is on dungeon and things like that

    !CAUTION! : This is a experimental code, not fully tested, can have many errors and is incomplete.
    @NOTE 1: As you don't say for what version of TFS I made this assuming something like 1.2/1.3
    @NOTE 2: I can't test this in a OT. But is free of lua syntax errors as checked with lua 5.1 interpreter
    @NOTE 3: This is very simple, and only assume the 4 vocations case

    Good lucky with this buddy. Would be nice to have such a system for the community to use
     
    zabuzo, Colors and supergt like this.
  4. supergt

    supergt Member

    Joined:
    May 11, 2017
    Messages:
    63
    Likes Received:
    22
    Best Answers:
    0
    I'm 100% percent uses this if had a system works to 0.4...

    A better way to kick players from dugeon was set cave no logout zone
    Add global storage to server, anyway idk how to do, just giving a idea...
     
    zabuzo likes this.
  5. TheRatazana

    TheRatazana Member

    Joined:
    Feb 5, 2015
    Messages:
    37
    Likes Received:
    29
    Best Answers:
    7
    But setting no logout zone will only make the char keep up, even if the client goes x closed no? If it really kicks, this will be a clever idea

    Nice to see that you would use this supergt. I don't see why we can't make this for 1.2/1.3 and for 0.4 too. I will try to make better solution for positions and vocations, and also make it compatible, or a version separated for 0.4 so you can try it out. Just need to have some free time for this
     
    zabuzo and supergt like this.
  6. supergt

    supergt Member

    Joined:
    May 11, 2017
    Messages:
    63
    Likes Received:
    22
    Best Answers:
    0
    Thats true, players also need a storage to get kicked off...
     
    zabuzo likes this.
  7. zabuzo

    zabuzo Member

    Joined:
    Jun 10, 2016
    Messages:
    116
    Likes Received:
    16
    Best Answers:
    0
    @TheRatazana thank you so much to this base

    Fuck, i should say that i'm using 0.4 source pack (topic edited)

    So to use this i have to add
    data/lib/dungeon_system.lua
    Code (Text):
    1.  
    2. local g_Dungeons = {
    3.     -- Dungeon(name, minLevel, maxLevel, rewards)
    4.     Dragons = Dungeon("Dragons", 15, 30, {1100, 1101, 1102})
    5. }
    6.  
    7. function Dungeon(name, minLevel, maxLevel, rewards)
    8.     local this = {
    9.         name = name or "unamed",
    10.         minLevel = minLevel or 1,
    11.         maxLevel = maxLevel or 1,
    12.         rewards = rewards or {},
    13.         druid = nil,
    14.         knight = nil,
    15.         sorcerer = nil,
    16.         paladin = nil
    17.     }
    18.     -- Check if all positions are occuped
    19.     function this.isFull(self)
    20.         return self.druid and self.knight and self.sorcerer and self.paladin
    21.     end
    22.     -- Start dungeon teleporting the players and setting additional events
    23.     function this.start(self)
    24.         if self:isFull() then
    25.         end
    26.     end
    27.     -- Add a player to dungeon
    28.     function this.addPlayer(self, player)
    29.         if player:isPlayer() and not self:isFull() then
    30.             local level = player:getLevel()
    31.             if level > this.maxLevel or level < this.minLevel then
    32.                 player:sendCancelMessage("You can't do this dungeon")
    33.                 return false
    34.             end
    35.             local vocation = this.getPlayerBaseVocation(player)
    36.             if vocation:getName() == "knight" and not this.knight then
    37.                 this.knight = player
    38.             elseif vocation:getName() == "druid" and not this.druid then
    39.                 this.druid = player
    40.             elseif vocation:getName() == "paladin" and not this.paladin then
    41.                 this.paladin = player
    42.             elseif vocation:getName() == "sorcerer" and not this.sorcerer then
    43.                 this.sorcerer = player
    44.             end
    45.             return true
    46.         end
    47.         return false
    48.     end
    49.     -- Clear the players on dungeon
    50.     function this.clearPlayers(self)
    51.         self.knight = nil
    52.         self.druid = nil
    53.         self.sorcerer = nil
    54.         self.paladin = nil
    55.     end
    56.     -- Finish the dungeon giving the prizes
    57.     function this.finish(self)
    58.     end
    59.     -- This will perform a check in a row style looking for player meeting the requirements
    60.     -- returns true if the isFull, otherwise returns false and clear the players from dungeon obj
    61.     function this.checkRow(self, position)
    62.         for y = position.y, position.y + 4 do
    63.             local tile = Tile(position)
    64.             if tile then
    65.                 local topPlayer = Player(tile:getTopCreature())
    66.                 if topPlayer then
    67.                     if topPlayer:getLevel() >= self.minLevel and topPlayer:getLevel() <= self.maxLevel then
    68.                         this:addPlayer(topPlayer)
    69.                     end
    70.                 end
    71.             end
    72.             -- Lets check next
    73.             position.y = y
    74.         end
    75.         if this:isFull() then
    76.             return true
    77.         end
    78.         this:clearPlayers()
    79.         return false
    80.     end
    81.     -- Teleport all the participantes to the passed destinations
    82.     -- positions is a table of positions = {{x,y,z},{x,y,z}}
    83.     function this.teleportTo(positions)
    84.         if this.isFull() then
    85.             if #positions >=4 then
    86.                 druid:teleportTo(positions[1])
    87.                 knight:teleportTo(positions[2])
    88.                 sorcerer:teleportTo(positions[3])
    89.                 paladin:teleportTo(positions[4])
    90.             elseif #positions == 1 then
    91.                 druid:teleportTo(positions[1])
    92.                 knight:teleportTo(positions[1])
    93.                 sorcerer:teleportTo(positions[1])
    94.                 paladin:teleportTo(positions[1])
    95.             end
    96.         end
    97.     end
    98.     -- This return the base vocation from a passed player
    99.     function this.getPlayerBaseVocation(player)
    100.         local vocation = player:getVocation()
    101.         while(vocation:getDemotion()) do
    102.             vocation = vocation:getDemotion()
    103.         end
    104.         return vocation
    105.     end
    106.     return this
    107. end
    108.  
    And on actions:
    <action actionid="9602" script="dungeon_lever.lua"/>
    Code (Text):
    1.  
    2. function onUse(cid, item, fromPosition, itemEx, toPosition)
    3.    if g_Dungeons.Dragons:checkRow({x = 952, y = 1039, z = 7}) then
    4.        g_Dungeons.Dragons:teleportTo({{x = 952, y = 1039, z = 6}, {x = 953, y = 1039, z = 6}, {x = 954, y = 1039, z = 6}, {x = 955, y = 1039, z = 6}})
    5.        g_Dungeons.Dragons:start()
    6.    end
    7. end
    8.  
     
    supergt likes this.
  8. TheRatazana

    TheRatazana Member

    Joined:
    Feb 5, 2015
    Messages:
    37
    Likes Received:
    29
    Best Answers:
    7
    Yes. Should be this way. But since you are using 0.4 you will need to change things from Player to cid, and use like doTeleportThing passing cid instead of player:teleportTo()
     
    supergt and zabuzo like this.
  9. zabuzo

    zabuzo Member

    Joined:
    Jun 10, 2016
    Messages:
    116
    Likes Received:
    16
    Best Answers:
    0
    Did u know about 0.4 sources?
    Idk if the problem is i'm trying to convert or another problem...

    But using this:

    The server is not open, just freeze in:
    Code (Text):
    1.  
    2. ./tfs
    3. [13:5:18.029] The Forgotten Server 0.4
    4.  
    5. [13:5:18.029] >> Loading config (config.lua)
    6. [13:5:18.056] >> Opening logs
    7.  
    8. >> Loading Demon Oak Lib V0.70 REV: 1 (June 26 2012) By Darkhaos (Contact: http://otland.net/members/darkhaos/)
    9.  
    10. [!] -> Checking demon oak lib...
    11. [!] -> 0 problems loaded in 8.9000000000002e-05 seconds.
    12.  
    13. [!] -> Demon Oak Lib loaded in 0.000483 seconds.
    14.  
    15. [13:5:18.071] >> Opening logs
    16.  
    17. ^C
    18.  
    Somebody could help me to convert it to 0.4?
    Searching i found:
    player:isPlayer()
    In some way have to be:
    isPlayer(player)

    But idk what more have to be changed
     
    supergt likes this.
  10. TheRatazana

    TheRatazana Member

    Joined:
    Feb 5, 2015
    Messages:
    37
    Likes Received:
    29
    Best Answers:
    7
    Hi zabuzo. So, you can try this:

    Code (Lua):
    1. local dungeons = {}
    2.  
    3. function Dungeon(name, minLevel, maxLevel, rewards)
    4.     local this = {
    5.         name = name or "unamed",
    6.         minLevel = minLevel or 1,
    7.         maxLevel = maxLevel or 1,
    8.         rewards = rewards or {},
    9.         druid = nil,
    10.         knight = nil,
    11.         sorcerer = nil,
    12.         paladin = nil
    13.     }
    14.  
    15.     -- Check if all positions are occuped
    16.     function this.isFull(self)
    17.         return self.druid and self.knight and self.sorcerer and self.paladin
    18.     end
    19.  
    20.     -- Start dungeon teleporting the players and setting additional events
    21.     function this.start(self)
    22.         if self:isFull() then
    23.         end
    24.     end
    25.  
    26.     -- Add a player to dungeon
    27.     function this.addPlayer(self, cid)
    28.         if isPlayer(cid) and not self:isFull() then
    29.             local level = getPlayerLevel(cid)
    30.             if level > this.maxLevel or level < this.minLevel then
    31.                 doPlayerSendTextMessage(cid, MSG_STATUS_DEFAULT,"You can't do this dungeon")
    32.                 return false
    33.             end
    34.  
    35.             local vocation = getVocationInfo(this.getPlayerBaseVocation(cid))
    36.             if vocation.name == "knight" and not this.knight then
    37.                 this.knight = cid
    38.             elseif vocation.name == "druid" and not this.druid then
    39.                 this.druid = cid
    40.             elseif vocation.name() == "paladin" and not this.paladin then
    41.                 this.paladin = cid
    42.             elseif vocation.name() == "sorcerer" and not this.sorcerer then
    43.                 this.sorcerer = cid
    44.             end
    45.             return true
    46.         end
    47.         return false
    48.     end
    49.  
    50.     -- Clear the players on dungeon
    51.     function this.clearPlayers(self)
    52.         self.knight = nil
    53.         self.druid = nil
    54.         self.sorcerer = nil
    55.         self.paladin = nil
    56.     end
    57.  
    58.     -- Finish the dungeon giving the prizes
    59.     function this.finish(self)
    60.  
    61.     end
    62.  
    63.     -- This will perform a check in a row style looking for player meeting the requirements
    64.     -- returns true if the isFull, otherwise returns false and clear the players from dungeon obj
    65.     function this.checkRow(self, position)
    66.         for y = position.y, position.y + 4 do
    67.             local topPlayer = getTopCreature(pos)
    68.             if topPlayer and isPlayer(topPlayer) then
    69.                 if getPlayerLevel(cid) >= self.minLevel and getPlayerLevel(cid) <= self.maxLevel then
    70.                     this:addPlayer(topPlayer)
    71.                 end
    72.             end
    73.             -- Lets check next
    74.             position.y = y
    75.         end
    76.  
    77.         if this:isFull() then
    78.             return true
    79.         end
    80.  
    81.         this:clearPlayers()
    82.         return false
    83.     end
    84.  
    85.     -- Teleport all the participantes to the passed destinations
    86.     -- positions is a table of positions = {{x,y,z},{x,y,z}}
    87.     function this.teleportTo(positions)
    88.         if this.isFull() then
    89.             if #positions >=4 then
    90.                 doTeleportThing(this.druid, positions[1])
    91.                 doTeleportThing(this.knight, positions[2])
    92.                 doTeleportThing(this.sorcerer, positions[3])
    93.                 doTeleportThing(this.paladin, positions[4])
    94.             elseif #positions == 1 then
    95.                 doTeleportThing(this.druid, positions[1])
    96.                 doTeleportThing(this.knight, positions[1])
    97.                 doTeleportThing(this.sorcerer, positions[1])
    98.                 doTeleportThing(this.paladin, positions[1])
    99.             end
    100.         end
    101.     end
    102.  
    103.     -- This return the base vocation from a passed player
    104.     function this.getPlayerBaseVocation(cid)
    105.         local vocation = getPlayerVocation(cid)
    106.         while(getVocationInfo(vocation).fromVocation ~= 0) do
    107.             vocation = getVocationInfo(vocation).fromVocation
    108.         end
    109.         return vocation
    110.     end
    111.  
    112.     return this
    113. end

    I tried to convert to 0.4. When I need to create something to 0.4 I use this source code:
    luanluciano93/TFS_0.4_3777

    Specially the luascript.cpp, const.h and enums.h. Very helpful
     
    supergt and zabuzo like this.
  11. zabuzo

    zabuzo Member

    Joined:
    Jun 10, 2016
    Messages:
    116
    Likes Received:
    16
    Best Answers:
    0

    It's freezing and not open after add:
    Code (Text):
    1.  
    2. local g_Dungeons = {
    3.     -- Dungeon(name, minLevel, maxLevel, rewards)
    4.     Dragons = Dungeon("Dragons", 15, 30, {1100, 1101, 1102})
    5. }
    6.  
    Code (Text):
    1.  
    2. local g_Dungeons = {
    3.     -- Dungeon(name, minLevel, maxLevel, rewards)
    4.     Dragons = Dungeon("Dragons", 15, 30, {1100, 1101, 1102})
    5. }
    6. function Dungeon(name, minLevel, maxLevel, rewards)
    7.     local this = {
    8.         name = name or "unamed",
    9.         minLevel = minLevel or 1,
    10.         maxLevel = maxLevel or 1,
    11.         rewards = rewards or {},
    12.         druid = nil,
    13.         knight = nil,
    14.         sorcerer = nil,
    15.         paladin = nil
    16.     }
    17.     -- Check if all positions are occuped
    18.     function this.isFull(self)
    19.         return self.druid and self.knight and self.sorcerer and self.paladin
    20.     end
    21.     -- Start dungeon teleporting the players and setting additional events
    22.     function this.start(self)
    23.         if self:isFull() then
    24.         end
    25.     end
    26.     -- Add a player to dungeon
    27.     function this.addPlayer(self, cid)
    28.         if isPlayer(cid) and not self:isFull() then
    29.             local level = getPlayerLevel(cid)
    30.             if level > this.maxLevel or level < this.minLevel then
    31.                 doPlayerSendTextMessage(cid, MSG_STATUS_DEFAULT,"You can't do this dungeon")
    32.                 return false
    33.             end
    34.             local vocation = getVocationInfo(this.getPlayerBaseVocation(cid))
    35.             if vocation.name == "knight" and not this.knight then
    36.                 this.knight = cid
    37.             elseif vocation.name == "druid" and not this.druid then
    38.                 this.druid = cid
    39.             elseif vocation.name() == "paladin" and not this.paladin then
    40.                 this.paladin = cid
    41.             elseif vocation.name() == "sorcerer" and not this.sorcerer then
    42.                 this.sorcerer = cid
    43.             end
    44.             return true
    45.         end
    46.         return false
    47.     end
    48.     -- Clear the players on dungeon
    49.     function this.clearPlayers(self)
    50.         self.knight = nil
    51.         self.druid = nil
    52.         self.sorcerer = nil
    53.         self.paladin = nil
    54.     end
    55.     -- Finish the dungeon giving the prizes
    56.     function this.finish(self)
    57.     end
    58.     -- This will perform a check in a row style looking for player meeting the requirements
    59.     -- returns true if the isFull, otherwise returns false and clear the players from dungeon obj
    60.     function this.checkRow(self, position)
    61.         for y = position.y, position.y + 4 do
    62.             local topPlayer = getTopCreature(pos)
    63.             if topPlayer and isPlayer(topPlayer) then
    64.                 if getPlayerLevel(cid) >= self.minLevel and getPlayerLevel(cid) <= self.maxLevel then
    65.                     this:addPlayer(topPlayer)
    66.                 end
    67.             end
    68.             -- Lets check next
    69.             position.y = y
    70.         end
    71.         if this:isFull() then
    72.             return true
    73.         end
    74.         this:clearPlayers()
    75.         return false
    76.     end
    77.     -- Teleport all the participantes to the passed destinations
    78.     -- positions is a table of positions = {{x,y,z},{x,y,z}}
    79.     function this.teleportTo(positions)
    80.         if this.isFull() then
    81.             if #positions >=4 then
    82.                 doTeleportThing(this.druid, positions[1])
    83.                 doTeleportThing(this.knight, positions[2])
    84.                 doTeleportThing(this.sorcerer, positions[3])
    85.                 doTeleportThing(this.paladin, positions[4])
    86.             elseif #positions == 1 then
    87.                 doTeleportThing(this.druid, positions[1])
    88.                 doTeleportThing(this.knight, positions[1])
    89.                 doTeleportThing(this.sorcerer, positions[1])
    90.                 doTeleportThing(this.paladin, positions[1])
    91.             end
    92.         end
    93.     end
    94.     -- This return the base vocation from a passed player
    95.     function this.getPlayerBaseVocation(cid)
    96.         local vocation = getPlayerVocation(cid)
    97.         while(getVocationInfo(vocation).fromVocation ~= 0) do
    98.             vocation = getVocationInfo(vocation).fromVocation
    99.         end
    100.         return vocation
    101.     end
    102.     return this
    103. end
    104.  
     
    supergt likes this.
  12. TheRatazana

    TheRatazana Member

    Joined:
    Feb 5, 2015
    Messages:
    37
    Likes Received:
    29
    Best Answers:
    7
    Sorry, but I can't help then. I know that the code is free of syntax errors and that the function dungeon works well even with lua 5.1. Maybe you're using a version more old? Is weird because there is not loop outside function declarations. And this local in dungeons or g_dungeons is an error I made. I was planning to use this as local and get dungeons through some other way, but is more complicated, just using g_dungeons = {} is better, just don't put local on it, or you will can't access this in others scripts.
     
    zabuzo and supergt like this.
  13. supergt

    supergt Member

    Joined:
    May 11, 2017
    Messages:
    63
    Likes Received:
    22
    Best Answers:
    0
    I don't undertood, the dungeons should not be added on
    Code (Text):
    1.  
    2. [LIST=1]
    3. [*]local g_Dungeons = {
    4. [*]    -- Dungeon(name, minLevel, maxLevel, rewards)
    5. [*]    Dragons = Dungeon("Dragons", 15, 30, {1100, 1101, 1102})
    6. [*]}
    7. [*]function Dungeon(name, minLevel, maxLevel, rewards)
    8. [*]    local this = {
    9. [*]        name = name or "unamed",
    10. [/LIST]
    11.  
    ???

    Lib are not public to use in all others scripts (actions,movemments...) !?
     
    zabuzo likes this.
  14. TheRatazana

    TheRatazana Member

    Joined:
    Feb 5, 2015
    Messages:
    37
    Likes Received:
    29
    Best Answers:
    7
    1 - Yes, they should be added there. But not using the keyword 'local' in front of g_Dungeons. This was a mistake I made for not maki the things clearly at first

    2 - Yes, they are. If not declared as local, an variable from some lib is available for all other scripts, but if declared as local it's only visible for the functions and routines in that specific lib file. In the first, I was going to use a local dungeons var to store dungeons and some other global methods to add and remove from it. But only using a non-local g_Dungeons is more easy, and I forgot to remove that, what cause confusion I think

    Understood now?
     
    zabuzo and supergt like this.
  15. supergt

    supergt Member

    Joined:
    May 11, 2017
    Messages:
    63
    Likes Received:
    22
    Best Answers:
    0
    Hmm ty..

    So you are suggesting to declare the g_Dungeons as a global variable?
    I mean, just omiting the local?
    Code (Text):
    1.  
    2. g_Dungeons = {
    3.     -- Dungeon(name, minLevel, maxLevel, rewards)
    4.     Dragons = Dungeon("Dragons", 15, 30, {1100, 1101, 1102})
    5. }
    6. function Dungeon(name, minLevel, maxLevel, rewards)
    7.  
    To use in the others scripts? I think there is some sintaxy error, because doing this, the server still not openning
     
    zabuzo likes this.
  16. TheRatazana

    TheRatazana Member

    Joined:
    Feb 5, 2015
    Messages:
    37
    Likes Received:
    29
    Best Answers:
    7
    Yes. Sadly I don't have a 0.4 to test this, but I can guarantee that it works with lua 5.1 so it's weird why is doing this. Look at the attached image
     

    Attached Files:

    supergt and zabuzo like this.
  17. zabuzo

    zabuzo Member

    Joined:
    Jun 10, 2016
    Messages:
    116
    Likes Received:
    16
    Best Answers:
    0
    Strange... Idk about this, but anyone else could show why if we use this lib:
    Code (Text):
    1.  
    2. local g_Dungeons = {
    3.     -- Dungeon(name, minLevel, maxLevel, rewards)
    4.     Dragons = Dungeon("Dragons", 15, 30, {1100, 1101, 1102})
    5. }
    6.  
    7. function Dungeon(name, minLevel, maxLevel, rewards)
    8.     local this = {
    9.         name = name or "unamed",
    10.         minLevel = minLevel or 1,
    11.         maxLevel = maxLevel or 1,
    12.         rewards = rewards or {},
    13.         druid = nil,
    14.         knight = nil,
    15.         sorcerer = nil,
    16.         paladin = nil
    17.     }
    18.     -- Check if all positions are occuped
    19.     function this.isFull(self)
    20.         return self.druid and self.knight and self.sorcerer and self.paladin
    21.     end
    22.     -- Start dungeon teleporting the players and setting additional events
    23.     function this.start(self)
    24.         if self:isFull() then
    25.         end
    26.     end
    27.     -- Add a player to dungeon
    28.     function this.addPlayer(self, player)
    29.         if player:isPlayer() and not self:isFull() then
    30.             local level = player:getLevel()
    31.             if level > this.maxLevel or level < this.minLevel then
    32.                 player:sendCancelMessage("You can't do this dungeon")
    33.                 return false
    34.             end
    35.             local vocation = this.getPlayerBaseVocation(player)
    36.             if vocation:getName() == "knight" and not this.knight then
    37.                 this.knight = player
    38.             elseif vocation:getName() == "druid" and not this.druid then
    39.                 this.druid = player
    40.             elseif vocation:getName() == "paladin" and not this.paladin then
    41.                 this.paladin = player
    42.             elseif vocation:getName() == "sorcerer" and not this.sorcerer then
    43.                 this.sorcerer = player
    44.             end
    45.             return true
    46.         end
    47.         return false
    48.     end
    49.     -- Clear the players on dungeon
    50.     function this.clearPlayers(self)
    51.         self.knight = nil
    52.         self.druid = nil
    53.         self.sorcerer = nil
    54.         self.paladin = nil
    55.     end
    56.     -- Finish the dungeon giving the prizes
    57.     function this.finish(self)
    58.     end
    59.     -- This will perform a check in a row style looking for player meeting the requirements
    60.     -- returns true if the isFull, otherwise returns false and clear the players from dungeon obj
    61.     function this.checkRow(self, position)
    62.         for y = position.y, position.y + 4 do
    63.             local tile = Tile(position)
    64.             if tile then
    65.                 local topPlayer = Player(tile:getTopCreature())
    66.                 if topPlayer then
    67.                     if topPlayer:getLevel() >= self.minLevel and topPlayer:getLevel() <= self.maxLevel then
    68.                         this:addPlayer(topPlayer)
    69.                     end
    70.                 end
    71.             end
    72.             -- Lets check next
    73.             position.y = y
    74.         end
    75.         if this:isFull() then
    76.             return true
    77.         end
    78.         this:clearPlayers()
    79.         return false
    80.     end
    81.     -- Teleport all the participantes to the passed destinations
    82.     -- positions is a table of positions = {{x,y,z},{x,y,z}}
    83.     function this.teleportTo(positions)
    84.         if this.isFull() then
    85.             if #positions >=4 then
    86.                 druid:teleportTo(positions[1])
    87.                 knight:teleportTo(positions[2])
    88.                 sorcerer:teleportTo(positions[3])
    89.                 paladin:teleportTo(positions[4])
    90.             elseif #positions == 1 then
    91.                 druid:teleportTo(positions[1])
    92.                 knight:teleportTo(positions[1])
    93.                 sorcerer:teleportTo(positions[1])
    94.                 paladin:teleportTo(positions[1])
    95.             end
    96.         end
    97.     end
    98.     -- This return the base vocation from a passed player
    99.     function this.getPlayerBaseVocation(player)
    100.         local vocation = player:getVocation()
    101.         while(vocation:getDemotion()) do
    102.             vocation = vocation:getDemotion()
    103.         end
    104.         return vocation
    105.     end
    106.     return this
    107. end
    108.  
    The server just not open?
     
    supergt likes this.
  18. TheRatazana

    TheRatazana Member

    Joined:
    Feb 5, 2015
    Messages:
    37
    Likes Received:
    29
    Best Answers:
    7
    What distro do you guys use? I downloaded and compiled the fir3element 3777 distro and started with library. The server doesn't hangup, but it appear to load the library 7 times when loading the script system and one more time after loading the map. Look at the ss:
     

    Attached Files:

    supergt and zabuzo like this.
  19. zabuzo

    zabuzo Member

    Joined:
    Jun 10, 2016
    Messages:
    116
    Likes Received:
    16
    Best Answers:
    0
    I do using the same source, are u using this lib?
    Code (Text):
    1.  
    2. local g_Dungeons = {
    3.     -- Dungeon(name, minLevel, maxLevel, rewards)
    4.     Dragons = Dungeon("Dragons", 15, 30, {1100, 1101, 1102})
    5. }
    6.  
    7. function Dungeon(name, minLevel, maxLevel, rewards)
    8.     local this = {
    9.         name = name or "unamed",
    10.         minLevel = minLevel or 1,
    11.         maxLevel = maxLevel or 1,
    12.         rewards = rewards or {},
    13.         druid = nil,
    14.         knight = nil,
    15.         sorcerer = nil,
    16.         paladin = nil
    17.     }
    18.     -- Check if all positions are occuped
    19.     function this.isFull(self)
    20.         return self.druid and self.knight and self.sorcerer and self.paladin
    21.     end
    22.     -- Start dungeon teleporting the players and setting additional events
    23.     function this.start(self)
    24.         if self:isFull() then
    25.         end
    26.     end
    27.     -- Add a player to dungeon
    28.     function this.addPlayer(self, player)
    29.         if player:isPlayer() and not self:isFull() then
    30.             local level = player:getLevel()
    31.             if level > this.maxLevel or level < this.minLevel then
    32.                 player:sendCancelMessage("You can't do this dungeon")
    33.                 return false
    34.             end
    35.             local vocation = this.getPlayerBaseVocation(player)
    36.             if vocation:getName() == "knight" and not this.knight then
    37.                 this.knight = player
    38.             elseif vocation:getName() == "druid" and not this.druid then
    39.                 this.druid = player
    40.             elseif vocation:getName() == "paladin" and not this.paladin then
    41.                 this.paladin = player
    42.             elseif vocation:getName() == "sorcerer" and not this.sorcerer then
    43.                 this.sorcerer = player
    44.             end
    45.             return true
    46.         end
    47.         return false
    48.     end
    49.     -- Clear the players on dungeon
    50.     function this.clearPlayers(self)
    51.         self.knight = nil
    52.         self.druid = nil
    53.         self.sorcerer = nil
    54.         self.paladin = nil
    55.     end
    56.     -- Finish the dungeon giving the prizes
    57.     function this.finish(self)
    58.     end
    59.     -- This will perform a check in a row style looking for player meeting the requirements
    60.     -- returns true if the isFull, otherwise returns false and clear the players from dungeon obj
    61.     function this.checkRow(self, position)
    62.         for y = position.y, position.y + 4 do
    63.             local tile = Tile(position)
    64.             if tile then
    65.                 local topPlayer = Player(tile:getTopCreature())
    66.                 if topPlayer then
    67.                     if topPlayer:getLevel() >= self.minLevel and topPlayer:getLevel() <= self.maxLevel then
    68.                         this:addPlayer(topPlayer)
    69.                     end
    70.                 end
    71.             end
    72.             -- Lets check next
    73.             position.y = y
    74.         end
    75.         if this:isFull() then
    76.             return true
    77.         end
    78.         this:clearPlayers()
    79.         return false
    80.     end
    81.     -- Teleport all the participantes to the passed destinations
    82.     -- positions is a table of positions = {{x,y,z},{x,y,z}}
    83.     function this.teleportTo(positions)
    84.         if this.isFull() then
    85.             if #positions >=4 then
    86.                 druid:teleportTo(positions[1])
    87.                 knight:teleportTo(positions[2])
    88.                 sorcerer:teleportTo(positions[3])
    89.                 paladin:teleportTo(positions[4])
    90.             elseif #positions == 1 then
    91.                 druid:teleportTo(positions[1])
    92.                 knight:teleportTo(positions[1])
    93.                 sorcerer:teleportTo(positions[1])
    94.                 paladin:teleportTo(positions[1])
    95.             end
    96.         end
    97.     end
    98.     -- This return the base vocation from a passed player
    99.     function this.getPlayerBaseVocation(player)
    100.         local vocation = player:getVocation()
    101.         while(vocation:getDemotion()) do
    102.             vocation = vocation:getDemotion()
    103.         end
    104.         return vocation
    105.     end
    106.     return this
    107. end
    108.  
    With a dugeon configured?

    I mean
    Code (Text):
    1.  
    2. Dragons = Dungeon("Dragons", 15, 30, {1100, 1101, 1102})
    3.  
     
    supergt likes this.
  20. TheRatazana

    TheRatazana Member

    Joined:
    Feb 5, 2015
    Messages:
    37
    Likes Received:
    29
    Best Answers:
    7
    Yes, exactly the same. Maybe could be a lib conflict then, since I using the default libs of distro and you're probably using others libs with it?
     
    supergt likes this.

Share This Page

Loading...