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.
Solution to script:
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: