Hello.
This script doesn't work - it have to teleport all creatures in range, but it doesn't teleport first creature on the left...
This script doesn't work - it have to teleport all creatures in range, but it doesn't teleport first creature on the left...
Code:
function getCreaturesInRange(fromPos, toPos, player)
local array = {}
local mpos = {}
for x = fromPos.x, toPos.x do
for y = fromPos.y, toPos.y do
mpos = {x = x, y = y, z = fromPos.z, stackpos = 253}
if getThingFromPos(mpos) then
if isCreature(getThingFromPos(mpos).uid) and ((not player) or isPlayer(getThingFromPos(mpos).uid)) then
table.insert(array, getThingFromPos(mpos))
end
end
end
end
return array
end
function onUse(cid, item, fromPosition, itemEx, toPosition)
local toPositions = {
pos(5376, 3670, 6),
pos(5376, 3869, 6),
pos(5375, 3869, 6),
pos(5377, 3868, 6),
pos(5376, 3868, 6),
pos(5375, 3868, 6)
}
local players = getCreaturesInRange(pos(5374, 3877, 13), pos(5380, 3877, 13), false)
local switch = {[1945] = 1946, [1946] = 1945}
if #players < 3 or getDistanceBetween(getCreaturePosition(cid), pos(fromPosition.x - 1, fromPosition.y, fromPosition.z)) > 0 then
doTransformItem(item.uid, switch[item.itemid])
doSendMagicEffect(getCreaturePosition(cid), CONST_ME_POFF)
return false
end
for i = 1, #players do
doTeleportThing(players[i], toPositions[i])
end
end