underewar
Well-Known Member
Description - The function of all transport objects, teleported of the selected type (players, NPCs, monsters) from one place to another.
The function structure looks like this:
data/lib/050-function.lua
Enjoy IT!
The function structure looks like this:
Lua:
doTeleportMassThings (leftTopCorner, rightBottomCorner, newPos, minPlayerCount, toSamenewPos, typeOfObjects)
Default parameter for that fuction.leftTopCorner is the top of the rectangle.
rightBottomCorner as above, just the bottom right corner. position
newPos where it will move all objects.
minPlayerCount if we want to have a proper amount needed for successful teleport object? in, let's define it here.
toSamenewPos alone? position? or will these be? spread out in a square with a side of 5qm.
typeOfObjects the type of objects that will be teleported.
Lua:
isCreature / isPlayer / isMonster / isNpc
data/lib/050-function.lua
Lua:
function getFreeTile(pos, rangeX, rangeY, ignoreCreature, ignoreProj)
local tablePositions = {}
for x = -rangeX, rangeX do
for y = -rangeY, rangeY do
local position = {x=pos.x,y=pos.y,z=pos.z}
position.x = pos.x + x
position.y = pos.y + y
if isWalkable(position, ignoreCreature, ignoreProj) then
tablePositions[#tablePositions+1] = position
end
end
end
return #tablePositions > 0 and tablePositions
end
function doTeleportMassThings(leftTopCorner, rightBottomCorner, newPos, minPlayerCount, toSamenewPos, typeOfObjects)
local rangeX, rangeY = math.abs(rightBottomCorner.x - leftTopCorner.x)/2, math.abs(rightBottomCorner.y - leftTopCorner.y)/2
local center, player = {x=leftTopCorner.x+rangeX,y=rightBottomCorner.y-rangeY}, {}
for z = math.min(leftTopCorner.z, rightBottomCorner.z), math.max(leftTopCorner.z, rightBottomCorner.z) do
center.z = z
if getSpectators(center, rangeX, rangeY) then
for _, cid in pairs(getSpectators(center, rangeX, rangeY)) do
table.insert(player, cid)
end
end
end
if #player >= minPlayerCount then
for _, cid in pairs(player) do
local newPosSpectators = getFreeTile(newPos, 5, 5, true)
local newPos = (toSamenewPos and newPos or newPosSpectators[math.random(#newPosSpectators)])
if newPos and typeOfObjects(cid) then
doTeleportThing(cid, newPos, true, true)
else
print('ERROR: [newPos value is false or some object is not a creature].')
end
end
end
return true
end