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

Can someone support me with this?

Nokturno

Not a human
Joined
Aug 7, 2009
Messages
558
Solutions
2
Reaction score
400
i manage to create this script by myself by reading some tutorials and sample scripts.
Code:
local timeToReset = 15 -- Time to reset the quest in seconds

local objectId = 5620 -- Id of the item Blocking the pathlocal
local barrel1 = 31992
local barrel2 = 31992


p = {  
    Position(4614, 5421, 3), -- Position of the item blocking the path
    Position(4614, 5422, 3), -- barrel 1
    Position(4615, 5422, 3), -- barrel 2
}

function onUse(cid, item, fromPosition, itemEx, toPosition, isHotkey)

    local stone = Tile(p[1])  
    local br1 = Tile(p[2])  
    local br2 = Tile(p[3])
        if item.itemid == 5598 or item.itemid == 5599 or item.itemid == 5600 or item.itemid == 5601 and player:getStorageValue(storage) == 0 then

            if timeToReset > 1 then    
                cid:sendTextMessage(MESSAGE_EVENT_ORANGE, 'The object in your path has been removed for ' .. timeToReset .. ' seconds.')
               
            else
               cid:sendTextMessage(MESSAGE_EVENT_ORANGE, 'The object in your path has been removed for ' .. timeToReset .. ' second.')
            return false  
            end

             
            stone:getItemById(objectId):remove()
            br1:getItemById(barrel1):remove()
            br2:getItemById(barrel2):remove()
           
            p[1]:sendMagicEffect(CONST_ME_EXLODEONE)      
            p[2]:sendMagicEffect(CONST_ME_EXPLODECLOUD)
            p[3]:sendMagicEffect(CONST_ME_EXPLODECLOUD)
           
           
           
           
            addEvent(function(stonePos)
            Game.createItem(objectId, 1, stonePos)          
            stonePos:sendMagicEffect(CONST_ME_TELEPORT)                    
            end, timeToReset * 1000, stone:getPosition())

            addEvent(function(br1Pos)
            Game.createItem(barrel1, 1, br1Pos)          
            br1Pos:sendMagicEffect(CONST_ME_TELEPORT)                  
       
            end, timeToReset * 1000, br1:getPosition())

            addEvent(function(br2Pos)
            Game.createItem(barrel1, 1, br2Pos)          
            br2Pos:sendMagicEffect(CONST_ME_TELEPORT)                
   
            end, timeToReset * 1000, br2:getPosition())
           
        else    
        cid:sendTextMessage(MESSAGE_EVENT_ORANGE, 'The object in your path is already removed')
            return false  
        end
       
    return true
end
and its working, im using this on 4 diferent places

it removes some barrels when i click on any of those items, and it works fine, the problem comes when sone click when the barrels are havent respawned yet i a get a console error , its a way to bypass all the function while the barrels are still mising from their position?
 
Solution
When you click the items after the barrels are deleted the script tries to access something that doesn't exist therefore it returns a "nil value" what you can do is check if checking if the barrels exist and if they return a nil value return that it's not possible.

Lua:
            if (stone:getItemById(objectId) == nil) then
                cid:sendTextMessage(MESSAGE_EVENT_ORANGE, 'The object in your path is already removed')
                return false
            end

There is different approaches since you already thought about the stone beeing removed in the end of the script but you didn't check anywhere if it actually existed you also could've used (which is not equal to) (~= nil)

Lua:
local timeToReset = 15 -- Time to reset...
When you click the items after the barrels are deleted the script tries to access something that doesn't exist therefore it returns a "nil value" what you can do is check if checking if the barrels exist and if they return a nil value return that it's not possible.

Lua:
            if (stone:getItemById(objectId) == nil) then
                cid:sendTextMessage(MESSAGE_EVENT_ORANGE, 'The object in your path is already removed')
                return false
            end

There is different approaches since you already thought about the stone beeing removed in the end of the script but you didn't check anywhere if it actually existed you also could've used (which is not equal to) (~= nil)

Lua:
local timeToReset = 15 -- Time to reset the quest in seconds

local objectId = 5620 -- Id of the item Blocking the pathlocal
local barrel1 = 31992
local barrel2 = 31992


p = {
    Position(4614, 5421, 3), -- Position of the item blocking the path
    Position(4614, 5422, 3), -- barrel 1
    Position(4615, 5422, 3), -- barrel 2
}

function onUse(cid, item, fromPosition, itemEx, toPosition, isHotkey)

    local stone = Tile(p[1])
    local br1 = Tile(p[2])
    local br2 = Tile(p[3])
        if item.itemid == 5598 or item.itemid == 5599 or item.itemid == 5600 or item.itemid == 5601 and player:getStorageValue(storage) == 0 then
            if (stone:getItemById(objectId) ~= nil) then --Checking if the object is already removed
      
                if timeToReset > 1 then  
                   cid:sendTextMessage(MESSAGE_EVENT_ORANGE, 'The object in your path has been removed for ' .. timeToReset .. ' seconds.')
                 
                else
                   cid:sendTextMessage(MESSAGE_EVENT_ORANGE, 'The object in your path has been removed for ' .. timeToReset .. ' second.')
                return false
                end

               
                stone:getItemById(objectId):remove()
                br1:getItemById(barrel1):remove()
                br2:getItemById(barrel2):remove()
             
                p[1]:sendMagicEffect(CONST_ME_EXLODEONE)    
                p[2]:sendMagicEffect(CONST_ME_EXPLODECLOUD)
                p[3]:sendMagicEffect(CONST_ME_EXPLODECLOUD)
             
             
             
             
                addEvent(function(stonePos)
                Game.createItem(objectId, 1, stonePos)        
                stonePos:sendMagicEffect(CONST_ME_TELEPORT)                  
                end, timeToReset * 1000, stone:getPosition())

                addEvent(function(br1Pos)
                Game.createItem(barrel1, 1, br1Pos)        
                br1Pos:sendMagicEffect(CONST_ME_TELEPORT)                
         
                end, timeToReset * 1000, br1:getPosition())

                addEvent(function(br2Pos)
                Game.createItem(barrel1, 1, br2Pos)        
                br2Pos:sendMagicEffect(CONST_ME_TELEPORT)              
     
                end, timeToReset * 1000, br2:getPosition())
             
            else  
                cid:sendTextMessage(MESSAGE_EVENT_ORANGE, 'The object in your path is already removed')
                return false
            end
        end
    return true
end
 
Last edited by a moderator:
Solution
tks for the help
i got this error

Oh yea i totally forgot a "then" just woke up guess i need my coffee to function :) fixed the script in the other message.
A tip is to read the error message, it says that it's missing a "then" around line 22 then go there and check what could be possible wrong and you'll learn to scout for small errors
 
yeah i added after the line , but got other error, now im trying to fix the problem cuz i want to delete the storage request. thks for help mate, ill update if i have an issue ty
 
Back
Top