• 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
 
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 = STACKPOS_SECOND_ITEM_ABOVE_GROUNDTILE}).itemid == (1945 or 1946) then
	local centerPos = {x = g.x, y = g.y-3, 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 = STACKPOS_SECOND_ITEM_ABOVE_GROUNDTILE}).itemid == (1945 or 1946) then
	local centerPos = {x = g.x-1, y = g.y-3, 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 = STACKPOS_SECOND_ITEM_ABOVE_GROUNDTILE}).itemid == (1945 or 1946) then
	local centerPos = {x = g.x+1, y = g.y-3, 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
 
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 = STACKPOS_SECOND_ITEM_ABOVE_GROUNDTILE}).item == (1945 or 1946) then
	local centerPos = {x = g.x, y = g.y-3, 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 = STACKPOS_SECOND_ITEM_ABOVE_GROUNDTILE}).item == (1945 or 1946) then
	local centerPos = {x = g.x-1, y = g.y-3, 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 = STACKPOS_SECOND_ITEM_ABOVE_GROUNDTILE}).item == (1945 or 1946) then
	local centerPos = {x = g.x+1, y = g.y-3, 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! PULLED ITEM ".. item ..".")
	return true
end
	return true
end

The problem lies in the fact that position of the lever is in a different place than it needs to be. We have only 3 options where we can pull the lever and the lever should be placed. In my opinion, the position of the lever are well defined. But unfortunately it is not, because the conditions are not met and refers to the condition that jumps out at the time did not meet any other condition.
 
Last edited:
While im pull the lever:
PHP:
[04/12/2011 16:51:38] [Error - Action Interface] 
[04/12/2011 16:51:38] data/actions/scripts/quests/wrathfinal.lua:onUse
[04/12/2011 16:51:38] Description: 
[04/12/2011 16:51:39] data/actions/scripts/quests/wrathfinal.lua:67: attempt to concatenate local 'item' (a table value)
[04/12/2011 16:51:39] stack traceback:
[04/12/2011 16:51:39] 	data/actions/scripts/quests/wrathfinal.lua:67: in function <data/actions/scripts/quests/wrathfinal.lua:1>
Maybe im doing something wrong? My actions.xml
PHP:
	<action uniqueid="3024" event="script" value="quests/wrathfinal.lua"/>
In map lever uid: 3024
 
Ok, now it would be works (tested) BUT you must place something around this area (some stones ect.) cause i have no idea how to zoom out area from which players will be charged. Now this script will pick all players from six boxes upwards, down, left and right...
Lua:
function onUse(cid, item, fromPosition, itemEx, toPosition)
local g = getCreaturePosition(cid)
local amountOfPlayers = 1
local teleport = {x = 999, y = 999, z = 7}

local centerPos = {x = g.x, y = g.y, z = g.z, stackpos = STACKPOS_TOP_MOVEABLE_ITEM_OR_CREATURE}
local rangeX = 6
local rangeY = 6
local p = getSpectators(centerPos, rangex, rangey)

local players = #p
if players >= 0 then
	for _, pid in pairs(p) 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)
	return true
end
end
 
Woohoo! Works, but lever also teleport a single person when I set amountOfPlayers = 10
Any solution?
+ You must spread some Reputation around before giving it to GarQet again. But will not forget this, and rep when i can :)
 
Yes, small mistake while testing.
Lua:
function onUse(cid, item, fromPosition, itemEx, toPosition)
local g = getCreaturePosition(cid)
local amountOfPlayers = 10
local teleport = {x = 999, y = 999, z = 7}

local centerPos = {x = g.x, y = g.y, z = g.z, stackpos = STACKPOS_TOP_MOVEABLE_ITEM_OR_CREATURE}
local rangeX = 6
local rangeY = 6
local p = getSpectators(centerPos, rangex, rangey)

local players = #p
if players >= amountOfPlayers then
	for _, pid in pairs(p) 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)
	return true
end
end
 
I found the problem.. Just change
PHP:
local p = getSpectators(centerPos, rangex, rangey)
To
PHP:
local p = getSpectators(centerPos, rangeX, rangeY)
Also Thread can be closed, thanks for all who helps me.
 
;)
missing "if isPlayer", in GarQet script.
I think that the second script is better but with "getTopCreature" function instead of "for _, pid in ipairs(getPlayersOnline()) do"
 
Back
Top