• 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!

[TFS 0.4/0.3.6] doTeleportMassThings

underewar

Well-Known Member
Joined
Feb 9, 2013
Messages
58
Reaction score
65
Location
Brazil
GitHub
Underewarrr
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:

Lua:
doTeleportMassThings (leftTopCorner, rightBottomCorner, newPos, minPlayerCount, toSamenewPos, typeOfObjects)
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.
Default parameter for that fuction.
Lua:
isCreature / isPlayer / isMonster / isNpc

Sem título-2022-06-27-1407.png

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
Enjoy IT!
 
Back
Top