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

RevScripts convert canary action script to tfs

Moody

Member
Joined
Feb 8, 2020
Messages
62
Reaction score
6
how to convert this script to use actionids instead of position and work the same?
LUA:
local cToneStorages = {
    Storage.BigfootBurden.MelodyTone1,
    Storage.BigfootBurden.MelodyTone2,
    Storage.BigfootBurden.MelodyTone3,
    Storage.BigfootBurden.MelodyTone4,
    Storage.BigfootBurden.MelodyTone5,
    Storage.BigfootBurden.MelodyTone6,
    Storage.BigfootBurden.MelodyTone7,
}

local Crystals = {
    { x = 32776, y = 31804, z = 10 },
    { x = 32781, y = 31807, z = 10 },
    { x = 32777, y = 31812, z = 10 },
    { x = 32771, y = 31810, z = 10 },
}

local bigfootMusic = Action()
function bigfootMusic.onUse(player, item, fromPosition, target, toPosition, isHotkey)
    if player:getStorageValue(Storage.BigfootBurden.QuestLine) == 21 then
        local value = player:getStorageValue(Storage.BigfootBurden.MelodyStatus)
        if Position(Crystals[player:getStorageValue(cToneStorages[value])]) == item:getPosition() then
            player:setStorageValue(Storage.BigfootBurden.MelodyStatus, value + 1)
            if value + 1 == 8 then
                toPosition:sendMagicEffect(CONST_ME_HEARTS)
                player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "That was the correct note! Now you know your soul melody!")
                player:setStorageValue(Storage.BigfootBurden.QuestLine, 22)
            else
                toPosition:sendMagicEffect(CONST_ME_SOUND_GREEN)
                player:getPosition():sendMagicEffect(CONST_ME_FIREWORK_YELLOW)
            end
        else
            player:setStorageValue(Storage.BigfootBurden.MelodyStatus, 1)
            toPosition:sendMagicEffect(CONST_ME_SOUND_RED)
        end
    end
    return true
end

for b = 1, #Crystals do
    bigfootMusic:position(Crystals[b])
end
bigfootMusic:register()
 
test
LUA:
local cToneStorages = {
    Storage.BigfootBurden.MelodyTone1,
    Storage.BigfootBurden.MelodyTone2,
    Storage.BigfootBurden.MelodyTone3,
    Storage.BigfootBurden.MelodyTone4,
    Storage.BigfootBurden.MelodyTone5,
    Storage.BigfootBurden.MelodyTone6,
    Storage.BigfootBurden.MelodyTone7,
}

local CrystalActionIDs = {
    [1001] = 1, -- Assign your action IDs here, with the corresponding melody tone index
    [1002] = 2,
    [1003] = 3,
    [1004] = 4,
}

local bigfootMusic = Action()
function bigfootMusic.onUse(player, item, fromPosition, target, toPosition, isHotkey)
    if player:getStorageValue(Storage.BigfootBurden.QuestLine) == 21 then
        local value = player:getStorageValue(Storage.BigfootBurden.MelodyStatus)
        local toneIndex = player:getStorageValue(cToneStorages[value])
        if CrystalActionIDs[item:getActionId()] == toneIndex then
            player:setStorageValue(Storage.BigfootBurden.MelodyStatus, value + 1)
            if value + 1 == 8 then
                toPosition:sendMagicEffect(CONST_ME_HEARTS)
                player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "That was the correct note! Now you know your soul melody!")
                player:setStorageValue(Storage.BigfootBurden.QuestLine, 22)
            else
                toPosition:sendMagicEffect(CONST_ME_SOUND_GREEN)
                player:getPosition():sendMagicEffect(CONST_ME_FIREWORK_YELLOW)
            end
        else
            player:setStorageValue(Storage.BigfootBurden.MelodyStatus, 1)
            toPosition:sendMagicEffect(CONST_ME_SOUND_RED)
        end
    end
    return true
end

for actionId, _ in pairs(CrystalActionIDs) do
    bigfootMusic:aid(actionId)
end
bigfootMusic:register()
Post automatically merged:

test 2
LUA:
local cToneStorages = {
    Storage.BigfootBurden.MelodyTone1,
    Storage.BigfootBurden.MelodyTone2,
    Storage.BigfootBurden.MelodyTone3,
    Storage.BigfootBurden.MelodyTone4,
    Storage.BigfootBurden.MelodyTone5,
    Storage.BigfootBurden.MelodyTone6,
    Storage.BigfootBurden.MelodyTone7,
}

local CrystalActionIDs = {
    1001, -- Action ID for the first crystal
    1002, -- Action ID for the second crystal
    1003, -- Action ID for the third crystal
    1004, -- Action ID for the fourth crystal
    1005, -- Action ID for the fifth crystal
    1006, -- Action ID for the sixth crystal
    1007, -- Action ID for the seventh crystal
}

local bigfootMusic = Action()

function bigfootMusic.onUse(player, item, fromPosition, target, toPosition, isHotkey)
    if player:getStorageValue(Storage.BigfootBurden.QuestLine) == 21 then
        local value = player:getStorageValue(Storage.BigfootBurden.MelodyStatus)
        local expectedActionID = CrystalActionIDs[value]

        if item:getActionId() == expectedActionID then
            player:setStorageValue(Storage.BigfootBurden.MelodyStatus, value + 1)
            if value + 1 == 8 then
                toPosition:sendMagicEffect(CONST_ME_HEARTS)
                player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "That was the correct note! Now you know your soul melody!")
                player:setStorageValue(Storage.BigfootBurden.QuestLine, 22)
            else
                toPosition:sendMagicEffect(CONST_ME_SOUND_GREEN)
                player:getPosition():sendMagicEffect(CONST_ME_FIREWORK_YELLOW)
            end
        else
            player:setStorageValue(Storage.BigfootBurden.MelodyStatus, 1)
            toPosition:sendMagicEffect(CONST_ME_SOUND_RED)
        end
    end
    return true
end

-- Register the action with the action IDs
for _, actionId in ipairs(CrystalActionIDs) do
    bigfootMusic:aid(actionId)
end

bigfootMusic:register()
 
second one is working but it only go in the same order of action ids not random

more information: i set these in the previous mission like this
LUA:
player:setStorageValue(Storage.BigfootBurden.MelodyStatus, 1)

            for i = 0, 6 do

                player:setStorageValue(Storage.BigfootBurden.MelodyTone1 + i, math.random(1, 4))

            end
 
test
LUA:
local cToneStorages = {
    Storage.BigfootBurden.MelodyTone1,
    Storage.BigfootBurden.MelodyTone2,
    Storage.BigfootBurden.MelodyTone3,
    Storage.BigfootBurden.MelodyTone4,
    Storage.BigfootBurden.MelodyTone5,
    Storage.BigfootBurden.MelodyTone6,
    Storage.BigfootBurden.MelodyTone7,
}

local CrystalActionIDs = {
    1001, -- Action ID for the first crystal
    1002, -- Action ID for the second crystal
    1003, -- Action ID for the third crystal
    1004, -- Action ID for the fourth crystal
    1005, -- Action ID for the fifth crystal
    1006, -- Action ID for the sixth crystal
    1007, -- Action ID for the seventh crystal
}

local bigfootMusic = Action()

function bigfootMusic.onUse(player, item, fromPosition, target, toPosition, isHotkey)
    if player:getStorageValue(Storage.BigfootBurden.QuestLine) == 21 then
        local value = player:getStorageValue(Storage.BigfootBurden.MelodyStatus)
        local currentToneStorage = cToneStorages[value]
        local expectedActionID = CrystalActionIDs[player:getStorageValue(currentToneStorage)]

        if item:getActionId() == expectedActionID then
            player:setStorageValue(Storage.BigfootBurden.MelodyStatus, value + 1)
            if value + 1 == 8 then
                toPosition:sendMagicEffect(CONST_ME_HEARTS)
                player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "That was the correct note! Now you know your soul melody!")
                player:setStorageValue(Storage.BigfootBurden.QuestLine, 22)
            else
                toPosition:sendMagicEffect(CONST_ME_SOUND_GREEN)
                player:getPosition():sendMagicEffect(CONST_ME_FIREWORK_YELLOW)
            end
        else
            player:setStorageValue(Storage.BigfootBurden.MelodyStatus, 1)
            toPosition:sendMagicEffect(CONST_ME_SOUND_RED)
        end
    end
    return true
end

-- Register the action with the action IDs
for _, actionId in ipairs(CrystalActionIDs) do
    bigfootMusic:aid(actionId)
end

bigfootMusic:register()
 
Back
Top