• 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 Shovel in desert floor

DiegoRulez

Member
Joined
Apr 16, 2012
Messages
93
Reaction score
11
Location
Feira de Santana - Brasil
TFS 1.2
With this script, when using shovel in the desert (231) there is a chance to create scarab coins or to summon a scarab.
But I would like that when using on floor 231, but that has an action id (which in my case (actionid = 100) would execute the action of opening a hole that would open a time and then return to normal.

I found a function that does this in actions.lua, but I would like this function to be inside the shovel script itself.
I'll be posting the script, and the function. But you do not need to use this function, if you write the code in any other way it works, it helps a lot.

shovel.lua
Code:
local holes = {468, 481, 483}
local pools = {2016, 2017, 2018, 2019, 2020, 2021, 2025, 2026, 2027, 2028, 2029, 2030}
function onUse(cid, item, fromPosition, target, toPosition, isHotkey)
    if isInArray(holes, target.itemid) then
        target:transform(target.itemid + 1)
        target:decay()
    elseif isInArray(pools, target.itemid) then
        local hole = 0
        for i = 1, #holes do
            local tile = Tile(target:getPosition()):getItemById(holes[i])
            if tile then
                hole = tile
            end
        end
        if hole ~= 0 then
            target:remove(1)
            hole:transform(hole:getId() + 1)
            hole:decay()
        end
    elseif target.itemid == 231 then
        local randomValue = math.random(1, 100) --random number, do 1 ate 100
        if randomValue <= 10 then --o random e 1
            Game.createItem(2159, 1, toPosition) --cria o scarab coin
        elseif randomValue > 95 then--random e maior do 95
            Game.createMonster("Scarab", toPosition)--cria um scarab
        end
        toPosition:sendMagicEffect(CONST_ME_POFF)
    else
        return false      
    end
    return true
end

Code in actions.lua
Code:
    local groundId = ground:getId()      
        elseif groundId == 231 then
           if (ground:getActionId() == 100) then
               ground:transform(482)
               addEvent(remove, 10000, 231, toPosition
           return true  
        end
 
Last edited:
Solution
@BahamutxD
If you do the script for me ok .. I can change the ID on the map
Well, seems simple enough. I'll patch the code together for you now that I'm home.

try this, I guess. xP
(Although I don't understand 1.2 scripting.. I dunno if this is actually correct.)
(It doesn't make sense to me to use the function 'remove' in this scenario. But hey, I hope it works.)

Lua:
local holes = {468, 481, 483}
local pools = {2016, 2017, 2018, 2019, 2020, 2021, 2025, 2026, 2027, 2028, 2029, 2030}
function onUse(cid, item, fromPosition, target, toPosition, isHotkey)
    if isInArray(holes, target.itemid) then
        target:transform(target.itemid + 1)
        target:decay()
    elseif isInArray(pools, target.itemid) then
        local...
I was thinking about this a couple weeks ago.. Ended using ids 8568 for this instead of an action ID. Why is there 4 sand sprites in Tibia btw?
 
@BahamutxD
If you do the script for me ok .. I can change the ID on the map
Well, seems simple enough. I'll patch the code together for you now that I'm home.

try this, I guess. xP
(Although I don't understand 1.2 scripting.. I dunno if this is actually correct.)
(It doesn't make sense to me to use the function 'remove' in this scenario. But hey, I hope it works.)

Lua:
local holes = {468, 481, 483}
local pools = {2016, 2017, 2018, 2019, 2020, 2021, 2025, 2026, 2027, 2028, 2029, 2030}
function onUse(cid, item, fromPosition, target, toPosition, isHotkey)
    if isInArray(holes, target.itemid) then
        target:transform(target.itemid + 1)
        target:decay()
    elseif isInArray(pools, target.itemid) then
        local hole = 0
        for i = 1, #holes do
            local tile = Tile(target:getPosition()):getItemById(holes[i])
            if tile then
                hole = tile
            end
        end
        if hole ~= 0 then
            target:remove(1)
            hole:transform(hole:getId() + 1)
            hole:decay()
        end
    elseif target.itemid == 231 then
        if target:getActionId() == 100 then
            target:transform(482)
            addEvent(remove, 10000, 231, toPosition)
        else
            local randomValue = math.random(1, 100) --random number, do 1 ate 100
            if randomValue <= 10 then --o random e 1
                Game.createItem(2159, 1, toPosition) --cria o scarab coin
            elseif randomValue > 95 then--random e maior do 95
                Game.createMonster("Scarab", toPosition)--cria um scarab
            end
            toPosition:sendMagicEffect(CONST_ME_POFF)
        end
    else
        return false    
    end
    return true
end
 
Solution
Back
Top