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

Custom script issue TFS 1.3

Musaab

NoxOts
Premium User
Joined
May 13, 2010
Messages
176
Reaction score
74
Location
Sweden
Hello fellas,

I have tried one of Sarahs codes from her service Lua - [TFS 1.3] Free Scripting Service đź“ť (https://otland.net/threads/tfs-1-3-free-scripting-service.274636/page-4#post-2645298).

The issue seems to be that the lever part does not work in production mode, only in debug Mode. Tried both with regular char and GOD char.

No error in console , only when u hit the lever 1945 it does not transform to 1946 upon use, it only gives msg "You cannot use this object" and only in production mode. On Debug mode it works without any issues, the code am using is:
Lua:
local configQuest = {
    actionId = 901,
    players = { -- Positions where players are standing to enter
        Tile(1116, 1010, 7),
        Tile(1116, 1011, 7),
        Tile(1116, 1012, 7),
        Tile(1116, 1013, 7),
        Tile(1116, 1014, 7)
    },
    minPlayers = 1, -- Minimum number of players that can enter. in this case 1 or more
    destination = Position(1124, 1010, 7), -- Position where the players will be teleported when entering the room
    requirements = {
        level = 8, -- level required to enter the room
        storages = {5001} -- if you need some storage to be able to enter or several storages
    },
    room = {
        centerPos = Position(1124, 1010, 7), -- center of the room
        fromPos = Position(1123, 1008, 7), -- the upper left corner of the room
        toPos = Position(1125, 1012, 7) -- the lower right corner of the room
    },
    boss = {
        name = "Demon", -- boss name
        spawnPos = Position(1127, 1009, 7), -- spawn boss position
        exitIn = 1 -- minutes to get out of the room
    },
    debug = {
        enabled = false, -- for testing with /reload scripts
        exitPos = Position(1116, 1017, 7), -- Position to which players will be sent off after a while
        leverIds = {9825, 9826}, -- lever on / lever off
        admins = false -- detect administrators in the room
    }
}

local function getPlayersInQuest()
    local spectators = Game.getSpectators(configQuest.room.centerPos, false, true, configQuest.radius.x, configQuest.radius.x, configQuest.radius.y, configQuest.radius.y)
    local players = {}
    for _, spectator in pairs(spectators) do
        if spectator:getGroup():getId() == 1 or configQuest.debug.admins then
            players[#players +1] = spectator
        end
    end
    return players
end

local function closeQuest()
    local ground = configQuest.players[1]:getGround()
    for _, p in pairs(getPlayersInQuest()) do
        p:teleportTo(configQuest.debug.exitPos)
    end
    local boss = Monster(ground:getCustomAttribute("bossId"))
    if boss then
        boss:remove()
    end
    ground:removeCustomAttribute("evId")
end

local action = Action()
function action.onUse(player, item, fromPos, target, toPos, isHotkey)
    if not configQuest.radius then
        configQuest.radius = {
            x = math.ceil((configQuest.room.toPos.x - configQuest.room.fromPos.x) / 2),
            y = math.ceil((configQuest.room.toPos.y - configQuest.room.fromPos.y) / 2)
        }
    end
    local leverCanUse = false
    local playerPosition = player:getPosition()
    for _, tile in pairs(configQuest.players) do
        leverCanUse = playerPosition == tile:getPosition()
        if leverCanUse then
            break
        end
    end
    if not leverCanUse then
        return false
    end
    local questPlayers = getPlayersInQuest()
    for _, p in pairs(questPlayers) do
        if configQuest.debug.enabled then
            p:teleportTo(configQuest.debug.exitPos)
        end
    end
    if configQuest.debug.enabled then
        configQuest.debug.exitPos:sendMagicEffect(CONST_ME_TELEPORT)
    end
    local ground = configQuest.players[1]:getGround()
    local boss = Monster(ground:getCustomAttribute("bossId"))
    if boss then
        if configQuest.debug.enabled or #questPlayers == 0 then
            boss:remove()
            stopEvent(ground:getCustomAttribute("evId"))
            ground:removeCustomAttribute("evId")
        else
            player:sendCancelMessage(string.format("You must wait for the boss to be defeated or wait %d seconds.", ground:getCustomAttribute("now") - os.time()))
            return true
        end
    end
    local players = {}
    for _, tile in pairs(configQuest.players) do
        local p = tile:getTopCreature()
        if p and p:isPlayer() then
            if p:getLevel() < configQuest.requirements.level then
                player:sendCancelMessage(string.format("%s must be level %d or higher.", p:getName(), configQuest.requirements.level))
                p:getPosition():sendMagicEffect(CONST_ME_POFF)
                return true
            end
            for _, storage in pairs(configQuest.requirements.storages) do
                if p:getStorageValue(storage) == -1 then
                    player:sendCancelMessage(string.format("%s still cannot face this boss.", p:getName()))
                    p:getPosition():sendMagicEffect(CONST_ME_POFF)
                    return true
                end
            end
            players[#players +1] = p
        end
    end
    if #players < configQuest.minPlayers then
        player:sendCancelMessage(string.format("Sorry, only groups of %d or more players are allowed.", configQuest.minPlayers))
        return true
    end
    for _, p in pairs(players) do
        p:getPosition():sendMagicEffect(CONST_ME_POFF)
        p:teleportTo(configQuest.destination)
    end
    configQuest.destination:sendMagicEffect(CONST_ME_TELEPORT)
    boss = Game.createMonster(configQuest.boss.name, configQuest.boss.spawnPos)
    if boss then
        ground:setCustomAttribute("bossId", boss:getId())
        ground:setCustomAttribute("evId", addEvent(closeQuest, configQuest.boss.exitIn * 60 * 1000))
        ground:setCustomAttribute("now", os.time() + (configQuest.boss.exitIn * 60))
    end
    item:transform(item:getId() == configQuest.debug.leverIds[1] and configQuest.debug.leverIds[2] or configQuest.debug.leverIds[1])
    return true
end

action:aid(configQuest.actionId)
action:register()



tried to get some help from a friend and we used this altered code to try get a fix
Code:
local configQuest = {
    storage = 4532562,
    actionId = 6666,
    players =
    {
        Tile(1116, 1010, 7),
        Tile(1116, 1011, 7),
        Tile(1116, 1012, 7),
        Tile(1116, 1013, 7),
        Tile(1116, 1014, 7)
    },
    minPlayers = 1, -- Minimum number of players that can enter. in this case 1 or more
    destination = Position(1166, 1011, 7), -- Position where the players will be teleported when entering the room
    requirements = {
        level = 8, -- level required to enter the room
        storages = {} -- if you need some storage to be able to enter or several storages
    },
    room = {

        centerPos = Position(1167, 1011, 7), -- center of the room
        fromPos = { x = 1161, y = 1004, z = 7 }, -- the upper left corner of the room               
        toPos = { x = 1172, y = 1015, z = 7 } -- the lower right corner of the room
    },
    boss = {
        name = "Demon", -- boss name
        spawnPos = Position(1166, 1008, 7), -- spawn boss position
        exitIn = 3 -- minutes to get out of the room
    },
    debug = {
        enabled = false, -- for testing with /reload scripts
        exitPos = Position(1116, 1017, 7), -- Position to which players will be sent off after a while
        leverIds = {9825, 9826}, -- lever on / lever off
        admins = false -- detect administrators in the room
    }
}

local function getPlayersInQuest()
    local spectators = Game.getSpectators(configQuest.room.centerPos, false, true, configQuest.radius.x, configQuest.radius.x, configQuest.radius.y, configQuest.radius.y)
    local players = {}
    for _, spectator in pairs(spectators) do
        if spectator:getGroup():getId() == 1 or configQuest.debug.admins then
            players[#players +1] = spectator
        end
    end
    return players
end

local _isBoss = false
local function getBoss()
    _isBoss = true
    local from = {x = configQuest.room.fromPos.x, y = configQuest.room.fromPos.y, z = configQuest.room.fromPos.z}
    local to = {x = configQuest.room.toPos.x, y = configQuest.room.toPos.y, z = configQuest.room.toPos.z}
    local monsters = {}
        for x = from.x, to.x do
            for y = from.y, to.y do
                local v = getTopCreature({x = x, y = y, z = configQuest.room.toPos.z}).uid
                if isMonster(v) then
                if v:getStorageValue(3) == 1 then
                    _isBoss = true
                end
                end
            end
        end
end
    
    
local function deleteBoss()
    local from = {x = configQuest.room.fromPos.x, y = configQuest.room.fromPos.y, z = configQuest.room.fromPos.z}
    local to = {x = configQuest.room.toPos.x, y = configQuest.room.toPos.y, z = configQuest.room.toPos.z}
    local monsters = {}
        for x = from.x, to.x do
            for y = from.y, to.y do
                local v = getTopCreature({x = x, y = y, z = configQuest.room.toPos.z}).uid
                if isMonster(v) then
                if v:getStorageValue(3) == 1 then
                    table.insert(monsters, v)
                end
                end
            end
        end
        for i = 1, #monsters do
            doRemoveCreature(monsters[i])
        end
    Game.setStorageValue(configQuest.storage, 0)
end

local function closeQuest()
    
    for _, p in pairs(getPlayersInQuest()) do
        p:teleportTo(configQuest.debug.exitPos)
    end
    
    deleteBoss()
end

local action = Action()
function action.onUse(player, item, fromPos, target, toPos, isHotkey)
    if not configQuest.radius then
        configQuest.radius = {
            x = math.ceil((configQuest.room.toPos.x - configQuest.room.fromPos.x) / 2),
            y = math.ceil((configQuest.room.toPos.y - configQuest.room.fromPos.y) / 2)
        }
    end
    
    local groundXYZ = nil
    local leverCanUse = false
    local playerPosition = player:getPosition()
        
    for _, tile in pairs(configQuest.players) do
        local p = tile:getTopCreature()
        if p then
        
          if player:getPosition() == p:getPosition() then
             leverCanUse = true
          end
        end
    end
    
    if leverCanUse == false then
    player:sendCancelMessage("You have to stay in right place.")
    player:getPosition():sendMagicEffect(CONST_ME_POFF)
        return true
    end
    
    local questPlayers = getPlayersInQuest()
    for _, p in pairs(questPlayers) do
        p:teleportTo(configQuest.debug.exitPos)
    end
    configQuest.debug.exitPos:sendMagicEffect(CONST_ME_TELEPORT)
    getBoss()
    if _isBoss then
        if configQuest.debug.enabled or #questPlayers == 0 then
            deleteBoss()
        else
            local checkStorage = Game.getStorageValue(configQuest.storage)
            if checkStorage > os.time() then
            player:sendCancelMessage(string.format("You must wait for the boss to be defeated or wait %d seconds.", checkStorage - os.time()))
            return true
            end
    end
    end
    local players = {}
    
    
    for _, tile in pairs(configQuest.players) do
        local p = tile:getTopCreature()
        if p and p:isPlayer() then
            if p:getLevel() < configQuest.requirements.level then
                player:sendCancelMessage(string.format("%s must be level %d or higher.", p:getName(), configQuest.requirements.level))
                p:getPosition():sendMagicEffect(CONST_ME_POFF)
                return true
            end
            for _, storage in pairs(configQuest.requirements.storages) do
                if p:getStorageValue(storage) == -1 then
                    player:sendCancelMessage(string.format("%s still cannot face this boss.", p:getName()))
                    p:getPosition():sendMagicEffect(CONST_ME_POFF)
                    return true
                end
            end
            players[#players +1] = p
        end
    end
    
    if #players < configQuest.minPlayers then
        player:sendCancelMessage(string.format("Sorry, only groups of %d or more players are allowed.", configQuest.minPlayers))
        return true
    end
    for _, p in pairs(players) do
        p:getPosition():sendMagicEffect(CONST_ME_POFF)
        p:teleportTo(configQuest.destination)
    end
    configQuest.destination:sendMagicEffect(CONST_ME_TELEPORT)
    boss = Game.createMonster(configQuest.boss.name, configQuest.boss.spawnPos)
    if boss then
    boss:setStorageValue(3,1)
    addEvent(closeQuest, configQuest.boss.exitIn * 60 * 1000)
    
    local executedTime = configQuest.boss.exitIn * 60
    Game.setStorageValue(configQuest.storage, os.time() + executedTime)
    end
    item:transform(item:getId() == configQuest.debug.leverIds[1] and configQuest.debug.leverIds[2] or configQuest.debug.leverIds[1])
    return true
end

action:aid(configQuest.actionId)
action:register()

Now no errors either , only get msg when use lever "You have to stay in right place".

double checked positions of tiles of code and tiles in game, correct ACTION ID in remere, the action code is displayed when i "Look" at the lever so there is no missed code edit or anything special, hence the script works in debug mode xD

Anyone experienced that can have a look at this? I have msged Sarah also but think she bit busy.
 
Top