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

[Request] Check amount of players in area and teleport

Sorbal

Member
Joined
Jul 23, 2010
Messages
406
Reaction score
11
Location
Poland
Hello Otlanders, can someone do for me a script? The script should check if in the area (blue square in the picture) is a minimum of 10 players, if yes, when you use the lever all the players located on the area will be teleported to the new location. If the number of players is less than 10 of the lever will display the description: "You need atleast 10 players to use lever."

9g8o6w.png
 
It could be much shorter, but i forgot how to use other function.
Please test that and past errors :)
Lua:
local place = {
	fromX = 31182,
	fromY = 33729,
	fromZ = 6,
	toX = 31186,
	toY = 33738,
	toZ = 6
}

local teleport = {x = 999, y = 999, z = 999}

function check()
for z=place.fromZ, place.toZ do
	for x=place.fromX, place.toX do
		for y=place.fromY, place.toY do
			local pos = {x=x, y=y, z=z, stackpos=253}
			local thing = getThingfromPos(pos)
			if(isPlayer(thing.uid) == FALSE) then
				return true
			end
		end
	end
end
	return false
end

function onUse(cid, item, fromPosition, itemEx, toPosition)
local pos = {x=x, y=y, z=z, stackpos=253}
local thing = getThingfromPos(pos)
local name = getCreatureName(thing.uid)

if((check)() >= 10) then
	for i = 1, #check do
		doTeleportThing(thing.uid, teleport)
		doSendMagicEffect(getCreaturePosition(thing.uid), CONST_ME_TELEPORAT)
	end
else
	doPlayerSendTextMessage(cid, 25, "You need atleast 10 players to use lever.")
	doSendMagicEffect(getCreaturePosition(cid), CONST_ME_POFF)
end
	return true
end
 
While using the lever:
PHP:
[03/12/2011 15:48:06] [Error - Action Interface] 
[03/12/2011 15:48:06] data/actions/scripts/quests/wrathfinal.lua:onUse
[03/12/2011 15:48:06] Description: 
[03/12/2011 15:48:06] (luaGetThingFromPos) Tile not found

[03/12/2011 15:48:06] [Error - Action Interface] 
[03/12/2011 15:48:06] data/actions/scripts/quests/wrathfinal.lua:onUse
[03/12/2011 15:48:06] Description: 
[03/12/2011 15:48:06] (luaGetCreatureName) Creature not found

[03/12/2011 15:48:06] [Error - Action Interface] 
[03/12/2011 15:48:06] data/actions/scripts/quests/wrathfinal.lua:onUse
[03/12/2011 15:48:06] Description: 
[03/12/2011 15:48:06] data/actions/scripts/quests/wrathfinal.lua:32: attempt to compare number with boolean
[03/12/2011 15:48:06] stack traceback:
[03/12/2011 15:48:06] 	data/actions/scripts/quests/wrathfinal.lua:32: in function <data/actions/scripts/quests/wrathfinal.lua:27>
 
Try this:
Lua:
local place = {
	fromX = 31182,
	fromY = 33729,
	fromZ = 6,
	toX = 31186,
	toY = 33738,
	toZ = 6
}

local teleport = {x = 999, y = 999, z = 999}

function check()
for z=place.fromZ, place.toZ do
	for x=place.fromX, place.toX do
		for y=place.fromY, place.toY do
			local pos = {x=x, y=y, z=z, stackpos=253}
			local thing = getThingfromPos(pos)
			if(isPlayer(thing.uid) == FALSE) then
				return true
			end
		end
	end
end
	return false
end

function onUse(cid, item, fromPosition, itemEx, toPosition)
local pos = {x=x, y=y, z=z, stackpos=253}
local thing = getThingfromPos(pos)
local name = getCreatureName(thing.uid)

if((check) >= 10) then
	for i = 1, #check do
		doTeleportThing(thing.uid, teleport)
		doSendMagicEffect(getCreaturePosition(thing.uid), CONST_ME_TELEPORT)
	end
else
	doPlayerSendTextMessage(cid, 25, "You need atleast 10 players to use lever.")
	doSendMagicEffect(getCreaturePosition(cid), CONST_ME_POFF)
end
	return true
end
or this:
Lua:
local place = {
	fromX = 31182,
	fromY = 33729,
	fromZ = 6,
	toX = 31186,
	toY = 33738,
	toZ = 6
}

local teleport = {x = 999, y = 999, z = 999}

function check()
for z=place.fromZ, place.toZ do
	for x=place.fromX, place.toX do
		for y=place.fromY, place.toY do
			local pos = {x=x, y=y, z=z, stackpos=253}
			local thing = getThingfromPos(pos)
			if(isPlayer(thing.uid) == FALSE) then
				return true
			end
		end
	end
end
	return false
end

function onUse(cid, item, fromPosition, itemEx, toPosition)
local pos = {x=x, y=y, z=z, stackpos=253}
local thing = getThingfromPos(pos)
local name = getCreatureName(thing.uid)

if((check >= 10)()) then
	for i = 1, #check do
		doTeleportThing(thing.uid, teleport)
		doSendMagicEffect(getCreaturePosition(thing.uid), CONST_ME_TELEPORT)
	end
else
	doPlayerSendTextMessage(cid, 25, "You need atleast 10 players to use lever.")
	doSendMagicEffect(getCreaturePosition(cid), CONST_ME_POFF)
end
	return true
end
 
Please past errors.

*Edit
maybe this:
Lua:
local place = {
	fromX = 31182,
	fromY = 33729,
	fromZ = 6,
	toX = 31186,
	toY = 33738,
	toZ = 6
}

local teleport = {x = 999, y = 999, z = 999}

function check()
for z=place.fromZ, place.toZ do
	for x=place.fromX, place.toX do
		for y=place.fromY, place.toY do
			local pos = {x=x, y=y, z=z, stackpos=253}
			local thing = getThingfromPos(pos)
			if(isPlayer(thing.uid) == FALSE) then
				return true
			end
		end
	end
end
	return false
end

function onUse(cid, item, fromPosition, itemEx, toPosition)
local pos = {x=x, y=y, z=z, stackpos=253}
local thing = getThingfromPos(pos)
local name = getCreatureName(thing.uid)

if((check()) >= 10 then
	for i = 1, #check do
		doTeleportThing(thing.uid, teleport)
		doSendMagicEffect(getCreaturePosition(thing.uid), CONST_ME_TELEPORT)
	end
else
	doPlayerSendTextMessage(cid, 25, "You need atleast 10 players to use lever.")
	doSendMagicEffect(getCreaturePosition(cid), CONST_ME_POFF)
end
	return true
end
 
While turning on server:
PHP:
[03/12/2011 16:14:46] [Error - LuaScriptInterface::loadFile] data/actions/scripts/quests/wrathfinal.lua:32: ')' expected near 'then'
[03/12/2011 16:14:46] [Warning - Event::loadScript] Cannot load script (data/actions/scripts/quests/wrathfinal.lua)
[03/12/2011 16:14:46] data/actions/scripts/quests/wrathfinal.lua:32: ')' expected near 'then'
I deleted '(' and its clean in console but while using lever:
PHP:
[03/12/2011 16:16:27] [Error - Action Interface] 
[03/12/2011 16:16:27] data/actions/scripts/quests/wrathfinal.lua:onUse
[03/12/2011 16:16:27] Description: 
[03/12/2011 16:16:27] (luaGetThingFromPos) Tile not found

[03/12/2011 16:16:27] [Error - Action Interface] 
[03/12/2011 16:16:27] data/actions/scripts/quests/wrathfinal.lua:onUse
[03/12/2011 16:16:27] Description: 
[03/12/2011 16:16:27] (luaGetCreatureName) Creature not found

[03/12/2011 16:16:27] [Error - Action Interface] 
[03/12/2011 16:16:27] data/actions/scripts/quests/wrathfinal.lua:onUse
[03/12/2011 16:16:27] Description: 
[03/12/2011 16:16:27] data/actions/scripts/quests/wrathfinal.lua:32: attempt to compare number with function
[03/12/2011 16:16:27] stack traceback:
[03/12/2011 16:16:27] 	data/actions/scripts/quests/wrathfinal.lua:32: in function <data/actions/scripts/quests/wrathfinal.lua:27>
 
Try this:
Lua:
local place = {
	fromX = 31182,
	fromY = 33729,
	fromZ = 6,
	toX = 31186,
	toY = 33738,
	toZ = 6
}
 
local teleport = {x = 999, y = 999, z = 999}
 
function check()
for z=place.fromZ, place.toZ do
	for x=place.fromX, place.toX do
		for y=place.fromY, place.toY do
			local pos = {x=x, y=y, z=z, stackpos=253}
			local thing = getThingfromPos(pos)
			if(isPlayer(thing.uid) == FALSE) then
				return true
			end
		end
	end
end
	return false
end
 
function onUse(cid, item, fromPosition, itemEx, toPosition)
local pos = {x=x, y=y, z=z, stackpos=253}
local thing = getThingfromPos(pos)
local name = getCreatureName(thing.uid)
 
if(check()) then
	for i = 1, #check do
		doTeleportThing(thing.uid, teleport)
		doSendMagicEffect(getCreaturePosition(thing.uid), CONST_ME_TELEPORT)
	end
else
	doPlayerSendTextMessage(cid, 25, "You need atleast 10 players to use lever.")
	doSendMagicEffect(getCreaturePosition(cid), CONST_ME_POFF)
end
	return true
end
 
Hmm..
PHP:
[03/12/2011 16:27:54] [Error - Action Interface] 
[03/12/2011 16:27:54] data/actions/scripts/quests/wrathfinal.lua:onUse
[03/12/2011 16:27:54] Description: 
[03/12/2011 16:27:54] (luaGetThingFromPos) Tile not found

[03/12/2011 16:27:54] [Error - Action Interface] 
[03/12/2011 16:27:54] data/actions/scripts/quests/wrathfinal.lua:onUse
[03/12/2011 16:27:54] Description: 
[03/12/2011 16:27:54] (luaGetCreatureName) Creature not found

[03/12/2011 16:27:54] [Error - Action Interface] 
[03/12/2011 16:27:54] data/actions/scripts/quests/wrathfinal.lua:onUse
[03/12/2011 16:27:54] Description: 
[03/12/2011 16:27:54] data/actions/scripts/quests/wrathfinal.lua:33: attempt to get length of global 'check' (a function value)
[03/12/2011 16:27:54] stack traceback:
[03/12/2011 16:27:54] 	data/actions/scripts/quests/wrathfinal.lua:33: in function <data/actions/scripts/quests/wrathfinal.lua:27>
 
Ok, try this:
Lua:
function onUse(cid, item, fromPosition, itemEx, toPosition)
local g = getCreaturePosition(cid)
local amountOfPlayers = 10
local teleport = {x = 999, y = 999, z = 999}

if getThingFromPos({x = g.x, y = g.y+1, z = g.z, stackpos = 253}).itemid == (1945 or 1946) then
	local centerPos = {x = g.x, y = g.y-4, z = g.z, stackpos = 253}
	local rangeX = 2
	local rangeY = 2
	local p = getSpectators(centerPos, rangex, rangey)
	for v, k in pairs(p)
		if(g.x > centerPos.x+1 or g.y > centerPos.y+1) then
			table.remove(p, v)
		end
	end
	local players = #p
	if players >= amountOfPlayers then
		for i = 1, players do
			doTeleportThing(p, teleport)
			doSendMagicEffect(getCreaturePosition(p), CONST_ME_TELEPORT)
		end
	else
		doPlayerSendTextMessage(cid, 25, "You need atleast 10 players to use lever.")
		doSendMagicEffect(getCreaturePosition(cid), CONST_ME_POFF)
	end
elseif getThingFromPos({x = g.x+1, y = g.y+1, z = g.z, stackpos = 253}).itemid == (1945 or 1946) then
	local centerPos = {x = g.x-1, y = g.y-4, z = g.z, stackpos = 253}
	local rangeX = 2
	local rangeY = 2
	local p = getSpectators(centerPos, rangex, rangey)
	for v, k in pairs(p)
		if(g.x > centerPos.x+1 or g.y > centerPos.y+1) then
			table.remove(p, v)
		end
	end
	local players = #p
	if players >= amountOfPlayers then
		for i = 1, players do
			doTeleportThing(p, teleport)
			doSendMagicEffect(getCreaturePosition(p), CONST_ME_TELEPORT)
		end
	else
		doPlayerSendTextMessage(cid, 25, "You need atleast 10 players to use lever.")
		doSendMagicEffect(getCreaturePosition(cid), CONST_ME_POFF)
	end
elseif getThingFromPos({x = g.x-1, y = g.y+1, z = g.z, stackpos = 253}).itemid == (1945 or 1946) then
	local centerPos = {x = g.x+1, y = g.y-4, z = g.z, stackpos = 253}
	local rangeX = 2
	local rangeY = 2
	local p = getSpectators(centerPos, rangex, rangey)
	for v, k in pairs(p)
		if(g.x > centerPos.x+1 or g.y > centerPos.y+1) then
			table.remove(p, v)
		end
	end
	local players = #p
	if players >= amountOfPlayers then
		for i = 1, players do
			doTeleportThing(p, teleport)
			doSendMagicEffect(getCreaturePosition(p), CONST_ME_TELEPORT)
		end
	else
		doPlayerSendTextMessage(cid, 25, "You need atleast 10 players to use lever.")
		doSendMagicEffect(getCreaturePosition(cid), CONST_ME_POFF)
	end
	return true
end
	return true
end
 
While turning on server:
PHP:
[03/12/2011 17:21:13] [Error - LuaScriptInterface::loadFile] data/actions/scripts/quests/wrathfinal.lua:12: 'do' expected near 'if'
[03/12/2011 17:21:13] [Warning - Event::loadScript] Cannot load script (data/actions/scripts/quests/wrathfinal.lua)
[03/12/2011 17:21:13] data/actions/scripts/quests/wrathfinal.lua:12: 'do' expected near 'if'
 
Maybe this:
Lua:
function onUse(cid, item, fromPosition, itemEx, toPosition)
local g = getCreaturePosition(cid)
local amountOfPlayers = 10
local teleport = {x = 999, y = 999, z = 999}
 
if getThingFromPos({x = g.x, y = g.y+1, z = g.z, stackpos = 253}).itemid == (1945 or 1946) then
	local centerPos = {x = g.x, y = g.y-4, z = g.z}
	local rangeX = 2
	local rangeY = 2
	local p = getSpectators(centerPos, rangex, rangey)
	for v, k in pairs(p) do
		if(g.x > centerPos.x+1 or g.y > centerPos.y+1) then
			table.remove(p, v)
		end
	end
	local players = #p
	if players >= amountOfPlayers then
		for i = 1, players do
			doTeleportThing(p.uid, teleport)
			doSendMagicEffect(getCreaturePosition(p.uid), CONST_ME_TELEPORT)
		end
	else
		doPlayerSendTextMessage(cid, 25, "You need atleast 10 players to use lever.")
		doSendMagicEffect(getCreaturePosition(cid), CONST_ME_POFF)
	end
elseif getThingFromPos({x = g.x+1, y = g.y+1, z = g.z, stackpos = 253}).itemid == (1945 or 1946) then
	local centerPos = {x = g.x-1, y = g.y-4, z = g.z}
	local rangeX = 2
	local rangeY = 2
	local p = getSpectators(centerPos, rangex, rangey)
	for v, k in pairs(p) do
		if(g.x > centerPos.x+1 or g.y > centerPos.y+1) then
			table.remove(p, v)
		end
	end
	local players = #p
	if players >= amountOfPlayers then
		for i = 1, players do
			doTeleportThing(p.uid, teleport)
			doSendMagicEffect(getCreaturePosition(p.uid), CONST_ME_TELEPORT)
		end
	else
		doPlayerSendTextMessage(cid, 25, "You need atleast 10 players to use lever.")
		doSendMagicEffect(getCreaturePosition(cid), CONST_ME_POFF)
	end
elseif getThingFromPos({x = g.x-1, y = g.y+1, z = g.z, stackpos = 253}).itemid == (1945 or 1946) then
	local centerPos = {x = g.x+1, y = g.y-4, z = g.z}
	local rangeX = 2
	local rangeY = 2
	local p = getSpectators(centerPos, rangex, rangey)
	for v, k in pairs(p) do
		if(g.x > centerPos.x+1 or g.y > centerPos.y+1) then
			table.remove(p, v)
		end
	end
	local players = #p
	if players >= amountOfPlayers then
		for i = 1, players do
			doTeleportThing(p.uid, teleport)
			doSendMagicEffect(getCreaturePosition(p.uid), CONST_ME_TELEPORT)
		end
	else
		doPlayerSendTextMessage(cid, 25, "You need atleast 10 players to use lever.")
		doSendMagicEffect(getCreaturePosition(cid), CONST_ME_POFF)
	end
	return true
end
	return true
end
or this:
Lua:
function onUse(cid, item, fromPosition, itemEx, toPosition)
local g = getCreaturePosition(cid)
local amountOfPlayers = 10
local teleport = {x = 999, y = 999, z = 999}
 
if getThingFromPos({x = g.x, y = g.y+1, z = g.z, stackpos = 253}).itemid == (1945 or 1946) then
	local centerPos = {x = g.x, y = g.y-4, z = g.z}
	local rangeX = 2
	local rangeY = 2
	local p = getSpectators(centerPos, rangex, rangey)
	for v, k in pairs(p) do
		if(g.x > centerPos.x+1 or g.y > centerPos.y+1) then
			table.remove(p, v)
		end
	end
	local players = #p
	if players >= amountOfPlayers then
		for _, pid in ipairs(players) do
			doTeleportThing(pid, teleport)
			doSendMagicEffect(getCreaturePosition(pid), CONST_ME_TELEPORT)
		end
	else
		doPlayerSendTextMessage(cid, 25, "You need atleast 10 players to use lever.")
		doSendMagicEffect(getCreaturePosition(cid), CONST_ME_POFF)
	end
elseif getThingFromPos({x = g.x+1, y = g.y+1, z = g.z, stackpos = 253}).itemid == (1945 or 1946) then
	local centerPos = {x = g.x-1, y = g.y-4, z = g.z}
	local rangeX = 2
	local rangeY = 2
	local p = getSpectators(centerPos, rangex, rangey)
	for v, k in pairs(p) do
		if(g.x > centerPos.x+1 or g.y > centerPos.y+1) then
			table.remove(p, v)
		end
	end
	local players = #p
	if players >= amountOfPlayers then
		for _, pid in ipairs(players) do
			doTeleportThing(pid, teleport)
			doSendMagicEffect(getCreaturePosition(pid), CONST_ME_TELEPORT)
		end
	else
		doPlayerSendTextMessage(cid, 25, "You need atleast 10 players to use lever.")
		doSendMagicEffect(getCreaturePosition(cid), CONST_ME_POFF)
	end
elseif getThingFromPos({x = g.x-1, y = g.y+1, z = g.z, stackpos = 253}).itemid == (1945 or 1946) then
	local centerPos = {x = g.x+1, y = g.y-4, z = g.z}
	local rangeX = 2
	local rangeY = 2
	local p = getSpectators(centerPos, rangex, rangey)
	for v, k in pairs(p) do
		if(g.x > centerPos.x+1 or g.y > centerPos.y+1) then
			table.remove(p, v)
		end
	end
	local players = #p
	if players >= amountOfPlayers then
		for _, pid in ipairs(players) do
			doTeleportThing(pid, teleport)
			doSendMagicEffect(getCreaturePosition(pid), CONST_ME_TELEPORT)
		end
	else
		doPlayerSendTextMessage(cid, 25, "You need atleast 10 players to use lever.")
		doSendMagicEffect(getCreaturePosition(cid), CONST_ME_POFF)
	end
	return true
end
	return true
end
 
Last edited:
Ok, test it, and past what scripts says:
Lua:
function onUse(cid, item, fromPosition, itemEx, toPosition)
local g = getCreaturePosition(cid)
local amountOfPlayers = 10
local teleport = {x = 999, y = 999, z = 999}
 
if getThingFromPos({x = g.x, y = g.y+1, z = g.z, stackpos = 253}).itemid == (1945 or 1946) then
	local centerPos = {x = g.x, y = g.y-4, z = g.z}
	local rangeX = 2
	local rangeY = 2
	local p = getSpectators(centerPos, rangex, rangey)
	for v, k in pairs(p) do
		if(g.x > centerPos.x+1 or g.y > centerPos.y+1) then
			table.remove(p, v)
		end
	end
	local players = #p
	if players >= amountOfPlayers then
		for _, pid in ipairs(players) do
			doTeleportThing(pid, teleport)
			doSendMagicEffect(getCreaturePosition(pid), CONST_ME_TELEPORT)
		end
	else
		doPlayerSendTextMessage(cid, 25, "You need atleast 10 players to use lever.")
		doSendMagicEffect(getCreaturePosition(cid), CONST_ME_POFF)
	end
elseif getThingFromPos({x = g.x+1, y = g.y+1, z = g.z, stackpos = 253}).itemid == (1945 or 1946) then
	local centerPos = {x = g.x-1, y = g.y-4, z = g.z}
	local rangeX = 2
	local rangeY = 2
	local p = getSpectators(centerPos, rangex, rangey)
	for v, k in pairs(p) do
		if(g.x > centerPos.x+1 or g.y > centerPos.y+1) then
			table.remove(p, v)
		end
	end
	local players = #p
	if players >= amountOfPlayers then
		for _, pid in ipairs(players) do
			doTeleportThing(pid, teleport)
			doSendMagicEffect(getCreaturePosition(pid), CONST_ME_TELEPORT)
		end
	else
		doPlayerSendTextMessage(cid, 25, "You need atleast 10 players to use lever.")
		doSendMagicEffect(getCreaturePosition(cid), CONST_ME_POFF)
	end
elseif getThingFromPos({x = g.x-1, y = g.y+1, z = g.z, stackpos = 253}).itemid == (1945 or 1946) then
	local centerPos = {x = g.x+1, y = g.y-4, z = g.z}
	local rangeX = 2
	local rangeY = 2
	local p = getSpectators(centerPos, rangex, rangey)
	for v, k in pairs(p) do
		if(g.x > centerPos.x+1 or g.y > centerPos.y+1) then
			table.remove(p, v)
		end
	end
	local players = #p
	if players >= amountOfPlayers then
		for _, pid in ipairs(players) do
			doTeleportThing(pid, teleport)
			doSendMagicEffect(getCreaturePosition(pid), CONST_ME_TELEPORT)
		end
	else
		doPlayerSendTextMessage(cid, 25, "You need atleast 10 players to use lever.")
		doSendMagicEffect(getCreaturePosition(cid), CONST_ME_POFF)
	end
else
	doPlayerSendTextMessage(cid, 25, "SOMETHING IS WRONG!.")
	return true
end
	return true
end
 
Ok then. You have to stand on the lever. Like this:

XXXXXX
XXXXXX
XXXXXX 6x6
XXXXXX
XXXXXX
XOOOXX
__L____

L - towed lever position
O - place for player who can pull the lever
X - other places from which you cannot pull the lever
_ - empty position

You are trying to pull lever from position O? If not, you will see an error with "SOMETHING IS WRONG!.", else script should work. Try this now.
 
Im pull from position O like this:
2052qn9.png

Also im change amountOfPlayers = 1 but it still sends me error:
Code:
SOMETHING IS WRONG!
 
@TibiaWR
I need this script to check amount in area (Look at first post) and if there is >= 10 players they will be teleported, no matter where they stand, one requirement is to stand in area.
 
Back
Top