• 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 [0.4] Stackpos item.

elnelson

Lunaria World Dev
Joined
Jun 20, 2009
Messages
579
Solutions
2
Reaction score
58
Location
México
Hello, good morning, im using this script: [MOD] Professions System (https://otland.net/threads/mod-professions-system.99754/)

but since its a post from 2010 and you guys hate old bumps, i decided to open this thread. When i try to cut a tree, and that tree is in a border (any border) it does not work, no error in console, just nothing. Also is there is a grass above the tree, does not work either. (see image for clear example)

So, i was thinking this is a stackpos problem, but i dont really know where to add it
this line took my attention.
Code:
itemPos = getThingPos(itemEx.uid)
How can i add a patch that reads if the item is in wathever stackpos it is? No matter if it is a border, a grass above, etc. It is very exhausting to remake the map moving each tree.
 

Attachments

Solution
it works. but has a detail, when i chop down a tree that is on a border (or have a grass on the top like i explained in the main post) it chop down the tree (appears the trunk) but the tree remains there, it gives the item and everything is normal, here is the script im using with the modification you gave me.

Lua:
<?xml version="1.0" encoding="UTF-8"?>
<mod name="Professions System" enabled="1">
    <action itemid="2405;2422;12722;12723;12724;2386" event="script"><![CDATA[
local professions = {
    ["herbalism"] = {storage = 1030, maxSkill = 500},
    ["mining"] = {storage = 1031, maxSkill = 500},
    ["lumberjack"] = {storage = 1033, maxSkill = 500},
    ["quarry"] = {storage = 1034, maxSkill = 500},
}
local stumps =...
Hello, good morning, im using this script: [MOD] Professions System (https://otland.net/threads/mod-professions-system.99754/)

but since its a post from 2010 and you guys hate old bumps, i decided to open this thread. When i try to cut a tree, and that tree is in a border (any border) it does not work, no error in console, just nothing. Also is there is a grass above the tree, does not work either. (see image for clear example)

So, i was thinking this is a stackpos problem, but i dont really know where to add it
this line took my attention.
Code:
itemPos = getThingPos(itemEx.uid)
How can i add a patch that reads if the item is in wathever stackpos it is? No matter if it is a border, a grass above, etc. It is very exhausting to remake the map moving each tree.
Lua:
local thing = getTileItemById(position, itemid).uid
Be careful with how you use this though.
If a player can put 10000 items onto the tile, your server will lag if the player wants to abuse it.

I typically only use this in cases where players can't put items onto the tiles I'm looking at.
 
Lua:
local thing = getTileItemById(position, itemid).uid
Be careful with how you use this though.
If a player can put 10000 items onto the tile, your server will lag if the player wants to abuse it.

I typically only use this in cases where players can't put items onto the tiles I'm looking at.
well since the target its a ummovable and blocking object, i guess it will be hard to abuse on this case.

Btw, should i replace the line itemPos for
local thing = getTileItemById(position, itemid).uid
¿? I tried to replace but its not working, i also added the local function but i got a bunch of errors in console, not working tho :/
 
Last edited:
remove this xD
Code:
        if itemEx.actionid > 0 or itemEx.uid > 0 then
            doCreatureSay(cid, "You can't do that.", TALKTYPE_ORANGE_1)
            doSendMagicEffect(getPlayerPosition(cid), CONST_ME_POFF)
            return true
        end
 
remove this xD
Code:
        if itemEx.actionid > 0 or itemEx.uid > 0 then
            doCreatureSay(cid, "You can't do that.", TALKTYPE_ORANGE_1)
            doSendMagicEffect(getPlayerPosition(cid), CONST_ME_POFF)
            return true
        end
yeah i noticed that part is useless. already removed, but still cant get to work on trees over a border
 
well since the target its a ummovable and blocking object, i guess it will be hard to abuse on this case.

Btw, should i replace the line itemPos for
local thing = getTileItemById(position, itemid).uid
¿? I tried to replace but its not working, i also added the local function but i got a bunch of errors in console, not working tho :/
Try this.
Lua:
function onUse(cid, item, fromPosition, itemEx, toPosition)
    local index = {}
    for k, v in pairs(recipes) do
        index[#index+1] = k
    end
 
    local pos = {x = toPosition.x, y = toPosition.y, z = toPosition.z}
    for i = 1, 255 do
        local check_pos = {x = pos.x, y = pos.y, z = pos.z, stackpos = i}
        local thing = getThingFromPos(check_pos).itemid
        if thing < 1 then
            return true
        elseif isInArray(index, thing) then
            itemEx = getTileItemById(toPosition, thing)
            break
        end
    end
 
    if recipes[itemEx.itemid] then
        -- rest of script
 
Last edited:
Try this.
Lua:
function onUse(cid, item, fromPosition, itemEx, toPosition)
    local index = {}
    for k, v in pairs(recipes) do
        index[#index+1] = k
    end

    local pos = {x = toPosition.x, y = toPosition.y, z = toPosition.z}
    for i = 1, 255 do
        local check_pos = {x = pos.x, y = pos.y, z = pos.z, stackpos = i}
        local thing = getThingFromPos(check_pos).itemid
        if thing < 1 then
            return true
        elseif isInArray(index, thing) then
            itemEx = getTileItemById(toPosition, thing)
            break
        end
    end

    if recipes[itemEx.itemid] then
        -- rest of script
it works. but has a detail, when i chop down a tree that is on a border (or have a grass on the top like i explained in the main post) it chop down the tree (appears the trunk) but the tree remains there, it gives the item and everything is normal, here is the script im using with the modification you gave me.

Lua:
<?xml version="1.0" encoding="UTF-8"?>
<mod name="Professions System" enabled="1">
    <action itemid="2405;2422;12722;12723;12724;2386" event="script"><![CDATA[
local professions = {
    ["herbalism"] = {storage = 1030, maxSkill = 500},
    ["mining"] = {storage = 1031, maxSkill = 500},
    ["lumberjack"] = {storage = 1033, maxSkill = 500},
    ["quarry"] = {storage = 1034, maxSkill = 500},
}
local stumps = {8788,8785,8786}
local grass = {2770,2770}
local rocks = {3666,3667,3668}

local recipes = {

  -- lumberjack (wood)
    [4025] = {tool = 2386, skill = 200, loot = {{2741, 1}}, effect = CONST_ME_GROUNDSHAKER, profession = "lumberjack"}, --bamboo
    [4026] = {tool = 2386, skill = 200, loot = {{2741, 1}}, effect = CONST_ME_GROUNDSHAKER, profession = "lumberjack"}, --bamboo
    [11563] = {tool = 2386, skill = 200, loot = {{2741, 1}}, effect = CONST_ME_GROUNDSHAKER, profession = "lumberjack"}, --bamboo
    [11562] = {tool = 2386, skill = 200, loot = {{2741, 1}}, effect = CONST_ME_GROUNDSHAKER, profession = "lumberjack"}, --bamboo
    [2700] = {tool = 2386, skill = 30, loot = {{5901, 2}, {5901, 2}}, effect = CONST_ME_GROUNDSHAKER, profession = "lumberjack"}, --twig
    [2768] = {tool = 2386, skill = 0, loot = {{5901, 2}}, effect = CONST_ME_GROUNDSHAKER, profession = "lumberjack"}, --twig
    [2701] = {tool = 2386, skill = 30, loot = {{5901, 2}, {5901, 2}}, effect = CONST_ME_MAGIC_GREEN, profession = "lumberjack"}, --twig
    [2702] = {tool = 2386, skill = 30, loot = {{5901, 2}, {5901, 2}}, effect = CONST_ME_GROUNDSHAKER, profession = "lumberjack"}, --twig
    [2703] = {tool = 2386, skill = 30, loot = {{5901, 2}, {5901, 2}}, effect = CONST_ME_GROUNDSHAKER, profession = "lumberjack"}, --twig
    [2705] = {tool = 2386, skill = 30, loot = {{5901, 2}, {5901, 2}}, effect = CONST_ME_GROUNDSHAKER, profession = "lumberjack"}, --twig
    [2707] = {tool = 2386, skill = 30, loot = {{5901, 2}, {5901, 2}}, effect = CONST_ME_GROUNDSHAKER, profession = "lumberjack"}, --twig
    [2708] = {tool = 2386, skill = 30, loot = {{5901, 2}, {5901, 2}}, effect = CONST_ME_GROUNDSHAKER, profession = "lumberjack"}, --twig
    [2706] = {tool = 2386, skill = 50, loot = {{12697, 1}}, effect = CONST_ME_GROUNDSHAKER, profession = "lumberjack"}, --maple
    [2704] = {tool = 2386, skill = 50, loot = {{12697, 1}}, effect = CONST_ME_GROUNDSHAKER, profession = "lumberjack"}, --maple
    [2711] = {tool = 2386, skill = 100, loot = {{12695, 1}}, effect = CONST_ME_GROUNDSHAKER, profession = "lumberjack"}, --dwarf tree
    [2712] = {tool = 2386, skill = 100, loot = {{12695, 1}}, effect = CONST_ME_GROUNDSHAKER, profession = "lumberjack"}, --pine

    -- herbalism (herbs)
    [2740] = {tool = 2405, skill = 0, loot = {{2741, 1}}, effect = CONST_ME_MAGIC_GREEN, profession = "herbalism"},
    [4158] = {tool = 2405, skill = 0, loot = {{2741, 1}}, effect = CONST_ME_MAGIC_GREEN, profession = "herbalism"},
    [2742] = {tool = 2405, skill = 0, loot = {{2741, 1}}, effect = CONST_ME_MAGIC_GREEN, profession = "herbalism"},
    [4156] = {tool = 2405, skill = 0, loot = {{2741, 1}}, effect = CONST_ME_MAGIC_GREEN, profession = "herbalism"},
    [2747] = {tool = 2405, skill = 0, loot = {{2741, 1}}, effect = CONST_ME_MAGIC_GREEN, profession = "herbalism"},
    [4157] = {tool = 2405, skill = 0, loot = {{2741, 1}}, effect = CONST_ME_MAGIC_GREEN, profession = "herbalism"},
    [2753] = {tool = 2405, skill = 10, loot = {{7732, 1}}, effect = CONST_ME_MAGIC_GREEN, profession = "herbalism"},
    [2752] = {tool = 2405, skill = 10, loot = {{7732, 1}}, effect = CONST_ME_MAGIC_GREEN, profession = "herbalism"},
    [2779] = {tool = 2405, skill = 20, loot = {{2804, 4}, {2803, 7}}, effect = CONST_ME_MAGIC_GREEN, profession = "herbalism"},
    [2771] = {tool = 2405, skill = 50, loot = {{2801, 4}, {2800, 4}}, effect = CONST_ME_MAGIC_GREEN, profession = "herbalism"},
    [2769] = {tool = 2405, skill = 55, loot = {{2805, 4}, {2801, 1},}, effect = CONST_ME_MAGIC_GREEN, profession = "herbalism"},
    [2773] = {tool = 2405, skill = 60, loot = {{2805, 4}, {2801, 1},}, effect = CONST_ME_MAGIC_GREEN, profession = "herbalism"},
    [2777] = {tool = 2405, skill = 65, loot = {{2805, 4}, {2801, 1},}, effect = CONST_ME_MAGIC_GREEN, profession = "herbalism"},
    [2778] = {tool = 2405, skill = 70, loot = {{2801, 4}, {2800, 4}}, effect = CONST_ME_MAGIC_GREEN, profession = "herbalism"},
    [2772] = {tool = 2405, skill = 75, loot = {{2805, 4}, {2801, 1},}, effect = CONST_ME_MAGIC_GREEN, profession = "herbalism"},
    [2775] = {tool = 2405, skill = 100, loot = {{2802, 6}, {2805, 5}, {2800, 5}}, effect = CONST_ME_MAGIC_GREEN, profession = "herbalism"},
    [2783] = {tool = 2405, skill = 100, loot = {{2760, 6}, {2805, 7}, {2800, 6}}, effect = CONST_ME_MAGIC_GREEN, profession = "herbalism"},
    [2743] = {tool = 2405, skill = 150, loot = {{2798, 4}, {5921,1}, {2804, 5}}, effect = CONST_ME_MAGIC_GREEN, profession = "herbalism"},
    [2780] = {tool = 2405, skill = 80, loot = {{2799, 4}}, effect = CONST_ME_MAGIC_GREEN, profession = "herbalism"},
    [4166] = {tool = 2405, skill = 350, loot = {{2107, 1}}, effect = CONST_ME_MAGIC_GREEN, profession = "herbalism"},
    --herbalism (mushrooms)
    [4180] = {tool = 2405, skill = 0, loot = {{2794, 1}}, effect = CONST_ME_MAGIC_RED, profession = "herbalism"},  
    [4182] = {tool = 2405, skill = 0, loot = {{2793, 1}}, effect = CONST_ME_MAGIC_RED, profession = "herbalism"},
    [4178] = {tool = 2405, skill = 0, loot = {{2794, 1}}, effect = CONST_ME_MAGIC_RED, profession = "herbalism"},
    [4170] = {tool = 2405, skill = 0, loot = {{2794, 5}}, effect = CONST_ME_MAGIC_RED, profession = "herbalism"},
    [4179] = {tool = 2405, skill = 10, loot = {{2787,1}}, effect = CONST_ME_MAGIC_RED, profession = "herbalism"},
    [4181] = {tool = 2405, skill = 20, loot = {{2797, 1}, {2789,1}}, effect = CONST_ME_MAGIC_RED, profession = "herbalism"},
    [4183] = {tool = 2405, skill = 40, loot = {{2788, 1},{2790,1}}, effect = CONST_ME_MAGIC_RED, profession = "herbalism"},
    [4171] = {tool = 2405, skill = 20, loot = {{2492, 1},{2789,1}}, effect = CONST_ME_MAGIC_RED, profession = "herbalism"},
    [4179] = {tool = 2405, skill = 40, loot = {{2789, 1}, {2792, 1}}, effect = CONST_ME_MAGIC_RED, profession = "herbalism"},
    [4177] = {tool = 2405, skill = 100, loot = {{2791, 5}, {2794, 7}}, effect = CONST_ME_MAGIC_RED, profession = "herbalism"},
    --herbalism (big mushrooms)
    [4167] = {tool = 2405, skill = 100, loot = {{2791, 3}}, effect = CONST_ME_MAGIC_RED, profession = "herbalism"},
    [4168] = {tool = 2405, skill = 100, loot = {{2791, 4}}, effect = CONST_ME_MAGIC_RED, profession = "herbalism"},
    [4169] = {tool = 2405, skill = 100, loot = {{2791, 5}}, effect = CONST_ME_MAGIC_RED, profession = "herbalism"},
    [4174] = {tool = 2405, skill = 100, loot = {{2796, 5}, {2496, 5}}, effect = CONST_ME_MAGIC_RED, profession = "herbalism"},
    [4175] = {tool = 2405, skill = 100, loot = {{2796, 4}, {2796, 6}}, effect = CONST_ME_MAGIC_RED, profession = "herbalism"},
    [4172] = {tool = 2405, skill = 100, loot = {{2796, 5}, {2791, 6}, {2796, 4}}, effect = CONST_ME_MAGIC_RED, profession = "herbalism"},
    [4173] = {tool = 2405, skill = 100, loot = {{2796, 5}, {2791, 6}, {2796, 4}}, effect = CONST_ME_MAGIC_RED, profession = "herbalism"},
    --herbalism (cotton)
    [2762] = {tool = 2405, skill = 50, loot = {{12708, 1}}, effect = CONST_ME_MAGIC_RED, profession = "herbalism"},
    [2763] = {tool = 2405, skill = 0, loot = {{12707, 2}}, effect = CONST_ME_MAGIC_RED, profession = "herbalism"},
    [2764] = {tool = 2405, skill = 50, loot = {{12710, 4}}, effect = CONST_ME_MAGIC_RED, profession = "herbalism"},
    [2765] = {tool = 2405, skill = 20, loot = {{12710, 2}}, effect = CONST_ME_MAGIC_RED, profession = "herbalism"},
    [2766] = {tool = 2405, skill = 0, loot = {{12706, 5}}, effect = CONST_ME_MAGIC_RED, profession = "herbalism"},
    [12718] = {tool = 2405, skill = 0, loot = {{12711, 1}}, effect = CONST_ME_MAGIC_RED, profession = "herbalism"},
    [12719] = {tool = 2405, skill = 0, loot = {{12709, 1}}, effect = CONST_ME_MAGIC_RED, profession = "herbalism"},
    --quarry (stones)
    --tier 1
    [3607] = {tool = 2422, skill = 0, loot = {{1294, 2}}, effect = CONST_ME_HITAREA, profession = "quarry"},
    [3608] = {tool = 2422, skill = 0, loot = {{1294, 2}}, effect = CONST_ME_HITAREA, profession = "quarry"},
    [3609] = {tool = 2422, skill = 0, loot = {{1294, 2}}, effect = CONST_ME_HITAREA, profession = "quarry"},
    [3615] = {tool = 2422, skill = 0, loot = {{1294, 2}}, effect = CONST_ME_HITAREA, profession = "quarry"},
    [3616] = {tool = 2422, skill = 0, loot = {{1294, 2}}, effect = CONST_ME_HITAREA, profession = "quarry"},
    [1357] = {tool = 2422, skill = 0, loot = {{1294, 2}}, effect = CONST_ME_HITAREA, profession = "quarry"},
    [1359] = {tool = 2422, skill = 0, loot = {{1294, 2}}, effect = CONST_ME_HITAREA, profession = "quarry"},
    [1358] = {tool = 2422, skill = 0, loot = {{1294, 2}}, effect = CONST_ME_HITAREA, profession = "quarry"},
    [386] = {tool = 2422, skill = 0, loot = {{1294, 2}}, effect = CONST_ME_HITAREA, profession = "quarry"},
    [1356] = {tool = 2422, skill = 0, loot = {{1294, 2}}, effect = CONST_ME_HITAREA, profession = "quarry"},
    [1285] = {tool = 2422, skill = 0, loot = {{1294, 2}}, effect = CONST_ME_HITAREA, profession = "quarry"},
    [3653] = {tool = 2422, skill = 0, loot = {{1294, 2}, {2146, 2}, {9970, 2}}, effect = CONST_ME_HITAREA, profession = "quarry"},
    [3654] = {tool = 2422, skill = 0, loot = {{1294, 2}, {2146, 2}, {9970, 2}}, effect = CONST_ME_HITAREA, profession = "quarry"},
    [3655] = {tool = 2422, skill = 0, loot = {{1294, 2}, {2146, 2}, {9970, 2}}, effect = CONST_ME_HITAREA, profession = "quarry"},
    [3656] = {tool = 2422, skill = 0, loot = {{1294, 2}, {2146, 2}, {9970, 2}}, effect = CONST_ME_HITAREA, profession = "quarry"},
    [3648] = {tool = 2422, skill = 50, loot = {{2149, 2}, {2146, 2}, {9970, 2}}, effect = CONST_ME_HITAREA, profession = "quarry"},
    [3649] = {tool = 2422, skill = 50, loot = {{2149, 2}, {2146, 2}, {9970, 2}}, effect = CONST_ME_HITAREA, profession = "quarry"},
    [3650] = {tool = 2422, skill = 50, loot = {{2149, 2}, {2146, 2}, {9970, 2}}, effect = CONST_ME_HITAREA, profession = "quarry"},
    [3651] = {tool = 2422, skill = 50, loot = {{2149, 2}, {2146, 2}, {9970, 2}}, effect = CONST_ME_HITAREA, profession = "quarry"},
    [3652] = {tool = 2422, skill = 50, loot = {{2149, 2}, {2146, 2}, {9970, 2}}, effect = CONST_ME_HITAREA, profession = "quarry"},
    --tier 2
    [5868] = {tool = 2422, skill = 200, loot = {{2149, 2}, {2146, 2}, {9970, 2}}, effect = CONST_ME_HITAREA, profession = "quarry"},
    [5867] = {tool = 2422, skill = 200, loot = {{5889, 1}, {2146, 2}, {9970, 2}}, effect = CONST_ME_HITAREA, profession = "quarry"},
    [5866] = {tool = 2422, skill = 300, loot = {{5892, 1}, {2149, 2}, {2147, 2}, {9970, 2}}, effect = CONST_ME_HITAREA, profession = "quarry"},
    [5753] = {tool = 2422, skill = 350, loot = {{5888, 1}, {2150, 2}, {2146,2 }, {9970, 2}, {2156, 1}}, effect = CONST_ME_HITAREA, profession = "quarry"},
    [5751] = {tool = 2422, skill = 400, loot = {{5887, 1}, {2149, 2}, {2147, 2}, {9970, 2}, {2158, 1}}, effect = CONST_ME_HITAREA, profession = "quarry"},
    [3608] = {tool = 2422, skill = 0, loot = {{5887, 1}, {2149, 2}, {2147, 2}, {9970, 2}, {2158, 1}}, effect = CONST_ME_HITAREA, profession = "quarry"},
    [3609] = {tool = 2422, skill = 400, loot = {{5887, 1}, {2149, 2}, {2147, 2}, {9970, 2}, {2158, 1}}, effect = CONST_ME_HITAREA, profession = "quarry"},
    [3615] = {tool = 2422, skill = 400, loot = {{5887, 1}, {2149, 2}, {2147, 2}, {9970, 2}, {2158, 1}}, effect = CONST_ME_HITAREA, profession = "quarry"},
    [3616] = {tool = 2422, skill = 400, loot = {{5887, 1}, {2149, 2}, {2147, 2}, {9970, 2}, {2158, 1}}, effect = CONST_ME_HITAREA, profession = "quarry"},
    [3666] = {tool = 2422, skill = 400, loot = {{5887, 1}, {2149, 2}, {2147, 2}, {9970, 2}, {2158, 1}}, effect = CONST_ME_HITAREA, profession = "quarry"},
    [3667] = {tool = 2422, skill = 400, loot = {{5887, 1}, {2149, 2}, {2147, 2}, {9970, 2}, {2158, 1}}, effect = CONST_ME_HITAREA, profession = "quarry"},
    --mossy
    [3632] = {tool = 2422, skill = 400, loot = {{5887, 1}, {2149, 2}, {2147, 2}, {9970, 2}, {2158, 1}}, effect = CONST_ME_HITAREA, profession = "quarry"},
    [3633] = {tool = 2422, skill = 400, loot = {{5887, 1}, {2149, 2}, {2147, 2}, {9970, 2}, {2158, 1}}, effect = CONST_ME_HITAREA, profession = "quarry"},
    [3634] = {tool = 2422, skill = 400, loot = {{5887, 1}, {2149, 2}, {2147, 2}, {9970, 2}, {2158, 1}}, effect = CONST_ME_HITAREA, profession = "quarry"},
    [3636] = {tool = 2422, skill = 400, loot = {{5887, 1}, {2149, 2}, {2147, 2}, {9970, 2}, {2158, 1}}, effect = CONST_ME_HITAREA, profession = "quarry"},
    --ore miner (minerals, metals)
    --tier 1 copper
    [12792] = {tool = 12722, skill = 1, loot = {{12798, 1}, {2148, 20}}, effect = CONST_ME_HITAREA, profession = "mining"},
    [12793] = {tool = 12722, skill = 1, loot = {{12798, 1}, {2148, 20}}, effect = CONST_ME_HITAREA, profession = "mining"},
    [390] = {tool = 2553, skill = 0, loot = {{5887, 1}, {2149, 2}, {2147, 2}, {9970, 2}, {2158, 1}}, effect = CONST_ME_HITAREA, profession = "mining"},
    [12794] = {tool = 12722, skill = 1, loot = {{12798, 1}, {2148, 20}}, effect = CONST_ME_HITAREA, profession = "mining"},
    [12795] = {tool = 12722, skill = 1, loot = {{12798, 2}, {2148, 20}}, effect = CONST_ME_HITAREA, profession = "mining"},
    [12796] = {tool = 12722, skill = 1, loot = {{12798, 2}, {2148, 20}}, effect = CONST_ME_HITAREA, profession = "mining"},
    --tier2 silver
    [12775] = {tool = 12723, skill = 25, loot = {{12804, 1}, {2148, 20}, {2152, 1}}, effect = CONST_ME_HITAREA, profession = "mining"},
    [12776] = {tool = 12723, skill = 25, loot = {{12804, 1}, {2148, 20}, {2152, 1}}, effect = CONST_ME_HITAREA, profession = "mining"},
    [12777] = {tool = 12723, skill = 25, loot = {{12804, 1}, {2148, 20}, {2152, 1}}, effect = CONST_ME_HITAREA, profession = "mining"},
    [12778] = {tool = 12723, skill = 25, loot = {{12804, 2}, {2148, 20}, {2152, 1}}, effect = CONST_ME_HITAREA, profession = "mining"},
    [12779] = {tool = 12723, skill = 25, loot = {{12804, 2}, {2148, 20}, {2152, 1}}, effect = CONST_ME_HITAREA, profession = "mining"},
    [12780] = {tool = 12723, skill = 25, loot = {{12804, 2}, {2148, 20}, {2152, 1}}, effect = CONST_ME_HITAREA, profession = "mining"},
    [12781] = {tool = 12723, skill = 25, loot = {{12804, 2}, {2148, 20}, {2152, 1}}, effect = CONST_ME_HITAREA, profession = "mining"},
    --tier 3 -mithril
    [12753] = {tool = 12724, skill = 50, loot = {{12801, 1}, {2148, 20}, {2152, 10}}, effect = CONST_ME_HITAREA, profession = "mining"},
    [12752] = {tool = 12724, skill = 50, loot = {{12801, 1}, {2148, 20}, {2152, 10}}, effect = CONST_ME_HITAREA, profession = "mining"},
    [12753] = {tool = 12724, skill = 50, loot = {{12801, 1}, {2148, 20}, {2152, 10}}, effect = CONST_ME_HITAREA, profession = "mining"},
    [12754] = {tool = 12724, skill = 50, loot = {{12801, 1}, {2148, 20}, {2152, 10}}, effect = CONST_ME_HITAREA, profession = "mining"},
    [12755] = {tool = 12724, skill = 50, loot = {{12801, 1}, {2148, 20}, {2152, 10}}, effect = CONST_ME_HITAREA, profession = "mining"},
    [12756] = {tool = 12724, skill = 50, loot = {{12801, 2}, {2148, 20}, {2152, 10}}, effect = CONST_ME_HITAREA, profession = "mining"},
    [12757] = {tool = 12724, skill = 50, loot = {{12801, 2}, {2148, 20}, {2152, 10}}, effect = CONST_ME_HITAREA, profession = "mining"},
    [12758] = {tool = 12724, skill = 50, loot = {{12801, 2}, {2148, 20}, {2152, 10}}, effect = CONST_ME_HITAREA, profession = "mining"},
    [12759] = {tool = 12724, skill = 50, loot = {{12801, 2}, {2148, 20}, {2152, 10}}, effect = CONST_ME_HITAREA, profession = "mining"},
}

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

     if math.random(200) == 200 then
        rand = math.random(5)
        if rand == 1 then
            doSendMagicEffect(toPosition, CONST_ME_HITAREA)
            doCreatureSay(cid, "You have disturbed some bats!", TALKTYPE_ORANGE_1, cid)
            monsters = math.random(2)
            for i = 1, monsters do
                doCreateMonster("bat", getThingPos(cid))
            end
        elseif rand == 2 then
            doSendMagicEffect(toPosition, CONST_ME_HITAREA)
            doCreatureSay(cid, "You knocked a wasps nest out of the tree!", TALKTYPE_ORANGE_1, cid)
            monsters = math.random(4)
            for i = 1, monsters do
                doCreateMonster("wasp", getThingPos(cid))
            end
        elseif rand == 3 then
            doSendMagicEffect(toPosition, CONST_ME_HITAREA)
            doCreatureSay(cid, "An angry squirrel throws an acorn at you.", TALKTYPE_ORANGE_1, cid)
            doCreateItem(11213, 1, getThingPos(cid)) -- acorn
            doSendMagicEffect(getThingPos(cid), CONST_ME_DRAWBLOOD)
            health = math.random(getCreatureMaxHealth(cid)/10*2, getCreatureMaxHealth(cid)/10*6)
            if getCreatureHealth(cid) > health then
                doCreatureAddHealth(cid, -(health))
            else
                doCreatureAddHealth(cid, -(getCreatureHealth(cid) - math.random(10)))
            end
            --angry squirrel acorn
        elseif rand == 4 then
            doCreatureSay(cid, "Lucky day! A bag of coins falls out of the tree.", TALKTYPE_ORANGE_1, cid)
            doSendMagicEffect(toPosition, CONST_ME_BLOCKHIT)
            bag = doCreateItem(1987, 1, toPosition)
            doAddContainerItem(bag, 2148, math.random(50))
        elseif rand == 5 then
            doCreatureSay(cid, "You found a birds nest and steal some eggs.", TALKTYPE_ORANGE_1, cid)
            doPlayerAddItem(cid, 2695, math.random(2, 6), true) -- eggs
        end
        return true
    end
   
    local index = {}
    for k, v in pairs(recipes) do
        index[#index+1] = k
    end

    local pos = {x = toPosition.x, y = toPosition.y, z = toPosition.z}
    for i = 1, 255 do
        local check_pos = {x = pos.x, y = pos.y, z = pos.z, stackpos = i}
        local thing = getThingFromPos(check_pos).itemid
        if thing < 1 then
            return true
        elseif isInArray(index, thing) then
            itemEx = getTileItemById(toPosition, thing)
            break
        end
    end

    if recipes[itemEx.itemid] then

        lootTable = {}
        lootName = "You recive: "
        local professionSkill = getPlayerStorageValue(cid, professions[recipes[itemEx.itemid].profession].storage)
        itemPos = getThingPos(itemEx.uid)
        if professionSkill < 1 then
            professionSkill = 1
        end
        if item.itemid == recipes[itemEx.itemid].tool then
            if professionSkill >= recipes[itemEx.itemid].skill then
            local R = math.random(professionSkill,500)
            --print ("chance to success "..R.."/400")
                if item.actionid ~= 5001 then              
                     if R >= 400 and R <= 500 then
                     local c1 = getPlayerStorageValue(cid, professions[recipes[itemEx.itemid].profession].storage)
                    local S = math.random(0, c1*1.15)
                    --print ("chance to lvl ".. S .."")
                    --print ("current level ".. c1 .."")
                        if S >= c1-1 then
                            if professionSkill < professions[recipes[itemEx.itemid].profession].maxSkill then
                                setPlayerStorageValue(cid, professions[recipes[itemEx.itemid].profession].storage, professionSkill + 1)
                                doPlayerSendTextMessage(cid, MESSAGE_EVENT_ADVANCE, "You advanced in "..recipes[itemEx.itemid].profession.." ["..professionSkill.."].")
                                end
                            end                       
        addEvent (function()
                doTransformItem(getThingfromPos(toPosition).uid, itemEx.itemid)   
        end, 60*1000)
       
                     if recipes[itemEx.itemid].profession == "herbalism" then
                     doTransformItem(getThingfromPos(toPosition).uid, grass[math.random(#grass)])
                        doSendMagicEffect(itemPos, recipes[itemEx.itemid].effect)
                        end
                        if R >= 400 and R <= 500 and recipes[itemEx.itemid].profession == "lumberjack" then
                            doSendMagicEffect(itemPos, recipes[itemEx.itemid].effect)
                            doTransformItem(getThingfromPos(toPosition).uid, stumps[math.random(#stumps)])
                                else if R >= 400 and R <= 500 and recipes[itemEx.itemid].profession == "mining" then
                                doSendMagicEffect(itemPos, recipes[itemEx.itemid].effect)
                                doTransformItem(getThingfromPos(toPosition).uid, rocks[math.random(#rocks)])
                    end

                        end
                        repeat
                            if #recipes[itemEx.itemid].loot == 0 then
                                break
                            end
                            for i = 1, #recipes[itemEx.itemid].loot do
                            local L = math.random(professionSkill,500)
                            --print("loot " .. L .. "")
                                if L >= 100 and R <= 500 then
                                    table.insert(lootTable, (recipes[itemEx.itemid].loot)[i])
                                end
                            end
                        until lootTable ~= {}
                        for i = 1, #lootTable do
                        --lootTable[i][2]
                            lootCount = math.random(1,math.ceil(professionSkill/250)) 
                            doPlayerAddItem(cid, lootTable[i][1], lootCount)
                            if i == #lootTable then
                                lootName = lootName..""..lootCount.."x ".. getItemNameById(lootTable[i][1]) .."."
                            else
                                lootName = lootName..""..lootCount.."x ".. getItemNameById(lootTable[i][1]) ..", "
                            end
                        end
                        if lootName == "You recive: " then
                            lootName = "You don't recive any loot."
                        end
                        doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, lootName)
                    else
                        doSendMagicEffect(itemPos, CONST_ME_BLOCKHIT)
                    end
                else
                    doSendMagicEffect(itemPos, CONST_ME_BLOCKHIT)
                    doCreatureSay(cid, "This tree was cut recenlty by someone else!", TALKTYPE_ORANGE_1)
                end
            else
                doSendMagicEffect(getPlayerPosition(cid), CONST_ME_POFF)
                doCreatureSay(cid, "You have to be at least skill ".. recipes[itemEx.itemid].skill  .." in ".. recipes[itemEx.itemid].profession .." to do that!", TALKTYPE_ORANGE_1)
        end
        else
            doSendMagicEffect(getPlayerPosition(cid), CONST_ME_BLOCKHIT)
            doCreatureSay(cid, "You need a "..getItemNameById(recipes[itemEx.itemid].tool).."!", TALKTYPE_ORANGE_1)
        end
    end
    return true
end
    ]]></action>
</mod>
 

Attachments

it works. but has a detail, when i chop down a tree that is on a border (or have a grass on the top like i explained in the main post) it chop down the tree (appears the trunk) but the tree remains there, it gives the item and everything is normal, here is the script im using with the modification you gave me.

Lua:
<?xml version="1.0" encoding="UTF-8"?>
<mod name="Professions System" enabled="1">
    <action itemid="2405;2422;12722;12723;12724;2386" event="script"><![CDATA[
local professions = {
    ["herbalism"] = {storage = 1030, maxSkill = 500},
    ["mining"] = {storage = 1031, maxSkill = 500},
    ["lumberjack"] = {storage = 1033, maxSkill = 500},
    ["quarry"] = {storage = 1034, maxSkill = 500},
}
local stumps = {8788,8785,8786}
local grass = {2770,2770}
local rocks = {3666,3667,3668}

local recipes = {

  -- lumberjack (wood)
    [4025] = {tool = 2386, skill = 200, loot = {{2741, 1}}, effect = CONST_ME_GROUNDSHAKER, profession = "lumberjack"}, --bamboo
    [4026] = {tool = 2386, skill = 200, loot = {{2741, 1}}, effect = CONST_ME_GROUNDSHAKER, profession = "lumberjack"}, --bamboo
    [11563] = {tool = 2386, skill = 200, loot = {{2741, 1}}, effect = CONST_ME_GROUNDSHAKER, profession = "lumberjack"}, --bamboo
    [11562] = {tool = 2386, skill = 200, loot = {{2741, 1}}, effect = CONST_ME_GROUNDSHAKER, profession = "lumberjack"}, --bamboo
    [2700] = {tool = 2386, skill = 30, loot = {{5901, 2}, {5901, 2}}, effect = CONST_ME_GROUNDSHAKER, profession = "lumberjack"}, --twig
    [2768] = {tool = 2386, skill = 0, loot = {{5901, 2}}, effect = CONST_ME_GROUNDSHAKER, profession = "lumberjack"}, --twig
    [2701] = {tool = 2386, skill = 30, loot = {{5901, 2}, {5901, 2}}, effect = CONST_ME_MAGIC_GREEN, profession = "lumberjack"}, --twig
    [2702] = {tool = 2386, skill = 30, loot = {{5901, 2}, {5901, 2}}, effect = CONST_ME_GROUNDSHAKER, profession = "lumberjack"}, --twig
    [2703] = {tool = 2386, skill = 30, loot = {{5901, 2}, {5901, 2}}, effect = CONST_ME_GROUNDSHAKER, profession = "lumberjack"}, --twig
    [2705] = {tool = 2386, skill = 30, loot = {{5901, 2}, {5901, 2}}, effect = CONST_ME_GROUNDSHAKER, profession = "lumberjack"}, --twig
    [2707] = {tool = 2386, skill = 30, loot = {{5901, 2}, {5901, 2}}, effect = CONST_ME_GROUNDSHAKER, profession = "lumberjack"}, --twig
    [2708] = {tool = 2386, skill = 30, loot = {{5901, 2}, {5901, 2}}, effect = CONST_ME_GROUNDSHAKER, profession = "lumberjack"}, --twig
    [2706] = {tool = 2386, skill = 50, loot = {{12697, 1}}, effect = CONST_ME_GROUNDSHAKER, profession = "lumberjack"}, --maple
    [2704] = {tool = 2386, skill = 50, loot = {{12697, 1}}, effect = CONST_ME_GROUNDSHAKER, profession = "lumberjack"}, --maple
    [2711] = {tool = 2386, skill = 100, loot = {{12695, 1}}, effect = CONST_ME_GROUNDSHAKER, profession = "lumberjack"}, --dwarf tree
    [2712] = {tool = 2386, skill = 100, loot = {{12695, 1}}, effect = CONST_ME_GROUNDSHAKER, profession = "lumberjack"}, --pine

    -- herbalism (herbs)
    [2740] = {tool = 2405, skill = 0, loot = {{2741, 1}}, effect = CONST_ME_MAGIC_GREEN, profession = "herbalism"},
    [4158] = {tool = 2405, skill = 0, loot = {{2741, 1}}, effect = CONST_ME_MAGIC_GREEN, profession = "herbalism"},
    [2742] = {tool = 2405, skill = 0, loot = {{2741, 1}}, effect = CONST_ME_MAGIC_GREEN, profession = "herbalism"},
    [4156] = {tool = 2405, skill = 0, loot = {{2741, 1}}, effect = CONST_ME_MAGIC_GREEN, profession = "herbalism"},
    [2747] = {tool = 2405, skill = 0, loot = {{2741, 1}}, effect = CONST_ME_MAGIC_GREEN, profession = "herbalism"},
    [4157] = {tool = 2405, skill = 0, loot = {{2741, 1}}, effect = CONST_ME_MAGIC_GREEN, profession = "herbalism"},
    [2753] = {tool = 2405, skill = 10, loot = {{7732, 1}}, effect = CONST_ME_MAGIC_GREEN, profession = "herbalism"},
    [2752] = {tool = 2405, skill = 10, loot = {{7732, 1}}, effect = CONST_ME_MAGIC_GREEN, profession = "herbalism"},
    [2779] = {tool = 2405, skill = 20, loot = {{2804, 4}, {2803, 7}}, effect = CONST_ME_MAGIC_GREEN, profession = "herbalism"},
    [2771] = {tool = 2405, skill = 50, loot = {{2801, 4}, {2800, 4}}, effect = CONST_ME_MAGIC_GREEN, profession = "herbalism"},
    [2769] = {tool = 2405, skill = 55, loot = {{2805, 4}, {2801, 1},}, effect = CONST_ME_MAGIC_GREEN, profession = "herbalism"},
    [2773] = {tool = 2405, skill = 60, loot = {{2805, 4}, {2801, 1},}, effect = CONST_ME_MAGIC_GREEN, profession = "herbalism"},
    [2777] = {tool = 2405, skill = 65, loot = {{2805, 4}, {2801, 1},}, effect = CONST_ME_MAGIC_GREEN, profession = "herbalism"},
    [2778] = {tool = 2405, skill = 70, loot = {{2801, 4}, {2800, 4}}, effect = CONST_ME_MAGIC_GREEN, profession = "herbalism"},
    [2772] = {tool = 2405, skill = 75, loot = {{2805, 4}, {2801, 1},}, effect = CONST_ME_MAGIC_GREEN, profession = "herbalism"},
    [2775] = {tool = 2405, skill = 100, loot = {{2802, 6}, {2805, 5}, {2800, 5}}, effect = CONST_ME_MAGIC_GREEN, profession = "herbalism"},
    [2783] = {tool = 2405, skill = 100, loot = {{2760, 6}, {2805, 7}, {2800, 6}}, effect = CONST_ME_MAGIC_GREEN, profession = "herbalism"},
    [2743] = {tool = 2405, skill = 150, loot = {{2798, 4}, {5921,1}, {2804, 5}}, effect = CONST_ME_MAGIC_GREEN, profession = "herbalism"},
    [2780] = {tool = 2405, skill = 80, loot = {{2799, 4}}, effect = CONST_ME_MAGIC_GREEN, profession = "herbalism"},
    [4166] = {tool = 2405, skill = 350, loot = {{2107, 1}}, effect = CONST_ME_MAGIC_GREEN, profession = "herbalism"},
    --herbalism (mushrooms)
    [4180] = {tool = 2405, skill = 0, loot = {{2794, 1}}, effect = CONST_ME_MAGIC_RED, profession = "herbalism"}, 
    [4182] = {tool = 2405, skill = 0, loot = {{2793, 1}}, effect = CONST_ME_MAGIC_RED, profession = "herbalism"},
    [4178] = {tool = 2405, skill = 0, loot = {{2794, 1}}, effect = CONST_ME_MAGIC_RED, profession = "herbalism"},
    [4170] = {tool = 2405, skill = 0, loot = {{2794, 5}}, effect = CONST_ME_MAGIC_RED, profession = "herbalism"},
    [4179] = {tool = 2405, skill = 10, loot = {{2787,1}}, effect = CONST_ME_MAGIC_RED, profession = "herbalism"},
    [4181] = {tool = 2405, skill = 20, loot = {{2797, 1}, {2789,1}}, effect = CONST_ME_MAGIC_RED, profession = "herbalism"},
    [4183] = {tool = 2405, skill = 40, loot = {{2788, 1},{2790,1}}, effect = CONST_ME_MAGIC_RED, profession = "herbalism"},
    [4171] = {tool = 2405, skill = 20, loot = {{2492, 1},{2789,1}}, effect = CONST_ME_MAGIC_RED, profession = "herbalism"},
    [4179] = {tool = 2405, skill = 40, loot = {{2789, 1}, {2792, 1}}, effect = CONST_ME_MAGIC_RED, profession = "herbalism"},
    [4177] = {tool = 2405, skill = 100, loot = {{2791, 5}, {2794, 7}}, effect = CONST_ME_MAGIC_RED, profession = "herbalism"},
    --herbalism (big mushrooms)
    [4167] = {tool = 2405, skill = 100, loot = {{2791, 3}}, effect = CONST_ME_MAGIC_RED, profession = "herbalism"},
    [4168] = {tool = 2405, skill = 100, loot = {{2791, 4}}, effect = CONST_ME_MAGIC_RED, profession = "herbalism"},
    [4169] = {tool = 2405, skill = 100, loot = {{2791, 5}}, effect = CONST_ME_MAGIC_RED, profession = "herbalism"},
    [4174] = {tool = 2405, skill = 100, loot = {{2796, 5}, {2496, 5}}, effect = CONST_ME_MAGIC_RED, profession = "herbalism"},
    [4175] = {tool = 2405, skill = 100, loot = {{2796, 4}, {2796, 6}}, effect = CONST_ME_MAGIC_RED, profession = "herbalism"},
    [4172] = {tool = 2405, skill = 100, loot = {{2796, 5}, {2791, 6}, {2796, 4}}, effect = CONST_ME_MAGIC_RED, profession = "herbalism"},
    [4173] = {tool = 2405, skill = 100, loot = {{2796, 5}, {2791, 6}, {2796, 4}}, effect = CONST_ME_MAGIC_RED, profession = "herbalism"},
    --herbalism (cotton)
    [2762] = {tool = 2405, skill = 50, loot = {{12708, 1}}, effect = CONST_ME_MAGIC_RED, profession = "herbalism"},
    [2763] = {tool = 2405, skill = 0, loot = {{12707, 2}}, effect = CONST_ME_MAGIC_RED, profession = "herbalism"},
    [2764] = {tool = 2405, skill = 50, loot = {{12710, 4}}, effect = CONST_ME_MAGIC_RED, profession = "herbalism"},
    [2765] = {tool = 2405, skill = 20, loot = {{12710, 2}}, effect = CONST_ME_MAGIC_RED, profession = "herbalism"},
    [2766] = {tool = 2405, skill = 0, loot = {{12706, 5}}, effect = CONST_ME_MAGIC_RED, profession = "herbalism"},
    [12718] = {tool = 2405, skill = 0, loot = {{12711, 1}}, effect = CONST_ME_MAGIC_RED, profession = "herbalism"},
    [12719] = {tool = 2405, skill = 0, loot = {{12709, 1}}, effect = CONST_ME_MAGIC_RED, profession = "herbalism"},
    --quarry (stones)
    --tier 1
    [3607] = {tool = 2422, skill = 0, loot = {{1294, 2}}, effect = CONST_ME_HITAREA, profession = "quarry"},
    [3608] = {tool = 2422, skill = 0, loot = {{1294, 2}}, effect = CONST_ME_HITAREA, profession = "quarry"},
    [3609] = {tool = 2422, skill = 0, loot = {{1294, 2}}, effect = CONST_ME_HITAREA, profession = "quarry"},
    [3615] = {tool = 2422, skill = 0, loot = {{1294, 2}}, effect = CONST_ME_HITAREA, profession = "quarry"},
    [3616] = {tool = 2422, skill = 0, loot = {{1294, 2}}, effect = CONST_ME_HITAREA, profession = "quarry"},
    [1357] = {tool = 2422, skill = 0, loot = {{1294, 2}}, effect = CONST_ME_HITAREA, profession = "quarry"},
    [1359] = {tool = 2422, skill = 0, loot = {{1294, 2}}, effect = CONST_ME_HITAREA, profession = "quarry"},
    [1358] = {tool = 2422, skill = 0, loot = {{1294, 2}}, effect = CONST_ME_HITAREA, profession = "quarry"},
    [386] = {tool = 2422, skill = 0, loot = {{1294, 2}}, effect = CONST_ME_HITAREA, profession = "quarry"},
    [1356] = {tool = 2422, skill = 0, loot = {{1294, 2}}, effect = CONST_ME_HITAREA, profession = "quarry"},
    [1285] = {tool = 2422, skill = 0, loot = {{1294, 2}}, effect = CONST_ME_HITAREA, profession = "quarry"},
    [3653] = {tool = 2422, skill = 0, loot = {{1294, 2}, {2146, 2}, {9970, 2}}, effect = CONST_ME_HITAREA, profession = "quarry"},
    [3654] = {tool = 2422, skill = 0, loot = {{1294, 2}, {2146, 2}, {9970, 2}}, effect = CONST_ME_HITAREA, profession = "quarry"},
    [3655] = {tool = 2422, skill = 0, loot = {{1294, 2}, {2146, 2}, {9970, 2}}, effect = CONST_ME_HITAREA, profession = "quarry"},
    [3656] = {tool = 2422, skill = 0, loot = {{1294, 2}, {2146, 2}, {9970, 2}}, effect = CONST_ME_HITAREA, profession = "quarry"},
    [3648] = {tool = 2422, skill = 50, loot = {{2149, 2}, {2146, 2}, {9970, 2}}, effect = CONST_ME_HITAREA, profession = "quarry"},
    [3649] = {tool = 2422, skill = 50, loot = {{2149, 2}, {2146, 2}, {9970, 2}}, effect = CONST_ME_HITAREA, profession = "quarry"},
    [3650] = {tool = 2422, skill = 50, loot = {{2149, 2}, {2146, 2}, {9970, 2}}, effect = CONST_ME_HITAREA, profession = "quarry"},
    [3651] = {tool = 2422, skill = 50, loot = {{2149, 2}, {2146, 2}, {9970, 2}}, effect = CONST_ME_HITAREA, profession = "quarry"},
    [3652] = {tool = 2422, skill = 50, loot = {{2149, 2}, {2146, 2}, {9970, 2}}, effect = CONST_ME_HITAREA, profession = "quarry"},
    --tier 2
    [5868] = {tool = 2422, skill = 200, loot = {{2149, 2}, {2146, 2}, {9970, 2}}, effect = CONST_ME_HITAREA, profession = "quarry"},
    [5867] = {tool = 2422, skill = 200, loot = {{5889, 1}, {2146, 2}, {9970, 2}}, effect = CONST_ME_HITAREA, profession = "quarry"},
    [5866] = {tool = 2422, skill = 300, loot = {{5892, 1}, {2149, 2}, {2147, 2}, {9970, 2}}, effect = CONST_ME_HITAREA, profession = "quarry"},
    [5753] = {tool = 2422, skill = 350, loot = {{5888, 1}, {2150, 2}, {2146,2 }, {9970, 2}, {2156, 1}}, effect = CONST_ME_HITAREA, profession = "quarry"},
    [5751] = {tool = 2422, skill = 400, loot = {{5887, 1}, {2149, 2}, {2147, 2}, {9970, 2}, {2158, 1}}, effect = CONST_ME_HITAREA, profession = "quarry"},
    [3608] = {tool = 2422, skill = 0, loot = {{5887, 1}, {2149, 2}, {2147, 2}, {9970, 2}, {2158, 1}}, effect = CONST_ME_HITAREA, profession = "quarry"},
    [3609] = {tool = 2422, skill = 400, loot = {{5887, 1}, {2149, 2}, {2147, 2}, {9970, 2}, {2158, 1}}, effect = CONST_ME_HITAREA, profession = "quarry"},
    [3615] = {tool = 2422, skill = 400, loot = {{5887, 1}, {2149, 2}, {2147, 2}, {9970, 2}, {2158, 1}}, effect = CONST_ME_HITAREA, profession = "quarry"},
    [3616] = {tool = 2422, skill = 400, loot = {{5887, 1}, {2149, 2}, {2147, 2}, {9970, 2}, {2158, 1}}, effect = CONST_ME_HITAREA, profession = "quarry"},
    [3666] = {tool = 2422, skill = 400, loot = {{5887, 1}, {2149, 2}, {2147, 2}, {9970, 2}, {2158, 1}}, effect = CONST_ME_HITAREA, profession = "quarry"},
    [3667] = {tool = 2422, skill = 400, loot = {{5887, 1}, {2149, 2}, {2147, 2}, {9970, 2}, {2158, 1}}, effect = CONST_ME_HITAREA, profession = "quarry"},
    --mossy
    [3632] = {tool = 2422, skill = 400, loot = {{5887, 1}, {2149, 2}, {2147, 2}, {9970, 2}, {2158, 1}}, effect = CONST_ME_HITAREA, profession = "quarry"},
    [3633] = {tool = 2422, skill = 400, loot = {{5887, 1}, {2149, 2}, {2147, 2}, {9970, 2}, {2158, 1}}, effect = CONST_ME_HITAREA, profession = "quarry"},
    [3634] = {tool = 2422, skill = 400, loot = {{5887, 1}, {2149, 2}, {2147, 2}, {9970, 2}, {2158, 1}}, effect = CONST_ME_HITAREA, profession = "quarry"},
    [3636] = {tool = 2422, skill = 400, loot = {{5887, 1}, {2149, 2}, {2147, 2}, {9970, 2}, {2158, 1}}, effect = CONST_ME_HITAREA, profession = "quarry"},
    --ore miner (minerals, metals)
    --tier 1 copper
    [12792] = {tool = 12722, skill = 1, loot = {{12798, 1}, {2148, 20}}, effect = CONST_ME_HITAREA, profession = "mining"},
    [12793] = {tool = 12722, skill = 1, loot = {{12798, 1}, {2148, 20}}, effect = CONST_ME_HITAREA, profession = "mining"},
    [390] = {tool = 2553, skill = 0, loot = {{5887, 1}, {2149, 2}, {2147, 2}, {9970, 2}, {2158, 1}}, effect = CONST_ME_HITAREA, profession = "mining"},
    [12794] = {tool = 12722, skill = 1, loot = {{12798, 1}, {2148, 20}}, effect = CONST_ME_HITAREA, profession = "mining"},
    [12795] = {tool = 12722, skill = 1, loot = {{12798, 2}, {2148, 20}}, effect = CONST_ME_HITAREA, profession = "mining"},
    [12796] = {tool = 12722, skill = 1, loot = {{12798, 2}, {2148, 20}}, effect = CONST_ME_HITAREA, profession = "mining"},
    --tier2 silver
    [12775] = {tool = 12723, skill = 25, loot = {{12804, 1}, {2148, 20}, {2152, 1}}, effect = CONST_ME_HITAREA, profession = "mining"},
    [12776] = {tool = 12723, skill = 25, loot = {{12804, 1}, {2148, 20}, {2152, 1}}, effect = CONST_ME_HITAREA, profession = "mining"},
    [12777] = {tool = 12723, skill = 25, loot = {{12804, 1}, {2148, 20}, {2152, 1}}, effect = CONST_ME_HITAREA, profession = "mining"},
    [12778] = {tool = 12723, skill = 25, loot = {{12804, 2}, {2148, 20}, {2152, 1}}, effect = CONST_ME_HITAREA, profession = "mining"},
    [12779] = {tool = 12723, skill = 25, loot = {{12804, 2}, {2148, 20}, {2152, 1}}, effect = CONST_ME_HITAREA, profession = "mining"},
    [12780] = {tool = 12723, skill = 25, loot = {{12804, 2}, {2148, 20}, {2152, 1}}, effect = CONST_ME_HITAREA, profession = "mining"},
    [12781] = {tool = 12723, skill = 25, loot = {{12804, 2}, {2148, 20}, {2152, 1}}, effect = CONST_ME_HITAREA, profession = "mining"},
    --tier 3 -mithril
    [12753] = {tool = 12724, skill = 50, loot = {{12801, 1}, {2148, 20}, {2152, 10}}, effect = CONST_ME_HITAREA, profession = "mining"},
    [12752] = {tool = 12724, skill = 50, loot = {{12801, 1}, {2148, 20}, {2152, 10}}, effect = CONST_ME_HITAREA, profession = "mining"},
    [12753] = {tool = 12724, skill = 50, loot = {{12801, 1}, {2148, 20}, {2152, 10}}, effect = CONST_ME_HITAREA, profession = "mining"},
    [12754] = {tool = 12724, skill = 50, loot = {{12801, 1}, {2148, 20}, {2152, 10}}, effect = CONST_ME_HITAREA, profession = "mining"},
    [12755] = {tool = 12724, skill = 50, loot = {{12801, 1}, {2148, 20}, {2152, 10}}, effect = CONST_ME_HITAREA, profession = "mining"},
    [12756] = {tool = 12724, skill = 50, loot = {{12801, 2}, {2148, 20}, {2152, 10}}, effect = CONST_ME_HITAREA, profession = "mining"},
    [12757] = {tool = 12724, skill = 50, loot = {{12801, 2}, {2148, 20}, {2152, 10}}, effect = CONST_ME_HITAREA, profession = "mining"},
    [12758] = {tool = 12724, skill = 50, loot = {{12801, 2}, {2148, 20}, {2152, 10}}, effect = CONST_ME_HITAREA, profession = "mining"},
    [12759] = {tool = 12724, skill = 50, loot = {{12801, 2}, {2148, 20}, {2152, 10}}, effect = CONST_ME_HITAREA, profession = "mining"},
}

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

     if math.random(200) == 200 then
        rand = math.random(5)
        if rand == 1 then
            doSendMagicEffect(toPosition, CONST_ME_HITAREA)
            doCreatureSay(cid, "You have disturbed some bats!", TALKTYPE_ORANGE_1, cid)
            monsters = math.random(2)
            for i = 1, monsters do
                doCreateMonster("bat", getThingPos(cid))
            end
        elseif rand == 2 then
            doSendMagicEffect(toPosition, CONST_ME_HITAREA)
            doCreatureSay(cid, "You knocked a wasps nest out of the tree!", TALKTYPE_ORANGE_1, cid)
            monsters = math.random(4)
            for i = 1, monsters do
                doCreateMonster("wasp", getThingPos(cid))
            end
        elseif rand == 3 then
            doSendMagicEffect(toPosition, CONST_ME_HITAREA)
            doCreatureSay(cid, "An angry squirrel throws an acorn at you.", TALKTYPE_ORANGE_1, cid)
            doCreateItem(11213, 1, getThingPos(cid)) -- acorn
            doSendMagicEffect(getThingPos(cid), CONST_ME_DRAWBLOOD)
            health = math.random(getCreatureMaxHealth(cid)/10*2, getCreatureMaxHealth(cid)/10*6)
            if getCreatureHealth(cid) > health then
                doCreatureAddHealth(cid, -(health))
            else
                doCreatureAddHealth(cid, -(getCreatureHealth(cid) - math.random(10)))
            end
            --angry squirrel acorn
        elseif rand == 4 then
            doCreatureSay(cid, "Lucky day! A bag of coins falls out of the tree.", TALKTYPE_ORANGE_1, cid)
            doSendMagicEffect(toPosition, CONST_ME_BLOCKHIT)
            bag = doCreateItem(1987, 1, toPosition)
            doAddContainerItem(bag, 2148, math.random(50))
        elseif rand == 5 then
            doCreatureSay(cid, "You found a birds nest and steal some eggs.", TALKTYPE_ORANGE_1, cid)
            doPlayerAddItem(cid, 2695, math.random(2, 6), true) -- eggs
        end
        return true
    end
  
    local index = {}
    for k, v in pairs(recipes) do
        index[#index+1] = k
    end

    local pos = {x = toPosition.x, y = toPosition.y, z = toPosition.z}
    for i = 1, 255 do
        local check_pos = {x = pos.x, y = pos.y, z = pos.z, stackpos = i}
        local thing = getThingFromPos(check_pos).itemid
        if thing < 1 then
            return true
        elseif isInArray(index, thing) then
            itemEx = getTileItemById(toPosition, thing)
            break
        end
    end

    if recipes[itemEx.itemid] then

        lootTable = {}
        lootName = "You recive: "
        local professionSkill = getPlayerStorageValue(cid, professions[recipes[itemEx.itemid].profession].storage)
        itemPos = getThingPos(itemEx.uid)
        if professionSkill < 1 then
            professionSkill = 1
        end
        if item.itemid == recipes[itemEx.itemid].tool then
            if professionSkill >= recipes[itemEx.itemid].skill then
            local R = math.random(professionSkill,500)
            --print ("chance to success "..R.."/400")
                if item.actionid ~= 5001 then             
                     if R >= 400 and R <= 500 then
                     local c1 = getPlayerStorageValue(cid, professions[recipes[itemEx.itemid].profession].storage)
                    local S = math.random(0, c1*1.15)
                    --print ("chance to lvl ".. S .."")
                    --print ("current level ".. c1 .."")
                        if S >= c1-1 then
                            if professionSkill < professions[recipes[itemEx.itemid].profession].maxSkill then
                                setPlayerStorageValue(cid, professions[recipes[itemEx.itemid].profession].storage, professionSkill + 1)
                                doPlayerSendTextMessage(cid, MESSAGE_EVENT_ADVANCE, "You advanced in "..recipes[itemEx.itemid].profession.." ["..professionSkill.."].")
                                end
                            end                      
        addEvent (function()
                doTransformItem(getThingfromPos(toPosition).uid, itemEx.itemid)  
        end, 60*1000)
      
                     if recipes[itemEx.itemid].profession == "herbalism" then
                     doTransformItem(getThingfromPos(toPosition).uid, grass[math.random(#grass)])
                        doSendMagicEffect(itemPos, recipes[itemEx.itemid].effect)
                        end
                        if R >= 400 and R <= 500 and recipes[itemEx.itemid].profession == "lumberjack" then
                            doSendMagicEffect(itemPos, recipes[itemEx.itemid].effect)
                            doTransformItem(getThingfromPos(toPosition).uid, stumps[math.random(#stumps)])
                                else if R >= 400 and R <= 500 and recipes[itemEx.itemid].profession == "mining" then
                                doSendMagicEffect(itemPos, recipes[itemEx.itemid].effect)
                                doTransformItem(getThingfromPos(toPosition).uid, rocks[math.random(#rocks)])
                    end

                        end
                        repeat
                            if #recipes[itemEx.itemid].loot == 0 then
                                break
                            end
                            for i = 1, #recipes[itemEx.itemid].loot do
                            local L = math.random(professionSkill,500)
                            --print("loot " .. L .. "")
                                if L >= 100 and R <= 500 then
                                    table.insert(lootTable, (recipes[itemEx.itemid].loot)[i])
                                end
                            end
                        until lootTable ~= {}
                        for i = 1, #lootTable do
                        --lootTable[i][2]
                            lootCount = math.random(1,math.ceil(professionSkill/250))
                            doPlayerAddItem(cid, lootTable[i][1], lootCount)
                            if i == #lootTable then
                                lootName = lootName..""..lootCount.."x ".. getItemNameById(lootTable[i][1]) .."."
                            else
                                lootName = lootName..""..lootCount.."x ".. getItemNameById(lootTable[i][1]) ..", "
                            end
                        end
                        if lootName == "You recive: " then
                            lootName = "You don't recive any loot."
                        end
                        doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, lootName)
                    else
                        doSendMagicEffect(itemPos, CONST_ME_BLOCKHIT)
                    end
                else
                    doSendMagicEffect(itemPos, CONST_ME_BLOCKHIT)
                    doCreatureSay(cid, "This tree was cut recenlty by someone else!", TALKTYPE_ORANGE_1)
                end
            else
                doSendMagicEffect(getPlayerPosition(cid), CONST_ME_POFF)
                doCreatureSay(cid, "You have to be at least skill ".. recipes[itemEx.itemid].skill  .." in ".. recipes[itemEx.itemid].profession .." to do that!", TALKTYPE_ORANGE_1)
        end
        else
            doSendMagicEffect(getPlayerPosition(cid), CONST_ME_BLOCKHIT)
            doCreatureSay(cid, "You need a "..getItemNameById(recipes[itemEx.itemid].tool).."!", TALKTYPE_ORANGE_1)
        end
    end
    return true
end
    ]]></action>
</mod>
change all

doTransformItem(getThingfromPos(toPosition).uid
to
doTransformItem(itemEx.uid
 
Solution
Back
Top