• 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 Som help with function

MxSoft

Leave Tibia, Live Life.
Joined
Dec 22, 2009
Messages
1,804
Solutions
1
Reaction score
43
Location
Mexico
Im getting this error:
Code:
Lua Script Error: [Action Interface]
data/actions/scripts/other/music.lua:onUse
data/actions/scripts/other/music.lua:39: attempt to index local 'player' (a number value)
stack traceback:
        [C]: in function '__index'
        data/actions/scripts/other/music.lua:39: in function <data/actions/scripts/other/music.lua:37>


This is my script:
Code:
local MusicEffect = {
    [2070] = CONST_ME_SOUND_GREEN,     --Wooden Flute
    [2071] = CONST_ME_SOUND_GREEN,     --Lyre
    [2072] = CONST_ME_SOUND_GREEN,     --Lute
    [2073] = CONST_ME_SOUND_GREEN,     --Drum
    [2074] = CONST_ME_SOUND_BLUE,     --Panpipes
    [2075] = CONST_ME_SOUND_GREEN,     --Simple Fanfare
    [2076] = CONST_ME_SOUND_GREEN,     --Fanfare
    [2077] = CONST_ME_SOUND_GREEN,     --Royal Fanfare
    [2078] = CONST_ME_SOUND_GREEN,     --Post Horn
    [2079] = CONST_ME_SOUND_RED,     --War Horn
    [2080] = CONST_ME_SOUND_BLUE,     --Piano
    [2081] = CONST_ME_SOUND_BLUE,     --Piano
    [2082] = CONST_ME_SOUND_BLUE,     --Piano
    [2083] = CONST_ME_SOUND_BLUE,     --Piano
    [2084] = CONST_ME_SOUND_BLUE,     --Harp
    [2085] = CONST_ME_SOUND_BLUE,     --Harp
    [2332] = CONST_ME_SOUND_GREEN,     --Waldo's Post Horn
    [2364] = CONST_ME_SOUND_GREEN,     --Post Horn
    -- non movable instruments
    [2367] = CONST_ME_SOUND_GREEN,     --Drum
    [2368] = CONST_ME_SOUND_GREEN,     --Simple Fanfare
    [2369] = CONST_ME_SOUND_YELLOW, --Cornucopia
    [2370] = CONST_ME_SOUND_GREEN,     --Lute
    [2371] = CONST_ME_SOUND_BLUE,     --Horn of Sundering
    [2372] = CONST_ME_SOUND_GREEN,     --Lyre
    [2373] = CONST_ME_SOUND_BLUE,     --Panpipes
    [2374] = CONST_ME_SOUND_GREEN,     --Wooden Flute
    --
    [3951] = CONST_ME_SOUND_BLUE,     --Bongo Drum
    [3952] = CONST_ME_SOUND_GREEN,     --Didgeridoo
    [3953] = CONST_ME_SOUND_RED,     --War Drum
    [5786] = CONST_ME_SOUND_GREEN,     --Wooden Whistle
    [13759] = CONST_ME_SOUND_BLUE,     --Small Whistle
}

function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    if item.itemid == 2071 then
        if isInRange(player:getPosition(), Position(32695, 31717, 2), Position(32699, 31719, 2)) then
            local lyreProgress = player:getStorageValue(Storage.Diapason.Lyre)
            if lyreProgress < 7
                    and player:getStorageValue(Storage.Diapason.Edala) ~= 1
                    and player:getStorageValue(Storage.Diapason.LyreTimer) < os.time() then
                player:setStorageValue(Storage.Diapason.Lyre, math.max(0, lyreProgress) + 1)
                player:setStorageValue(Storage.Diapason.Edala, 1)
                player:setStorageValue(Storage.Diapason.LyreTimer, os.time() + 86400)
            end
        end
    end

    player:addAchievementProgress('Rockstar', 10000)
    item:getPosition():sendMagicEffect(MusicEffect[item.itemid])
    return true
end

Please i need some help with this
 
Please tell us your TFS.

But from what I know of scripting.. It looks like player is never defined in the script.
 
Either you update to latest tfs or add under the function onUse:
Code:
local player = Player(player)
 
Perfect ty, just one more thing, here with this function item:getPosition():sendMagicEffect(MusicEffect[item.itemid])
I got the error:
Code:
Lua Script Error: [Action Interface]
data/actions/scripts/other/music.lua:onUse
data/actions/scripts/other/music.lua:52: attempt to call method 'getPosition' (a nil value)
stack traceback:
        [C]: in function 'getPosition'
        data/actions/scripts/other/music.lua:52: in function <data/actions/scripts/other/music.lua:37>
 
Item(item):getPosition()
Code:
Lua Script Error: [Action Interface]
data/actions/scripts/other/music.lua:onUse
data/actions/scripts/other/music.lua:53: attempt to index a nil value
stack traceback:
        [C]: in function '__index'
        data/actions/scripts/other/music.lua:53: in function <data/actions/scripts/other/music.lua:37>
Line 52
Item(item):getPosition():sendMagicEffect(MusicEffect[item.itemid])
:(
 
Back
Top