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

TFS 0.X When logout on trainer generator teleport to temple and destroy trainer

newby

Active Member
Joined
Jun 11, 2016
Messages
183
Reaction score
43
I'm using this amazing trainer generator system made by @Evil Hero

But there is a problem...
If player get kicked, after 15 min or just logout there, the player still on that position and trainer room still existing

There is a way to if player logout there, send player to temple
Code:
        doTeleportThing(cid, getTownTemplePosition(getPlayerTown(cid)))
        doSendMagicEffect(getPlayerPosition(cid), 10)

And destroy the room?
 
I havn't tested this but it should do the trick, you just have to register it correctly in creaturescripts.xml
<event type="logout" name="trainingLogout" script="YOURFILE.lua"/>
Lua:
function onStepIn(cid, item, position, fromPosition)
    if item.actionid == 8770 then
        if getNextRoom() <= (config.gridX * config.gridY * config.gridZ) then
            local currentRoom = getNextRoom()
            createTrainingRoom(getRoomPosFromIndex(getNextRoom()))
            doTeleportThing(cid, getRoomPosFromIndex(currentRoom), false)
            setRoomInUse(currentRoom)
            registerCreatureEvent(cid, "trainingLogout")
        else
            doPlayerSendCancel(cid, "All rooms are taken at the moment.")
            doTeleportThing(cid, fromPosition, true)
        end
    elseif item.actionid == 8771 then
        doTeleportThing(cid, config.temple, false)
        deleteTrainingRoom(position)
        setRoomUnused(getRoomIndexFromPos(fromPosition))
        unregisterCreatureEvent(cid, "trainingLogout")
    end
    return true
end

function onLogout(cid)
    doTeleportThing(cid, config.temple, false)
    deleteTrainingRoom(getCreaturePosition(cid))
    setRoomUnused(getRoomIndexFromPos(getCreaturePosition(cid)))
    return true
end
 
I havn't tested this but it should do the trick, you just have to register it correctly in creaturescripts.xml
<event type="logout" name="trainingLogout" script="YOURFILE.lua"/>
Lua:
function onStepIn(cid, item, position, fromPosition)
    if item.actionid == 8770 then
        if getNextRoom() <= (config.gridX * config.gridY * config.gridZ) then
            local currentRoom = getNextRoom()
            createTrainingRoom(getRoomPosFromIndex(getNextRoom()))
            doTeleportThing(cid, getRoomPosFromIndex(currentRoom), false)
            setRoomInUse(currentRoom)
            registerCreatureEvent(cid, "trainingLogout")
        else
            doPlayerSendCancel(cid, "All rooms are taken at the moment.")
            doTeleportThing(cid, fromPosition, true)
        end
    elseif item.actionid == 8771 then
        doTeleportThing(cid, config.temple, false)
        deleteTrainingRoom(position)
        setRoomUnused(getRoomIndexFromPos(fromPosition))
        unregisterCreatureEvent(cid, "trainingLogout")
    end
    return true
end

function onLogout(cid)
    doTeleportThing(cid, config.temple, false)
    deleteTrainingRoom(getCreaturePosition(cid))
    setRoomUnused(getRoomIndexFromPos(getCreaturePosition(cid)))
    return true
end

For some reason it's destroying the temple XD

Code:
function onLogout(cid)
    doTeleportThing(cid, getTownTemplePosition(getPlayerTown(cid)))
    deleteTrainingRoom(getCreaturePosition(cid))
    setRoomUnused(getRoomIndexFromPos(getCreaturePosition(cid)))
    return true
end

And i think it need a if to check if player was in trainers, because its teleporting everybody to temple when logout
 
I forgot that it registers login/logout functions automaticly for all players
Just give a player a certain storagevalue when he stepin and then check in onLogout if he has that certain storagevalue in order for it to execute
 
I forgot that it registers login/logout functions automaticly for all players
Just give a player a certain storagevalue when he stepin and then check in onLogout if he has that certain storagevalue in order for it to execute

I've tried:
Code:
function onLogout(cid)
    local storage = 87700
    if getPlayerStorageValue(cid, storage) == 1 then
        doTeleportThing(cid, getTownTemplePosition(getPlayerTown(cid)))
        deleteTrainingRoom(getCreaturePosition(cid))
        setRoomUnused(getRoomIndexFromPos(getCreaturePosition(cid)))
    end
    return true
end

Code:
function onStepIn(cid, item, position, fromPosition)
    local storage = 87700
    if item.actionid == 8770 then
        if getNextRoom() <= (config.gridX * config.gridY * config.gridZ) then
            local currentRoom = getNextRoom()
            createTrainingRoom(getRoomPosFromIndex(getNextRoom()))
            doTeleportThing(cid, getRoomPosFromIndex(currentRoom), false)
            setRoomInUse(currentRoom)
            setPlayerStorageValue(cid, storage, 1)
        else
            doPlayerSendCancel(cid, "All rooms are taken at the moment.")
            doTeleportThing(cid, fromPosition, true)
        end
    elseif item.actionid == 8771 then
        doTeleportThing(cid, getTownTemplePosition(getPlayerTown(cid)))
        doSendMagicEffect(getPlayerPosition(cid), 10)


        deleteTrainingRoom(position)
        setRoomUnused(getRoomIndexFromPos(fromPosition))
        setPlayerStorageValue(cid, storage, 0)
    end
    return true
end


Trainer still not destroying when player get kicked, and when login the temple is destroyed

Errors:
 
Lua:
function onLogout(cid)
    local storage = 87700
    if getPlayerStorageValue(cid, storage) == 1 then
        local pos = getCreaturePosition(cid)
        doTeleportThing(cid, getTownTemplePosition(getPlayerTown(cid)))
        deleteTrainingRoom(pos)
        setRoomUnused(getRoomIndexFromPos(pos))
    end
    return true
end
 
Lua:
function onLogout(cid)
    local storage = 87700
    if getPlayerStorageValue(cid, storage) == 1 then
        local pos = getCreaturePosition(cid)
        doTeleportThing(cid, getTownTemplePosition(getPlayerTown(cid)))
        deleteTrainingRoom(pos)
        setRoomUnused(getRoomIndexFromPos(pos))
    end
    return true
end

Some pieces dosent destroy, like u can see


And after player back he start on > not on < where was the first trainer
like u can see


---

Why the old players on trainers cant see the ground tiles?


Code:
function onStepIn(cid, item, position, fromPosition)
    local storage = 87700
    if item.actionid == 8770 then
        if getNextRoom() <= (config.gridX * config.gridY * config.gridZ) then
            local currentRoom = getNextRoom()
            createTrainingRoom(getRoomPosFromIndex(getNextRoom()))
            doTeleportThing(cid, getRoomPosFromIndex(currentRoom), false)
            setRoomInUse(currentRoom)
            setPlayerStorageValue(cid, storage, 1)
        else
            doPlayerSendCancel(cid, "All rooms are taken at the moment.")
            doTeleportThing(cid, fromPosition, true)
        end
    elseif item.actionid == 8771 then
        doTeleportThing(cid, getTownTemplePosition(getPlayerTown(cid)))
        doSendMagicEffect(getPlayerPosition(cid), 10)


        deleteTrainingRoom(position)
        setRoomUnused(getRoomIndexFromPos(fromPosition))
        setPlayerStorageValue(cid, storage, 0)
    end
    return true
end
 
Lua:
function onStepIn(cid, item, position, fromPosition)
    local storage = 87700
    if item.actionid == 8770 then
        if getNextRoom() <= (config.gridX * config.gridY * config.gridZ) then
            local currentRoom = getNextRoom()
            createTrainingRoom(getRoomPosFromIndex(getNextRoom()))
            doTeleportThing(cid, getRoomPosFromIndex(currentRoom), false)
            setRoomInUse(currentRoom)
            setPlayerStorageValue(cid, storage, 1)
        else
            doPlayerSendCancel(cid, "All rooms are taken at the moment.")
            doTeleportThing(cid, fromPosition, true)
        end
    elseif item.actionid == 8771 then
        doTeleportThing(cid, getTownTemplePosition(getPlayerTown(cid)))
        doSendMagicEffect(getPlayerPosition(cid), 10)
        deleteTrainingRoom(fromPosition)
        setRoomUnused(getRoomIndexFromPos(fromPosition))
        setPlayerStorageValue(cid, storage, 0)
    end
    return true
end
 
Lua:
function onStepIn(cid, item, position, fromPosition)
    local storage = 87700
    if item.actionid == 8770 then
        if getNextRoom() <= (config.gridX * config.gridY * config.gridZ) then
            local currentRoom = getNextRoom()
            createTrainingRoom(getRoomPosFromIndex(getNextRoom()))
            doTeleportThing(cid, getRoomPosFromIndex(currentRoom), false)
            setRoomInUse(currentRoom)
            setPlayerStorageValue(cid, storage, 1)
        else
            doPlayerSendCancel(cid, "All rooms are taken at the moment.")
            doTeleportThing(cid, fromPosition, true)
        end
    elseif item.actionid == 8771 then
        doTeleportThing(cid, getTownTemplePosition(getPlayerTown(cid)))
        doSendMagicEffect(getPlayerPosition(cid), 10)
        deleteTrainingRoom(fromPosition)
        setRoomUnused(getRoomIndexFromPos(fromPosition))
        setPlayerStorageValue(cid, storage, 0)
    end
    return true
end

Same problem:
And now, entering on teleport is not deleting the north walls, it was working before, the bug before was only on logout

there was some problem with ground tiles, that it doesn't send players new tiles when they get updated, I don't have 0.x sources here, so I cannot tell you where it needs changes in source code.

Can u say here:

???
Don't need to download, say what u think should change and i test here
 
And now when enter on exit teleport floods:
Code:
[13:29:24.028] [Error - MoveEvents Interface] 
[13:29:24.028] data/movements/scripts/trainerstp.lua:onStepIn
[13:29:24.028] Description: 
[13:29:24.028] (luaGetThingFromPos) Tile not found

[13:29:24.028] [Error - MoveEvents Interface] 
[13:29:24.028] data/movements/scripts/trainerstp.lua:onStepIn
[13:29:24.028] Description: 
[13:29:24.028] (luaGetThingFromPos) Tile not found

[13:29:24.028] [Error - MoveEvents Interface] 
[13:29:24.028] data/movements/scripts/trainerstp.lua:onStepIn
[13:29:24.028] Description: 
[13:29:24.028] (luaGetThingFromPos) Tile not found

[13:29:24.028] [Error - MoveEvents Interface] 
[13:29:24.029] data/movements/scripts/trainerstp.lua:onStepIn
[13:29:24.029] Description: 
[13:29:24.029] (luaGetThingFromPos) Tile not found

[13:29:24.029] [Error - MoveEvents Interface] 
[13:29:24.029] data/movements/scripts/trainerstp.lua:onStepIn
[13:29:24.029] Description: 
[13:29:24.029] (luaGetThingFromPos) Tile not found

[13:29:24.029] [Error - MoveEvents Interface] 
[13:29:24.029] data/movements/scripts/trainerstp.lua:onStepIn
[13:29:24.029] Description: 
[13:29:24.029] (luaGetThingFromPos) Tile not found

[13:29:24.029] [Error - MoveEvents Interface] 
[13:29:24.029] data/movements/scripts/trainerstp.lua:onStepIn
[13:29:24.029] Description: 
[13:29:24.029] (luaGetThingFromPos) Tile not found

[13:29:24.029] [Error - MoveEvents Interface] 
[13:29:24.030] data/movements/scripts/trainerstp.lua:onStepIn
[13:29:24.030] Description: 
[13:29:24.030] (luaGetThingFromPos) Tile not found

[13:29:24.030] [Error - MoveEvents Interface] 
[13:29:24.030] data/movements/scripts/trainerstp.lua:onStepIn
[13:29:24.030] Description: 
[13:29:24.030] (luaGetThingFromPos) Tile not found

[13:29:24.030] [Error - MoveEvents Interface] 
[13:29:24.030] data/movements/scripts/trainerstp.lua:onStepIn
[13:29:24.030] Description: 
[13:29:24.030] (luaGetThingFromPos) Tile not found

[13:29:24.030] [Error - MoveEvents Interface] 
[13:29:24.030] data/movements/scripts/trainerstp.lua:onStepIn
[13:29:24.030] Description: 
[13:29:24.030] (luaGetThingFromPos) Tile not found

[13:29:24.030] [Error - MoveEvents Interface] 
[13:29:24.030] data/movements/scripts/trainerstp.lua:onStepIn
[13:29:24.030] Description: 
[13:29:24.030] (luaGetThingFromPos) Tile not found

[13:29:24.031] [Error - MoveEvents Interface] 
[13:29:24.031] data/movements/scripts/trainerstp.lua:onStepIn
[13:29:24.031] Description: 
[13:29:24.031] (luaGetThingFromPos) Tile not found

[13:29:24.031] [Error - MoveEvents Interface] 
[13:29:24.031] data/movements/scripts/trainerstp.lua:onStepIn
[13:29:24.031] Description: 
[13:29:24.031] (luaGetThingFromPos) Tile not found

[13:29:24.031] [Error - MoveEvents Interface] 
[13:29:24.031] data/movements/scripts/trainerstp.lua:onStepIn
[13:29:24.031] Description: 
[13:29:24.031] (luaGetThingFromPos) Tile not found


And if someone get kicked on trainers floods:
Code:
[13:30:25.707] [Error - CreatureScript Interface] 
[13:30:25.707] data/creaturescripts/scripts/trainers_gn_logoutdestroy.lua:onLogout
[13:30:25.707] Description: 
[13:30:25.708] (luaGetThingFromPos) Tile not found

[13:30:25.708] [Error - CreatureScript Interface] 
[13:30:25.708] data/creaturescripts/scripts/trainers_gn_logoutdestroy.lua:onLogout
[13:30:25.708] Description: 
[13:30:25.708] (luaGetThingFromPos) Tile not found

[13:30:25.708] [Error - CreatureScript Interface] 
[13:30:25.708] data/creaturescripts/scripts/trainers_gn_logoutdestroy.lua:onLogout
[13:30:25.708] Description: 
[13:30:25.708] (luaGetThingFromPos) Tile not found

[13:30:25.708] [Error - CreatureScript Interface] 
[13:30:25.708] data/creaturescripts/scripts/trainers_gn_logoutdestroy.lua:onLogout
[13:30:25.708] Description: 
[13:30:25.708] (luaGetThingFromPos) Tile not found

[13:30:25.708] [Error - CreatureScript Interface] 
[13:30:25.708] data/creaturescripts/scripts/trainers_gn_logoutdestroy.lua:onLogout
[13:30:25.708] Description: 
[13:30:25.708] (luaGetThingFromPos) Tile not found

[13:30:25.708] [Error - CreatureScript Interface] 
[13:30:25.708] data/creaturescripts/scripts/trainers_gn_logoutdestroy.lua:onLogout
[13:30:25.709] Description: 
[13:30:25.709] (luaGetThingFromPos) Tile not found

[13:30:25.709] [Error - CreatureScript Interface] 
[13:30:25.709] data/creaturescripts/scripts/trainers_gn_logoutdestroy.lua:onLogout
[13:30:25.709] Description: 
[13:30:25.709] (luaGetThingFromPos) Tile not found

[13:30:25.709] [Error - CreatureScript Interface] 
[13:30:25.709] data/creaturescripts/scripts/trainers_gn_logoutdestroy.lua:onLogout
[13:30:25.709] Description: 
[13:30:25.709] (luaGetThingFromPos) Tile not found

[13:30:25.709] [Error - CreatureScript Interface] 
[13:30:25.709] data/creaturescripts/scripts/trainers_gn_logoutdestroy.lua:onLogout
[13:30:25.709] Description: 
[13:30:25.709] (luaGetThingFromPos) Tile not found

[13:30:25.709] [Error - CreatureScript Interface] 
[13:30:25.709] data/creaturescripts/scripts/trainers_gn_logoutdestroy.lua:onLogout
[13:30:25.709] Description: 
[13:30:25.709] (luaGetThingFromPos) Tile not found

[13:30:25.710] [Error - CreatureScript Interface] 
[13:30:25.710] data/creaturescripts/scripts/trainers_gn_logoutdestroy.lua:onLogout
[13:30:25.710] Description: 
[13:30:25.710] (luaGetThingFromPos) Tile not found

[13:30:25.710] [Error - CreatureScript Interface] 
[13:30:25.710] data/creaturescripts/scripts/trainers_gn_logoutdestroy.lua:onLogout
[13:30:25.710] Description: 
[13:30:25.711] (luaGetThingFromPos) Tile not found

[13:30:25.711] [Error - CreatureScript Interface] 
[13:30:25.711] data/creaturescripts/scripts/trainers_gn_logoutdestroy.lua:onLogout
[13:30:25.711] Description: 
[13:30:25.711] (luaGetThingFromPos) Tile not found

[13:30:25.711] [Error - CreatureScript Interface] 
[13:30:25.711] data/creaturescripts/scripts/trainers_gn_logoutdestroy.lua:onLogout
[13:30:25.711] Description: 
[13:30:25.711] (luaGetThingFromPos) Tile not found

[13:30:25.711] [Error - CreatureScript Interface] 
[13:30:25.711] data/creaturescripts/scripts/trainers_gn_logoutdestroy.lua:onLogout
[13:30:25.711] Description: 
[13:30:25.711] (luaGetThingFromPos) Tile not found
[13:30:25.771] Dawn King has logged out.
 
Lua:
function onStepIn(cid, item, position, fromPosition)
    local storage = 87700
    if item.actionid == 8770 then
        if getNextRoom() <= (config.gridX * config.gridY * config.gridZ) then
            local currentRoom = getNextRoom()
            createTrainingRoom(getRoomPosFromIndex(getNextRoom()))
            doTeleportThing(cid, getRoomPosFromIndex(currentRoom), false)
            setRoomInUse(currentRoom)
            setPlayerStorageValue(cid, storage, 1)
        else
            doPlayerSendCancel(cid, "All rooms are taken at the moment.")
            doTeleportThing(cid, fromPosition, true)
        end
    elseif item.actionid == 8771 then
        doTeleportThing(cid, getTownTemplePosition(getPlayerTown(cid)))
        doSendMagicEffect(getPlayerPosition(cid), 10)
        deleteTrainingRoom(position)
        setRoomUnused(getRoomIndexFromPos(position))
        setPlayerStorageValue(cid, storage, 0)
    end
    return true
end
Lua:
function onLogout(cid)
    local storage = 87700
    if getPlayerStorageValue(cid, storage) == 1 then
        local pos = getCreaturePosition(cid)
        pos.y = pos.y - 1 -- need an offset of 1sqm to the north (y)
        doTeleportThing(cid, getTownTemplePosition(getPlayerTown(cid)))
        deleteTrainingRoom(pos)
        setRoomUnused(getRoomIndexFromPos(pos))
    end
    return true
end
 
Lua:
function onStepIn(cid, item, position, fromPosition)
    local storage = 87700
    if item.actionid == 8770 then
        if getNextRoom() <= (config.gridX * config.gridY * config.gridZ) then
            local currentRoom = getNextRoom()
            createTrainingRoom(getRoomPosFromIndex(getNextRoom()))
            doTeleportThing(cid, getRoomPosFromIndex(currentRoom), false)
            setRoomInUse(currentRoom)
            setPlayerStorageValue(cid, storage, 1)
        else
            doPlayerSendCancel(cid, "All rooms are taken at the moment.")
            doTeleportThing(cid, fromPosition, true)
        end
    elseif item.actionid == 8771 then
        doTeleportThing(cid, getTownTemplePosition(getPlayerTown(cid)))
        doSendMagicEffect(getPlayerPosition(cid), 10)
        deleteTrainingRoom(position)
        setRoomUnused(getRoomIndexFromPos(position))
        setPlayerStorageValue(cid, storage, 0)
    end
    return true
end
Lua:
function onLogout(cid)
    local storage = 87700
    if getPlayerStorageValue(cid, storage) == 1 then
        local pos = getCreaturePosition(cid)
        pos.y = pos.y - 1 -- need an offset of 1sqm to the north (y)
        doTeleportThing(cid, getTownTemplePosition(getPlayerTown(cid)))
        deleteTrainingRoom(pos)
        setRoomUnused(getRoomIndexFromPos(pos))
    end
    return true
end

It's destroying right now, when u enter on TP or logout, but there is still a problem:
When u destroy a trainer, u cant go back there
1 Dawn King enter on trainer
2 Convidador enter on trainer
3 Dawn King exit a trainer leaving
4 Dawn King enter on trainer, but insted of come on 1 position he come on 3
5 Dawn King exit a trainer logouting
6 Dawn King enter on trainer, but insted of come on position 1 or 3 he come on position 4

 
tell me if the print returns the correct room number, when someone leaves/logout
Lua:
function onStepIn(cid, item, position, fromPosition)
    local storage = 87700
    if item.actionid == 8770 then
        if getNextRoom() <= (config.gridX * config.gridY * config.gridZ) then
            local currentRoom = getNextRoom()
            createTrainingRoom(getRoomPosFromIndex(getNextRoom()))
            doTeleportThing(cid, getRoomPosFromIndex(currentRoom), false)
            setRoomInUse(currentRoom)
            setPlayerStorageValue(cid, storage, 1)
        else
            doPlayerSendCancel(cid, "All rooms are taken at the moment.")
            doTeleportThing(cid, fromPosition, true)
        end
    elseif item.actionid == 8771 then
        doTeleportThing(cid, getTownTemplePosition(getPlayerTown(cid)))
        doSendMagicEffect(getPlayerPosition(cid), 10)
        deleteTrainingRoom(position)
        setRoomUnused(getRoomIndexFromPos(position))
        print(getRoomIndexFromPos(position))
        setPlayerStorageValue(cid, storage, 0)
    end
    return true
end
Lua:
function onLogout(cid)
    local storage = 87700
    if getPlayerStorageValue(cid, storage) == 1 then
        local pos = getCreaturePosition(cid)
        pos.y = pos.y - 1 -- need an offset of 1sqm to the north (y)
        doTeleportThing(cid, getTownTemplePosition(getPlayerTown(cid)))
        deleteTrainingRoom(pos)
        setRoomUnused(getRoomIndexFromPos(pos))
        print(getRoomIndexFromPos(pos))
    end
    return true
end
 
tell me if the print returns the correct room number, when someone leaves/logout
Lua:
function onStepIn(cid, item, position, fromPosition)
    local storage = 87700
    if item.actionid == 8770 then
        if getNextRoom() <= (config.gridX * config.gridY * config.gridZ) then
            local currentRoom = getNextRoom()
            createTrainingRoom(getRoomPosFromIndex(getNextRoom()))
            doTeleportThing(cid, getRoomPosFromIndex(currentRoom), false)
            setRoomInUse(currentRoom)
            setPlayerStorageValue(cid, storage, 1)
        else
            doPlayerSendCancel(cid, "All rooms are taken at the moment.")
            doTeleportThing(cid, fromPosition, true)
        end
    elseif item.actionid == 8771 then
        doTeleportThing(cid, getTownTemplePosition(getPlayerTown(cid)))
        doSendMagicEffect(getPlayerPosition(cid), 10)
        deleteTrainingRoom(position)
        setRoomUnused(getRoomIndexFromPos(position))
        print(getRoomIndexFromPos(position))
        setPlayerStorageValue(cid, storage, 0)
    end
    return true
end
Lua:
function onLogout(cid)
    local storage = 87700
    if getPlayerStorageValue(cid, storage) == 1 then
        local pos = getCreaturePosition(cid)
        pos.y = pos.y - 1 -- need an offset of 1sqm to the north (y)
        doTeleportThing(cid, getTownTemplePosition(getPlayerTown(cid)))
        deleteTrainingRoom(pos)
        setRoomUnused(getRoomIndexFromPos(pos))
        print(getRoomIndexFromPos(pos))
    end
    return true
end

the first print -1
the second print 0
... 1
 
Back
Top