• 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 If logout in town 2, respawn in town 1. Its possible?

Kaivan

New Member
Joined
Apr 29, 2021
Messages
13
Reaction score
1
Hello people,

I would like to know how I could make a system in which, if a player logs out of a town other than ID 1, upon logging in, he respawn in the temple of town 1. Its possible? How?

Sorry for my bad english, thx
 
Solution
It’s good to think, to define an area to identify the territory in which the player is.


idk what happened, but even in Town 1, he respawn at the temple after logging in.

I tried it both as an event and in the login script and I had the same result.
mm probably need to grab the number.

change
Lua:
if player:getTown() ~= 1 then
to
Lua:
if player:getTown():getId() ~= 1 then
Yes, it's possible. Everything is possible if you have an idea.

In my opinion - you should make an script in creaturescripts using onLogout function which will be checking where player excatly is when he is doing "logout action", so you have to check areaPos (fromX, toY left top corner to right bottom corner) - an area - which will be "territory" of town 1 and if player is in this area and he is doing logout move (teleport) the character to position of town 2 temple.
Remember to declare perfectly the area because the "area" is always rectangle so it might be tricky.
I don't remember if character will be straight teleported while clicking Logout because TFS may recognize this action as "remove character from game (logout)" without any delay, so you can do it by giving storage to character (onLogout) and check the storage in onLogin and do the teleport thing in onLogin.


I don't know why you making that type of thing because it's kinda useless, but I gave you an tip how to do that. I don't know if there are other options to do that kind of thing.
 
Last edited:
Hello people,

I would like to know how I could make a system in which, if a player logs out of a town other than ID 1, upon logging in, he respawn in the temple of town 1. Its possible? How?

Sorry for my bad english, thx
Lua:
local loginEvent = CreatureEvent("onLogin_EventName")
loginEvent:type("login")

function loginEvent.onLogin(player)
    if player:getTown() ~= 1 then
        player:teleportTo(Town(1):getTemplePosition())
    end
    return true
end

loginEvent:register()
 
Yes, it's possible. Everything is possible if you have an idea.

In my opinion - you should make an script in creaturescripts using onLogout function which will be checking where player excatly is when he is doing "logout action", so you have to check areaPos (fromX, toY left top corner to right bottom corner) - an area - which will be "territory" of town 1 and if player is in this area and he is doing logout move (teleport) the character to position of town 2 temple.
Remember to declare perfectly the area because the "area" is always rectangle so it might be tricky.
I don't remember if character will be straight teleported while clicking Logout because TFS may recognize this action as "remove character from game (logout)" without any delay, so you can do it by giving storage to character (onLogout) and check the storage in onLogin and do the teleport thing in onLogin.


I don't know why you making that type of thing because it's kinda useless, but I gave you an tip how to do that. I don't know if there are other options to do that kind of thing.
It’s good to think, to define an area to identify the territory in which the player is.

Lua:
local loginEvent = CreatureEvent("onLogin_EventName")
loginEvent:type("login")

function loginEvent.onLogin(player)
    if player:getTown() ~= 1 then
        player:teleportTo(Town(1):getTemplePosition())
    end
    return true
end

loginEvent:register()
idk what happened, but even in Town 1, he respawn at the temple after logging in.

I tried it both as an event and in the login script and I had the same result.
 
It’s good to think, to define an area to identify the territory in which the player is.


idk what happened, but even in Town 1, he respawn at the temple after logging in.

I tried it both as an event and in the login script and I had the same result.
mm probably need to grab the number.

change
Lua:
if player:getTown() ~= 1 then
to
Lua:
if player:getTown():getId() ~= 1 then
 
Solution
mm probably need to grab the number.

change
Lua:
if player:getTown() ~= 1 then
to
Lua:
if player:getTown():getId() ~= 1 then
This worked, put in the login script, and in the end, for set player to town 1, like:

Lua:
        if player:getTown():getId() ~= 1 then
            player:teleportTo(Town(1):getTemplePosition())
            player:setTown(Town(1))
        end

Thank you very much.
 
Back
Top