• 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 TFS 1.2 clicking switch

Lopaskurwa

Well-Known Member
Joined
Oct 6, 2017
Messages
912
Solutions
2
Reaction score
50
Anyone got a switch system with this feature. 4 switches that have to be pressed at the same time by 4 players, can be a small delay or something but basically all 4 switches have to be clicked so X item is removed from the game and after 2 minutes switches go back to their original presset and the X item appears back
Post automatically merged:

Anyone got a switch system with this feature. 4 switches that have to be pressed at the same time by 4 players, can be a small delay or something but basically all 4 switches have to be clicked so X item is removed from the game and after 2 minutes switches go back to their original presset and the X item appears back
Found this Xikini lever system, but cant get the part if timing, and all 4 levers clicked part to remove the object
LUA:
local levers = {left = 20992, right = 20993}
local config = {
-- [actionid] = {"object", "add", position, itemid, relocate_direction}
-- [actionid] = {"object", "remove", position, itemid, relocate_direction}
-- [actionid] = {"object", "replace", position, {itemid_from, itemid_to}}
    [4650] = {"object", "remove", Position(222, 366, 7), 1100, "south"},
    [4651] = {"object", "remove", Position(222, 366, 7), 1100, "south"},
    [4652] = {"object", "remove", Position(222, 366, 7), 1100, "south"},
    [4653] = {"object", "remove", Position(222, 366, 7), 1100, "south"},
}

local relocateDirections = {
    ["north"] = {0, -1},
    ["east"]  = {1, 0},
    ["south"] = {0, 1},
    ["west"]  = {-1, 0},
}

local function transposeFields(fromPosition, toPosition, transpose)
    local tile = Tile(fromPosition)
    if tile then
        local items = tile:getItems()
        if items then
            for i, item in ipairs(items) do
                if transpose == true then
                    item:moveTo(toPosition)
                else
                    item:remove()
                end
            end
        end
    end
end


function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    local item_id = item.itemid
    local index = config[item.actionid]
    local tile = Tile(index[3])
    
    -- add
    if index[2] == "add" and item_id == levers.left or index[2] == "remove" and item_id == levers.right then
        if index[1] == "object" then
            local relocatePosition = Position(index[3].x + relocateDirections[index[5]][1], index[3].y + relocateDirections[index[5]][2], index[3].z)
            tile:relocateTo(relocatePosition)
            transposeFields(index[3], relocatePosition, true)
            Game.createItem(index[4], 1, index[3])
        elseif index[1] == "floor" then
            Game.createTile(index[3], true)
            Game.createItem(index[4], 1, index[3])
        end
        
    -- remove
    elseif index[2] == "remove" and item_id == levers.left or index[2] == "add" and item_id == levers.right then
        if index[1] == "object" then
            local object = tile:getItemById(index[4])
            object:remove()
        elseif index[1] == "floor" then
            local relocatePosition = Position(index[3].x, index[3].y, index[3].z + 1)
            tile:relocateTo(relocatePosition)
            transposeFields(index[3], relocatePosition, false)
            tile:getGround():remove()
        end
        
    -- replace
    elseif index[2] == "replace" then
        local transformTo = tile:getItemCountById(index[4][1]) > 0 and 2 or 1
        local object = tile:getItemById(transformTo == 2 and index[4][1] or index[4][2])           
        object:transform(index[4][transformTo])
        if index[1] == "floor" and index[5][transformTo] == true then
            local relocatePosition = Position(index[3].x, index[3].y, index[3].z + 1)
            tile:relocateTo(relocatePosition)
            transposeFields(index[3], relocatePosition, false)
        end
        
    end
    
    item:transform(item_id == levers.left and levers.right or levers.left)
    return true
end
 
Last edited:
All levers must be used within 3 seconds of each other, to change the configuration, use the translator...


LUA:
local levers = {20992, 20993}  -- Lista ID dźwigni
local config = {
    [4650] = Position(222, 366, 7),
    [4651] = Position(222, 366, 7),
    [4652] = Position(222, 366, 7),
    [4653] = Position(222, 366, 7),
}

local leverTimes = {}  -- Przechowuje czas użycia dźwigni
local maxTimeDiff = 3000  -- Maksymalna różnica czasu w milisekundach

function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    local actionId = item.actionid
    if not config[actionId] then return false end
    
    local currentTime = os.mtime()  -- Pobranie aktualnego czasu w milisekundach
    table.insert(leverTimes, currentTime)
    
    -- Usunięcie starych wpisów
    if #leverTimes > 4 then
        table.remove(leverTimes, 1)
    end
    
    -- Sprawdzenie, czy 4 dźwignie zostały aktywowane w wymaganym czasie
    if #leverTimes == 4 then
        local timeDiff = leverTimes[4] - leverTimes[1]
        if timeDiff <= maxTimeDiff then
            player:say("IN TIME!", TALKTYPE_MONSTER_SAY)
        else
            player:say("TOO SLOW!", TALKTYPE_MONSTER_SAY)
        end
        leverTimes = {}  -- Resetowanie licznika po zakończeniu próby
    end
    
    -- Zmiana stanu dźwigni
    item:transform(item.itemid == levers[1] and levers[2] or levers[1])
    return true
end
 

Similar threads

Back
Top