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

Action Herblore / Mining Skill [TFS 1.1]

Ramirow

Veteran OT User
Joined
Aug 22, 2009
Messages
584
Solutions
15
Reaction score
301
Location
Argentina
YouTube
ramirogrant
As the title says, an Herblore Skill created using the custom skill system by Codex NG!
You NEED the system for this script to work!

Here:
https://otland.net/threads/player-spell-experience-1-2.238208/

Also, remember to add the skill storages to the player (With firstitems.lua) or whatever method you see fit.

Well, there you go!
Code:
-- Herblore Skill by Ramirow
-- Script optimized and system created by Codex NG -THANKS! (https://otland.net/members/codex-ng.213653/)
-- For TFS version 1.1

local name = "Herblore"       -- Name of the Custom Skill
local storage = 15000       -- Storage used to store Custom Skill Levels
local seconds = 30         -- Time to recreate the plant

function doCreateBush(pos, itemid)     -- Recreates the plant after some time
     local tile = Tile(pos)
     if tile:getTopCreature() then
     pos:sendMagicEffect(CONST_ME_POFF)
     return addEvent(doCreateBush, seconds * 1000, pos, itemid)
     else
       Game.createItem(itemid, 1, pos)
       pos:sendMagicEffect(CONST_ME_MAGIC_BLUE)
     end
end

local powders = {               -- Contains all plants and their data
  [2743] = {
  itemid = 2743,
  herbtype = 'red',
  item = 8303,
  level = {min = 1, max = 30},
  roundChance = {min = 1, max = 2},
  chance = 2,
  round = 8,
     xp = 1
  },
  [4135] = {
  itemid = 4135,
  herbtype = 'red',
  item = 8303,
  level = {min = 15, max = 30},
  roundChance = {min = 4, max = 5},
  chance = 6,
     round = 3,
     xp = 5
  }
}

function onUse(cid, item, fromPosition, target, toPosition, isHotkey)
  local player = type(cid) == 'number' and Player(cid) or cid

  local herbSkill = player:getCustomSkill(storage)
  if powders[target.itemid] then

  local herbLevel = powders[target.itemid].level
  if herbSkill >= herbLevel.min then

  local chance = math.floor((math.random(1, 100)) - (herbSkill / powders[target.itemid].chance))
  if chance <= herbLevel.max then
         local loop = powders[target.itemid].xp
  local roundChance = powders[target.itemid].roundChance
  local amount = math.floor((math.random(roundChance.min, roundChance.max)) + (herbSkill / powders[target.itemid].round))
  player:addItem(powders[target.itemid].item, amount)
         toPosition:sendMagicEffect(CONST_ME_MAGIC_GREEN)
         target:remove()
         addEvent(doCreateBush, seconds * 1000, toPosition, target.itemid)
           for i = loop, 1, -1 do
             player:addCustomSkillTry(name, storage)
           end
  player:sendTextMessage(MESSAGE_STATUS_CONSOLE_RED, "You gathered " .. amount .. " " .. powders[target.itemid].herbtype .. " powders.")
  else
         local failure = math.random(1,100)
         if   failure <= 50 then
         toPosition:sendMagicEffect(CONST_ME_POFF)
  player:sendTextMessage(MESSAGE_STATUS_SMALL, "You failed.")
         target:remove()
         addEvent(doCreateBush, seconds * 1000, toPosition, target.itemid)
         else
         player:sendTextMessage(MESSAGE_STATUS_SMALL, "You failed.")
         toPosition:sendMagicEffect(CONST_ME_POFF)
         end
  end
  else
  player:sendTextMessage(MESSAGE_STATUS_SMALL, "You need level " .. herbLevel.min .. " of " .. name .. " to harvest.")
  end
  end
  return true
end

HOW IT WORKS:
1)
You use for example a machete on the plant you wish to harvest.
2) You have a chance to fail or succeed. (The chance of success as well as the amount of powders gathered increases with your Herblore Skill)
3) If you succeed the plant will be destroyed, when you fail, the plant has a chance to also be destroyed (50% chance)
4) After some time the plant will be recreated in it's original position ONLY if there's no player in that spot. (If a player is standing there at the time of creation, it will just reset the creation event.)

-- Additional Information on HERBLORE Here --
https://otland.net/threads/herblore-mining-skill-tfs-1-1.242309/#post-2347207

Mining Skill
Here's the script:

Code:
-- Mining Skill by Ramirow
-- Skill System created by Codex NG -THANKS! (https://otland.net/members/codex-ng.213653/)
-- For TFS version 1.1

local name = "Mining"  -- Name of the Custom Skill
local storage = 15002  -- Storage used to store Custom Skill Levels
local minutes = 1  -- Minutes to recreate the stone

function doCreateStone(pos, itemid)  -- Recreates the stone after given time
  local tile = Tile(pos)
  if tile:getTopCreature() then
  pos:sendMagicEffect(CONST_ME_POFF)
  return addEvent(doCreateStone, minutes * 60 * 1000, pos, itemid)
  else
  Game.createItem(itemid, 1, pos)
  pos:sendMagicEffect(CONST_ME_MAGIC_RED)
  end
end

local stones = {  -- Contains all stones and their data
  [8639] = {
   itemid = 8639,
   stonetype = 'small ruby',
   stonetype2 = 'small enchanted ruby',
   item = 2147,
   item2 = 7760,
   level = {min = 1, max = 30},
   bonusLevel = 15,
   bonusChance = 20,
   roundChance = {min = 1, max = 2},
   chance = 2,
   round = 8,
   xp = 1,
   xp2 = 2
  },
  [8635] = {
   itemid = 8635,
   stonetype = 'small enchanted ruby',
   stonetype2 = 'red gem',
   item = 7760,
   item2 = 2156,
   level = {min = 15, max = 30},
   bonusLevel = 25,
   roundChance = {min = 1, max = 2},
   chance = 4,
   round = 10,
   xp = 3,
   xp2 = 5
  }
}

function onUse(cid, item, fromPosition, target, toPosition, isHotkey)
  local player = type(cid) == 'number' and Player(cid) or cid

  local miningSkill = player:getCustomSkill(storage)
  if stones[target.itemid] then

  local miningLevel = stones[target.itemid].level
  if miningSkill >= miningLevel.min then

  local chance = math.floor((math.random(1, 100)) - (miningSkill / stones[target.itemid].chance))
  if chance <= miningLevel.max then
     local roundChance = stones[target.itemid].roundChance
     local amount = math.floor((math.random(roundChance.min, roundChance.max)) + (miningSkill / stones[target.itemid].round))
     if miningSkill >= stones[target.itemid].bonusLevel and math.random(1,100) <= stones[target.itemid].bonusChance then
      local loop2 = stones[target.itemid].xp2
      player:addItem(stones[target.itemid].item2, amount)
  toPosition:sendMagicEffect(CONST_ME_MAGIC_GREEN)
  target:remove()
  addEvent(doCreateStone, minutes * 60 * 1000, toPosition, target.itemid)
  for i = loop2, 1, -1 do
  player:addCustomSkillTry(name, storage)
  end
  player:sendTextMessage(MESSAGE_STATUS_CONSOLE_RED, "You mined " .. amount .. " " .. stones[target.itemid].stonetype2 .. ".")
     else
     local loop = stones[target.itemid].xp
     player:addItem(stones[target.itemid].item, amount)
  toPosition:sendMagicEffect(CONST_ME_MAGIC_RED)
  target:remove()
  addEvent(doCreateStone, minutes * 60 * 1000, toPosition, target.itemid)
  for i = loop, 1, -1 do
  player:addCustomSkillTry(name, storage)
  end
  player:sendTextMessage(MESSAGE_STATUS_CONSOLE_RED, "You mined " .. amount .. " " .. stones[target.itemid].stonetype .. ".")
     end
   else
  local failure = math.random(1,100)
  if  failure <= 50 then
  toPosition:sendMagicEffect(CONST_ME_POFF)
      player:sendTextMessage(MESSAGE_STATUS_SMALL, "You failed and the rock was destroyed.")
  target:remove()
  addEvent(doCreateStone, minutes * 60 * 1000, toPosition, target.itemid)
  else
  player:sendTextMessage(MESSAGE_STATUS_SMALL, "You couldn't mine anything.")
  toPosition:sendMagicEffect(CONST_ME_HITAREA)
  end
  end
  else
  player:sendTextMessage(MESSAGE_STATUS_SMALL, "You need a " .. name .. " level of " .. miningLevel.min .. " to mine this stone.")
  end
  end
  return true
end

It's really similar to the Herblore Skill.
HOW IT WORKS:

1) You use for example a pick or dwarven pickaxe (Or whatever item you assign this script to) on the rock you wish to mine.
2) You have a chance to fail or succeed. (The chance of success as well as the amount of small rubies / Small Enchanted Rubies -In this case- mined increases with your Mining Skill)
3) If you succeed the rock will be destroyed, when you fail, the rock has a chance to also be destroyed (50% chance). In addition to this, if your skill is high enough for a particular rock, you have a chance to mine better items. (Small Enchanted Rubies in the lower tier stone, and Red Gems in the higher tier stone in this case.)
4) After some time the rock will be recreated in it's original position ONLY if there's no player in that spot. (If a player is standing there at the time of creation, it will just reset the creation event.)


-- Additional Information on MINING Here --
https://otland.net/threads/herblore-mining-skill-tfs-1-1.242309/#post-2347208

Enjoy! :p
 
Last edited:
Hi great work! but i've got some questions:
1-Where does that script go?
2-Where are the coords for the bushes spawn pos?
 
Hi great work! but i've got some questions:
1-Where does that script go?
2-Where are the coords for the bushes spawn pos?
Hi mate! This script, as the title says, is an action. You can assign it to a machete for example.
It doesn't need a specific position, it uses the id of the bush and it's original positión.
If you need a more step by step guide I could make it.
 
oh! i get it.. no no, thats was more than enough! Thanks!
Will test it later, any known bugs?
 
very good script !!

if you change the variables of to make a Miner or lumberjack in the same script ?
 
very good script !!

if you change the variables of to make a Miner or lumberjack in the same script ?
It's possible to do it yes, this script could be used as a base! With minor changes you could turn this into a Mining or Lumberjacking script.
I'll try to code a Mining script and will post it here soon!

Already updated the main post!
 
Last edited:
NOTE: Some more info on Herblore for easier editing can be found here:
Glossary:

Code:
  [2743] = {
  itemid = 2743,
In this section of the script, inside the "Powders" table you should place the ID of a plant you wish to harvest.

Code:
herbtype = 'red',
This stands for the string used when sending the console message. "You received x RED powders.".

Code:
item = 8303,
The ID here determines the reward after a succesfull harvest. Again, in this case, a red powder.

Code:
level = {min = 1, max = 30},
This one could be somehow confusing for the max part.
'min' sets the level requirement to be able to harvest the plant. Duh!
But 'max' stands for the base chance of success. In this case, with 1 Herblore the chance would be '30%'.

Code:
roundChance = {min = 1, max = 2},
'min' stands for the base amount of powders you will get.
'max' stands for the maximun amount of powders you will get.
These values are base ones, remember that higher skill will increase the rewards.

Code:
chance = 2,
This one could be a little tricky. (Not for everyone!)
What this value does is increasing your chance of success.
In this case, it divides your HERBLORE SKILL by 2 and adds the result to your success rate!
Easy as that, in this example, using the value of 2. Having 4 Herblore Skill will add 2% (4 / 2) to our success rate, which was 30% at it's base (Expressed as I said, in level.max). That gives us a total of 32% rate of success. With an Herblore Skill of 100 we will have 80% success rate. (30% base + 50% for skill(100 / 2))

Code:
round = 8,
This value works somehow like 'chance' but adds to the amount of powders you will receive.
8 means that every 8 Skill Levels you will increase the powders gained by 1. (8 / 8)
Having 64 Herblore Skill will give you 1 - 2 powders (Base reward set in 'roundChance') + 8 additional powders.

Code:
xp = 1
This interacts with the Skill System (Again, created by Codex NG, thanks!)
It just sets how many tries you will receive for a successful harvest.
Higher means higher experience in the skill.
 
NOTE: Some more info on Mining for easier editing can be found here:
Pretty similar to Herblore.


Code:
  [8639] = {
   itemid = 8639,
In this section of the script, inside the "Stones" table you should place the ID of the rock you wish to mine.

Code:
stonetype = 'small ruby',
stonetype2 = 'small enchanted ruby',
These stand for the strings used when sending the console messages. "You received x SMALL RUBY / SMALL ENCHANTED RUBY."
'stonetype' stands for the regular mining reward.
'stonetype2' stands for the bonus mining reward.

Code:
item = 8303,
item2 = 7760,
The IDS here determine the rewards after a succesfull attempt.
'item' references to the ID of the regular item.
'item2' referenced to the ID of the bonus item.

Code:
level = {min = 1, max = 30},
'min' sets the level requirement to be able to mine the stone.
But 'max' stands for the base chance of success. In this case, with 1 Mining the chance would be '30%'.

Code:
bonusLevel = 15,
Minimun level to be able to mine the bonus item ('item2').

Code:
bonusChance = 20,
This stands for the chance you have to get the bonus reward everytime you make a successful attempt.
It's always 20% in this case. It does not receive a Skill Bonus.

Code:
roundChance = {min = 1, max = 2},
'min' stands for the base amount of rubies you will get.
'max' stands for the maximun amount of rubies you will get.
These values are base ones, remember that higher skill will increase the rewards.
Also note that these values are counted for bonus rewards too.

Code:
chance = 2,
What this value does is increasing your chance of success.
In this case, it divides your MINING SKILL by 2 and adds the result to your success rate!
Easy as that, in this example, using the value of 2. Having 4 Mining Skill will add 2% (4 / 2) to our success rate, which was 30% at it's base (Expressed as I said, in level.max). That gives us a total of 32% rate of success. With a Mining Skill of 100 we will have 80% success rate. (30% base + 50% for skill(100 / 2))

Code:
round = 8,
This value works somehow like 'chance' but adds to the amount of rubies you will receive.
8 means that every 8 Skill Levels you will increase the rubies gained by 1. (8 / 8)
Having 64 Mining Skill will give you 1 - 2 rubies (Base reward set in 'roundChance') + 8 additional rubies.

Code:
xp = 2,
xp2 = 5
This interacts with the Skill System (Again, created by Codex NG, thanks!)
It just sets how many tries you will receive for a successful attempt.
Higher means higher experience gain in the skill.
Again, 'xp' stands for a normal attempt success.
'xp2' stands for a bonus attempt success.
 
Last edited:
@Ramirow
No point explaining to them the code step by step... if they have to ask if a script could be used for something else just by changing the name and id's then they have no idea what they are looking at or what you are explaining to them.

Sadly its a waste of time...
 
@Ramirow
No point explaining to them the code step by step... if they have to ask if a script could be used for something else just by changing the name and id's then they have no idea what they are looking at or what you are explaining to them.

Sadly its a waste of time...
Oh..You may have a point there, never thought about that.. :(
 
@Ramirow Hi! I've been trying to implement your code but i've been unsuccessfull. I added the needed functions on my player.lua and replaced the scythe action with the one you provided. Added those plant ID to my map, but nothing happens at all, no msg, no error on console, nothing. What i am missing here? Those plants needs any action or uid?

PD: Btw, there's a missing "end" on the script.
 
Last edited:
@Ramirow Hi! I've been trying to implement your code but i've been unsuccessfull. I added the needed functions on my player.lua and replaced the scythe action with the one you provided. Added those plant ID to my map, but nothing happens at all, no msg, no error on console, nothing. What i am missing here? Those plants needs any action or uid?
No bodies code seems to work with your distro... i wonder why that is?
 
@Ramirow Hi! I've been trying to implement your code but i've been unsuccessfull. I added the needed functions on my player.lua and replaced the scythe action with the one you provided. Added those plant ID to my map, but nothing happens at all, no msg, no error on console, nothing. What i am missing here? Those plants needs any action or uid?
That's weird, you are sure you registered the action in actions.xml correctly?
Without an error it's really hard to help you out. Also remember I tested this in TFS 1.1
No bodies code seems to work with your distro... i wonder why that is?
What do you mean with his distro? I assume he has a modified version of TFS then?
And about the gif, he was serious about it? D:
 
Codex, i have maaany scripts from people working on my server. Many of those are yours btw. In this one is just feels like im missing something, and i dont know what is it.

@Codex NG Stop being so sarcastic, it doesnt helps at all. All im doing here is trying by myself and asking politely.
 
Back
Top