• 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:
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 = area[1].x, area[2].x do
        for y = area[1].y, area[2].y do
            local thing = getThingfromPos({x = x, y = y, z = area[1].z, stackpos = 253}).uid
            if thing > 0 then
                if isPlayer(thing) then
                    table.insert(players, thing)
                elseif isMonster(thing) then
                    table.insert(monsters, thing)
                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
 
Or this even, but the 1st way is probably better
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 = area[1].x, area[2].x do
        for y = area[1].y, area[2].y do
            local thing = getThingfromPos({x = x, y = y, z = area[1].z, stackpos = 253}).uid
            if thing > 0 then
                table.insert(isPlayer(thing) and players or monsters, thing)
            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 still " .. (#players) .. " players inside, please be patient.")
        elseif #monsters > 0 then
            for _, monster in pairs(monsters) do
                doRemoveCreature(monster)
            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
 
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 = area[1].x, area[2].x do
        for y = area[1].y, area[2].y do
            local thing = getThingfromPos({x = x, y = y, z = area[1].z, stackpos = 253}).uid
            if thing > 0 then
                table.insert(isPlayer(thing) and players or monsters, thing)
            end
        end
    end
    return monsters, players
end

function onUse(player, item, fromPosition, target, toPosition, isHotkey)
   
    if player:getPosition() ~= Position(config.stand) then
        player:sendTextMessage(MESSAGE_INFO_DESCR, "You must stand on the tile.")
        return true
    end
   
    if player:getStorageValue(config.storage) == 1 then
        player:sendTextMessage(MESSAGE_INFO_DESCR, "You have already completed this quest.")
        return true
    else
        local monsters, players = areaCheck(config.room)
        if #players > 0 then
            player:sendTextMessage(MESSAGE_INFO_DESCR, "There are still " .. (#players) .. " players inside, please be patient.")
            return true
        elseif #monsters > 0 then
            for _, monster in pairs(monsters) do
                doRemoveCreature(monster)
            end
        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)
    end
    return true
end
 
I am getting rusty..
productclr.jpg
 
Code:
if player:getPosition() ~= Position(config.stand) then

Should be:

Code:
if player:getPosition() ~= Position(config.stand[1]) then
Still the same issue as before. I have checked my "stand' pos, just to make sure. Even yet, if I remove the check, I still do not get a teleport. I am getting the sendMagicEffect & sendTextMessage.
 
Still the same issue as before. I have checked my "stand' pos, just to make sure. Even yet, if I remove the check, I still do not get a teleport. I am getting the sendMagicEffect & sendTextMessage.
Well at least we are getting closer to a solution :p
 
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 = area[1].x, area[2].x do
        for y = area[1].y, area[2].y do
            local thing = getThingfromPos({x = x, y = y, z = area[1].z, stackpos = 253}).uid
            if thing > 0 then
                if isPlayer(thing) then
                    table.insert(players, thing)
                elseif isMonster(thing) then
                    table.insert(monsters, thing)
                end
            end
        end
    end
    return monsters, players
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
    else
        local monsters, players = areaCheck(config.room)
        print(#monsters, #players)
        if #players > 0 then
            player:sendTextMessage(MESSAGE_INFO_DESCR, "There are still players inside, please be patient.")
            return true
        elseif #monsters > 0 then
            for _, monster in pairs(monsters) do
                doRemoveCreature(monster)
            end
        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
 
Last edited:
After
Code:
 local monsters, players = areaCheck(config.room)
put
Code:
print(#monsters, #players)
and let me know what it prints out
 
prints 0 0 Makes no difference if there is a player or a monster in the room.
 
Last edited:
try this for the areaCheck function
Code:
local function areaCheck(area)
    local monsters, players = {}, {}
    for x = area[1].x, area[2].x do
        for y = area[1].y, area[2].y do
            local creature = Tile(x, y, area[1].z):getTopCreature()
            if creature then
                table.insert(creature:isPlayer() and players or monsters, creature)
            end
        end
    end
    return monsters, players
end

and change
Code:
for _, monster in pairs(monsters) do
    doRemoveCreature(monster)
end
to
Code:
for _, monster in pairs(monsters) do
     if Creature(monster) then
        monster:remove()
    end
end
 
Back
Top