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

Lua TFS 1.1 (Need help fixing a script that I converted)

Lava Titan

Developer
Joined
Jul 25, 2009
Messages
1,571
Solutions
3
Reaction score
98
Location
Portugal
Hi can someone help me fixing this script I converted?
So far I got no errors in console but it's teleporting me to temple while all position spots are avaible...

Code:
local location = {
    {x=480, y=463, z=8},
    {x=484, y=463, z=8},
    {x=488, y=463, z=8},
    {x=500, y=479, z=8}
}
function onStepIn(cid, item, pos)
    for i = 1, #location do
        if getTopCreature(location[i]).uid > 0 then
            playerteleported = 1
        else
            doTeleportThing(cid,location[i])
            doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "Welcome to the training monks! Open the door to leave.")
            playerteleported = 0
            break
        end
    end
    if playerteleported > 0 then
        doTeleportThing(cid, {x=469, y=471, z=8})
        doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "There was no empty training spot.")
    end
    return true
end

Code:
local location = {
    {x = 994, y = 987, z = 4},
    {x = 998, y = 987, z = 4},
    {x = 1002, y = 987, z = 4},
    {x = 1006, y = 987, z = 4}
}
function onStepIn(player, creature, item, position, fromPosition, toPosition)
    for i = 1, #location do
        local tile = creature:getTile()
        if tile:getTopCreature(location[i]).uid > 0 then
            playerteleported = 1
        else
            player:teleportTo(location[i])
            player:sendTextMessage(MESSAGE_INFO_DESCR, "Welcome to the training monks! Open the door to leave.")
            playerteleported = 0
            break
        end
    end
    if playerteleported > 0 then
        local temple = Position(1000,1000,5)
        player:teleportTo(temple)
        player:sendTextMessage(MESSAGE_INFO_DESCR, "There was no empty training spot.")
    end
    return true
end

Thanks in advance!
 
Last edited:
Code:
local location = {
    {x=480, y=463, z=8},
    {x=484, y=463, z=8},
    {x=488, y=463, z=8},
    {x=500, y=479, z=8}
}
local playerteleported = nil
function onStepIn(creature, item, position, fromPosition)
    for i = 1, #location do
        local player = Tile(location[i]):getTopCreature()
        if player:isPlayer() then
            playerteleported = true
        else
            creature:teleportTo(location[i], false)
            creature:sendTextMessage(MESSAGE_INFO_DESCR, "Welcome to the training monks! Open the door to leave.")
            playerteleported = false
            break
        end
    end
    if playerteleported then
        creature:teleportTo({x=469, y=471, z=8}, false)
        creature:sendTextMessage(MESSAGE_INFO_DESCR, "There are no empty training spots. :(")
    end
    return true
end
 
@Codex NG thanks for your help, but it's not working :(
got some console error about player

Anyways I managed to get it working just had to fix getTopCreature part :p

Code:
local location = {
    --floor 4
    {x = 994, y = 987, z = 4},
    {x = 998, y = 987, z = 4},
    {x = 1002, y = 987, z = 4},
    {x = 1006, y = 987, z = 4}
}
function onStepIn(player, creature, item, position, fromPosition, toPosition)
    local playerteleported = 0

    for i = 1, #location do
        if getTopCreature(location[i]).uid > 0 then
            playerteleported = 1
        else
            player:teleportTo(location[i])
            player:sendTextMessage(MESSAGE_INFO_DESCR, "See you later!")
            playerteleported = 0
            break
        end
    end

    if playerteleported > 0 then
        local temple = Position(1000,1000,5)
        player:teleportTo(temple)
        player:sendTextMessage(MESSAGE_INFO_DESCR, "Trainers are full, please try again later.")
    end
    return true
end

Btw any idea how to count number of busy spots?

for example when some1 enters trainers he gets message

Code:
player:sendTextMessage(MESSAGE_INFO_DESCR, "Theres "..busyTrainers.." training at this moment.")

".. busyTrainers .." will return number of people training at the moment
 
Last edited:
I gotta stop using notepad :p
Code:
local location = {
    --floor 4
    {x = 994, y = 987, z = 4},
    {x = 998, y = 987, z = 4},
    {x = 1002, y = 987, z = 4},
    {x = 1006, y = 987, z = 4}
}

function onStepIn(player, creature, item, position, fromPosition, toPosition)
    local playerteleported = 0

    local function getPeopleTraining()
        local inUse = 0
        for n = 1, #location do
            if getTopCreature(location[n]).uid > 0 then
               inUse = inUse + 1
            end
        end
        return inUse
    end

    for i = 1, #location do
        if getTopCreature(location[i]).uid > 0 then
            playerteleported = 1
        else
            player:teleportTo(location[i])
            player:sendTextMessage(MESSAGE_INFO_DESCR, "See you later!")
            player:sendTextMessage(MESSAGE_INFO_DESCR, "Theres are currently "..getPeopleTraining().." people training at this moment.")
            playerteleported = 0
            break
        end
    end


    if playerteleported > 0 then
        local temple = Position(1000,1000,5)
        player:teleportTo(temple)
        player:sendTextMessage(MESSAGE_INFO_DESCR, "Trainers are full, please try again later.")
    end
    return true
end
 
Last edited:
Back
Top