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

Change townID Player spawn after step on tile

noobofthecity

New Member
Joined
Aug 17, 2009
Messages
5
Reaction score
0
Hello guys.

I'm retro tibia player that haven't been playing tibia for years. Now i started to have fun with creating my own little world using tibia 8.6 client with tfs 0.4

And here is first of probably many incomming problems.

I wanted to make bridge with 2 switches (the ones you can stand on id 446) on my rook-like island.

The problem is that my idea is to make those switches change your spawn id (after your incomming death to rook temple). It is because on my map you spawn somewhere else but i want you to spawn in temple after your next death.

So the clue is to have a bridge with those 2 switches, and after passing it your spawn point should be switched to temple position.

Is it possible? Can you guys help me doing it?

Im not so good with scripting but im also not complete retard.

Greetings and looking froward to hearing from you guys.
 
Solution
So it's 1 line in movements.xml and 1 script.
I realized later that UID will cause them errors in console when loading the map.
And, I don't want to tie down an entire itemID for a citizen teleport script, to do the config[item.actionid], idea.

But sure, both ways would likely work.

If I'm being stupid and not understanding, maybe you could provide the short script for the OP?
you're not tying down the item id to the script, i said action id
simple example
Lua:
local config = {
    -- [action id] = town id
    [45001] = 6,
    [45002] = 7
}

function onStepIn(cid, item, fromPosition, toPosition)
    local town = config[item.actionid]
    if town then
        doPlayerSetTown(cid, town)
    end
    return true
end
in data/movements/movements.xml
-- set actionid to whatever you want.
XML:
<movevent type="StepIn" actionid="45001" event="script" value="setPlayerTown.lua"/>
create new lua file
in data/movements/scripts/setPlayerTown.lua
Lua:
function onStepIn(cid, item, position, fromPosition)
    if item.uid > 0 and item.uid < 100 then -- this is basically a failsafe, so the players aren't being assigned a nil value, and so ground floor tiles don't interfere with the script.
        doPlayerSetTown(cid, item.uid)
    end
    return true
end

In RME, create the different towns you want to use, and set the town co-ordinates.
Remember the TownID for Rookgaard.

On the tiles you want to set the town of the player..
Right click -> properties
-> ActionID -> set to same as movements.xml
-> UniqueID -> set to TownID for Rookgaard


-------
In 0.3.7 we use item.aid / item.uid
I think 0.4 uses item.actionid / item.uniqueid

So if it doesn't work the first time, try changing those parts in the script.
 
Hello Xikini.

Ive tried your hints, used the code with item.aid/item.uid and item.actionid / item.uniqueid abd this is what i get:

M7sSJLvPRBWWOxvTl4SpMw.png

Maybe im doing something wrong but also in RME:
YaEdv3SCTzSTVEqbiLcdyA.png


So it seems like i cann't put my town id which is 6 in this tile uid.
 
Last edited:
Hello Xikini.

Ive tried your hints, used the code with item.aid/item.uid and item.actionid / item.uniqueid abd this is what i get:

M7sSJLvPRBWWOxvTl4SpMw.png

Maybe im doing something wrong but also in RME:
YaEdv3SCTzSTVEqbiLcdyA.png


So it seems like i cann't put my town id which is 6 in this tile uid.
Sorry, wasn't aware of that limitation for the UniqueID in rme.

Remove the UniqueID from the tiles, leaving only the ActionID.

Use the below script, and update the positions accordingly.
Ensure that the 'spacing' is kept.
Lua:
"x = 1000, y = 1000, z = 7" -- will work
"x=1000,y=1000,z=7" -- will note work
Lua:
local config = {
    ["x = 1000, y = 1000, z = 7"] = {town_id = 6},
    ["x = 1001, y = 1000, z = 7"] = {town_id = 6},
    ["x = 1002, y = 1000, z = 7"] = {town_id = 6}
}

function onStepIn(cid, item, position, fromPosition)
    local xyz = "x = " .. position.x .. ", y = " .. position.y .. ", z = " .. position.z .. ""
    if config[xyz] then
        doPlayerSetTown(cid, config[xyz].town_id)
    end
    return true
end
 
why dont you just do 1000 + townid
to get the id in the table just do uid - 1000 which will give you the town id
more efficient than string keys and 3 concatenations
OR
have the action ids as the keys in the table and the values as the town id to set to
config[item.actionid]
 
why dont you just do 1000 + townid
to get the id in the table just do uid - 1000 which will give you the town id
more efficient than string keys and 3 concatenations
OR
have the action ids as the keys in the table and the values as the town id to set to
config[item.actionid]
So it's 1 line in movements.xml and 1 script.
I realized later that UID will cause them errors in console when loading the map.
And, I don't want to tie down an entire itemID for a citizen teleport script, to do the config[item.actionid], idea.

But sure, both ways would likely work.

If I'm being stupid and not understanding, maybe you could provide the short script for the OP?
 
So it's 1 line in movements.xml and 1 script.
I realized later that UID will cause them errors in console when loading the map.
And, I don't want to tie down an entire itemID for a citizen teleport script, to do the config[item.actionid], idea.

But sure, both ways would likely work.

If I'm being stupid and not understanding, maybe you could provide the short script for the OP?
you're not tying down the item id to the script, i said action id
simple example
Lua:
local config = {
    -- [action id] = town id
    [45001] = 6,
    [45002] = 7
}

function onStepIn(cid, item, fromPosition, toPosition)
    local town = config[item.actionid]
    if town then
        doPlayerSetTown(cid, town)
    end
    return true
end
 
Solution
you're not tying down the item id to the script, i said action id
simple example
Lua:
local config = {
    -- [action id] = town id
    [45001] = 6,
    [45002] = 7
}

function onStepIn(cid, item, fromPosition, toPosition)
    local town = config[item.actionid]
    if town then
        doPlayerSetTown(cid, town)
    end
    return true
end
Right, but now you gotta go
Lua:
<movevent type="StepIn" actionid="45001" event="script" value="setPlayerTown.lua"/>
<movevent type="StepIn" actionid="45002" event="script" value="setPlayerTown.lua"/>
And each tile on the map is going to use a different actionid.

It's effectively the same amount of work as my method. xD

But yeah, this is another way to do it.

Please read the rules; Rules for the Support board#1@noobofthecity
It's the request board.
What's wrong with his title?
 
Last edited:
Right, but now you gotta go
Lua:
<movevent type="StepIn" actionid="45001" event="script" value="setPlayerTown.lua"/>
<movevent type="StepIn" actionid="45002" event="script" value="setPlayerTown.lua"/>
And each tile on the map is going to use a different actionid.

It's effectively the same amount of work as my method. xD

But yeah, this is another way to do it.


It's the request board.
What's wrong with his title?
no
fromaid="45001" toaid="45002"
also the problem with his title was screaming HELP ME WITH SCRIPT which is an invalid title
 
@WibbenZ Sorry for that, fixed already

@Xikini and @Static_

Thank you guys for efford. Just came back home and tested one solution. So with @Static_ script

Lua:
local config = {
    -- [action id] = town id
    [45001] = 6,
    [45002] = 7
}

function onStepIn(cid, item, fromPosition, toPosition)
    local town = config[item.actionid]
    if town then
        doPlayerSetTown(cid, town)
    end
    return true
end

Also added this in movements.xml:
Lua:
<movevent type="StepIn" actionid="45001" event="script" value="setPlayerTown.lua"/>
<movevent type="StepIn" actionid="45002" event="script" value="setPlayerTown.lua"/>


There is nothing happening. Tile is now like not even working with the animation. I mean when i step on it it doeasnt press, no console ERRORS etc. Also my test character town id doesnt change.

Ywek89fKRtK_ADmYCx7gOw.png


Ill try @Xikini script also today.

Am i doing it right tho?

EDIT:

Little update. It seems to work with @Static_ solution but town id updates after relog, when i pass the switch, then die for exampe i spawn in town that ive been citizen before but if i pass switch, relog and then die i spawn in my destination town id (in my example 6)
 
Last edited:
It's the request board.
What's wrong with his title?

Same rules applies to the request board, the rules are pretty much for the support board(s) including the child boards.
It was changed, now it's fine.
 
@WibbenZ Sorry for that, fixed already

@Xikini and @Static_

Thank you guys for efford. Just came back home and tested one solution. So with @Static_ script



Also added this in movements.xml:



There is nothing happening. Tile is now like not even working with the animation. I mean when i step on it it doeasnt press, no console ERRORS etc. Also my test character town id doesnt change.

Ywek89fKRtK_ADmYCx7gOw.png


Ill try @Xikini script also today.

Am i doing it right tho?
Yup.
Map editor with AID on tile.
Movements.xml with the AID's you are wanting to use with the script.
script.lua adjust the table with the AID's you are wanting to use.

and of course, change aid/actionid in the script based on what your server is wanting to use.

If your stepping on the tile and it's not doing anything, check your console to see if there is any errors, either upon loading the server, or when the tile is being stepped on.

If all else fails, give us screenshots of everything.
Scripts/map/in-game/console
 
@Xikini Ive edited my pervious post. Dont know yet how to properly use your code, but with the other solution it works, kinda. Becaus ei need to relog to apply the change. Town id deosnt change until i relog. No errors in console.
 
@Xikini Ive edited my pervious post. Dont know yet how to properly use your code, but with the other solution it works, kinda. Becaus ei need to relog to apply the change. Town id deosnt change until i relog. No errors in console.
Yeah, most changes in the database don't show they've happened until the character is saved.
You can forcibly save the character inside of a script, but in most cases it's best to allow the logout and server close functions to save the characters permanently.

You could do an easy test to check if it's applying immediately to the character though.

Placing the below line into any script, will teleport the player to their current temple position.
If you know the temple position of each town, it's a fairly quick and effective way to test that the temple positions are correct, and that the townID of a player is changing.
Lua:
doTeleportThing(cid, getTownTemplePosition(getPlayerTown(cid)))
Of course if you can always print the players town to console, to check that way as well.
Lua:
print(getPlayerTown(cid)) -- prints players town number to console
 
Ok. Thank you guys very much for help. I get it working thank to your codes / advices.
The only thing i would like to improve is to actually see the magic blue effect or at least tile animation (when you step on it) because so far with this code it doesnt like interact with player stepping on it. It does change town id and im gładka, but would like this improvement so much.
 
Last edited:
Back
Top