• 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!
  • If you're using Gesior 2012 or MyAAC, please review this thread for information about a serious security vulnerability and a fix.

Lua HELP TFS 1.4 MINING SYSTEM

VagosClubTM

Member
Joined
Aug 16, 2019
Messages
150
Reaction score
19
Location
Chile
Code:
local rewards = {
    { item = 8298, count = 1, chance = 50 },
    { item = 8299, count = 1, chance = 50 },
    { item = 8301, count = 1, chance = 50 },
    { item = 8302, count = 1, chance = 50 },
    { item = 8303, count = 1, chance = 50 },
    { item = 8310, count = 1, chance = 50 },
    { item = 9971, count = 1, chance = 50 },
    { item = 5944, count = 1, chance = 100 }
}

local storage = 5000
local delay_timer = 5

function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    
    local cur_time, cur_storage = os.time(), player:getStorageValue(storage)
 
    if cur_storage > cur_time then
        player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You can mining again in " .. os.date("!%Hh %Mm %Ss", cur_storage - cur_time) .. ".")
        return true
    end
    
    local function addbackstone()
    local stones = {5750, 5751, 5752, 5753, 5754}
    local stone = Game.createItem(stones[math.random(#stones)], 1, toPosition)
        stone:setActionId(40041)
    end
    
    if player:getLevel() < 10 then
        player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You dont have the required level of 10 to mining.")
        return true
    end
    
    if not target then
        return false
    end
    
    if not target:isItem() then
        return false
    end

    if target.actionid ~= 40041 then
    local pos = player:getPosition()
        player:sendTextMessage(MESSAGE_EVENT_ADVANCE, 'You cannot use it here.')
        return false
    end
    
    if target.actionid == 40041 then
    local ran = math.random(100)
        if ran <= 10 then
            toPosition:sendMagicEffect(3)
            target:remove()
            addEvent(addbackstone, 120000)
            return true
        end
    end
 
    local text = "You have found "
    for i = 1, #rewards do
        local rand = math.random(1000)
        if rand <= rewards[i].chance then
            player:addItem(rewards[i].item, rewards[i].count)
            if text ~= "You have found " then
                text = text .. ", "
            end
            text = text .. rewards[i].count .. " " .. ItemType(rewards[i].item):getName()
        end         
    end
    if text == "You have found " then
        text = text .. "nothing"
    end
    player:sendTextMessage(36, text .. ".")
    cur_time = cur_time + delay_timer
    player:setStorageValue(storage, cur_time)
    return true
end

hello friends, I would like to know if it is possible to add to this mining system, the option that if you manage to chop the stone, it gives you experience directly to the character.

Thank you very much in advance if someone takes the time to help me
 
OP
OP
VagosClubTM

VagosClubTM

Member
Joined
Aug 16, 2019
Messages
150
Reaction score
19
Location
Chile
Put player:addExperience(amount) somewhere near line 75 above return true
thanks bro it worked well, the other thing is it possible to add that the peak breaks in a certain percentage of probability?

that is, the player is chipping the stone and has a 15% chance that the chipping tool will break
 

Roddet

life.rbegin()
Joined
May 1, 2013
Messages
649
Solutions
64
Reaction score
392
Location
Mexico
thanks bro it worked well, the other thing is it possible to add that the peak breaks in a certain percentage of probability?

that is, the player is chipping the stone and has a 15% chance that the chipping tool will break

Add this above if target.actionid == 40041 then condition
Lua:
    local break_chance = 15
    if math.random(1, 100) <= break_chance then
        item:remove(1)
        player:getPosition():sendMagicEffect(CONST_ME_BLOCKHIT)
        player:sendTextMessage(MESSAGE_EVENT_ADVANCE, 'Your pick just broke.')
    end
 
OP
OP
VagosClubTM

VagosClubTM

Member
Joined
Aug 16, 2019
Messages
150
Reaction score
19
Location
Chile
Add this above if target.actionid == 40041 then condition
Lua:
    local break_chance = 15
    if math.random(1, 100) <= break_chance then
        item:remove(1)
        player:getPosition():sendMagicEffect(CONST_ME_BLOCKHIT)
        player:sendTextMessage(MESSAGE_EVENT_ADVANCE, 'Your pick just broke.')
    end
thanks bro work nice 100%
 

raynerjunior

New Member
Joined
Jul 31, 2014
Messages
12
Reaction score
3
player:addExperience(amount)

@Xikini
Can you help me ?
I added as mentioned, but it's still giving an error, in fact it works, but it doesn't recognize the stone.
Confirm that the action is in the correct location

1644950916728.png

Action:
Lua:
local rewards = {
    { item = 8298, count = 1, chance = 50 },
    { item = 8299, count = 1, chance = 50 },
    { item = 8301, count = 1, chance = 50 },
    { item = 8302, count = 1, chance = 50 },
    { item = 8303, count = 1, chance = 50 },
    { item = 8310, count = 1, chance = 50 },
    { item = 9971, count = 1, chance = 50 },
    { item = 5944, count = 1, chance = 100 }
}

local storage = 5000
local delay_timer = 5

function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    
    local cur_time, cur_storage = os.time(), player:getStorageValue(storage)
 
    if cur_storage > cur_time then
        player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You can mining again in " .. os.date("!%Hh %Mm %Ss", cur_storage - cur_time) .. ".")
        return true
    end
    
    local function addbackstone()
    local stones = {5750, 5751, 5752, 5753, 5754}
    local stone = Game.createItem(stones[math.random(#stones)], 1, toPosition)
        stone:setActionId(5991)
    end
    
    if player:getLevel() < 10 then
        player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You dont have the required level of 10 to mining.")
        return true
    end
    
    if not target then
        return false
    end
    
    if not target:isItem() then
        return false
    end

    if target.actionid ~= 5991 then
    local pos = player:getPosition()
        player:sendTextMessage(MESSAGE_EVENT_ADVANCE, 'You cannot use it here.')
        return false
    end
    
        local break_chance = 15
    if math.random(1, 100) <= break_chance then
        item:remove(1)
        player:getPosition():sendMagicEffect(CONST_ME_BLOCKHIT)
        player:sendTextMessage(MESSAGE_EVENT_ADVANCE, 'Your pick just broke.')
    end
    
    if target.actionid == 5991 then
    local ran = math.random(100)
        if ran <= 10 then
            toPosition:sendMagicEffect(3)
            target:remove()
            addEvent(addbackstone, 120000)
            return true
        end
    end
 
    local text = "You have found "
    for i = 1, #rewards do
        local rand = math.random(1000)
        if rand <= rewards[i].chance then
            player:addItem(rewards[i].item, rewards[i].count)
            if text ~= "You have found " then
                text = text .. ", "
            end
            text = text .. rewards[i].count .. " " .. ItemType(rewards[i].item):getName()
        end         
    end
    if text == "You have found " then
        text = text .. "nothing"
    end
    player:sendTextMessage(36, text .. ".")
    cur_time = cur_time + delay_timer
    player:addExperience(amount)
    player:setStorageValue(storage, cur_time)
    return true
end
 

Levi999x

AoT
Joined
Dec 14, 2017
Messages
2,060
Solutions
52
Reaction score
1,324
Location
Germany
@Xikini
Can you help me ?
I added as mentioned, but it's still giving an error, in fact it works, but it doesn't recognize the stone.
Confirm that the action is in the correct location

View attachment 65555

Action:
Lua:
local rewards = {
    { item = 8298, count = 1, chance = 50 },
    { item = 8299, count = 1, chance = 50 },
    { item = 8301, count = 1, chance = 50 },
    { item = 8302, count = 1, chance = 50 },
    { item = 8303, count = 1, chance = 50 },
    { item = 8310, count = 1, chance = 50 },
    { item = 9971, count = 1, chance = 50 },
    { item = 5944, count = 1, chance = 100 }
}

local storage = 5000
local delay_timer = 5

function onUse(player, item, fromPosition, target, toPosition, isHotkey)
  
    local cur_time, cur_storage = os.time(), player:getStorageValue(storage)
 
    if cur_storage > cur_time then
        player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You can mining again in " .. os.date("!%Hh %Mm %Ss", cur_storage - cur_time) .. ".")
        return true
    end
  
    local function addbackstone()
    local stones = {5750, 5751, 5752, 5753, 5754}
    local stone = Game.createItem(stones[math.random(#stones)], 1, toPosition)
        stone:setActionId(5991)
    end
  
    if player:getLevel() < 10 then
        player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You dont have the required level of 10 to mining.")
        return true
    end
  
    if not target then
        return false
    end
  
    if not target:isItem() then
        return false
    end

    if target.actionid ~= 5991 then
    local pos = player:getPosition()
        player:sendTextMessage(MESSAGE_EVENT_ADVANCE, 'You cannot use it here.')
        return false
    end
  
        local break_chance = 15
    if math.random(1, 100) <= break_chance then
        item:remove(1)
        player:getPosition():sendMagicEffect(CONST_ME_BLOCKHIT)
        player:sendTextMessage(MESSAGE_EVENT_ADVANCE, 'Your pick just broke.')
    end
  
    if target.actionid == 5991 then
    local ran = math.random(100)
        if ran <= 10 then
            toPosition:sendMagicEffect(3)
            target:remove()
            addEvent(addbackstone, 120000)
            return true
        end
    end
 
    local text = "You have found "
    for i = 1, #rewards do
        local rand = math.random(1000)
        if rand <= rewards[i].chance then
            player:addItem(rewards[i].item, rewards[i].count)
            if text ~= "You have found " then
                text = text .. ", "
            end
            text = text .. rewards[i].count .. " " .. ItemType(rewards[i].item):getName()
        end       
    end
    if text == "You have found " then
        text = text .. "nothing"
    end
    player:sendTextMessage(36, text .. ".")
    cur_time = cur_time + delay_timer
    player:addExperience(amount)
    player:setStorageValue(storage, cur_time)
    return true
end

The stone doesnt have the required actionid

Lua:
    if target.actionid ~= 5991 then
    local pos = player:getPosition()
        player:sendTextMessage(MESSAGE_EVENT_ADVANCE, 'You cannot use it here.')
        return false
    end
 

raynerjunior

New Member
Joined
Jul 31, 2014
Messages
12
Reaction score
3
The stone doesnt have the required actionid

Lua:
    if target.actionid ~= 5991 then
    local pos = player:getPosition()
        player:sendTextMessage(MESSAGE_EVENT_ADVANCE, 'You cannot use it here.')
        return false
    end

@Levi999x
But I put it, look at the image.


1644953234091.png

Something is wrong!
I'm using OTClient 1.0 compiled for Windows, here it doesn't work. - Link: OTClient 1.0
More use OTClientV8, it works.

Using OTClientV8 it works.

1644953451814.png


I need it to work on OTClient 1.0. Because I have other actions done in the sources;
 

Evil Puncker

I know nothing
TFS Developer
Joined
May 30, 2009
Messages
8,508
Solutions
260
Reaction score
4,441
seems like OTC 1.0 is targeting ground instead of top item, add this print to your script after line 44 and see what console prints when you try to mine in otc 1.0:

Lua:
print(target.actionid)
 

Evil Puncker

I know nothing
TFS Developer
Joined
May 30, 2009
Messages
8,508
Solutions
260
Reaction score
4,441
it worked indeed (it prints 0 because ground doesn't have action id), have you tried with OTC v8 to see what value does it return? also you can add print(target.itemid) to see which item id your client is targeting, if that is only not working on otc 1.0 it might be worth to make a bug report at its github
 

raynerjunior

New Member
Joined
Jul 31, 2014
Messages
12
Reaction score
3
it worked indeed (it prints 0 because ground doesn't have action id), have you tried with OTC v8 to see what value does it return? also you can add print(target.itemid) to see which item id your client is targeting, if that is only not working on otc 1.0 it might be worth to make a bug report at its github

I'm using pick, ID 2553

1644955981682.png

Using the action you mentioned, he accuses you of using ID 4544. - Using OTClient 1.0 - " Print(target.itemid) "

1644956001921.png

@Evil Puncker When I use OTClient V8, I have no return with the print actions, the action is executed without even a return on the TFS screen, but the action works.
Sources Edubart It's also having the same error. - Link: Edubart OTClient Sources
Sources Meah It's also having the same error. - Link: Mehah OTClient Sources
 

Evil Puncker

I know nothing
TFS Developer
Joined
May 30, 2009
Messages
8,508
Solutions
260
Reaction score
4,441
yeah my bad, print is never executed because otc v8 returns the correct item and action id so that check is never executed (if you still want to print, just move it to line 48)

I'm pretty sure there is some workaround for your problem thought (like getting top item actionID instead of target) but overall, it is an OTC issue, I recommend you to open a new thread thought since it is a new issue not related to this thread at all
 

arthurluna

Member
Joined
Apr 12, 2008
Messages
169
Reaction score
5
yeah my bad, print is never executed because otc v8 returns the correct item and action id so that check is never executed (if you still want to print, just move it to line 48)

I'm pretty sure there is some workaround for your problem thought (like getting top item actionID instead of target) but overall, it is an OTC issue, I recommend you to open a new thread thought since it is a new issue not related to this thread at all
I need to talk to you, how do I contact you?
 
Top