• 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+ Requesting an edit to this script TFS 1.2 (lever script)

FenX

Advanced OT User
Joined
Jul 8, 2019
Messages
360
Solutions
1
Reaction score
159
Hello otlanders,

I roughly put together 2 scripts to test something out but now I need little help.
THE SCRIPT:
Lua:
local wallPos = {
    [1] = {x=1018, y=971, z=7, stackpos=1},
    [2] = {x=1019, y=971, z=7, stackpos=1},
    [3] = {x=1020, y=971, z=7, stackpos=1}
}

local time_ = 10
     
local config = {
    [6677] = { sacrificePosition = Position(1018, 976, 6) }
}

function onUse(player, item, fromPosition, target, toPosition, isHotkey)

    local lever = config[item.actionid]
    if not lever then
    end

    local sacrificeId, sacrifice = Tile(lever.sacrificePosition):getThing(1).itemid, true
    if not isInArray({8303}, sacrificeId) then
       sacrifice = false
    end

    if not sacrifice then
       toPosition:sendMagicEffect(CONST_ME_POFF)
       player:sendTextMessage(MESSAGE_INFO_DESCR, "A sacrifice is required first.")
       return false
    end

    local soilItem = Tile(lever.sacrificePosition):getItemById(sacrificeId)
    if soilItem then
       soilItem:remove()
       player:sendTextMessage(MESSAGE_INFO_DESCR, "Your sacrifice has been accepted, you may pass.")
    elseif item.itemid == 1946 then
       player:sendTextMessage(MESSAGE_INFO_DESCR, "The sacrifice has already been made.")
       toPosition:sendMagicEffect(CONST_ME_POFF)
    end

local function reset()
       item:transform(1945)
       Game.createItem(1355, 1, wallPos[1])
       Game.createItem(1355, 1, wallPos[2])
       Game.createItem(1355, 1, wallPos[3])            
    end
 
    item:transform(1946)
    addEvent(reset, time_ * 1000)
 
    for i = 1, #wallPos do
        doRemoveItem(getThingfromPos(wallPos[i]).uid,1)
    end
end
WHAT IT DOES:
  • requires for player to put specific item on the sacrifice position
  • if item is present on position and lever pulled, item is removed and...
  • this removes stones/walls from specific position
  • lever/walls reset after 10 seconds

I need a little help with making a specific line work and also adding in some features (hence why I am posting this is in the request section as I feel like it fits the request category more).
Lua:
    elseif item.itemid == 1946 then
       player:sendTextMessage(MESSAGE_INFO_DESCR, "The sacrifice has already been made.")
       toPosition:sendMagicEffect(CONST_ME_POFF)
This line currently doesn't work, need some help fixing it up. What I want to happen is that after player puts sacrifice on position, uses lever (lever transforms to 1946), if lever is pulled again a different message is sent stating that a "a sacrifice has already been made" (like shown above), this will also not remove any further items that are placed onto the position upon using the lever hence the sacrifice is already "active".

ALSO
1.
I thought about this script having a feature where multiple sacrifices are required in different positions
Example:
a8faa4b76daa9917e3c734da78cb5153

2. On the line where sacrifice is removed, add a line which will send magic effect to sacrifice position
Is anyone capable of doing these 2 things?

đź‘Ť.
 
Give this a go, if success remove the console prints with numbers, if fail, let me know what the console is saying.
Lua:
local wallPos = {
    [1] = {x=1018, y=971, z=7, stackpos=1},
    [2] = {x=1019, y=971, z=7, stackpos=1},
    [3] = {x=1020, y=971, z=7, stackpos=1}
}

local time_ = 10
   
local config = {
    [6677] = { sacrificePosition = Position(1018, 976, 6) }
}

function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    print("1: onUse")
    local lever = config[item.actionid]
    if not lever then
        print("2: Action assignment error in lever script")
    end

    local sacrificeId, sacrifice = Tile(lever.sacrificePosition):getThing(1).itemid, true
    if not isInArray({8303}, sacrificeId) then
        print("3: sacrifice is not 8303")
       sacrifice = false
    end

    if not sacrifice then
        print("4: Inform user that a sacrifice is required")
        toPosition:sendMagicEffect(CONST_ME_POFF)
        player:sendTextMessage(MESSAGE_INFO_DESCR, "A sacrifice is required first.")
        return false
    end

    local soilItem = Tile(lever.sacrificePosition):getItemById(sacrificeId)
    if item.itemid == 1946 then
        print("5: Used item is 1946, which is presumed to mean the sacrifice has already been made.")
       player:sendTextMessage(MESSAGE_INFO_DESCR, "The sacrifice has already been made.")
       toPosition:sendMagicEffect(CONST_ME_POFF)

       local function reset()
           print("7: Reset function executed")
           item:transform(1945)
           Game.createItem(1355, 1, wallPos[1])
           Game.createItem(1355, 1, wallPos[2])
           Game.createItem(1355, 1, wallPos[3])          
       end
     
       item:transform(1946)
       addEvent(reset, time_ * 1000)
     
       for i = 1, #wallPos do
           print("6: Attempt to remove item")
           doRemoveItem(getThingfromPos(wallPos[i]).uid,1)
       end
    elseif soilItem then
        print("8: soilItem success, inform user he can pass")
        soilItem:remove()
        player:sendTextMessage(MESSAGE_INFO_DESCR, "Your sacrifice has been accepted, you may pass.")
    else
        print("9: Unhandled exception occured, soilItem is not success, and used item [" .. item.itemid .."] is not 1946")
    end
end

I just swapped your if and elseif statement with each other, so it first checks if item is used, if not then if we got the soilItem. And only execute the remove walls + reset function if soilItem statement is executed.
 
Give this a go, if success remove the console prints with numbers, if fail, let me know what the console is saying.
Lua:
local wallPos = {
    [1] = {x=1018, y=971, z=7, stackpos=1},
    [2] = {x=1019, y=971, z=7, stackpos=1},
    [3] = {x=1020, y=971, z=7, stackpos=1}
}

local time_ = 10
  
local config = {
    [6677] = { sacrificePosition = Position(1018, 976, 6) }
}

function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    print("1: onUse")
    local lever = config[item.actionid]
    if not lever then
        print("2: Action assignment error in lever script")
    end

    local sacrificeId, sacrifice = Tile(lever.sacrificePosition):getThing(1).itemid, true
    if not isInArray({8303}, sacrificeId) then
        print("3: sacrifice is not 8303")
       sacrifice = false
    end

    if not sacrifice then
        print("4: Inform user that a sacrifice is required")
        toPosition:sendMagicEffect(CONST_ME_POFF)
        player:sendTextMessage(MESSAGE_INFO_DESCR, "A sacrifice is required first.")
        return false
    end

    local soilItem = Tile(lever.sacrificePosition):getItemById(sacrificeId)
    if item.itemid == 1946 then
        print("5: Used item is 1946, which is presumed to mean the sacrifice has already been made.")
       player:sendTextMessage(MESSAGE_INFO_DESCR, "The sacrifice has already been made.")
       toPosition:sendMagicEffect(CONST_ME_POFF)

       local function reset()
           print("7: Reset function executed")
           item:transform(1945)
           Game.createItem(1355, 1, wallPos[1])
           Game.createItem(1355, 1, wallPos[2])
           Game.createItem(1355, 1, wallPos[3])         
       end
    
       item:transform(1946)
       addEvent(reset, time_ * 1000)
    
       for i = 1, #wallPos do
           print("6: Attempt to remove item")
           doRemoveItem(getThingfromPos(wallPos[i]).uid,1)
       end
    elseif soilItem then
        print("8: soilItem success, inform user he can pass")
        soilItem:remove()
        player:sendTextMessage(MESSAGE_INFO_DESCR, "Your sacrifice has been accepted, you may pass.")
    else
        print("9: Unhandled exception occured, soilItem is not success, and used item [" .. item.itemid .."] is not 1946")
    end
end

I just swapped your if and elseif statement with each other, so it first checks if item is used, if not then if we got the soilItem. And only execute the remove walls + reset function if soilItem statement is executed.

One issue, when I place the "8303" item on sacrifice position and use the lever, item is removed but walls are not removed and I get "print("3: sacrifice is not 8303")" in console.
 
Back
Top