• 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.2 help script

rogersenchou

New Member
Joined
Nov 27, 2016
Messages
36
Reaction score
3
hi otland,
i want some scripts: i need a script that a chest give you a storage and then a door that need storage.

just the chest need to give you a storage :)

my otservers is tfs 1.2

please help me
 
Solution
Chest:

Lua:
local storage = 123

function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    if player:getStorageValue(storage) ~= 1 then
        player:sendCancelMessage("You may not pass here.")
        return true
    end

    local itemId = item:getId()
    item:transform(itemId + 1)
    player:teleportTo(toPosition, true)
    return true
end

Door:
Lua:
function onUse(player, item, fromPosition, target, toPosition, isHotkey)

local storage = YOUR STORAGE
if player:getStorageValue(storage) == 1 then
    item:transform(itemId + 1)
    player:teleportTo(toPosition, true)
else
    player:sendCancelMessage("You may not pass here.")
    return true
end
return true
end

Finally you must add them in actions.xml and add...
Chest:

Lua:
local storage = 123

function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    if player:getStorageValue(storage) ~= 1 then
        player:sendCancelMessage("You may not pass here.")
        return true
    end

    local itemId = item:getId()
    item:transform(itemId + 1)
    player:teleportTo(toPosition, true)
    return true
end

Door:
Lua:
function onUse(player, item, fromPosition, target, toPosition, isHotkey)

local storage = YOUR STORAGE
if player:getStorageValue(storage) == 1 then
    item:transform(itemId + 1)
    player:teleportTo(toPosition, true)
else
    player:sendCancelMessage("You may not pass here.")
    return true
end
return true
end

Finally you must add them in actions.xml and add the respective uniqueid or actionid to the chest and door.
 
Solution
bro i have this error in the script door

Code:
Lua Script Error: [Action Interface]
data/actions/scripts/doorstorage.lua:onUse
data/actions/scripts/doorstorage.lua:5: attempt to perform arithmetic on global 'itemId' (a nil value)
stack traceback:
        [C]: in function '__add'
        data/actions/scripts/doorstorage.lua:5: in function <data/actions/scripts/doorstorage.lua:1>
 
Code:
local storage = 123

function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    if player:getStorageValue(storage) ~= 1 then
        player:sendCancelMessage("You may not pass here.")
        return true
    end

    local itemId = item:getId()
    item:transform(itemId + 1)
    player:teleportTo(toPosition, true)
    return true
end
 
Code:
local storage = 123

function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    if player:getStorageValue(storage) ~= 1 then
        player:sendCancelMessage("You may not pass here.")
        return true
    end

    local itemId = item:getId()
    item:transform(itemId + 1)
    player:teleportTo(toPosition, true)
    return true
end
why make variables for something you use once :thinking:
 
Back
Top