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

[TFS 1.X] Dwarf mining

Idletibia

Banned User
Joined
Apr 17, 2023
Messages
74
Reaction score
31
Lua:
function onStepIn(cid, item, position, lastPosition, fromPosition, toPosition)
    local monsterName = getCreatureName(cid)
    local items = {2145, 2146, 2147, 2149, 2150}
    local poofEffect = CONST_ME_POFF
   
    local chance = 0
    local tileX, tileY, tileZ = position.x, position.y, position.z
    local isStoneNearby = false
   
     if not isMonster(cid) then
        return false
    end
   
    -- Check if there is a stone nearby
    for x = tileX - 1, tileX + 1 do
        for y = tileY - 1, tileY + 1 do
            local tile = getTileItemById({x = x, y = y, z = tileZ}, 1285)
            if tile and tile.uid > 0 then
                isStoneNearby = true
                doSendMagicEffect({x = x, y = y, z = tileZ}, 4)
                break
            end
        end
        if isStoneNearby then
            break
        end
    end
   
    if monsterName:lower() == "dwarf" then
        chance = 1
        doSendMagicEffect(position, poofEffect)
    elseif monsterName:lower() == "dwarf soldier" then
        chance = 5
        doSendMagicEffect(position, poofEffect)
    elseif monsterName:lower() == "dwarf guard" then
        doSendMagicEffect(position, poofEffect)
        chance = 10
    end
   
    if chance > 0 and os.time() - getGlobalStorageValue(20001) >= 300 and isStoneNearby then
        local stonePos = {x = tileX, y = tileY, z = tileZ}
        local roll = math.random(1, 100)
        if roll <= chance then
            local newItem = doCreateItem(items[math.random(#items)], 1, stonePos)
            if newItem ~= nil then
                setGlobalStorageValue(20001, os.time())
            end
        else
            -- Do nothing since the roll was not successful
        end
    end
   
    return true
end

declare in movements altough thinking about it now maybe creaturescript could have been easier but it would run for EVERY monster instead on selected ActionID tiles like here :) its set to only allow to mine every 300 seconds and then 1/10 for guard 1/20 soldier 1/100 dwarf :p item table above is changeable maybe add ore?

ezgif-1-a0afb2e02d.gif
 
v3
Lua:
function onStepIn(cid, item, position, lastPosition, fromPosition, toPosition)
    local monsterName = getCreatureName(cid)
    local items = {2145, 2146, 2147, 2149, 2150}
    local poofEffect = CONST_ME_POFF
   
    local chance = 0
    local tileX, tileY, tileZ = position.x, position.y, position.z
    local isStoneNearby = false
   
    if not isMonster(cid) then
        return false
    end
   
    -- Check if there is a stone nearby
    for x = tileX - 1, tileX + 1 do
        for y = tileY - 1, tileY + 1 do
            local tile = getTileItemById({x = x, y = y, z = tileZ}, 1285)
            if tile and tile.uid > 0 then
                isStoneNearby = true
                doSendMagicEffect({x = x, y = y, z = tileZ}, 4)
                local stonePos = {x = x, y = y, z = tileZ} -- update stone position
                if monsterName:lower() == "dwarf" then
                    chance = 1
                    doSendMagicEffect(position, poofEffect)
                    cid:say("<click clang>", TALKTYPE_MONSTER_SAY, false, nil, stonePos) -- send creature message on stone tile
                elseif monsterName:lower() == "dwarf soldier" then
                    chance = 5
                    doSendMagicEffect(position, poofEffect)
                    cid:say("<click clang>", TALKTYPE_MONSTER_SAY, false, nil, stonePos) -- send creature message on stone tile
                elseif monsterName:lower() == "dwarf guard" then
                    doSendMagicEffect(position, poofEffect)
                    chance = 10
                    cid:say("<click clang>", TALKTYPE_MONSTER_SAY, false, nil, stonePos) -- send creature message on stone tile
                end
                if chance > 0 and os.time() - getGlobalStorageValue(20001) >= 300 then
                    local roll = math.random(1, 100)
                    if roll <= chance then
                        local newItem = doCreateItem(items[math.random(#items)], 1, stonePos) -- create item on stone tile
                        if newItem ~= nil then
                            setGlobalStorageValue(20001, os.time())
                        end
                    else
                        -- Do nothing since the roll was not successful
                    end
                end
                break
            end
        end
        if isStoneNearby then
            break
        end
    end
   
    return true
end

because chatgpt is writing this and I am a stubborn guy which is gonna show all of you that you can make quality product with the help of this tool and laziness. :)

ezgif-1-200c540806.gif

more advanced options.
1683491335493.png

of course i sometimes change some lines for it too to work with my distro but debugging is taking less and less time the more input it has so. :)
a free thinking rock? i don't think i can match its talent and versatility plus speed. + hey this shit will work on 0.4 aswell with smallest changes to stuff
 
Last edited:
Back
Top