• 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 1.2 - Incomplete Version

Codex NG

Recurrent Flamer
Joined
Jul 24, 2015
Messages
2,994
Solutions
12
Reaction score
1,657
Since I've decided to work on a Runescape based server, I don't think I will be needing this system anymore, so I will just provide this community with the incomplete version of the library I was building and then possibly one of you can expand upon the idea. :)

Had to remove most of the comments to post the code :(, I don't like using pastebin.

Magic Library, this can be placed in its own file and referenced via global.lua, it is used to assign, attributes, transformations and even spells to items when equipped :p
Code:
--[[
MIT License
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
documentation files (the "Software"), to deal in the Software without restriction, including without
limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software is furnished to do so, subject to the following
conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial
portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO
EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
USE OR OTHER DEALINGS IN THE SOFTWARE.
]]
Code:
function generateConditions(c)
    local condition = {}
    condition[c.name] = {}
    if c.attribute then
        for i = 1, #c.tiers do
            c.subIds[i] = c.basesubId + i
            condition[c.name][c.tiers[i]] = Condition(c.attribute, c.subIds[i])
            condition[c.name][c.tiers[i]]:setTicks(c.time_ or -1)
            for x = 1, #c.parameters do
                local increment = c.increments < 1 and 1 or c.increments
                condition[c.name][c.tiers[i]]:setParameter(c.parameters[x].skill, c.parameters[x].baseValue + (i * increment) )
            end
            if c.buff then
                condition[c.name][c.tiers[i]]:setParameter(CONDITION_PARAM_BUFF_SPELL, true)
            end
        end
        return condition, c.subIds
    end
end
 
Last edited:
The index of equipment corresponds to the slot id.
Code:
-- name of all the items we will use which will be effected by this lib
equipment = {
    [1] = { -- 1 is the head
        ['golden helmet'] = {
         
            name = 'golden helmet',
            tiers = {1, 2, 3, 4, 5},
            attribute = CONDITION_ATTRIBUTES,
            basesubId = 1,
            increments = 1,
            parameters = {
                {
                    skill = CONDITION_PARAM_SKILL_SHIELD,
                    baseValue = 15
                }
            },
            time_ = -1,
            buff = false,
            spell = {},
            permanent = false,
            condition = {}, subIds = {},
            upgradeable = true,
            upgradeTo = {},
            storage = 10000
        }
    },
    [2] = { -- 2 is the amulet slot
        ['platinum amulet'] = {
         
            name = 'platinum amulet',
     
            tiers = {1, 2, 3, 4, 5, 6, 7, 8, 9},
            attribute = CONDITION_ATTRIBUTES,
            basesubId = 20,
            increments = 5,
            parameters = {
                {
                    skill = CONDITION_PARAM_STAT_MAXHITPOINTSPERCENT,
                    baseValue = 110
                },
                {
                    skill = CONDITION_PARAM_STAT_MAXMANAPOINTSPERCENT,
                    baseValue = 110
                }
            },
            time_ = -1,
            buff = false,
            spell = {},
            permanent = false,
            condition = {}, subIds = {},
            upgradeable = true,
            upgradeTo = {},
            storage = 10000
        }
    },
    [6] = { -- 6 is the left hand
        ['stonecutter axe'] = {
         
            name = 'stonecutter axe',
         
            tiers = {1, 2, 3, 4, 5},
            attribute = CONDITION_ATTRIBUTES,
            basesubId = 60,
            increments = 1,
            parameters = {
                {
                    skill = CONDITION_PARAM_SKILL_AXE,
                    baseValue = 10
                }
            },
            time_ = -1,
            buff = false,
            spell = {'food', 'haste'},
            permanent = false,
            condition = {}, subIds = {},
            upgradeable = true,
            upgradeTo = {},
            storage = 10000
        },
        ['spike sword'] = {
         
            name = 'spike sword',
         
            tiers = {1, 2, 3, 4, 5},
            attribute = nil,
            transform = {
                to = {
                    2383, -- normal -- tier 1
                    7854, -- earth -- tier 2
                    7763, -- icy -- tier 3
                    7869, -- energy -- tier 4
                    7744, -- fire -- tier 5
                },
                from = 2383
            },
            storage = 10000
        },
        ['earth spike sword'] = {
         
            name = 'earth spike sword',
         
            tiers = {1, 2, 3, 4, 5},
            attribute = CONDITION_ATTRIBUTES,
            basesubId = 62,
            increments = 2,
            parameters = {
                {
                    skill = CONDITION_PARAM_SKILL_SWORD,
                    baseValue = 2
                }
            },
            time_ = -1,
            buff = false,
            spell = {'Terra Strike'},
            permanent = false,
            condition = {}, subIds = {},
            upgradeable = true,
            upgradeTo = {},
            transform = {
                to = 7854, from = 2383
            },
            storage = 10000
        },
        ['icy spike sword'] = {
         
            name = 'icy spike sword',
         
            tiers = {1, 2, 3, 4, 5},
            attribute = CONDITION_ATTRIBUTES,
            basesubId = 63,
            increments = 2,
            parameters = {
                {
                    skill = CONDITION_PARAM_SKILL_SWORD,
                    baseValue = 3
                }
            },
            time_ = -1,
            buff = false,
            spell = {'Ice Strike'},
            permanent = false,
            condition = {}, subIds = {},
            upgradeable = true,
            upgradeTo = {},
            transform = {
                to = 7763, from = 2383
            },
            storage = 10000
        },
        ['energy spike sword'] = {
         
            name = 'energy spike sword',
         
            tiers = {1, 2, 3, 4, 5},
            attribute = CONDITION_ATTRIBUTES,
            basesubId = 64,
            increments = 2,
            parameters = {
                {
                    skill = CONDITION_PARAM_SKILL_SWORD,
                    baseValue = 4
                }
            },
            time_ = -1,
            buff = false,
            spell = {'Energy Strike'},
            permanent = false,
            condition = {}, subIds = {},
            upgradeable = true,
            upgradeTo = {},
            transform = {
                to = 7869, from = 2383
            },
            storage = 10000
        },
        ['fiery spike sword'] = {
         
            name = 'fiery spike sword',
         
            tiers = {1, 2, 3, 4, 5},
            attribute = CONDITION_ATTRIBUTES,
            basesubId = 65,
            increments = 2,
            parameters = {
                {
                    skill = CONDITION_PARAM_SKILL_SWORD,
                    baseValue = 5
                }
            },
            time_ = -1,
            buff = false,
            spell = {'Flame Strike'},
            permanent = false,
            condition = {}, subIds = {},
            upgradeable = true,
            upgradeTo = {},
            transform = {
                to = 7744, from = 2383
            },
            storage = 10000
        }
    },
    [8] = { -- 8 is the feet
        ['soft boots'] = {
         
            name = 'soft boots',
         
            tiers = {1, 2, 3, 4, 5, 6, 7, 8, 9},
            attribute = CONDITION_REGENERATION,
            basesubId = 80,
            increments = 5,
            parameters = {
                {
                    skill = CONDITION_PARAM_HEALTHGAIN,
                    baseValue = 10
                },
                {
                    skill = CONDITION_PARAM_HEALTHTICKS,
                    baseValue = 1
                },
                {
                    skill = CONDITION_PARAM_MANAGAIN,
                    baseValue = 10
                },
                {
                    skill = CONDITION_PARAM_MANATICKS,
                    baseValue = 1
                }
            },
            time_ = -1,
            buff = false,
            spell = {'food', 'haste'},
            permanent = false,
            condition = {}, subIds = {},
            upgradeable = true,
            upgradeTo = {},
            transform = {
                to = 2640, from = 6132
            },
            storage = 10000
        }
    }
}


-- this should be the last thing in the file
for slot, items in pairs(equipment) do
    for name, item in pairs(items) do
        equipment[slot][name].condition, equipment[slot][name].subIds = generateConditions(item)
    end
end
 
Last edited:
This goes in movements, all items which utilize the magical items functionality will reference this script, no other script needs to be made.
Code:
--[[
    This script will handle all equipment which is equipped to the player
]]
-- tier was just used to test this script, you can use a storage value to create a tier system instead
local tier = 5

local storages = {}

function onEquip(player, item, slot)
    -- onEquip is called 3 times, this will alleviate that
    local slots = player:getSlotItem(slot)
    if slots then
        if slots.itemid ~= item.itemid then
            return true
        else
            -- only needs to be called 1 time
            player:getSlottedItems()
            local name = player.name[slot]
            local magicItem = equipment[slot][name]
       
            if magicItem.transform then
                item:transform(magicItem.transform.to)
            end
       
            local condition = magicItem.condition[name][tier]
            player:addCondition(condition)
       
            local spells = magicItem.spell
            if spells then
                if type(spells) == 'table' then
                    for i = 1, #spells do
                        if not player:hasLearnedSpell(spells[i]) then
                            player:learnSpell(spells[i])
                        end
                    end
                else
                    if not player:hasLearnedSpell(spells) then
                        player:learnSpell(spells)
                    end
                end
            end
        end
    end

    return true
end

-- onDeEquip is only called one time
function onDeEquip(player, item, slot)
    local name = player.name[slot]
    local magicItem = equipment[slot][name]
   
    player:removeCondition(magicItem.attribute, magicItem.subIds[tier])

    local spells = magicItem.spell
    -- do we want them to forget this spell?
    local permanent = magicItem.permanent
    if spells then
        if not permanent then
            if type(spells) == 'table' then
                for i = 1, #spells do
                    player:forgetSpell(spells[i])
                end
            else
                player:forgetSpell(spells)
            end
        end
    end
    if magicItem.transform then
        item:transform(magicItem.transform.from)
    end
    return true
end
 
Last edited:
This goes in player.lua
Code:
Player.name, Player.desc = {}, {}

function Player:getSlottedItems()
    for i = 1, 10 do
        local x = self:getSlotItem(i)
        local item = pushThing(x).itemid
        if item ~= 0 and item then
            -- ignore the backpack slot
            if i ~= 3 then
                table.insert(self.name, i, x:getName())
                self.desc[x:getName()] = x:getDescription()
            end
        end
    end
end

function Player:getNameOfSlotItem(slot)
    self:getSlottedItems()
    return self.name[slot]
end

function Player:getDescriptionOfSlotItem(name)
    self:getSlottedItems()
    return self.desc[name]
end
 
Last edited:
I was making custom weapons, so I will just include this as well, although it doesn't really have anything to do with the library, you can make your own custom weapons :)

This is an axe weapon
Code:
-- we will need to add a description to the item of what type of damage it does
local combat = Combat()
combat:setParameter(COMBAT_PARAM_TYPE, COMBAT_PHYSICALDAMAGE)
combat:setParameter(COMBAT_PARAM_EFFECT, CONST_ME_HITAREA)
combat:setParameter(COMBAT_PARAM_DISTANCEEFFECT, CONST_ANI_WEAPONTYPE)
combat:setParameter(COMBAT_PARAM_BLOCKARMOR, true)
combat:setParameter(COMBAT_PARAM_USECHARGES, true)

function onGetFormulaValues(player, skill, attack, factor)
    local min = (player:getLevel() / 5) + (skill * attack * 0.02) + 4
    local max = (player:getLevel() / 5) + (skill * attack * 0.04) + 9
    return -min, -max
end

combat:setCallback(CALLBACK_PARAM_SKILLVALUE, "onGetFormulaValues")

function onUseWeapon(player, variant)
    return combat:execute(player, variant)
end

this is a rod
Code:
local combat = Combat()
combat:setParameter(COMBAT_PARAM_TYPE, COMBAT_ICEDAMAGE)
combat:setParameter(COMBAT_PARAM_EFFECT, CONST_ME_ICEATTACK)
combat:setParameter(COMBAT_PARAM_DISTANCEEFFECT, CONST_ANI_SMALLICE)

function onGetFormulaValues(player, level, maglevel)
    local min = (level / 5) + (maglevel * 1.4) + 8
    local max = (level / 5) + (maglevel * 2.2) + 14
    return -min, -max
end

combat:setCallback(CALLBACK_PARAM_LEVELMAGICVALUE, "onGetFormulaValues")

function onUseWeapon(player, variant)
    return combat:execute(player, variant)
end
 
Last edited:
First of all, thanks for your release. I've been trying to fully understand your lib, but i can't really understand the "upgrade" part and tiers. Do you mind giving me a short explanation about it please? Thanks for your time.
 
First of all, thanks for your release. I've been trying to fully understand your lib, but i can't really understand the "upgrade" part and tiers. Do you mind giving me a short explanation about it please? Thanks for your time.
Well the 1st 2 posts of the thread go in its own file and referenced via global.lua or just added to global.lua, I am adding this explanation for those who have pm'd me about it.

The tier system can be used in conjunction with some of the other systems I have released, for instance the spell upgrade system where the items can posses different attributes or bonuses, or more powerful spells based on their tier, this is why spells were applied to the table.

As with most of my system releases, these systems or libraries are not meant to run straight out of the box, they will require you the developer to implement in how you see fit.

Since it is unfinished, there is a bit missing from the library like functions to aid in description and upgrading... but this is why you are a developer :)

@ semi-off-topic
I could of done like so many others have done in the past and released a complete system where it is just install x and y and then we have a thousand servers all with the same content, but I am not really interested in holding everyone's hand when it comes to their dream project.

For those who can't see the value in this library or how to integrate it, good, for those that can, great. :)

Enjoy!
 
@Codex NG I thank you for your explanation! I know its not ready to go, but its not hard to make it work. Just wanted to know what were those "tier" used for! Really thanks for your time, it helped a lot.
 
Back
Top