• 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 1.2 Actions script help, please

Caduceus

Unknown Member
Joined
May 10, 2010
Messages
321
Solutions
2
Reaction score
24
I am trying to perform a check for players/monsters inside of a room. Then teleport the player into the room if no other players inside. If monsters left after player death, they are to be cleared. However, it is not working that way. When you click on the lever, you get the cancel message for not being on the "stand" pos. I have tried removing the "stand" check, but the lever does not teleport player to "playerDestination". I'm sure the script is nowhere near right. I was trying to use the anni script as a base.

Solution below original script.

Code:
local config = {
    level = 250,
    storage = 15009,
    room = {
        {x = 472, y = 1309, z = 10},
        {x = 574, y = 1427, z = 10}
    },
    stand = {
        {x = 545, y = 1289, z = 8}
    },
    playerDestination = {
        {x = 520, y = 1375, z = 10}
    }
}
local function areaCheck(area)
    local monsters, players = {}, {}
    for x = config.room[1].x, config.room[2].x do
        for y = config.room[1].y, config.room[2].y do
            local t = getThingfromPos({x=x, y=y, z=config.room[1].z, stackpos=253})
            if t.uid > 0 then
                if isPlayer(t.uid) then
                    table.insert(players, t.uid)
                elseif isMonster(t.uid) then
                    table.insert(monsters, t.uid)
                end
            end
        end
    end
    return monsters, players
end

function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    if item.itemid == 1945 then
            local monsters, players = areaCheck(config.room)
            if #players > 0 then
                player:sendTextMessage(MESSAGE_INFO_DESCR, "There are players inside, please be patient.")
            elseif #monsters > 0 then
                for _, k in pairs(monsters) do
                    doRemoveCreature(k)
                end
            end
        
    if player:getPosition() ~= Position(config.stand) then
            player:sendTextMessage(MESSAGE_INFO_DESCR, "You must stand on the tile.")
            return false
        end

    if player:getStorageValue(config.storage) == 1 then
            player:sendTextMessage(MESSAGE_INFO_DESCR, "You have already completed this quest.")
            return true
        end
    
    player:teleportTo(config.playerDestination, false)
    player:getPosition():sendMagicEffect(CONST_ME_TELEPORT)
    player:sendTextMessage(MESSAGE_INFO_DESCR, "Good luck. You will need it!")
end

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



Solution to script:
Code:
local config = {
    level = 250,
    storage = 15009,
    centerRoomPosition = Position(520, 1358, 10),
    stand = {x = 545, y = 1289, z = 8},
    playerDestination = {x = 520, y = 1375, z = 10}
}



function onUse(player, item, fromPosition, target, toPosition, isHotkey)
local specs, spec = Game.getSpectators(config.centerRoomPosition, false, false, 20, 20, 20, 20)
        for i = 1, #specs do
            spec = specs[i]
            if spec:isPlayer() then
                player:sendTextMessage(MESSAGE_STATUS_SMALL, "A player is already inside the quest room.")
                return true
            end

            spec:remove()
        end

    if player:getStorageValue(config.storage) == 1 then
        player:sendTextMessage(MESSAGE_INFO_DESCR, "You have already completed this quest.")
        return true
    end
    
        player:teleportTo(config.playerDestination, false)
        player:getPosition():sendMagicEffect(CONST_ME_TELEPORT)
        player:sendTextMessage(MESSAGE_INFO_DESCR, "Good luck. You will need it!")
        item:transform(item.itemid == 1945 and 1946 or 1945)
    return true
end
 
Last edited:
Why don't you try using the built-in Game.getSpectators?
Code:
Game.getSpectators(position[, multifloor = false[, onlyPlayer = false[, minRangeX = 0[, maxRangeX = 0[, minRangeY = 0[, maxRangeY = 0]]]]]])
 
I am trying this, but keep getting .. :44 <eof> expected near 'end'

Code:
local config = {
    level = 250,
    storage = 15009,
    centerRoomPosition = Position(520, 1358, 10),
    stand = {
        {x = 545, y = 1289, z = 8}
    },
    playerDestination = {
        {x = 520, y = 1375, z = 10}
    }
}

--Game.getSpectators(position[, multifloor = false[, onlyPlayer = false[, minRangeX = 0[, maxRangeX = 0[, minRangeY = 0[, maxRangeY = 0]]]]]])
local specs, spec = Game.getSpectators(config.centerDemonRoomPosition, false, false, 20, 20, 20, 20)
        for i = 1, #specs do
            spec = specs[i]
            if spec:isPlayer() then
                player:sendTextMessage(MESSAGE_STATUS_SMALL, "A player is already inside the quest room.")
                return true
            end

            spec:remove()
        end

function onUse(player, item, fromPosition, target, toPosition, isHotkey)

  -- stand check that is not working yet
    --if player:getPosition() ~= config.stand[1] then
        --player:sendTextMessage(MESSAGE_INFO_DESCR, "You must stand on the tile.")
        --return false
    --end
 
    if player:getStorageValue(config.storage) == 1 then
        player:sendTextMessage(MESSAGE_INFO_DESCR, "You have already completed this quest.")
        return true
        end
       
        player:teleportTo(config.playerDestination[1], false)
        player:getPosition():sendMagicEffect(CONST_ME_TELEPORT)
        player:sendTextMessage(MESSAGE_INFO_DESCR, "Good luck. You will need it!")
        item:transform(item.itemid == 1945 and 1946 or 1945)
    end
    return true
end
 
remove the end above return true
Code:
end
    return true
tried this already

95mzwm.png
 
Code:
local config = {
    level = 250,
    storage = 15009,
    centerRoomPosition = Position(520, 1358, 10),
    stand = {x = 545, y = 1289, z = 8},
    playerDestination = {x = 520, y = 1375, z = 10}
}

--Game.getSpectators(position[, multifloor = false[, onlyPlayer = false[, minRangeX = 0[, maxRangeX = 0[, minRangeY = 0[, maxRangeY = 0]]]]]])
local specs, spec = Game.getSpectators(config.centerRoomPosition, false, false, 20, 20, 20, 20)
        for i = 1, #specs do
            spec = specs[i]
            if spec:isPlayer() then
                player:sendTextMessage(MESSAGE_STATUS_SMALL, "A player is already inside the quest room.")
                return true
            end

            spec:remove()
        end

function onUse(player, item, fromPosition, target, toPosition, isHotkey)

  -- stand check that is not working yet
    --if player:getPosition() ~= config.stand[1] then
        --player:sendTextMessage(MESSAGE_INFO_DESCR, "You must stand on the tile.")
        --return false
    --end
    if player:getStorageValue(config.storage) == 1 then
        player:sendTextMessage(MESSAGE_INFO_DESCR, "You have already completed this quest.")
        return true
    end
      
        player:teleportTo(config.playerDestination[1], false)
        player:getPosition():sendMagicEffect(CONST_ME_TELEPORT)
        player:sendTextMessage(MESSAGE_INFO_DESCR, "Good luck. You will need it!")
        item:transform(item.itemid == 1945 and 1946 or 1945)
    return true
end
 
Also you can't send a message to player.. outside of onUse
You have to omit this or turn the chunk of code into a function and pass player to it.
Code:
player:sendTextMessage(MESSAGE_STATUS_SMALL, "A player is already inside the quest room.")
 
Also you can't send a message to player.. outside of onUse
You have to omit this or turn the chunk of code into a function and pass player to it.
Code:
player:sendTextMessage(MESSAGE_STATUS_SMALL, "A player is already inside the quest room.")

omitted & now I am getting Event onUse not found.
 
my bad i didn't edit the rest of the code :p
I didn't care for the table in tables

Just remove the [1] from config.playerDestination
also change player to spec

I caught that already, but on removal of "player:sendTextMessage(MESSAGE_STATUS_SMALL, "A player is already inside the quest room.")" is where the issue began.
 
Code:
local specs, spec = Game.getSpectators(config.centerRoomPosition, false, false, 20, 20, 20, 20)
for i = 1, #specs do
    spec = specs[i]
    if spec:isPlayer() then
        player:sendTextMessage(MESSAGE_STATUS_SMALL, "A player is already inside the quest room.")
        return true
    end

    spec:remove()
end

This should be inside the onUse function.
 
Code:
local specs, spec = Game.getSpectators(config.centerRoomPosition, false, false, 20, 20, 20, 20)
for i = 1, #specs do
    spec = specs[i]
    if spec:isPlayer() then
        player:sendTextMessage(MESSAGE_STATUS_SMALL, "A player is already inside the quest room.")
        return true
    end

    spec:remove()
end

This should be inside the onUse function.

This solved the issue. Thank you all for your help. Main post edited with full solution.
 
Something like this
Code:
local config = {
    level = 250,
    storage = 15009,
    centerRoomPosition = Position(520, 1358, 10),
    stand = {x = 545, y = 1289, z = 8},
    playerDestination = {x = 520, y = 1375, z = 10},
    removePlayerDestination {x = 0, y = 0, z = 0}
}

--Game.getSpectators(position[, multifloor = false[, onlyPlayer = false[, minRangeX = 0[, maxRangeX = 0[, minRangeY = 0[, maxRangeY = 0]]]]]])

function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    -- before we do anything we want to make sure they have not done the quest yet
    if player:getStorageValue(config.storage) == 1 then
        player:sendTextMessage(MESSAGE_INFO_DESCR, "You have already completed this quest.")
        return true
    else
        -- if they haven't check to see if anyone is in the room
        local creatures = Game.getSpectators(config.centerRoomPosition, false, false, 20, 20, 20, 20)
        if #creatures > 0 then
            player:sendTextMessage(MESSAGE_STATUS_SMALL, "A player is already inside the quest room.")
            -- start to remove both the creatures and the players in the room
            for _, creature in pairs(creatures) do
                if creature:isPlayer() then
                    creature:teleportTo(config.removePlayerDestination, false)
                elseif creature:isMonster() then
                    creature:remove()
                end
            end
        -- if there isn't anyone/thing in the room let them do the quest
        else
            player:teleportTo(config.playerDestination, false)
            player:getPosition():sendMagicEffect(CONST_ME_TELEPORT)
            player:sendTextMessage(MESSAGE_INFO_DESCR, "Good luck. You will need it!")
            item:transform(item.itemid == 1945 and 1946 or 1945)   
        end
    end
    return true
end
 
Back
Top