• 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+ Help with script

Piquenoelmal

I'm in an eternal depression
Joined
Dec 1, 2009
Messages
31
Reaction score
8
Location
São Paulo
Hello!

I'm using a simple script for mining. I made some changes and it's possible to use a Pick in a rock(1295), then the rock turns to debris and you gather an item.

My problem here is that the rock that turn to debris doesn't re spawn again, even when I made a function to do so. And the other problem is that the skill("club" for now), doesn't receive the exp(tries) to it.

Here is the code.
Lua:
local config = {
    stones = {1285},
    t = {
        [{1, 100}] = {tree = 1285}
    },
    level = 20, skill = SKILL_CLUB, skillReq = 15, effect = CONST_ME_BLOCKHIT, addTries = 100, debris = 1336, msgType = MESSAGE_EVENT_ADVANCE, soul = 1, minutes = 0
}

local t = {
    [{1, 10000}] = {msg = "You mined an Iron Ore.", item = 5880, amountmax = 3},
    --[{101, 200}] = {msg = "Your pick broke...", destroy = true}
}

local function newStones(parameter)
    local stone = getThingfromPos{x = parameter.position.x, y = parameter.position.y, z = parameter.position.z, stackpos = 1}

    for i2, k2 in pairs(config.t) do
        local v2 = math.random(1500), 1, nil
        if v2 >= i2[1] and v2 <= i2[2] then
            if k2.stone then
                if (stone.itemid == config.debris) then
                    doTransformItem(stone.uid, k2.stone)
                end
            end
        end  
    end
end

function onUse(cid, item, fromPosition, itemEx, toPosition)
    if isInArray(config.stones, itemEx.itemid) and config.level <= getPlayerLevel(cid) and config.skillReq <= getPlayerSkill(cid, config.skill) and config.soul <= getPlayerSoul(cid) then
        local v, amount, damage = math.random(2000), 1, nil
        for i, k in pairs(t) do
            if v >= i[1] and v <= i[2] then
                if k.destroy then
                    doRemoveItem(item.uid)
                end
                if k.item then
                    if k.amountmax then
                        amount = math.random(k.amountmax)
                    end
                    doPlayerAddItem(cid, k.item, amount)
                end
                if k.msg then
                    local msg = k.msg
                    doPlayerSendTextMessage(cid, config.msgType, msg)
                end

                addEvent(newStones, config.minutes*60*1000, {position = toPosition, cid = cid})
                doTransformItem(itemEx.uid, config.debris)
                doPlayerAddSoul(cid, -config.soul)
                doSendMagicEffect(toPosition, k.destroy and CONST_ME_HITAREA or config.effect)
                return doPlayerAddSkillTry(cid, config.skill, config.addTries)
            end
        end
    end

    return doPlayerSendCancel(cid, "It's not possible.")
end
 
Last edited:
Solution
So, my idea is to make a crafting system. Players gathers ore to transform in ingots to forge armors, weapons, etc...

I tested the scripted and waited like, 15-25 minutes, changed the 'minutes' variable, tried to disable the 'if' conditions, but the stones will not respawn haha that's sad. :(

The only thing that I have to do is make the script and register in the actions.xml, right?
Yeah, and whatever 'tool' your using must have the 'use with' command available.

Try using some prints, and see what happens in console.
Lua:
local config = {
    level = 20,
    skill = SKILL_CLUB,
    skillReq = 15,
    effect = CONST_ME_BLOCKHIT,
    addTries = 100,
    debris = 1336,
    msgType = MESSAGE_EVENT_ADVANCE,
    soul = 1,
    minutes =...
Hello!

I'm using a simple script for mining. I made some changes and it's possible to use a Pick in a rock(1295), then the rock turns to debris and you gather an item.

My problem here is that the rock that turn to debris doesn't re spawn again, even when I made a function to do so. And the other problem is that the skill("axe" for now), doesn't receive the exp(tries) to it.

Here is the code.
Lua:
local config = {
    stones = {1285},
    t = {
        [{1, 100}] = {tree = 1285}
    },
    level = 20, skill = SKILL_CLUB, skillReq = 15, effect = CONST_ME_BLOCKHIT, addTries = 100, debris = 1336, msgType = MESSAGE_EVENT_ADVANCE, soul = 1, minutes = 0
}

local t = {
    [{1, 10000}] = {msg = "You mined an Iron Ore.", item = 5880, amountmax = 3},
    --[{101, 200}] = {msg = "Your pick broke...", destroy = true}
}

local function newStones(parameter)
    local stone = getThingfromPos{x = parameter.position.x, y = parameter.position.y, z = parameter.position.z, stackpos = 1}

    for i2, k2 in pairs(config.t) do
        local v2 = math.random(1500), 1, nil
        if v2 >= i2[1] and v2 <= i2[2] then
            if k2.stone then
                if (stone.itemid == config.debris) then
                    doTransformItem(stone.uid, k2.stone)
                end
            end
        end 
    end
end

function onUse(cid, item, fromPosition, itemEx, toPosition)
    if isInArray(config.stones, itemEx.itemid) and config.level <= getPlayerLevel(cid) and config.skillReq <= getPlayerSkill(cid, config.skill) and config.soul <= getPlayerSoul(cid) then
        local v, amount, damage = math.random(2000), 1, nil
        for i, k in pairs(t) do
            if v >= i[1] and v <= i[2] then
                if k.destroy then
                    doRemoveItem(item.uid)
                end
                if k.item then
                    if k.amountmax then
                        amount = math.random(k.amountmax)
                    end
                    doPlayerAddItem(cid, k.item, amount)
                end
                if k.msg then
                    local msg = k.msg
                    doPlayerSendTextMessage(cid, config.msgType, msg)
                end

                addEvent(newStones, config.minutes*60*1000, {position = toPosition, cid = cid})
                doTransformItem(itemEx.uid, config.debris)
                doPlayerAddSoul(cid, -config.soul)
                doSendMagicEffect(toPosition, k.destroy and CONST_ME_HITAREA or config.effect)
                return doPlayerAddSkillTry(cid, config.skill, config.addTries)
            end
        end
    end

    return doPlayerSendCancel(cid, "It's not possible.")
end
Lua:
if k2.stone then
    ......
        doTransformItem(........, k2.stone)
stone doesn't appear in your t table.
If you check your console, it would probably tell you an error about it being a nil value.

---
No idea about the skill tries not working.
(Although you are bringing up the CLUB value not axe.. so maybe that's the problem?)
 
Thanks for the answer.

I changed the axe for club and changed the table(it was 'tree' instead of 'stone').

k2 is a nil value, so I try pass the k value. In this way, will it work?
Lua:
doTransformItem(itemEx.uid, config.debris, k.stone)

Edit: I don't know why but the skill system is capping at 30. What should I change in order to continue getting skill?
 
Last edited:
Thanks for the answer.

I changed the axe for club and changed the table(it was 'tree' instead of 'stone').

k2 is a nil value, so I try pass the k value. In this way, will it work?
Lua:
doTransformItem(itemEx.uid, config.debris, k.stone)

Edit: I don't know why but the skill system is capping at 30. What should I change in order to continue getting skill?
Windows - Skills get very slow at low levels.
[TFS 0.3.6] Star skills problem

For the skill cap thing, check my answers in the threads above.

---
For the script, can you post your current version?
 
So, it is pretty much the same. Just put the function newStones() inside the main function and change some names. Stills, the rocks doesn't spawn. :(

Mining Code
Lua:
local config = {
    stones = {1285},

    t = {
        [{1, 10000}] = {stone = 1285}
    },

    level = 20, skill = SKILL_CLUB, skillReq = 15, effect = CONST_ME_BLOCKHIT, addTries = 100, debris = 1336, msgType = MESSAGE_EVENT_ADVANCE, soul = 1, minutes = 5
}
local t = {
    [{1, 10000}] = {msg = "You mined an Iron Ore.", item = 5880, amountmax = 3}
}
function onUse(cid, item, fromPosition, itemEx, toPosition)
    if isInArray(config.stones, itemEx.itemid) and config.level <= getPlayerLevel(cid) and config.skillReq <= getPlayerSkill(cid, config.skill) and config.soul <= getPlayerSoul(cid) then
        local v, amount, damage = math.random(3000), 1, nil
        for i, k in pairs(t) do
            if v >= i[1] and v <= i[2] then
                if k.destroy then
                    doRemoveItem(item.uid)
                end
                if k.item then
                    if k.amountmax then
                        amount = math.random(k.amountmax)
                    end
                    doPlayerAddItem(cid, k.item, amount)
                end
                if k.msg then
                    local msg = k.msg
                    doPlayerSendTextMessage(cid, config.msgType, msg)
                end

                local function newStones(parameter)
                    local stone = getThingfromPos{x = parameter.position.x, y = parameter.position.y, z = parameter.position.z, stackpos = 1}
                    for i2, k2 in pairs(config.t) do
                        local v2 = math.random(1500), 1, nil
                        if v2 >= i2[1] and v2 <= i2[2] then
                            if k2.stone then
                                if (stone.itemid == config.debris) then
                                    doTransformItem(stone.uid, k2.stone)
                                end
                            end
                        end
                    end
                end
                addEvent(newStones, config.minutes*60*1000, {position = toPosition, cid = cid})
                doTransformItem(itemEx.uid, config.debris)
                doPlayerAddSoul(cid, -config.soul)
                doSendMagicEffect(toPosition, k.destroy and CONST_ME_HITAREA or config.effect)
                return doPlayerAddSkillTry(cid, config.skill, config.addTries)
            end
        end
    end
    return doPlayerSendCancel(cid, "It's not possible.")
end

The strange thing is that a change another script for wood cutting and in this one the tree spawns normally.

Lumberjacking
Lua:
local config = {
    trees = {2701},

    t = {
        [{1, 10000}] = {tree = 2701}
    },

    level = 15, skill = SKILL_AXE, skillReq = 10, effect = CONST_ME_BLOCKHIT, addTries = 100, branches = 6432, msgType = MESSAGE_EVENT_ADVANCE, soul = 3, minutes = 5
}
local t = {
    [{1, 10000}] = {msg = "You choped the tree and got some wood", item = 5901, amountmax = 3}
}
function onUse(cid, item, fromPosition, itemEx, toPosition)
    if isInArray(config.trees, itemEx.itemid) and config.level <= getPlayerLevel(cid) and config.skillReq <= getPlayerSkill(cid, config.skill) and config.soul <= getPlayerSoul(cid) then
        local v, amount, damage = math.random(3000), 1, nil
        for i, k in pairs(t) do
            if v >= i[1] and v <= i[2] then
                if k.destroy then
                    doRemoveItem(item.uid)
                end
                if k.item then
                    if k.amountmax then
                        amount = math.random(k.amountmax)
                    end
                    doPlayerAddItem(cid, k.item, amount)
                end
                if k.msg then
                    local msg = k.msg
                    doPlayerSendTextMessage(cid, config.msgType, msg)
                end
             
                local function newTrees(parameter)
                    local tree = getThingfromPos{x = parameter.position.x, y = parameter.position.y, z = parameter.position.z, stackpos = 1}
                    for i2, k2 in pairs(config.t) do
                        local v2 = math.random(1500), 1, nil
                        if v2 >= i2[1] and v2 <= i2[2] then
                            if k2.tree then
                                if (tree.itemid == config.branches) then
                                    doTransformItem(tree.uid, k2.tree)
                                end
                            end
                        end  
                    end
                end

                addEvent(newTrees, config.minutes*60*1000, {position = toPosition, cid = cid})
                doTransformItem(itemEx.uid, config.branches)
                doPlayerAddSoul(cid, -config.soul)
                doSendMagicEffect(toPosition, k.destroy and CONST_ME_HITAREA or config.effect)
                return doPlayerAddSkillTry(cid, config.skill, config.addTries)
            end
        end
  end
 
    return doPlayerSendCancel(cid, "It's not possible.")
end

Don't know what is happening. haha
 
So, it is pretty much the same. Just put the function newStones() inside the main function and change some names. Stills, the rocks doesn't spawn. :(

Mining Code
Lua:
local config = {
    stones = {1285},

    t = {
        [{1, 10000}] = {stone = 1285}
    },

    level = 20, skill = SKILL_CLUB, skillReq = 15, effect = CONST_ME_BLOCKHIT, addTries = 100, debris = 1336, msgType = MESSAGE_EVENT_ADVANCE, soul = 1, minutes = 5
}
local t = {
    [{1, 10000}] = {msg = "You mined an Iron Ore.", item = 5880, amountmax = 3}
}
function onUse(cid, item, fromPosition, itemEx, toPosition)
    if isInArray(config.stones, itemEx.itemid) and config.level <= getPlayerLevel(cid) and config.skillReq <= getPlayerSkill(cid, config.skill) and config.soul <= getPlayerSoul(cid) then
        local v, amount, damage = math.random(3000), 1, nil
        for i, k in pairs(t) do
            if v >= i[1] and v <= i[2] then
                if k.destroy then
                    doRemoveItem(item.uid)
                end
                if k.item then
                    if k.amountmax then
                        amount = math.random(k.amountmax)
                    end
                    doPlayerAddItem(cid, k.item, amount)
                end
                if k.msg then
                    local msg = k.msg
                    doPlayerSendTextMessage(cid, config.msgType, msg)
                end

                local function newStones(parameter)
                    local stone = getThingfromPos{x = parameter.position.x, y = parameter.position.y, z = parameter.position.z, stackpos = 1}
                    for i2, k2 in pairs(config.t) do
                        local v2 = math.random(1500), 1, nil
                        if v2 >= i2[1] and v2 <= i2[2] then
                            if k2.stone then
                                if (stone.itemid == config.debris) then
                                    doTransformItem(stone.uid, k2.stone)
                                end
                            end
                        end
                    end
                end
                addEvent(newStones, config.minutes*60*1000, {position = toPosition, cid = cid})
                doTransformItem(itemEx.uid, config.debris)
                doPlayerAddSoul(cid, -config.soul)
                doSendMagicEffect(toPosition, k.destroy and CONST_ME_HITAREA or config.effect)
                return doPlayerAddSkillTry(cid, config.skill, config.addTries)
            end
        end
    end
    return doPlayerSendCancel(cid, "It's not possible.")
end

The strange thing is that a change another script for wood cutting and in this one the tree spawns normally.

Lumberjacking
Lua:
local config = {
    trees = {2701},

    t = {
        [{1, 10000}] = {tree = 2701}
    },

    level = 15, skill = SKILL_AXE, skillReq = 10, effect = CONST_ME_BLOCKHIT, addTries = 100, branches = 6432, msgType = MESSAGE_EVENT_ADVANCE, soul = 3, minutes = 5
}
local t = {
    [{1, 10000}] = {msg = "You choped the tree and got some wood", item = 5901, amountmax = 3}
}
function onUse(cid, item, fromPosition, itemEx, toPosition)
    if isInArray(config.trees, itemEx.itemid) and config.level <= getPlayerLevel(cid) and config.skillReq <= getPlayerSkill(cid, config.skill) and config.soul <= getPlayerSoul(cid) then
        local v, amount, damage = math.random(3000), 1, nil
        for i, k in pairs(t) do
            if v >= i[1] and v <= i[2] then
                if k.destroy then
                    doRemoveItem(item.uid)
                end
                if k.item then
                    if k.amountmax then
                        amount = math.random(k.amountmax)
                    end
                    doPlayerAddItem(cid, k.item, amount)
                end
                if k.msg then
                    local msg = k.msg
                    doPlayerSendTextMessage(cid, config.msgType, msg)
                end
            
                local function newTrees(parameter)
                    local tree = getThingfromPos{x = parameter.position.x, y = parameter.position.y, z = parameter.position.z, stackpos = 1}
                    for i2, k2 in pairs(config.t) do
                        local v2 = math.random(1500), 1, nil
                        if v2 >= i2[1] and v2 <= i2[2] then
                            if k2.tree then
                                if (tree.itemid == config.branches) then
                                    doTransformItem(tree.uid, k2.tree)
                                end
                            end
                        end 
                    end
                end

                addEvent(newTrees, config.minutes*60*1000, {position = toPosition, cid = cid})
                doTransformItem(itemEx.uid, config.branches)
                doPlayerAddSoul(cid, -config.soul)
                doSendMagicEffect(toPosition, k.destroy and CONST_ME_HITAREA or config.effect)
                return doPlayerAddSkillTry(cid, config.skill, config.addTries)
            end
        end
  end
 
    return doPlayerSendCancel(cid, "It's not possible.")
end

Don't know what is happening. haha
Are you sure your rock is on stackpos 1?
Check your console, is it not providing you with any errors?
 
No errors in the console, no warnings either.

After some tests, the trees spawns in random times, one spawns at 3:37 another in 45:55 o.o Don't know if I'm making the counts in the wrong way, but you have to transform minutes to milliseconds, right? Then minute(5 minutes in the example)*60*1000 = trees respawn time.

The rocks stand still in debris. If the stone is broken, it's stays in stackpos = 1, right? 1 level above the tile she is currently in.
That was my way to see it...
 
No errors in the console, no warnings either.

After some tests, the trees spawns in random times, one spawns at 3:37 another in 45:55 o.o Don't know if I'm making the counts in the wrong way, but you have to transform minutes to milliseconds, right? Then minute(5 minutes in the example)*60*1000 = trees respawn time.

The rocks stand still in debris. If the stone is broken, it's stays in stackpos = 1, right? 1 level above the tile she is currently in.
That was my way to see it...
Not sure what to say.
I'd try adding prints everywhere and find out what's going wrong where.
Everything looks like it's 'working', and with no errors to go by, it's probably something that is being filtered or run unexpectedly.
Code:
print(config.debris)
print(stone.itemid)
print(stone.uid)

Couple of things that I would change or look at regardless of what else happens..
damage isn't being used.
k.destroy isn't being used. (2 places)
When you call the function 'newStones' you are sending cid as a parameter, but never use it.
v2 is being assigned 2 extra variables that won't exist.
v2's math.random seems pointless, as from your script it looks like you are wanting the stone/tree to reappear after X time.
-> But if you are wanting it to spawn at a random interval, you'd either want to calculate the interval beforehand, or you'd want the function to call itself repeatedly on a timer until the expected outcome (restoring the rock) actually achieves itself.
-> If it's the latter, there is no point in naming the function, just keep it as an anonymous function inside of the addEvent.
Lua:
addEvent (
    function ()
        -- do stuff 
    end, timer
)
 
Ok, I made some changes in the code, it seems 'clear' now. But, I'm very newbie in .lua. Could you see if this is the right way to use the timer?

Lua:
local config = {
    stones = {1285},
    t = {[{1, 10000}] = {stone = 1285}},
    level = 20, skill = SKILL_CLUB, skillReq = 15, effect = CONST_ME_BLOCKHIT, addTries = 100, debris = 1336, msgType = MESSAGE_EVENT_ADVANCE, soul = 1, minutes = 1
}
local t = {[{1, 10000}] = {msg = "You mined an Iron Ore.", item = 5880, amountmax = 3}}
function onUse(cid, item, fromPosition, itemEx, toPosition)
    if isInArray(config.stones, itemEx.itemid) and config.level <= getPlayerLevel(cid) and config.skillReq <= getPlayerSkill(cid, config.skill) and config.soul <= getPlayerSoul(cid) then
        local v, amount = math.random(3000), 1
        for i, k in pairs(t) do
            if v >= i[1] and v <= i[2] then
                if k.item then
                    if k.amountmax then
                        amount = math.random(k.amountmax)
                    end
                    doPlayerAddItem(cid, k.item, amount)
                end
                if k.msg then
                    local msg = k.msg
                    doPlayerSendTextMessage(cid, config.msgType, msg)
                end
                addEvent(
                    function ()
                        local stone = getThingfromPos{x = parameter.position.x, y = parameter.position.y, z = parameter.position.z, stackpos = 1}
                        for i2, k2 in pairs(config.t) do
                            local v2 = 1
                            if v2 >= i2[1] and v2 <= i2[2] then
                                if k2.stone then
                                    if (stone.itemid == config.debris) then
                                        doTransformItem(stone.uid, k2.stone)
                                    end
                                end
                            end
                        end
                    end, config.minutes*60*1000, {position = toPosition}
                )

                doTransformItem(itemEx.uid, config.debris)
                doPlayerAddSoul(cid, -config.soul)
                doSendMagicEffect(toPosition, k.destroy and CONST_ME_HITAREA or config.effect)
                return doPlayerAddSkillTry(cid, config.skill, config.addTries)
            end
        end
    end
    return doPlayerSendCancel(cid, "It's not possible.")
end

After this changes, the console returns me a error that I put in the image below.

Thanks again!

D8W0vDL
 

Attachments

Ok, I made some changes in the code, it seems 'clear' now. But, I'm very newbie in .lua. Could you see if this is the right way to use the timer?

Lua:
local config = {
    stones = {1285},
    t = {[{1, 10000}] = {stone = 1285}},
    level = 20, skill = SKILL_CLUB, skillReq = 15, effect = CONST_ME_BLOCKHIT, addTries = 100, debris = 1336, msgType = MESSAGE_EVENT_ADVANCE, soul = 1, minutes = 1
}
local t = {[{1, 10000}] = {msg = "You mined an Iron Ore.", item = 5880, amountmax = 3}}
function onUse(cid, item, fromPosition, itemEx, toPosition)
    if isInArray(config.stones, itemEx.itemid) and config.level <= getPlayerLevel(cid) and config.skillReq <= getPlayerSkill(cid, config.skill) and config.soul <= getPlayerSoul(cid) then
        local v, amount = math.random(3000), 1
        for i, k in pairs(t) do
            if v >= i[1] and v <= i[2] then
                if k.item then
                    if k.amountmax then
                        amount = math.random(k.amountmax)
                    end
                    doPlayerAddItem(cid, k.item, amount)
                end
                if k.msg then
                    local msg = k.msg
                    doPlayerSendTextMessage(cid, config.msgType, msg)
                end
                addEvent(
                    function ()
                        local stone = getThingfromPos{x = parameter.position.x, y = parameter.position.y, z = parameter.position.z, stackpos = 1}
                        for i2, k2 in pairs(config.t) do
                            local v2 = 1
                            if v2 >= i2[1] and v2 <= i2[2] then
                                if k2.stone then
                                    if (stone.itemid == config.debris) then
                                        doTransformItem(stone.uid, k2.stone)
                                    end
                                end
                            end
                        end
                    end, config.minutes*60*1000, {position = toPosition}
                )

                doTransformItem(itemEx.uid, config.debris)
                doPlayerAddSoul(cid, -config.soul)
                doSendMagicEffect(toPosition, k.destroy and CONST_ME_HITAREA or config.effect)
                return doPlayerAddSkillTry(cid, config.skill, config.addTries)
            end
        end
    end
    return doPlayerSendCancel(cid, "It's not possible.")
end

After this changes, the console returns me a error that I put in the image below.

Thanks again!

D8W0vDL
I took a few guesses on what you were wanting to do.

Try this. ¯\_(ツ)_/¯
Lua:
local config = {
    level = 20,
    skill = SKILL_CLUB,
    skillReq = 15,
    effect = CONST_ME_BLOCKHIT,
    addTries = 100,
    debris = 1336,
    msgType = MESSAGE_EVENT_ADVANCE,
    soul = 1,
    minutes = 1
}

local stones = {
    [1285] = {item_id = 5880, amount_max = 3, chance = {1, 10000}, msg = "You mined an Iron Ore."}
}

local function resetStones(position, stone_id)
    local debris = getTileItemById(position, config.debris)
    doTransformItem(debris.uid, stone_id)
    return true
end

function onUse(cid, item, fromPosition, itemEx, toPosition)
    if getPlayerLevel(cid) < config.level then
        return doPlayerSendCancel(cid, "It's not possible.")
    end
    if getPlayerSkill(cid, config.skill) < config.skillReq then
        return doPlayerSendCancel(cid, "It's not possible.")
    end
    if getPlayerSoul(cid) < config.soul then
        return doPlayerSendCancel(cid, "It's not possible.")
    end
    local index = itemEx.itemid
    if stones[index] then
        local rand = math.random(10000)
        if rand >= stones[index].chance[1] and rand <= stones[index].chance[2] then
            doPlayerAddSoul(cid, -config.soul)
            local amount = math.random(stones[index].amount_max)
            doPlayerAddItem(cid, stones[index].item_id, amount)
            doPlayerAddSkillTry(cid, config.skill, config.addTries)
            doTransformItem(itemEx.uid, config.debris)
            addEvent(resetStones, config.minutes * 60 * 1000, index)
            doSendMagicEffect(toPosition, config.effect)
            doPlayerSendTextMessage(cid, config.msgType, stones[index].msg)
        end
    end
    return true
end

-- EDIT

Some small adjustments.
Reload page and re-copy.
 
Last edited:
So, my idea is to make a crafting system. Players gathers ore to transform in ingots to forge armors, weapons, etc...

I tested the scripted and waited like, 15-25 minutes, changed the 'minutes' variable, tried to disable the 'if' conditions, but the stones will not respawn haha that's sad. :(

The only thing that I have to do is make the script and register in the actions.xml, right?
 
So, my idea is to make a crafting system. Players gathers ore to transform in ingots to forge armors, weapons, etc...

I tested the scripted and waited like, 15-25 minutes, changed the 'minutes' variable, tried to disable the 'if' conditions, but the stones will not respawn haha that's sad. :(

The only thing that I have to do is make the script and register in the actions.xml, right?
Yeah, and whatever 'tool' your using must have the 'use with' command available.

Try using some prints, and see what happens in console.
Lua:
local config = {
    level = 20,
    skill = SKILL_CLUB,
    skillReq = 15,
    effect = CONST_ME_BLOCKHIT,
    addTries = 100,
    debris = 1336,
    msgType = MESSAGE_EVENT_ADVANCE,
    soul = 1,
    minutes = 1
}

local stones = {
    [1285] = {item_id = 5880, amount_max = 3, chance = {1, 10000}, msg = "You mined an Iron Ore."}
}

local function resetStones(position, stone_id)
    print(8)
    local debris = getTileItemById(position, config.debris)
    doTransformItem(debris.uid, stone_id)
    return true
end

function onUse(cid, item, fromPosition, itemEx, toPosition)
    print(1)
    if getPlayerLevel(cid) < config.level then
        print(2)
        return doPlayerSendCancel(cid, "It's not possible.")
    end
    if getPlayerSkill(cid, config.skill) < config.skillReq then
        print(3)
        return doPlayerSendCancel(cid, "It's not possible.")
    end
    if getPlayerSoul(cid) < config.soul then
        print(4)
        return doPlayerSendCancel(cid, "It's not possible.")
    end
    local index = itemEx.itemid
    print(index)
    if stones[index] then
        print(5)
        local rand = math.random(10000)
        print(rand)
        if rand >= stones[index].chance[1] and rand <= stones[index].chance[2] then
            print(6)
            doPlayerAddSoul(cid, -config.soul)
            local amount = math.random(stones[index].amount_max)
            doPlayerAddItem(cid, stones[index].item_id, amount)
            doPlayerAddSkillTry(cid, config.skill, config.addTries)
            doTransformItem(itemEx.uid, config.debris)
            addEvent(resetStones, config.minutes * 60 * 1000, toPosition, index)
            doSendMagicEffect(toPosition, config.effect)
            doPlayerSendTextMessage(cid, config.msgType, stones[index].msg)
        end
    end
    print(7)
    return true
end
 
Last edited:
Solution
Yep, pretty much everything that I did. Even create a new item, so didn't make duplicate register.

Everything is working fine, the only problem is the respawn.

EDIT--
Ok, will try the prints.
 
Yep, pretty much everything that I did. Even create a new item, so didn't make duplicate register.

Everything is working fine, the only problem is the respawn.

EDIT--
Ok, will try the prints.
I'm so sorry, I missed something.
Lua:
addEvent(resetStones, config.minutes * 60 * 1000, index)
change to this
Lua:
addEvent(resetStones, config.minutes * 60 * 1000, toPosition, index)
 
Back
Top