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

Teleport all players in area.

Serp

/* No comment */
Joined
Mar 23, 2008
Messages
249
Reaction score
1
I tryied this myself but no luck.

Q: How can i teleport all players in a certain area to a diffrent area when someone hits a level[Typo: level = LEVER] or something.

the level and w/e i can do but its making it teleport ALL players in a 'certain' area, any ideas o.o?
 
Last edited:
The anni script specifies each of the 4 locations lol, i wanted a way to do it isntead of me having to write about 3000 locations for what i want to us eit.
 
global.lua
Code:
function mapArea(fromPos, toPos, stack)
	-- Area iterator by Colandus @ ******.net
	local pos = {x=fromPos.x, y=fromPos.y-1, z=fromPos.z}
	return function()
		if (pos.y < toPos.y) then
			pos.y = pos.y+1
		elseif (pos.x <= toPos.x) then
			pos.y = fromPos.y
			pos.x = pos.x+1
		else
			pos.x = fromPos.x
			pos.y = fromPos.y
			pos.z = pos.z+1
		end
		if (pos.x <= toPos.x and pos.y <= toPos.y or pos.z < toPos.z) then
			if (stack == nil) then
				return pos
			else
				pos.stackpos = stack
				return pos, getThingfromPos(pos)
			end
		end
	end
end

If you want to make it teleport all players in the area, then you should need onAdvance, else, just an example of onUse:
Code:
function onUse(cid, item, position)
    fromPos = {x = 10, y = 15, z = 5}
    toPos = {x = 20, y = 30, z = 7}
    newPos = {x = 50, y = 30, z = 10}
    for pos, uid in mapArea(fromPos, toPos, 253) do
        if isPlayer(thing) == TRUE then
            doTeleportThing(thing, newPos, 0)
	end
    end
end

Not sure about that ;p
- post the errors :mad:
 
What did you mean by onAdvance? :eek:

And thing is nil, it should be uid ;p Also, don't forget to declare the variables local and preferably place them before the function onUse :)
 
What did you mean by onAdvance? :eek:

And thing is nil, it should be uid ;p Also, don't forget to declare the variables local and preferably place them before the function onUse :)

I just woke up when writing this... :p
With onAdvance Ive meant that if the teleporting must be after reaching x skill.
 
this is how i've used it

PHP:
fromPos = {x = 1024, y = 1242, z = 7}
toPos = {x = 1081, y = 1310, z = 7}
newPos = {x = 1055, y = 1283, z = 6}

function onDeath(cid, corpse, killer, target, pos)
	    for pos, uid in mapArea(fromPos, toPos, 253) do
        	if isPlayer(thing) == TRUE then
	            doTeleportThing(thing, newPos, 0)
		end
	end
end

i don't get any errors but nothing happens either o.o, did i miss something out?
 
Code:
local area = { fromx = XXX, fromy = YYY, fromz = ZZZ, tox = XXX, toy = YYY, toz = ZZZ }
local exitpos = {x=XXX,y=YYY,z=ZZZ}

local function getPlayersInArea(area)
         local players = {} 
         for x = area.fromx,area.tox do
                  for y = area.fromy,area.toy do
                           for z = area.fromz,area.toz do
                                    playerpos = {x=x,y=y,z=z,stackpos=253}
                                    player = getTileThingByPos(playerpos)
                                    if isPlayer(player.uid) == TRUE then
                                             table.insert(players, player.uid)
                                    end
                           end
                  end
         end
         return players
end

function onUse(cid, item, frompos, item2, topos)
         local players = getPlayersInArea(area)
         for i = 1,#players do
                  doTeleportThing(players[i],exitpos,FALSE)  
         end
         return TRUE       
end
 
this is how i've used it

PHP:
fromPos = {x = 1024, y = 1242, z = 7}
toPos = {x = 1081, y = 1310, z = 7}
newPos = {x = 1055, y = 1283, z = 6}

function onDeath(cid, corpse, killer, target, pos)
	    for pos, uid in mapArea(fromPos, toPos, 253) do
        	if isPlayer(thing) == TRUE then
	            doTeleportThing(thing, newPos, 0)
		end
	end
end

i don't get any errors but nothing happens either o.o, did i miss something out?

If you atleast could have read my post, I said switch 'thing' to 'uid':
Code:
local fromPos = {x=10, y=15, z=5}
local toPos = {x=20, y=30, z=7}
local newPos = {x=50, y=30, z=10}

function onDeath(cid, corpse, killer, target, pos) 
    for _, uid in mapArea(fromPos, toPos, 253) do
        if isPlayer(uid) == TRUE then
            doTeleportThing(uid, newPos, 0)
	end
    end
end
 
global.lua
Code:

function mapArea(fromPos, toPos, stack)
-- Area iterator by Colandus @ ******.net
local pos = {x=fromPos.x, y=fromPos.y-1, z=fromPos.z}
return function()
if (pos.y < toPos.y) then
pos.y = pos.y+1
elseif (pos.x <= toPos.x) then
pos.y = fromPos.y
pos.x = pos.x+1
else
pos.x = fromPos.x
pos.y = fromPos.y
pos.z = pos.z+1
end
if (pos.x <= toPos.x and pos.y <= toPos.y or pos.z < toPos.z) then
if (stack == nil) then
return pos
else
pos.stackpos = stack
return pos, getThingfromPos(pos)
end
end
end
end

If you want to make it teleport all players in the area, then you should need onAdvance, else, just an example of onUse:
Code:

function onUse(cid, item, position)
fromPos = {x = 10, y = 15, z = 5}
toPos = {x = 20, y = 30, z = 7}
newPos = {x = 50, y = 30, z = 10}
for pos, uid in mapArea(fromPos, toPos, 253) do
if isPlayer(thing) == TRUE then
doTeleportThing(thing, newPos, 0)
end
end
end


Just this man =)
 
If you atleast could have read my post, I said switch 'thing' to 'uid':
Code:
local fromPos = {x=10, y=15, z=5}
local toPos = {x=20, y=30, z=7}
local newPos = {x=50, y=30, z=10}

function onDeath(cid, corpse, killer, target, pos) 
    for _, uid in mapArea(fromPos, toPos, 253) do
        if isPlayer(uid) == TRUE then
            doTeleportThing(uid, newPos, 0)
	end
    end
end

@ Colandus. Sorry i did actually set thing to 'uid' i pasted the previous version with thing, my mistake i'll try the onDeath you posted.

@ rafa, you just wrote exactly what marci did on page 1, why?

@ Everyone helping, sorry i didn't reply my computers been out for 3 days, ty for everyone trying to help
 
Back
Top