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

How to use this script?

Bug

New Member
Joined
Jan 7, 2011
Messages
111
Reaction score
1
Code:
local t = {
	a = {
		{x=26019, y=26454, z=7}, --TOP LEFT training monk spot pos
		{x=26205, y=26454, z=7}, --TOP RIGHT training monk spot pos
		{x=26205, y=26616, z=7} --last training monk spot
		},
	b = {
		{6}, --tiles between trianing spots from north to south.
		{5} --tiles between trianing spots from west to east.
		}
	}
local i, a, b, c, d, e = 0, t.a[1], t.a[2], t.a[3], t.b[1], t.b[2]
function onStepIn(cid, item, fromPosition, toPosition)
i = a
if isPlayer(cid) then
	if getTopCreature(a).type == 1 then
		check(cid, fromPosition)
	else
		doTeleportThing(cid, a)
	end
end
a = i
i = 0
return TRUE
end
 
function check(w, s)
repeat
	a.x = a.x+e
until a.x == b.x or a == c or getTopCreature(a).type ~= 1
	if a.x == b.x then
		a.y = a.y+d
		check(w, s)
	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
Is an action creaturescript or what, also do someon knows if it will work?
 
It has onStepIn function, it goes on movements.

XML:
<movevent type="StepIn" actionid="0000" event="script" value="script_name.lua"/>

If it will work.. test it by yourself, you can check if something's wrong if a error appears on console related to your script.
 
I got this
Code:
[Error - MoveEvents Interface]
data/movements/scripts/training.lua:onStepIn
Description:
data/movements/scripts/training.lua:29: attempt to perform arithmetic on upvalue 'e' (a table value)
stack traceback:
        data/movements/scripts/training.lua:29: in function 'check'
        data/movements/scripts/training.lua:17: in function <data/movements/scripts/training.lua:13>
 
Register the event into login.lua
There is no even to register in login.lua..

The script couldn't be uglier..

Try replacing:
local i, a, b, c, d, e = 0, t.a[1], t.a[2], t.a[3], t.b[1], t.b[2]
with:
local i, a, b, c, d, e = 0, t.a[1], t.a[2], t.a[3], t.b[1][1], t.b[2][1]
 
Now i get this
Code:
[Error - MoveEvents Interface]
data/movements/scripts/training.lua:onStepIn
Description:
attempt to index a number value
stack traceback:
        [C]: in function 'getTopCreature'
        data/movements/scripts/training.lua:17: in function <data/movements/scripts/training.lua:14>
And last guy appears in the void
c]A6-a.png


- - - Updated - - -

Those are my trainers.
 
Last edited:
No, is not that, last player that can enter, get the message that all the spots are full, the problem here is that there are like 300 spots, also this last guy get teleported to a void space, where nothing is in it.

- - - Updated - - -

I fpund this, but dont works
Code:
function isWalkable(pos)  --found: posted by Cyko
	pos.stackpos = 0
	local tile = getThingfromPos(pos, false)
	if tile ~= 0 and not hasProperty(tile.uid, CONST_PROP_BLOCKSOLID) and not isCreature(getTopCreature(pos).uid) then
		return true
	end
end


local area = {
	from = {x=1012,y=1017,z=7},
	to = {x=1027,y=1029,z=7}
}

function onStepIn(cid, item, position, fromPosition)
	for x = area.from.x, area.to.x do
		for y = area.from.y, area.to.y do
			local p = {x=x,y=y,z=area.from.z}
			if isWalkable(p) then
				return doTeleportThing(cid, p) and doSendMagicEffect(getThingPos(cid), 10) and doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "You were brought to a free training spot.")
			end
		end
	end
	doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "There is no free training spot at the moment.")
    return true
end
 
This is a simple script, does the job at least. It will teleport a player to a tile that has the mentioned UID in the script. 17000 - 17300.

XML:
<movevent type="StepIn" uniqueid="XXXX" event="script" value="trainingspot.lua" />

LUA:
function onStepIn(cid, item, position, fromPosition)
    for i = 17000, 17300 do
        local pos = getThingPos(i)
        if not isPlayer(getTopCreature(pos).uid) then
            doTeleportThing(cid, pos)
             doCreatureSay(cid, 'Using a tool to cast spells or to keep your character online is ok.', 19, false, cid)
            doSendMagicEffect(position, CONST_ME_TELEPORT)
            doSendMagicEffect(pos, CONST_ME_TELEPORT)
            return
        end
    end
    doTeleportThing(cid, fromPosition, true)
    doCreatureSay(cid, 'All training slots are taken', 19, false, cid)
    doSendMagicEffect(fromPosition, CONST_ME_TELEPORT)
end
 
Try this:
LUA:
function isWalkable(pos)  --found: posted by Cyko
	pos.stackpos = 0
	local tile = getThingfromPos(pos, false)
	if tile ~= 0 and not hasProperty(tile.uid, CONST_PROP_BLOCKSOLID) and not isCreature(getTopCreature(pos).uid) then
		return true
	end
end


local area = {
	from = {x=1012,y=1017,z=7},
	to = {x=1027,y=1029,z=7}
}

function onStepIn(cid, item, position, fromPosition)
	for x = area.from.x, area.to.x do
		for y = area.from.y, area.to.y do
			local p = {x=x,y=y,z=area.from.z}
			if isWalkable(p) then
				doTeleportThing(cid, p) 
                                doSendMagicEffect(getThingPos(cid), 10)
                                doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "You were brought to a free training spot.")
			else
                                doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "There is no free training spot at the moment.")
				end
			end
		end
	return true
end
 
Last edited:
LUA:
function isWalkable(pos) -- Credits to whoever..
    pos.stackpos = 0
    local tile = getThingfromPos(pos, false)
    if tile ~= 0 and not hasProperty(tile.uid, CONST_PROP_BLOCKSOLID) and not isCreature(getTopCreature(pos).uid) then
        return true
    end
end
 
local area = {
    {x=1012,y=1017,z=7,
    {x=1027,y=1029,z=7},
    distX = 5,
    distY = 6
}

if ((area[2].x - area[1].x) % area.distX) ~= 0 then
    print("Training script: Invalid values [X]")
elseif ((area[2].y - area[1].y) % area.distY) ~= 0 then
    print("Training script: Invalid values [Y]")
end
 
function onStepIn(cid, item, position, fromPosition)
    local amountX, amountY = (area[2].x - area[1].x) / area.distX, (area[2].y - area[1].y) / area.distY
    for x = 0, (area[2].x - area[1].x) / area.distX do
        for y = 0, (area[2].y - area[1].y) / area.distY do
            local p = {x = (area[1].x + x * area.distX), y = (area[1].y + y * area.distY), z = area[1].z}
            if isWalkable(p) then
                doTeleportThing(cid, p) 
                doSendMagicEffect(getThingPos(cid), CONST_ME_TELEPORT)
                doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "You were brought to a free training spot.")
                return true
            end
            
            if x == amountX and y == amountY then
                doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "There is no free training spot at the moment.")
                return true
            end
        end
    end
    return true
end
 
Last edited:
Using this function:
LUA:
function isWalkable(pos) -- Credits to whoever..
	pos.stackpos = 0
	local tile = getThingfromPos(pos, false)
	if tile ~= 0 and not hasProperty(tile.uid, CONST_PROP_BLOCKSOLID) and not isCreature(getTopCreature(pos).uid) then
		return true
	end
end

And trying teleport someone to void tiles = which arent walkable. I dont think it works.
 
Back
Top