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

help with script error

matthew123456

New Member
Joined
Aug 24, 2013
Messages
121
Reaction score
3
Code:
Lua Script Error: [Action Interface]
data/actions/scripts/quests/forgotten knowledge/lloydLever.lua:onUse
...ctions/scripts/quests/forgotten knowledge/lloydLever.lua:55: attempt to call method 'setExhaustion' (a nil value)
stack traceback:
        [C]: in function 'setExhaustion'
        ...ctions/scripts/quests/forgotten knowledge/lloydLever.lua:55: in function <...ctions/scripts/quests/forgotten knowledge/lloydLever.lua:28>


here is the full script
Code:
local config = {
    centerRoom = Position(32799, 32832, 14),
    bossPosition = Position(32799, 32827, 14),
    newPosition = Position(32800, 32831, 14)
}

local monsters = {
    {cosmic = 'cosmic energy prism a', pos = Position(32801, 32827, 14)},
    {cosmic = 'cosmic energy prism b', pos = Position(32798, 32827, 14)},
    {cosmic = 'cosmic energy prism c', pos = Position(32803, 32826, 14)},
    {cosmic = 'cosmic energy prism d', pos = Position(32796, 32826, 14)}
}

local function clearForgottenLloyd()
    local spectators = Game.getSpectators(config.centerRoom, false, false, 15, 15, 15, 15)
    for i = 1, #spectators do
        local spectator = spectators[i]
        if spectator:isPlayer() then
            spectator:teleportTo(Position(32815, 32873, 13))
            spectator:getPosition():sendMagicEffect(CONST_ME_TELEPORT)
            spectator:say('Time out! You were teleported out by strange forces.', TALKTYPE_MONSTER_SAY)
        elseif spectator:isMonster() then
            spectator:remove()
        end
    end
end

function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    if item.itemid == 9825 then
        if player:getPosition() ~= Position(32759, 32868, 14) then
            item:transform(9826)
            return true
        end
    end
    if item.itemid == 9825 then
        local specs, spec = Game.getSpectators(config.centerRoom, false, false, 15, 15, 15, 15)
        for i = 1, #specs do
            spec = specs[i]
            if spec:isPlayer() then
                player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "Someone is fighting with Lloyd.")
                return true
            end
        end
        for n = 1, #monsters do
            Game.createMonster(monsters[n].cosmic, monsters[n].pos, true, true)
        end
        Game.createMonster("lloyd", config.bossPosition, true, true)
        for y = 32868, 32872 do
            local playerTile = Tile(Position(32759, y, 14)):getTopCreature()
            if playerTile and playerTile:isPlayer() then
                if playerTile:getStorageValue(Storage.ForgottenKnowledge.LloydTimer) < os.time() then
                    playerTile:getPosition():sendMagicEffect(CONST_ME_POFF)
                    playerTile:teleportTo(config.newPosition)
                    playerTile:getPosition():sendMagicEffect(CONST_ME_TELEPORT)
                    playerTile:setExhaustion(Storage.ForgottenKnowledge.LloydTimer, os.time() + 20 * 3600)
                else
                    player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You need to wait a while, recently someone challenge Lloyd.")
                    return true
                end
            end
        end
        addEvent(clearForgottenLloyd, 30 * 60 * 1000)
        item:transform(9826)
    elseif item.itemid == 9826 then
        item:transform(9825)
    end
    return true
end
engine otx otserv br
the cript is somewhat working it telports the player and spawns the boss its just the exaust error i get any way to fix? thanks
 
Lua:
        for y = 32868, 32872 do
            local playerTile = Tile(Position(32759, y, 14)):getTopCreature()
            if playerTile and playerTile:isPlayer() then
                if playerTile:getStorageValue(Storage.ForgottenKnowledge.LloydTimer) < os.time() then
                    playerTile:getPosition():sendMagicEffect(CONST_ME_POFF)
                    playerTile:teleportTo(config.newPosition)
                    playerTile:getPosition():sendMagicEffect(CONST_ME_TELEPORT)
                    playerTile:setExhaustion(Storage.ForgottenKnowledge.LloydTimer, os.time() + 20 * 3600)

Ok so this iterates over the tiles and tries to grab the top creature.
if that returns something, and is player, checks a stored value against the current UTC timestamp.
If it's under that (sooner) player gets teleported...

My best guess is
1.) setExhaustion player method doesn't exist.
2.) even if it did, it wasn't meant to be used here.
3.) when you get teleported you're supposed reset that clock a bit into the future. (20*60*60 in this case; 20 hours? So more than a bit.)

change line 8 (55 in your post) to this. String replace: s/setExhaustion/setStorageValue/
Lua:
                    playerTile:setStorageValue(Storage.ForgottenKnowledge.LloydTimer, os.time() + 20 * 3600)
 
Last edited:
that fixed that problem now problem number two if someone pulls the lever it spawns a new one even if one is all ready spawned in as in people can stand to the side and spam the lever
 
When the player presses the lever (with 1 already spawned) does it show "loyd has already been spawned message?"

If it does, then change the return true on line 41 to return false.

Otherwise, there is a problem with the spectator code. (I think dont have much time sorry)

Maybe try replacing with this

Code:
local specs = Game.getSpectators(config.centerRoom, false, false, 15, 15, 15, 15)
        for i = 1, #specs do
            local tmp_spec = Player(specs[i])
            if tmp_spec then
                player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "Someone is fighting with Lloyd.")
                return true
            end
        end
 
It looks like that code checks the battle area for players, but doesn't check for the existence of this monster? What happens if the players are removed by some other force while the monster is spawned?

I guess it would be helpful to see a pic of the associated map?
 
Back
Top