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

teleporting Chest?

Tyhawk master

New Member
Joined
Jan 10, 2015
Messages
149
Reaction score
4
is there a way to make a Chest. but when u open it, it gives you the Loot but then teleports you back to the main city (Example: Open chest teleports you to Coordinates 1000, 1000, 7)
if possible please tell me how this can be done?
 
After addItem add this:

player:teleportTo(Position(1, 2, 3)
 
Last edited:
Code:
local c = {
    itemId = 12345,
    amount = 1,
    newPos = {x = 1000, y = 1000, z = 7}
}
function onUse(player, item, fromPosition, itemEx, toPosition)
    player:addItem(c.itemId, c.amount)
    player:teleportTo(c.newPos)
    return true
end
 
Code:
local c = {
    itemId = 2148,
    amount = 1,
    newPos = {x = 677, y = 639, z = 7},
}

function onUse(player) return player:addItem(c.itemId, c.amount), player:teleportTo(c.newPos) end
Just wondering, if I do this, and that item cant be added to player, will it return false and not teleport the player then?
 
Code:
local c = {
    itemId = 2148,
    amount = 1,
    newPos = {x = 677, y = 639, z = 7},
}

function onUse(player) return player:addItem(c.itemId, c.amount), player:teleportTo(c.newPos) end
Just wondering, if I do this, and that item cant be added to player, will it return false and not teleport the player then?
It was just an example, but yes the player will be tp'd regardless since lua like many other languages is procedural.
 
Would probably be best to check if the item was added successfully, and then teleport, otherwise send error to player, (weight/space)
In either case OP just wanted to know how to teleport the players.
 
It was just an example, but yes the player will be tp'd regardless since lua like many other languages is procedural.
hmm ok, though maybe its same like with functions when the first statement doesn't match the standard its not going to check the others.
Hence the question
 
hmm ok, though maybe its same like with functions when the first statement doesn't match the standard its not going to check the others.
Hence the question
The only time a function will return false and or stop the execution of a script is if you tell it to.
 
hmm ok, though maybe its same like with functions when the first statement doesn't match the standard its not going to check the others.
Hence the question
Looking at data/talkactions/scripts/create_item.lua, it looks like Player:addItem() returns nil if it didn't add the item and the added item's userdata or a table of userdata values on success, so you could do like so:
Code:
local c = {
itemId = 2148,
amount = 1,
newPos = {x = 677, y = 639, z = 7},
}

function onUse(player) return player:addItem(c.itemId, c.amount) and player:teleportTo(c.newPos) end
With "and" operator the expressions are evaluated in order until one yields false, while "or" would evaluate every expression regardless.
If player:addItem(c.itemId, c.amount) returns nil it will stop and not evaluate (hence not call) player:teleportTo(c.newPos).

Topic:
These methods could come in handy when you want to send players to town.
Player:getTown()
Town(id or "name")
Town:getTemplePosition()

Code:
-- Get temple position of player's home town
player:getTown():getTemplePosition()

-- Get Thais temple position
Town("Thais"):getTemplePosition()
 
You know I just looked at whitevo's code and now yours forgee and I see the return which i overlooked, i guess I am just distracted atm.. it happens i suppose :p
 
Back
Top