• 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 1.X+ Teleport onUse object when having specific storage

BBQ Fanatic

New Member
Joined
Jul 10, 2022
Messages
13
Reaction score
3
Hello guys ;)

A while ago @Xikini helped me with some script (below named "existing script"). Now I would like to make a similar, extended script.

On the map there would be a objects (like statues or sth) which clicked by player teleport him to the specific location, but only if he has a specific storage (which is given by stepping on the specific tile for the first time). Thanks to Xikini's script linked above, I do know how to give player storage by stepping on the tile. But can't solve the rest.

I guess I do understand a logic: when clicking an object with ActionId = A, script checks if player has Storage = B. If yes - teleport to XYZ. Otherwise, send a message. And for each Action ID, there will be a different Storages and coordinates (here comes arrays).

I was trying to support myself with following threads:

The second one works properly, but only brainlessly copy+pasted as a different script, without arrays, and using Actions.xml. I was trying to edit Xikini's script (the first link in this post) he gave me, but something gone wrong and idk what.

I ended up having something like this:
(needs review, because I was editing exisiting script, maybe something is not longer needed, maybe I deleted something needed)

Code:
local altars = {
    [65535] = { -- actionId given to the statue on map
        storage = 69420,
        name = "Rat's Cave",
        newpos = {posx = 94, posy = 127, posz = 7},
    },
}

local shortcutAltars = MoveEvent()
shortcutAltars:type("onUse")

function shortcutAltars.onUse(player, item, fromPosition, target, toPosition, isHotkey)
    local index = altars[item:getActionId()]
   
    if player:getStorageValue(index.storage) == 1 then
        player:teleportTo(Position(index.newpos.posx, index.newpos.posy, index.newpos.posz))
    else
        player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You are not allowed to do that")
   
    end
end

for actionId, config in pairs(altars) do
    shortcutAltars:aid(actionId)
end
shortcutAltars:register()

But this attempt was to only check if teleportation itself works. I does not include giving a storage by stepping on a tile (which I can solve by the existing script, but for testing I was giving a storage manually through PMA). That's why there is a "name", because I wanted to make this script independent from existing script, but still missing tile's id which will give that storage on stepping :p

I am aware it's relatively simple script, but don't understand syntax properly to make it done, so I'm asking you for help 🥺
 

Similar threads

Back
Top