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

GlobalEvent [Spell Upgrade System] for 1.2

Codex NG

Recurrent Flamer
Joined
Jul 24, 2015
Messages
2,994
Solutions
12
Reaction score
1,657
I wrote this some time ago back on another account and sadly removed it from the forums.
It was originally written for 1.0, but does work for 1.2

This should be placed in the global.lua
Code:
function upGradeSpells(player, words, tier, max)
    if player:getStorageValue(SPELL_WORDS[words]) < max then
        if player:getStorageValue(SPELL_WORDS[words]) < TIER[tier] then
            player:setStorageValue(SPELL_WORDS[words], TIER[tier])
            player:getPosition():sendMagicEffect(CONST_ME_CONFETTI_HORIZONTAL)
            doCreatureSay(cid, tier, TALKTYPE_ORANGE_1, false, 0, player:getPosition())
        elseif player:getStorageValue(SPELL_WORDS[words]) == TIER[tier] then
            player:sendCancelMessage("You've already scribed a this version of the spell.")
            player:getPosition():sendMagicEffect(CONST_ME_POFF)
            return false
        else
            player:sendCancelMessage("You already have a higher spell version scribed.")
            player:getPosition():sendMagicEffect(CONST_ME_POFF)
            return false
        end
    else
        player:sendCancelMessage("You've reached the maximum tier for this spell.")
        player:getPosition():sendMagicEffect(CONST_ME_POFF)
        return false
    end
end

Code:
    --light, haste, single targets, area, single target heal, support spell, speed
    SPELL_WORDS =
    {
        ["exura dis"] = 1001,
        ["exevo dis flam hur"] = 1002,
        ["exiva"] = 1003,
        ["exori min flam"] = 1004,
        ["utevo lux"] = 1005,
        ["exura"] = 1006,
        ["exani tera"] = 1007,
        ["exura ico"] = 1008,
        ["exana pox"] = 1009,
        ["exani hur"] = 10010,
        ["exori vis"] = 10011,
        ["exori tera"] = 10012,
        ["exevo con"] = 10013,
        ["utevo gran lux"] = 10014,
        ["exori flam"] = 10015,
        ["exevo pan"] = 10016,
        ["adevo grav pox"] = 10017,
        ["utamo vita"] = 10018,
        ["utani hur"] = 10019,
        ["adevo grav flam"] = 10020,
        ["exori frigo"] = 10021,
        ["adori min vis"] = 10022,
        ["adana pox"] = 10023,
        ["adura gran"] = 10024,
        ["exori moe ico"] = 10025,
        ["exevo con pox"] = 10026,
        ["exori mort"] = 10027,
        ["exori ico"] = 10028,
        ["adeta sio"] = 10029,
        ["adito grav"] = 10030,
        ["exevo con mort"] = 10031,
        ["adevo grav vis"] = 10032,
        ["exevo flam hur"] = 10033,
        ["exura sio"] = 10034,
        ["exevo frigo hur"] = 10035,
        ["exura gran"] = 10036,
        ["utani gran hur"] = 10037,
        ["exeta res"] = 10038,
        ["adori blank"] = 10039,
        ["adito tera"] = 10040,
        ["exana vis"] = 10041,
        ["exevo vis lux"] = 10042,
        ["utevo res ina"] = 10043,
        ["exori con"] = 10044,
        ["exevo con hur"] = 10045,
        ["adori tera"] = 10046,
        ["adura vita"] = 10047,
        ["adevo mas pox"] = 10048,
        ["adori vis"] = 10049,
        ["exevo con flam"] = 10050,
        ["utani tempo hur"] = 10051,
        ["utevo res"] = 10052,
        ["utori flam"] = 10053,
        ["utevo vis lux"] = 10054,
        ["exana ina"] = 10055,
        ["adevo mas flam"] = 10056,
        ["adevo res flam"] = 10057,
        ["adori san"] = 10058,
        ["adori flam"] = 10059,
        ["adevo ina"] = 10060,
        ["adana mort"] = 10061,
        ["adevo grav vita"] = 10062,
        ["adori frigo"] = 10063,
        ["exori hur"] = 10064,
        ["adori mas vis"] = 10065,
        ["adori mas tera"] = 10066,
        ["exevo gran vis lux"] = 10067,
        ["adevo mas grav pox"] = 10068,
        ["exura vita"] = 10069,
        ["exana flam"] = 10070,
        ["adori mas frigo"] = 10071,
        ["adori mas flam"] = 10072,
        ["adevo mas hur"] = 10073,
        ["adevo grav tera"] = 10074,
        ["utura mas sio"] = 10075,
        ["utori mas sio"] = 10076,
        ["utito mas sio"] = 10077,
        ["utamo mas sio"] = 10078,
        ["adevo mas grav flam"] = 10079,
        ["exevo con grav"] = 10080,
        ["exori mas"] = 10081,
        ["utori vis"] = 10082,
        ["utana vid"] = 10083,
        ["exori"] = 10084,
        ["exura san"] = 10085,
        ["exura gran mas res"] = 10086,
        ["adevo mas vis"] = 10087,
        ["exevo vis hur"] = 10088,
        ["exevo tera hur"] = 10089,
        ["exori san"] = 10090,
        ["exevo gran frigo hur"] = 10091,
        ["utori kor"] = 10092,
        ["adevo mas grav vis"] = 10093,
        ["exeta vis"] = 10094,
        ["exeta con"] = 10095,
        ["exana kor"] = 10096,
        ["adori gran mort"] = 10097,
        ["utura"] = 10098,
        ["utori pox"] = 10099,
        ["exevo mas san"] = 100100,
        ["adana ani"] = 100101,
        ["utamo tempo san"] = 100102,
        ["exevo gran mas tera"] = 100103,
        ["utamo tempo"] = 100104,
        ["exevo gran mas vis"] = 100105,
        ["exori amp vis"] = 100106,
        ["exevo con vis"] = 100107,
        ["utito tempo san"] = 100108,
        ["exura gran san"] = 100109,
        ["exevo gran mas frigo"] = 100110,
        ["exevo gran mas flam"] = 100111,
        ["utito tempo"] = 100112,
        ["exori gran tera"] = 100113,
        ["exori gran flam"] = 100114,
        ["exori min"] = 100115,
        ["utori san"] = 100116,
        ["utori mort"] = 100117,
        ["exori gran vis"] = 100118,
        ["exana mort"] = 100119,
        ["exura gran ico"] = 100120,
        ["exori gran frigo"] = 100121,
        ["exori max flam"] = 100122,
        ["exori max tera"] = 100123,
        ["exori gran con"] = 100124,
        ["exori gran"] = 100125,
        ["exori max frigo"] = 100126,
        ["exori max vis"] = 100127,
        ["utura gran"] = 100128,
        ["exori gran ico"] = 100129
    }

    TIER =
    {
        ["Apprentice"] = 0,
        ["Journeyman"] = 1,
        ["Adept"] = 2,
        ["Expert"] = 3,
        ["Master"] = 4,
        ["Grandmaster"] = 5
    }

This is saved in chatchannels
data\chatchannels\chatchannels.xml
Code:
<?xml version="1.0" encoding="UTF-8"?>
<channels>
    <channel id="2" name="Tutor" script="tutor.lua" />
    <channel id="3" name="World Chat" public="1" script="worldchat.lua" />
    <channel id="4" name="Spells" public="1" script="spells.lua" />
    <channel id="5" name="Trade" public="1" script="advertising.lua" />
    <channel id="6" name="Advertising-Rookgaard" public="1" script="advertising-rook.lua" />
    <channel id="7" name="Help" public="1" script="help.lua" />
    <channel id="8" name="Gamemaster" script="gamemaster.lua" />
</channels>

data\chatchannels\scripts\spells.lua
Code:
local CHANNEL_CHARACTER = 4
local tier =
    {
        [0] = "[ Apprentice ]",
        [1] = "[ Journeyman ]",
        [2] = "[ Adept ]",
        [3] = "[ Expert ]",
        [4] = "[ Master ]",
        [5] = "[ Grandmaster ]"
    }

local function listSpells(player)
    local count = getPlayerInstantSpellCount(player)
    local text = ""
    local t = {}
    for i = 0, count - 1 do
        local spell = getPlayerInstantSpellInfo(player, i)
        if spell.level ~= 0 then
            if spell.manapercent > 0 then
                spell.mana = spell.manapercent .. "%"
            end
            t[#t+1] = spell
        end
    end
    table.sort(t, function(a, b) return a.level < b.level end)
    local prevLevel = -1
    for i, spell in ipairs(t) do
        local line = ""
        if prevLevel ~= spell.level then
            if i ~= 1 then
                line = "\n"
            end
            line = line .. "\nSpells for Level " .. spell.level .. "\n"
            prevLevel = spell.level
            player:sendChannelMessage(cid, line, TALKTYPE_CHANNEL_O, CHANNEL_CHARACTER)
        end
        if player:getStorageValue(SPELL_WORDS[spell.words]) > 0 then
            local index = player:getStorageValue(SPELL_WORDS[spell.words])
            text =  "  " .. spell.words .. " " .. tier[index] .. " - " .. spell.name .. " : " .. spell.mana .. "\n"
        else
            text = "  " .. spell.words .. " " .. tier[0] .. " - " .. spell.name .. " : " .. spell.mana .. "\n"
        end
        player:sendChannelMessage(cid, text, TALKTYPE_CHANNEL_Y, CHANNEL_CHARACTER)
    end
 
end

function onJoin(player)
    addEvent(listSpells, 100, player)
    return true
end

function onSpeak(player, type, message)
    player:sendCancelMessage("You may not speak in this chat.")
    return false
end
Example:
data\actions\scripts\spells.lua

Code:
function onUse(cid, item, fromPosition, itemEx, toPosition, isHotkey)
    upGradeSpells(cid, "exevo pan", 1, item)
    return true
end

Example in a spell
Code:
local food = {
    2666, -- meat
    2671, -- ham
    2681, -- grape
    2674, -- apple
    2689, -- bread
    2690, -- roll
    2696  -- cheese
}


function onCastSpell(creature, var)
    if not creature:isPlayer() then
        return false
    end
    if creature:getStorageValue(SPELL_WORDS["exevo pan"]) > 0 then
        -- if the tier is higher then apprentice increase the amount of food created
        creature:addItem(food[math.random(#food)], (creature:getStorageValue(SPELL_WORDS["exevo pan"]) + 1))
        creature:getPosition():sendMagicEffect(CONST_ME_MAGIC_GREEN)
    else
        -- else give 1 piece of food
        creature:addItem(food[math.random(#food)], 1)
        creature:getPosition():sendMagicEffect(CONST_ME_MAGIC_GREEN)
    end
    return true
end
 
Last edited:
"frankly I don't work well with others in that I end up doing most of the work myself"

Never have I read a bigger stretch of the truth in my life.
 
^ The ego on this one has grown to much for his own well being.
 
Recycled is the word I would most likely use. But to each their own!
 
Recycled is the word I would most likely use. But to each their own!
Are you done?
Lets not talk bout recycled.. your server is nothing but the very definition of recycled content / ideas..
Good luck trying to find someone to build your server for you!
 
[/CODE]
Example:
data\actions\scripts\spells.lua

Code:
function onUse(cid, item, fromPosition, itemEx, toPosition, isHotkey)
    upGradeSpells(cid, "exevo pan", 1, item)
    return true
end
I have one question, what is parameters?
Code:
upGradeSpells(cid, "exevo pan", 1, item)
what is value of "1" and "item"
 
I have one question, what is parameters?
Code:
upGradeSpells(cid, "exevo pan", 1, item)
what is value of "1" and "item"
function upGradeSpells(player, words, tier, max)
player, spell words, advance tier in +1 or any, maximum tier (example: 5)
 
function upGradeSpells(player, words, tier, max)
player, spell words, advance tier in +1 or any, maximum tier (example: 5)
so, item = max of advance ?
so much thanks for answer
 
Maybe I'm wrong though =[
you're right man
see in the scope of the function
Code:
function upGradeSpells(player, words, tier, max)
I finally understand it and how use it ;D
thanks
 
This looks pretty sweet. So I have to go through and edit every script, or am I looking at this all wrong?
 
how i can add it in a npc. like the king tibianus. to pay a fee and upgrade the skill level ?
i'm using it to upgrade damage of the spells. but i can't search a mode to upgrade the skill with one npc

ps. srry the bad english
 
Hi, I'm using TFS 1.2 and It didn't work.
When I use the item from actions wherever I use it, this error appears.
EVENT LOG:
Lua Script Error: [Action Interface]
Jul 28 22:39:16 [25017]: data/actions/scripts/upgrade/spells.lua:eek:nUse
Jul 28 22:39:16 [25017]: data/global.lua:126: attempt to compare number with userdata
Jul 28 22:39:16 [25017]: stack traceback:
Jul 28 22:39:16 [25017]: [C]: in function '__lt'
Jul 28 22:39:16 [25017]: data/global.lua:126: in function 'upGradeSpells'
Jul 28 22:39:16 [25017]: data/actions/scripts/upgrade/spells.lua:2: in function <data/actions/scripts/upgrade/spells.lua:1>
:eek: = : o (post error)

Can someone help?
I think I dind't understand the system as well...
What function does the Spell chat channel have?
Where do I use the item atached to actions?
I'm sorry but I'm new with this system and I'm interested on adding it to my OTS.
Thanks!
 
Back
Top