• 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!
  • 2026 staff recruitment is open! Check it out and consider applying!

Lua TP To trainers script not working

jiotrus

New Member
Joined
Feb 26, 2012
Messages
5
Reaction score
0
I scripted a trainer tp script, but it only works for 1 row, is there any error in code below ??

Code:
function tpToTrainers(cid)
	local pos = {x = 32286, y = 32222, z = 15, stackpos = 1} -- left row
	while pos.y < 32338 do
		if(getTopCreature(pos).uid ~= 0) then
			pos.y = pos.y + 4
		else
			doTeleportThing(cid, pos, true)
			return true
		end
	end
	
	pox.y = 32222 -- right row
	pos.x = 32306
	
	while pos.y < 32338 do
		if(getTopCreature(pos).uid ~= 0) then
			pos.y = pos.y + 4
		else
			doTeleportThing(cid, pos, true)
			return true
		end
	end
	
	pos.y = 32230 -- down left row
	pos.x = 32294

	while pos.y < 32338 do
		if(getTopCreature(pos).uid ~= 0) then
			pos.y = pos.y + 4
		else
			doTeleportThing(cid, pos, true)
			return true
		end
	end
	pos.y = 32230 -- down right row
	pos.x = 32298

	while pos.y < 32338 do
		if(getTopCreature(pos).uid ~= 0) then
			pos.y = pos.y + 4
		else
			doTeleportThing(cid, pos, true)
			return true
		end
	end
	
	pos = {x = 32286, y = 32222, z = 14, stackpos = 1} -- left row
	while pos.y < 32338 do
		if(getTopCreature(pos).uid ~= 0) then
			pos.y = pos.y + 4
		else
			doTeleportThing(cid, pos, true)
			return true
		end
	end
	
	pox.y = 32222 -- right row
	pos.x = 32306
	
	while pos.y < 32338 do
		if(getTopCreature(pos).uid ~= 0) then
			pos.y = pos.y + 4
		else
			doTeleportThing(cid, pos, true)
			return true
		end
	end
	
	pos.y = 32230 -- down left row
	pos.x = 32294

	while pos.y < 32338 do
		if(getTopCreature(pos).uid ~= 0) then
			pos.y = pos.y + 4
		else
			doTeleportThing(cid, pos, true)
			return true
		end
	end
	pos.y = 32230 -- down right row
	pos.x = 32298

	while pos.y < 32338 do
		if(getTopCreature(pos).uid ~= 0) then
			pos.y = pos.y + 4
		else
			doTeleportThing(cid, pos, true)
			return true
		end
	end
	
	pos = {x = 32286, y = 32222, z = 13, stackpos = 1} -- left row
	while pos.y < 32338 do
		if(getTopCreature(pos).uid ~= 0) then
			pos.y = pos.y + 4
		else
			doTeleportThing(cid, pos, true)
			return true
		end
	end
	
	pox.y = 32222 -- right row
	pos.x = 32306
	
	while pos.y < 32338 do
		if(getTopCreature(pos).uid ~= 0) then
			pos.y = pos.y + 4
		else
			doTeleportThing(cid, pos, true)
			return true
		end
	end
	
	pos.y = 32230 -- down left row
	pos.x = 32294

	while pos.y < 32338 do
		if(getTopCreature(pos).uid ~= 0) then
			pos.y = pos.y + 4
		else
			doTeleportThing(cid, pos, true)
			return true
		end
	end
	pos.y = 32230 -- down right row
	pos.x = 32298

	while pos.y < 32338 do
		if(getTopCreature(pos).uid ~= 0) then
			pos.y = pos.y + 4
		else
			doTeleportThing(cid, pos, true)
			return true
		end
	end
end
 
LUA:
local t = {
	a = {
		{x=1000, y=1000, z=7}, --TOP LEFT training monk spot pos
		{x=1000, y=1006, z=7}, --TOP RIGHT training monk spot pos
		{x=1003, y=1006, z=7}, --last training monk in the first floor
		{x=1003, y=1006, z=3} -- last training monk in the last floor
		},
	b = {
		{4}, --tiles between trianing spots from north to south.
		{4} --tiles between trianing spots from west to east.
		},
	c = 'true' --multifloor
	}
local i, a, b, c, d, e, m = 0, t.a[1], t.a[2], t.a[3], t.b[1], t.b[2], t.a[4]
function onStepIn(cid, item, fromPosition, toPosition)
i = a
if isPlayer(cid) then
	if getTopCreature(a).type == 1 then
		check(cid, fromPosition, t.c)
	else
		doTeleportThing(cid, a)
	end
end
a = i
i = 0
return TRUE
end

function check(w, s, k)
repeat
	a.x = a.x+e
until a.x == b.x or a.z == m.z or a == c or a == m or getTopCreature(a).type ~= 1
	if a == c then
		if (k == 'true') then
			a.z = (a.z+1)
			c.z = (a.z+1)
			check(w, s, k)
		end
	end
	if a.x == b.x then
		a.y = a.y+d
		check(w, s, k)
	end
	if getTopCreature(a).type == 1 then
		doPlayerSendTextMessage(w, 21, 'Sorry, all training spots are occupied')
		doTeleportThing(w, s)
	else
		doTeleportThing(w, a)
	end
end
Haven't tested it yet, it should work with more than 1 floors.
 
Last edited:
Back
Top