• 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!
  • 2026 staff recruitment is open! Check it out and consider applying!

TFS 1.X+ Show wand min/max damage in description

peteralto

Active Member
Joined
Nov 1, 2020
Messages
130
Solutions
1
Reaction score
33
I'm using TFS 1.3+ and would like to display the minimum and maximum damage of the Wand/Rod in the item description when I look at it.

Something like:
02:34 You see a wand of inferno (Dmg: 35~50, Range: 4, magic level +1).

Any suggestions on how to do this?
 
Solution
I will leave here an idea but it rather requires more changes in order to display something like that.

You can define your wands using scripts instead of regular weapons.xml. You can check here examples available on main repo: forgottenserver/data/scripts/weapons/#example.lua at master · otland/forgottenserver (https://github.com/otland/forgottenserver/blob/master/data/scripts/weapons/%23example.lua)
Let's take wand of vortex as an example:
LUA:
local wov = Weapon(WEAPON_WAND)
wov:id(2190)
wov:damage(8, 18)
wov:element("energy")
wov:level(7)
wov:mana(2)
wov:vocation("sorcerer", true, true)
wov:vocation("master sorcerer")
wov:register()

As you can see, you can define many properties for such wand. Ok, so what's next?
Values for...
I will leave here an idea but it rather requires more changes in order to display something like that.

You can define your wands using scripts instead of regular weapons.xml. You can check here examples available on main repo: forgottenserver/data/scripts/weapons/#example.lua at master · otland/forgottenserver (https://github.com/otland/forgottenserver/blob/master/data/scripts/weapons/%23example.lua)
Let's take wand of vortex as an example:
LUA:
local wov = Weapon(WEAPON_WAND)
wov:id(2190)
wov:damage(8, 18)
wov:element("energy")
wov:level(7)
wov:mana(2)
wov:vocation("sorcerer", true, true)
wov:vocation("master sorcerer")
wov:register()

As you can see, you can define many properties for such wand. Ok, so what's next?
Values for weapon definitions should be stored somewhere else and be available for other scripts. Let's define structure in separate file (don't forget to add this to your libs). For example (of course you will have to adapt it better):
LUA:
wands = {
  [2190] = {
    level = 7,
    mana = 2,
    range = 6,
    element = "energy",
    damage = { 8, 18 },
    vocations = {
      { name = "sorcerer", primary = true, promoted = true },
      { name = "master sorcerer" },
    },
  },

  [2191] = {
    level = 7,
    mana = 2,
    range = 6,
    element = "fire",
    damage = { 9, 19 },
    vocations = {
      { name = "sorcerer", primary = true, promoted = true },
      { name = "master sorcerer" },
    },
  },

  [2187] = {
    level = 13,
    mana = 3,
    range = 6,
    element = "energy",
    damage = { 13, 24 },
    vocations = {
      { name = "sorcerer", primary = true, promoted = true },
      { name = "master sorcerer" },
    },
  },

  [2189] = {
    level = 33,
    mana = 4,
    range = 6,
    element = "fire",
    damage = { 22, 37 },
    vocations = {
      { name = "sorcerer", primary = true, promoted = true },
      { name = "master sorcerer" },
    },
  },
}
Iterate over wand collection and initialize all your wands as in example from TFS.

Now when we've 'initialized' wands and have useful structure with wands definitions we're almost there - it will be helpful for our onLook eventcallbacks.
I will share here my example where I have custom description for specific wand.

Code:
local ec = EventCallback

local customDescription = {
    [34070] = function(cid, item, description)
        local bonusManadrainFactor = item:getCustomAttribute(SPELLWAND_BONUS_MANADRAIN_FACTOR_ATTR) or 0
        description = string.gsub(description, "1.25%% of your maximum mana",
        string.format("%.2f%%%% of your maximum mana (upgradeable to %.2f%%%%)",
                SPELLWAND_MANADRAIN_BASE + bonusManadrainFactor,
                SPELLWAND_MANADRAIN_BASE + SPELLWAND_MAX_LIMIT))
        return description
    end
}

ec.onLook = function(cid, thing, position, distance, description)
    if thing:isItem() then
        local handler = customDescription[thing.itemid]
        if handler then
            return handler(cid, thing, description)
        end
    end
    return description
end

ec:register(7)
Short explanation. We have custom onLook function which will return handler for specific item (based on ID). In your case you can change that code and make common handler (for all wands same description) but filled with different values from your wands collection. Eventcallback is called -> check if item is in wands collection -> fill description with proper values -> return your new description.

Hope it will help you :)
 
Last edited:
Solution
Back
Top