• 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!

Solved Adding additional table and check

Caduceus

Unknown Member
Joined
May 10, 2010
Messages
321
Solutions
2
Reaction score
24
I am trying to add an additional check with this script. Example. so when a Knight uses the switch , they get a different creature than other vocations. In doing this, I am unsure of how the structure should be to create this.


Can it be done as below, with a vocation check of "if player:getVocation():getBase():getId() == 4 then" ...

Code:
local config = {
    reqLevel = 100,
    storage = 15001,
    waitTime = 10 * 60,
    monsterSpawnPosition = Position(1232, 1103, 10),
    removeMonsterTime = 10 * 60,
    playerDestination = Position(1237, 1099, 10),
},
local monsterName = {
                    [1] = {"monster1"},
                    [2] = {"monster2"}
}

Original
Code:
local config = {
    reqLevel = 100,
    storage = 15001,
    waitTime = 10 * 60,
    monsterSpawnPosition = Position(1232, 1103, 10),
    monsterName = "Stormblast",
    removeMonsterTime = 10 * 60,
    playerDestination = Position(1237, 1099, 10)
}

local nextTime = 0
function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    if item.itemid == 1945 then
        if item.uid ~= 15102 then
            player:sendTextMessage(MESSAGE_STATUS_SMALL, Game.getReturnMessage(RETURNVALUE_CANNOTUSETHISOBJECT))
            return true
        end

        if player:getLevel() < config.reqLevel then
            player:sendTextMessage(MESSAGE_STATUS_SMALL, "Switch requires level ".. config.reqLevel ..".")
            return true
        end

        if player:getStorageValue(config.storage) == 1 then
            player:sendTextMessage(MESSAGE_INFO_DESCR, "You have already completed the catacombs quest.")
            return true
        end

        if os.time() <= nextTime then
            player:sendTextMessage(MESSAGE_INFO_DESCR, "Sorry, you need to wait ".. os.time() - nextTime .." more seconds.")
            return true
        end

        local spawnMonster = Game.createMonster(config.monsterName, config.monsterSpawnPosition, false, true)
        if spawnMonster then
            addEvent(function(cid)
                local monster = Monster(cid)
                if monster then
                    monster:remove()
                end
            end, config.removeMonsterTime * 1000, spawnMonster:getId())
        end
   
        player:teleportTo(config.playerDestination, false)
        player:getPosition():sendMagicEffect(CONST_ME_FIREWORK_RED)
        player:sendTextMessage(MESSAGE_INFO_DESCR, "Hope to see you on the other side!")
        nextTime = os.time() + config.waitTime
    end

    item:transform(item.itemid == 1945 and 1946 or 1945)
    return true
end
 
Last edited:
Code:
local config = {
    reqLevel = 100,
    storage = 15001,
    waitTime = 10 * 60,
    monsterSpawnPosition = Position(1232, 1103, 10),
    monsterName = "Stormblast",
    MonsterNameKnight = "Stormblast2",
    removeMonsterTime = 10 * 60,
    playerDestination = Position(1237, 1099, 10)
}

local nextTime = 0
function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    if item.itemid == 1945 then
        if item.uid ~= 15102 then
            player:sendTextMessage(MESSAGE_STATUS_SMALL, Game.getReturnMessage(RETURNVALUE_CANNOTUSETHISOBJECT))
            return true
        end

        if player:getLevel() < config.reqLevel then
            player:sendTextMessage(MESSAGE_STATUS_SMALL, "Switch requires level ".. config.reqLevel ..".")
            return true
        end

        if player:getStorageValue(config.storage) == 1 then
            player:sendTextMessage(MESSAGE_INFO_DESCR, "You have already completed the catacombs quest.")
            return true
        end

        if os.time() <= nextTime then
            player:sendTextMessage(MESSAGE_INFO_DESCR, "Sorry, you need to wait ".. os.time() - nextTime .." more seconds.")
            return true
        end
        if player:getVocation():getBase():getId() == 4 or player:getVocation():getBase():getId() == 8 then
            local spawnMonster = Game.createMonster(config.monsterNameKnight, config.monsterSpawnPosition, false, true)
             if spawnMonster then
                addEvent(function(cid)
                    local monster = Monster(cid)
                    if monster then
                        monster:remove()
                    end
                end, config.removeMonsterTime * 1000, spawnMonster:getId())
            end
        else
            local spawnMonster = Game.createMonster(config.monsterName, config.monsterSpawnPosition, false, true)
            if spawnMonster then
                addEvent(function(cid)
                    local monster = Monster(cid)
                    if monster then
                        monster:remove()
                    end
                end, config.removeMonsterTime * 1000, spawnMonster:getId())
            end
        end
   
        player:teleportTo(config.playerDestination, false)
        player:getPosition():sendMagicEffect(CONST_ME_FIREWORK_RED)
        player:sendTextMessage(MESSAGE_INFO_DESCR, "Hope to see you on the other side!")
        nextTime = os.time() + config.waitTime
    end

    item:transform(item.itemid == 1945 and 1946 or 1945)
    return true
end
not tested .. I just make a little part to check the vocation and do the rest, I had to edit, was missing an end ;P
 
this seems to check for vocation, but is not summoning the creature. I changed it to a rat, just to test. So I know the creature is ingame.
 
Code:
local config = {
    reqLevel = 100,
    storage = 15001,
    waitTime = 10 * 60,
    monsterSpawnPosition = Position(1232, 1103, 10),
    removeMonsterTime = 10 * 60,
    playerDestination = Position(1237, 1099, 10),
    monsterName = {
        [4] = "Stormblast",
        [8] = "Stormblast2"
    }
}

local nextTime = 0
function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    if item.itemid == 1945 then
        if item.uid ~= 15102 then
            player:sendTextMessage(MESSAGE_STATUS_SMALL, Game.getReturnMessage(RETURNVALUE_CANNOTUSETHISOBJECT))
            return true
        end

        if player:getLevel() < config.reqLevel then
            player:sendTextMessage(MESSAGE_STATUS_SMALL, "Switch requires level ".. config.reqLevel ..".")
            return true
        end

        if player:getStorageValue(config.storage) == 1 then
            player:sendTextMessage(MESSAGE_INFO_DESCR, "You have already completed the catacombs quest.")
            return true
        end

        if os.time() <= nextTime then
            player:sendTextMessage(MESSAGE_INFO_DESCR, "Sorry, you need to wait ".. os.time() - nextTime .." more seconds.")
            return true
        end
       
        local id = player:getVocation():getId()
        if isInArray({4, 8}, id) then
            local spawnMonster = Game.createMonster(config.monsterName[id], config.monsterSpawnPosition, false, true)
            if spawnMonster then
                addEvent(function(cid)
                    local monster = Monster(cid)
                    if monster then
                        monster:remove()
                    end
                end, config.removeMonsterTime * 1000, spawnMonster:getId())
            end
        end
   
        player:teleportTo(config.playerDestination, false)
        player:getPosition():sendMagicEffect(CONST_ME_FIREWORK_RED)
        player:sendTextMessage(MESSAGE_INFO_DESCR, "Hope to see you on the other side!")
        nextTime = os.time() + config.waitTime
    end

    item:transform(item.itemid == 1945 and 1946 or 1945)
    return true
end
 
Code:
local config = {
    reqLevel = 100,
    storage = 15001,
    waitTime = 10,
    monsterSpawnPosition = Position(1232, 1103, 10),
    removeMonsterTime = 10 * 60,
    playerDestination = Position(1237, 1099, 10),
    monsterName = {
        [1] = "monster1",
        [2] = "monster2"
    }
}

Code:
if player:getVocation():getBase():getId() == 4 then
            local spawnMonster = Game.createMonster(config.monsterName[2], config.monsterSpawnPosition, false, true)
            if spawnMonster then
                addEvent(function(cid)
                    local monster = Monster(cid)
                    if monster then
                        monster:remove()
                    end
                end, config.removeMonsterTime * 1000, spawnMonster:getId())
            end
         else
         local spawnMonster = Game.createMonster(config.monsterName[1], config.monsterSpawnPosition, false, true)
            if spawnMonster then
                addEvent(function(cid)
                    local monster = Monster(cid)
                    if monster then
                        monster:remove()
                    end
                end, config.removeMonsterTime * 1000, spawnMonster:getId())
            end
        end
 
Last edited:
Code:
local config = {
    reqLevel = 100,
    storage = 15001,
    waitTime = 10 * 60,
    monsterSpawnPosition = Position(1232, 1103, 10),
    removeMonsterTime = 10 * 60,
    playerDestination = Position(1237, 1099, 10),
    monsterName = {
        ['A'] = "Stormblast",
        ['B'] = "Stormblast2"
    }
}

local knights = {4}

local nextTime = 0
function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    if item.itemid == 1945 then
        if item.uid ~= 15102 then
            player:sendTextMessage(MESSAGE_STATUS_SMALL, Game.getReturnMessage(RETURNVALUE_CANNOTUSETHISOBJECT))
            return true
        end

        if player:getLevel() < config.reqLevel then
            player:sendTextMessage(MESSAGE_STATUS_SMALL, "Switch requires level ".. config.reqLevel ..".")
            return true
        end

        if player:getStorageValue(config.storage) == 1 then
            player:sendTextMessage(MESSAGE_INFO_DESCR, "You have already completed the catacombs quest.")
            return true
        end

        if os.time() <= nextTime then
            player:sendTextMessage(MESSAGE_INFO_DESCR, "Sorry, you need to wait ".. os.time() - nextTime .." more seconds.")
            return true
        end
     
        local id = player:getVocation():getId()
        local spawnMonster = Game.createMonster(config.monsterName[isInArray(knights, id) and 'B' or 'A'], config.monsterSpawnPosition, false, true)
        if spawnMonster then
            addEvent(function(cid)
                local monster = Monster(cid)
                if monster then
                    monster:remove()
                end
            end, config.removeMonsterTime * 1000, spawnMonster:getId())
        end
     
 
        player:teleportTo(config.playerDestination, false)
        player:getPosition():sendMagicEffect(CONST_ME_FIREWORK_RED)
        player:sendTextMessage(MESSAGE_INFO_DESCR, "Hope to see you on the other side!")
        nextTime = os.time() + config.waitTime
    end

    item:transform(item.itemid == 1945 and 1946 or 1945)
    return true
end
 
Back
Top