• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

Lua Dont have conditional level

warriorfrog

Active Member
Joined
Jul 29, 2015
Messages
334
Reaction score
35
Im looking on web, i found this desert quest script
But im looking on code, and dont have conditional if someone have lvl 19-
Right?
Code:
local config = {
  items = {
  {position = {x = 1552, y = 1678, z = 10}, itemid = 2175},
  {position = {x = 1542, y = 1678, z = 10}, itemid = 2674},
  {position = {x = 1547, y = 1673, z = 10}, itemid = 2455},
     {position = {x = 1547, y = 1682, z = 10}, itemid = 2376},
  --etc
  },
  players = {
     {position = {x = 1550, y = 1678, z = 10}, toPos = {x = 1588, y = 1635, z = 8}, vocation = {1, 5, 9}},
  {position = {x = 1544, y = 1678, z = 10}, toPos = {x = 1589, y = 1635, z = 8}, vocation = {2, 6, 10}},
  {position = {x = 1547, y = 1675, z = 10}, toPos = {x = 1589, y = 1636, z = 8}, vocation = {3, 7, 11}},
     {position = {x = 1547, y = 1681, z = 10}, toPos = {x = 1588, y = 1636, z = 8}, vocation = {4, 8, 12}},
  --etc
  }
}
function onUse(cid)
  local items, quest_players = {}, {}
  for _, item in pairs(config.items) do
  local position_item = getTileItemById(item.position, item.itemid).uid
  if position_item > 0 then
  table.insert(items, position_item)
  else
  return doPlayerSendCancel(cid, "There's missing some item(s).")
  end
  end
  for _, player in pairs(config.players) do
  local pid = getTopCreature(player.position).uid
  if isPlayer(pid) and isInArray(player.vocation, getPlayerVocation(pid)) then
  table.insert(quest_players, pid)
  else
  return doPlayerSendCancel(cid, "There's some player(s) missing or there's some wrong vocation(s).")
  end
  end
  for i = 1, #items do
  doRemoveItem(items[i])
  end
  for i = 1, #quest_players do
  doPlayerSendTextMessage(quest_players[i], MESSAGE_INFO_DESCR, "Good luck at the quest!")
  doTeleportThing(quest_players[i], config.players[i].toPos)
  end
  return true
end

if not, how to do it? need a for (using pid) and check pid players?
 
Code:
-- table based on base vocations
local p = {
    [1] = { --sorcerer
        player = {
            position = {x = 1550, y = 1678, z = 10},
            toPos = {x = 1588, y = 1635, z = 8}
        },
        item = {
            position = {x = 1552, y = 1678, z = 10},
            itemid = 2175
        }
    },
    [2] = { -- druid
        player = {
            position = {x = 1544, y = 1678, z = 10},
            toPos = {x = 1589, y = 1635, z = 8}
        },
        item = {
            position = {x = 1542, y = 1678, z = 10},
            itemid = 2674
        }
    },
    [3] = { -- paladin
        player = {
            position = {x = 1547, y = 1675, z = 10},
            toPos = {x = 1589, y = 1636, z = 8}
        },
        item = {
            position = {x = 1547, y = 1673, z = 10},
            itemid = 2455
        }
    },
    [4] = { -- knight
        player = {
            position = {x = 1547, y = 1681, z = 10},
            toPos = {x = 1588, y = 1636, z = 8}
        },
        item = {
            position = {x = 1547, y = 1682, z = 10},
            itemid = 2376
        }
    }
}

local playerMinimumLevel  = 19

-- get a vocation's base vocation
function getBaseVocation(vocation)
    if vocation >= 5 and vocation <= 8 then
        return vocation - 4
    elseif vocation >= 9 and vocation <= 12 then
        return vocation - 8
    end
    return vocation
end

function onUse(cid)
    local questItems, questPlayers = {}, {}
    for i = 1, #p do
        local pid = getTopCreature(p[i].player.position).uid
        if isPlayer(pid) then
            if getPlayerLevel(pid) >= playerMinimumLevel then
                if getBaseVocation( getPlayerVocation(pid) ) == i then
                    local neededItem = getTileItemById(p[i].item.position, p[i].item.itemid).uid
                    if neededItem > 0 then
                        table.insert(questItems, neededItem)
                        table.insert(questPlayers, pid)
                    else
                        doPlayerSendCancel(cid, "Some items are missing.")
                        return false
                    end
                else
                    doPlayerSendCancel(cid, "A vocation is on the wrong spot.")
                    return false
                end
            else
                doPlayerSendCancel(cid, getCreatureName(pid) .. ", is not high enough in level, they must be atleast level " .. playerMinimumLevel .. ".")
                return false
            end
        else
            doPlayerSendCancel(cid, "A player is missing.")
            return false
        end
    end
    for x = 1, #questPlayers do
        doRemoveItem(questItems[x])
        doPlayerSendTextMessage(questPlayers[x], MESSAGE_INFO_DESCR, "Good luck!")
        doTeleportThing(questPlayers[x], p[x].player.toPos)
    end
    return true
end
 
Last edited:
Code:
-- table based on base vocations
local p = {
    [1] = { --sorcerer
        player = {
            position = {x = 1550, y = 1678, z = 10},
            toPos = {x = 1588, y = 1635, z = 8}
        },
        item = {
            position = {x = 1552, y = 1678, z = 10},
            itemid = 2175
        }
    },
    [2] = { -- druid
        player = {
            position = {x = 1544, y = 1678, z = 10},
            toPos = {x = 1589, y = 1635, z = 8}
        },
        item = {
            position = {x = 1542, y = 1678, z = 10},
            itemid = 2674
        }
    },
    [3] = { -- paladin
        player = {
            position = {x = 1547, y = 1675, z = 10},
            toPos = {x = 1589, y = 1636, z = 8}
        },
        item = {
            position = {x = 1547, y = 1673, z = 10},
            itemid = 2455
        }
    },
    [4] = { -- knight
        player = {
            position = {x = 1547, y = 1681, z = 10},
            toPos = {x = 1588, y = 1636, z = 8}
        },
        item = {
            position = {x = 1547, y = 1682, z = 10},
            itemid = 2376
        }
    }
}

local playerMinimumLevel,  = 19

-- get a vocation's base vocation
function getBaseVocation(vocation)
    if vocation >= 5 and vocation <= 8 then
        return vocation - 4
    elseif vocation >= 9 and vocation <= 12 then
        return vocation - 8
    end
    return vocation
end

function onUse(cid)
    local questItems, questPlayers = {}, {}
    for i = 1, #p do
        local pid = getTopCreature(p[i].player.position).uid
        if isPlayer(pid) then
            if getPlayerLevel(pid) >= playerMinimumLevel then
                if getBaseVocation( getPlayerVocation(pid) ) == i then
                    local neededItem = getTileItemById(p[i].item.position, p[i].item.itemid).uid
                    if neededItem > 0 then
                        table.insert(questItems, neededItem)
                        table.insert(questPlayers, pid)
                    else
                        doPlayerSendCancel(cid, "Some items are missing.")
                        return false
                    end
                else
                    doPlayerSendCancel(cid, "A vocation is on the wrong spot.")
                    return false
                end
            else
                doPlayerSendCancel(cid, getCreatureName(pid) .. ", is not high enough in level, they must be atleast level " .. playerMinimumLevel .. ".")
                return false
            end
        else
            doPlayerSendCancel(cid, "A player is missing.")
            return false
        end
    end
    for x = 1, #questPlayers do
        doRemoveItem(questItems[x])
        doPlayerSendTextMessage(questPlayers[x], MESSAGE_INFO_DESCR, "Good luck!")
        doTeleportThing(questPlayers[x], p[x].player.toPos)
    end
    return true
end

Ty, this script is much better written than mine
 
Back
Top