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

Magical Items for TFS 1.2/3

Are you excited to try out this system?

  • Yes!

  • No


Results are only viewable after voting.

bayview

Banned User
Joined
Jan 25, 2018
Messages
611
Solutions
25
Reaction score
324
I am about to become homeless.. well in 24 days I will be homeless so I have no need for my ot server code. I was going to launch an ot server but that is a lot of work. Although I was almost done with the project, it still requires a lot more time to finish than I have.

But in reality I need to find a real job so with that said. I am releasing this system I made some time last year.

If you follow the instructions you shouldn't have any issues with getting it to work.

Guide
This guide will help you install and create the necessary files needed to run Magical Items.
If you follow this guide step by step you shouldn't have any problems, this system is written entirely in lua & the TFS framework, no source editing is required.

A little bit about Magical Items:
Magical Items by @Codex NG, is a tiered based system for all items which can be equipped to a player.
These items can have all sorts of conditions applied to them, they can also be transformed from one item to another.
This system allows you to set and stack damage types for both attack and defense.
You can also assign existing spells which are not normally meant for that vocation at different tiers that a player can use temporarily or forever.

An example of this system:
Code:
17:03 You see a backpack (Vol:20).
It weighs 150.60 oz.
Wearing this backpack will grant the bearer these attributes [Axe:20] in stats.
Damage Reduction [Fire: +9] [Physical: +9]
In addition to everything listed above, Magical Items has been assigned an auto heal script which determines the type of damage a player takes and uses the appropriate potion (health / mana) regardless of level or vocation requirement.

When a player logins they will receive a msg some thing similar to this:
Code:
17:03 Your autoheal is not active, the warning msg is on, has not been set, it is at its default of 50%, for more info type /autoheal help.

To see exactly what autoheal does type the command /autoheal help
Which should look like this:
Code:
17:07 To see the status autoheal type:
17:07 /autoheal status
17:07 To turn on autoheal type:
17:07 /autoheal on
17:07 To turn off autoheal type:
17:07 /autoheal off
17:07 To toggle the warning message you get when out of potions type:
17:07 /autoheal warning toggle
17:07 To change the percentage of healing type:
17:07 /autoheal n
17:07 Where n is a number, the number must be between 1 - 100.
17:07 If the number is the same, less than 1 or greater than 100, then no change will take place.

The execution per heal will show an emote at what percentage you are healing and a message in the console will tell you what potions you are using.
When a player runs out of potions of the required type an emote warning is executed, this warning can be toggled off.
Code:
17:19 Using 1 of 136x super ultimate health potions heals both hp/mana.

Installation

Step 1
Copy this below and place it at the bottom of your global.lua
Code:
dofile('data/items/magical_items.lua')

Step 2
Copy magical_items_lib.lua, run_first.lua, run_second.lua and run_third.lua to data/items/

There are 7 files that go in this directory, you will are given 4 the remaining 3 will be created, you will need a lua interpreter to run run_first.lua, run_second.lua and run_third.lua

Zerobrane is a completely free lua interpreter for Windows, Linux & Mac.
You can download it here Download - ZeroBrane Studio - Lua IDE/editor/debugger for Windows, Mac OSX, and Linux

run_first.lua
This file creates a file called items.lua and must be run 1st, it parses your items.xml file.
If you have custom items with different names or properties such as a shield which you made into a helmet it will read that shield as a helmet.

items.lua
This is the base file you want to edit to add or remove items you won't be using with this system.
The next two files parse the information which is retained in items.lua.

run_second.lua
This file parses the items.lua file and generates a file called magical_items.lua and should be run 2nd

run_third.lua
This file also parses the items.lua file and creates a file called magical_items.xml

magical_items_lib.lua
This is the library which contains all the code needed to run the magical items system.


Step 3
magicItems_creaturescript.lua
Place this file in data/creaturescripts/scripts/

Then edit creaturescripts.xml and add this entry
HTML:
<event type="healthchange" name="MagicItems" script="magicItems_creaturescript.lua" />

Open up login.lua in data/creaturescripts/scripts/ and add this somewhere inside onLogin
Lua:
        x:onLogin(player:getId())
        player:registerEvent("MagicItems")


Step 4
Go to data/events/scripts and open up creature.lua

Select everything in there and paste this in, if you have other custom code in there then make the adjustments.
Lua:
    function Creature:onChangeOutfit(outfit)
        if self:isPlayer() and self:getCondition(CONDITION_OUTFIT) then
            return false
        end
        return true
    end

    function Creature:onAreaCombat(tile, isAggressive)
        return RETURNVALUE_NOERROR
    end

    function Creature:onTargetCombat(target)
        if target:isMonster() then
            target:registerEvent("MagicItems")
        end
        return RETURNVALUE_NOERROR
    end

Now open up events.xml in data/events/ and make sure these lines match the one's in your events.xml
HTML:
        <event class="Creature" method="onChangeOutfit" enabled="1" />
        <event class="Creature" method="onTargetCombat" enabled="1" />

        <event class="Player" method="onLook" enabled="1" />
        <event class="Player" method="onLookInTrade" enabled="1" />

Step 5
Next we need to do is open up player.lua in data/events/scripts

Look for this in Player onLook
Lua:
local description = "You see " .. thing:getDescription(distance)


You are going to replace that code with this, if you have custom code here, make the adjustments.
Lua:
local description = "You see " .. thing:getDescription(distance) .. self:getMagicItemDescription(thing)

Next inside of that method look for
Lua:
            local uniqueId = thing:getAttribute(ITEM_ATTRIBUTE_UNIQUEID)
            if uniqueId > 0 and uniqueId < 65536 then
                description = string.format("%s, Unique ID: %d", description, uniqueId)
            end

Underneath that section of code you are going to place this
Lua:
            local text = thing:getAttribute(ITEM_ATTRIBUTE_TEXT)
            if text and text ~= '' then
                description = string.format("%s, Text : %s", description, text)
            end

            local serial = x:getSerial(thing:getName())
            if serial and serial ~= '' then
                description = string.format("%s, Serial : %s", description, serial)
            end

Next look for in Player onLookInTrade
Lua:
            self:sendTextMessage(MESSAGE_INFO_DESCR, "You see " .. item:getDescription(distance))

Replace that code with this
Lua:
            self:sendTextMessage(MESSAGE_INFO_DESCR, item:getDescription(distance) .. self:getMagicItemDescription(item) )


Step 6
Open up the magical_items.xml which was created in data/items/ and then open up your movements.xml in data/movements/

Copy the entries in magical_items.xml and replace the existing onEquip/DeEquip entries in movements.xml

Next place the magical_items_movements.lua in your data/movement/scripts/ directory.

Step 7
Go to data/talkactions and open talkactions.xml and place this in there.
HTML:
        <talkaction words="/autoheal" separator=" " script="autoHeal.lua" />

Next go to data/talkactions/scripts and drop autoheal.lua in there


Step 8

Editing

magical_items.lua
This file will contain all of items which will be used with this system.

On server startup all the items in this file will be set with a default of tier 1 with no conditions associated with them.
It will be your job to use the methods in the magical items library to set the different attributes to your equipment in this file.

Please note all methods are procedural, also you can not (or shouldn't) stack the same condition on top of another.

Example:
Lua:
[B][/B]
        -- sets the item ancient tiara to tier 1 at slot 1
        -- x:setTier(slot, item name, tier)
        x:setTier(1, 'ancient tiara', 1)
        -- everything below will be a tier 1 value until it reaches another set tier
        -- ancient tiara is given a condition of manashield
        x:manashield()
        -- ancient tiara attributes
        x:attributes({'max health', 'max mana', 'fist%','club', 'sword'}, {500, 1000, 20, 30, 50})
        -- ancient tiara is assigned an outfit
        x:outfit(2)
        -- ancient tiara is assigned a condition of hp regen of 50
        x:regen('hp', 50)
        -- ancient tiara is given a damage reduction of 20 physical and 10 death damage
        x:damageReduction('defense physical', 'defense death', 20, 10)

        -- sets the item ancient tiara to tier 2 at slot 1
        x:setTier(1, 'ancient tiara', 2)
        -- everything below will be a tier 2 value
        x:dot({'fire', 'energy'}, 100, 1000, {-1, -2})
        x:outfit(1)
        x:damageReduction('defense energy', nil, 50)

The onLook properties of the ancient tiara on a GOD character will look something like this
Lua:
        17:15 You see an ancient tiara.
        It weighs 8.20 oz.
        Ye who bears this mystical ancient tiara is granted an ancient magical shield.
        Wearing this ancient tiara will grant the bearer these attributes [Max Health:500] [Max Mana:1000] [Fist%:20] [Club:30] [Sword:50] in stats.
        By dressing ancient tiara your true identity will be masked.
        Wearing this ancient tiara will grant the bearer a boost in [Hp:50] regen.
        Damage Reduction [Physical: +20] [Death: +10]
        Item ID: 2139, Serial : 1|0|1|0|1|1|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|1|0|0|0|0|0|0|0|0|0|0|0|1|0|0
        Position: 93, 130, 7

A little info on the Magical Items Methods (not all of them)
Lua:
        -- this is the 1st thing called before each tier, and must be set 1st
        -- slot is the equipment slot, item name is the name of the item in items.xml, and tier is the tier it has to be to
        -- benefit from this system
        x:setTier(slot, item name, tier)

        -- this is used to up/downgrade and items tier (think crafting)
        x:setMagicItemTier(item, subtype, tier)

        -- gives the player manashield when an item is equipped, manashield does not stack or scale
        x:manashield([description[, isCustomItem]])

        -- gives the player invisible when an item is equipped, invisible does not stack or scale
        x:invisible([description[, isCustomItem]])

        -- gives the player an outfit to wear which they can not remove unless they unequip the item
        -- outfit does not stack or scale
        -- the outfitIndex corresponds to both v & d table's index
        x:outfit(outfitIndex[, description[, isCustomItem]])

        -- gives the player a haste condition, there are a few haste formulas, you can define your own by editing the v table
        -- the hasteIndex corresponds to the v table's index
        x:haste(hasteIndex[, description[, isCustomItem]])

        -- gives the player a paralyze condition, there are a few paralyze formulas, you can define your own by editing the v table
        -- the paralyzeIndex corresponds to the v table's index
        x:paralyze(paralyzeIndex[, description[, isCustomItem]])

        -- applies a regen buff for either hp or mana or both
        -- both attributeType & attribute can be a table/variable, if attributeType is a variable so should attribute
        x:regen(attributeType, attribute[, description[, isCustomItem]])

        -- applies attributes such as health, mana, sword, health percentage, magic level etc to the player when the item is equipped
        -- both type and attribute can be a table/variable, if type is not a table then attribute has to be a variable
        x:attributes(type, attribute[, description[, isCustomItem]])

        -- applies light to a player when the item is equipped
        -- color is anything in the v table, level is a range value of 1 being the lowest and 8 possibly being the highest
        x:light([color[, level[, description[, isCustomItem]]]])

        -- applies soulgain to a player when an item is equipped
        -- gain is how much soul to gain and ticks is how often to gain them
        x:soul(gain, ticks[, description[, isCustomItem]])

        -- applies damage over time to the player when the item is equipped
        -- (think, this item has great stats but it's cursed or it does not belong to them)
        -- time, round or interval can be a table/variable, if time is a variable the rest should be aswell
        -- this can not be applied to weapon damage... yet ;)
        x:dot(time, round, interval, damage[, description[, isCustomItem]])

        -- this method is enabled by default and just detects if the player has manashield
        -- this method was written because I found the internal manashield not working as expected
        x:hasManashield(cid, aid, primaryDamage, primaryType, secondaryDamage, secondaryType, origin)

        -- this method only applies to weapons and shields, it gives the item additional attack damage
        -- in the primary or secondary types
        -- example of this is
        -- x:directDamage('combat physical', 12, 'combat fire', 10)
        x:directDamage(primaryType, primaryValue, secondaryType, secondaryValue, isCustomItem)

        -- this method applies to all items that can be equipped and stacks meaning if you have damage reduction on an
        -- armor of say 10 and a shield of 15 then you get reduced fire damage of 25 
        -- in the primary or secondary types
        -- example of this is
        -- x:damageReduction('defense physical', 12, 'defense fire', 10)
        x:damageReduction(primaryType, secondaryType, primaryValue, secondaryValue, isCustomItem)

        -- sets spell(s) to an item which can be removed when the item is equipped or made a permanent part of the player's arsonal
        x:setSpells(spells[, permanent[, isCustomItem]])

        -- this physically transforms an item from one to another
        -- name is the name of the item you want this item to transform to
        -- keep is if you want to keep this item as is, as in not change it back
        x:setTransformItem(name[, keep[, isCustomItem]])

        -- this method will execute the autoheal aspect of Magical Items, its 1st parameter is the player id
        -- the second parameter is the threshold (the percentage to heal at), the 3rd parameter is the type of heal
        -- or potion type rather to heal, both the 2nd and 3rd parameters are optional.
        -- Currently the auto heal does not work on monsters, pets, or summons.
        x:autoHeal(cid[, threshold[, type_]])
 

Attachments

I paid for this system, and i havent given him any permission to release it.

That the way he is. You show some kindness, and they stab you hard! Well done!
 
I paid for this system, and i havent given him any permission to release it.
I did not exclusively write this system for you, you do not own the rights to it.
So I do not need your permission as I can do what I like with it.
I wrote it for me, what sane person would spend an entire month writing and re-writing a library for $100?
I have already explain this to you on numerous occasions.

That the way he is. You show some kindness, and they stab you hard! Well done!
Kindness?
You are one of the worst and cheapest "clients" I have ever have had to work for, I wouldn't exactly call you or your actions kind.

That the way he is.
Yes I am very generous :)
 
I did not exclusively write this system for you, you do not own the rights to it.
So I do not need your permission as I can do what I like with it.
I wrote it for me, what sane person would spend an entire month writing and re-writing a library for $100?
I have already explain this to you on numerous occasions.

100$? You got more than 150$ when we stablished 100$ for that system. And now you did it for yourself? REALLY?
At least karma seems to work.
 
100$? You got more than 150$ when we stablished 100$ for that system. And now you did it for yourself? REALLY?
At least karma seems to work.
Do I need to provide proof that you only paid me $100?
Because I have the records...
 
Actually yeah, you are right. I thought it was more. I paid exactly 101$ to you. 60$ in advance. (Just checked paypal)
So i paid you to work in something for yourself? Why would i pay if i could get it for free?

But ey! I wish you did enjoy that money! Have a happy life mate!
 
I paid exactly 101$ to you. 60$ in advance. (Just checked paypal)
No you paid me exactly $100 total,
$25 on May 9th, 2017
$35 on May 25th, 2017
$40 on May 29th 2017
So i paid you to work in something for yourself? Why would i pay if i could get it for free?
Because you have a difficult time understanding verbal or written English, I explained this to you on several occasions that I would either use this for my project, resell it or make it public.

I don't know what the goal of your posting here is, I never pointed out in this thread or its sources that this system was made for your server.
You have your own self to blame for this admission, especially when its not 100% accurate.

Have a happy life mate!
Thanks! I'll try ;)
 
My goal was to let the community know something about you that they seem to know already.

But i will not get to your level and i will just live with it. Its a good system! :)
 
My goal was to let the community know something about you that they seem to know already.

But i will not get to your level and i will just live with it. Its a good system! :)
If you didn't state when buying that this script is exclusively made for you, and cannot be shared anywhere, then he is right. You bought the script, but he is free to do whatever he likes with it, even share it for free (which I don't support, because it's just not fair for the one who bought it, but that's his desire.).
 
I don't understand how your autoheal script is taking informations about potions that have to be used to heal and how to configure the potion that it needs to use?
 
Where is magical_items_movements.lua?
'-'
Same as above ;<
can you make magical_items_movements.lua available?

I don't understand how your autoheal script is taking informations about potions that have to be used to heal and how to configure the potion that it needs to use?
It takes from this table
Lua:
potions = {
  [7439] = {mana = {0, 0}, health = {250, 350}, flask = 7634, name = 'berserker', status = ''}, -- berserker
  [7440] = {mana = {0, 0}, health = {250, 350}, flask = 7634, name = 'mastermind', status = ''}, -- mastermind
  [7443] = {mana = {0, 0}, health = {250, 350}, flask = 7634, name = 'bullseye', status = ''}, -- bullseye
  [7588] = {mana = {0, 0}, health = {250, 350}, flask = 7634, name = 'strong health', status = ''}, -- strong hp
  [7589] = {mana = {115, 185}, health = {0, 0}, flask = 7634, name = 'strong mana', status = ''}, -- strong mana
  [7590] = {mana = {150, 250}, health = {0, 0}, flask = 7635, name = 'great mana', status = ''}, -- great mana
  [7591] = {mana = {0, 0}, health = {425, 575}, flask = 7635, name = 'great health', status = ''}, -- great hp
  [7618] = {mana = {0, 0}, health = {125, 175}, flask = 7636, name = 'health', status = ''}, -- hp
  [7620] = {mana = {75, 125}, health = {0, 0}, flask = 7636, name = 'small mana', status = ''}, -- small mana
  [8472] = {mana = {100, 200}, health = {250, 350}, flask = 7635, name = 'great spirit', status = ' heals both hp/mana'}, -- great spirit
  [8473] = {mana = {0, 0}, health = {650, 850}, flask = 7635, name = 'ultimate health', status = ''}, -- ultimate hp
  [8474] = {combat = antidote, flask = 7636}, -- antidote
  [8704] = {mana = {0, 0}, health = {60, 90}, flask = 7636, name = 'small health', status = ''}, -- small hp
  [26029] = {mana = {425, 575}, health = {0, 0}, flask = 7635, name = 'ultimate mana', status = ''}, -- ultimate mana
  [26030] = {mana = {250, 350}, health = {420, 580}, flask = 7635, name = 'ultimate spirit', status = ' heals both hp/mana'}, -- ultimate spirit
  [26031] = {mana = {875, 1125}, health = {875, 1125}, flask = 7635, name = 'super ultimate health', status = ' heals both hp/mana'}, -- super ultimate hp
}
The method which is called is this
Lua:
x:autoHeal(cid[, threshold[, type_]])
Here is it's definition
Lua:
function EQ.autoHeal(self, cid, threshold, type_, count)
  count = count or 1
  local player = Player(cid)
  if player then
    local pos = player:getPosition()
    local activated = player:getStorageValue(active)
    if activated > 0 then
      local store = player:getStorageValue(storage)
      store = store < 1 and 50 or store
      threshold = threshold and (threshold * .01) or (store * 0.01)
      local d, p = 1, 0
      local condition = type_ or self:hasCon(cid)
      local itemid, amount = self:hasItem(cid, count, condition)
      local mLevel = player:getMagicLevel()
      local potion = itemid and potions[itemid] or nil
      if potion and next(potion) then
        if potion.health or potion.mana or potion.combat then
          if condition == 'mana' then
            d = player:getMana()
            local maxMana = player:getMaxMana()
            p = math.floor(maxMana * threshold)
            if d <= p then
              --print(potion.mana[1], potion.mana[2], itemid, 'mana')
              player:addMana(math.random(potion.mana[1], potion.mana[2]))
              player:getPosition():sendMagicEffect(CONST_ME_MAGIC_BLUE)
            end
          elseif condition == 'health' then
            d = player:getHealth()
            local maxHealth = player:getMaxHealth()
            p = math.floor(maxHealth * threshold)
            if d <= p then
              --print(potion.health[1], potion.health[2], itemid, 'health')
              player:addHealth(math.random(potion.health[1], potion.health[2]))
              player:removeCondition(CONDITION_PARALYZE)
              player:getPosition():sendMagicEffect(CONST_ME_MAGIC_BLUE)
            end
          end
          if d <= p then
            doPlayerRemoveItem(cid, itemid, count)
            player:addItem(potion.flask, count)
            Game.sendAnimatedText("Healing "..condition.." at "..(threshold * 100).."%", pos, textColors[math.random(#textColors)])
            player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "Using "..count.." of " .. amount .. "x " .. potion.name .. " potions"..potion.status..".")
          end
        end
      end
    end
  end
end

I don't know what happened to the original movements scripts because this does not look like it.. I would have to look it over which i really don't have the time for but here is link to the github which @Peonso forked.
peonso/Magical-Items-1.2-3-Otx3
 

Attachments

  • magical_items_movements.lua
    2.2 KB · Views: 24 · VirusTotal
Last edited by a moderator:
@bayview
Thanks for including movements.xml :)
however am having this error while equip or desequip "doesn't add stats anyhow also"
Code:
Lua Script Error: [MoveEvents Interface]
data/movements/scripts/magical_items.lua:onEquip
data/movements/scripts/magical_items.lua:19: attempt to call method 'getSlottedI
tems' (a nil value)
stack traceback:
        [C]: in function 'getSlottedItems'
        data/movements/scripts/magical_items.lua:19: in function <data/movements
/scripts/magical_items.lua:11>

Lua Script Error: [MoveEvents Interface]
data/movements/scripts/magical_items.lua:onEquip
data/movements/scripts/magical_items.lua:19: attempt to call method 'getSlottedI
tems' (a nil value)
stack traceback:
        [C]: in function 'getSlottedItems'
        data/movements/scripts/magical_items.lua:19: in function <data/movements
/scripts/magical_items.lua:11>
 
Back
Top