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

Lua Show spell on default when up mlvl

gmstrikker

Well-Known Member
Joined
Jul 30, 2014
Messages
458
Solutions
1
Reaction score
50
My script is working fine, but i have a problem with
needlearn = "1"

when i UP magic lvl if needlearn="0", show the spell and all's ok, but if i have needlearn="1" on spell, dont show..
Pls look my script to see
Code:
function onAdvance(cid, skill, oldLevel, newLevel)
   if skill == SKILL__MAGLEVEL then     
     local spells = {}
     for index = 0,    getPlayerInstantSpellCount(cid) - 1 do
       local spell = getPlayerInstantSpellInfo(cid, index)
       if spell.mlevel > oldLevel and spell.mlevel <= newLevel then
         table.insert(spells, "  [".. spell.name .."] \"".. spell.words .. "\" Mana[".. spell.mana .."]")
       end
     end
   
     if #spells > 0 then       
       doPlayerSendTextMessage(cid, MESSAGE_EVENT_ORANGE, "You have just advanced to magic level ".. newLevel .." and learned new spells!")

       for _, v in pairs(spells) do
         doPlayerSendTextMessage(cid, MESSAGE_EVENT_ORANGE, v)
       end
     end
   end
   
   return true
end

Code:
  <event type="advance" name="SpellUp" event="script" value="spellup.lua"/>
 
You get spells of player. If he did not learn it, it's not 'his' spells. What do you expect? Second list of spells that he can learn, but not learnt yet?

WHAT TFS DO YOU USE?
 
You get spells of player. If he did not learn it, it's not 'his' spells. What do you expect? Second list of spells that he can learn, but not learnt yet?

WHAT TFS DO YOU USE?

Im using 0.4
I want show to they... For exemple:
Now you have ML to 'exevo gran mas vis' and player go to buy spell :(

Sorry to my english
 
A way you could handle this is a few step process,
1. set a storage value in all your spells and only allow those spells to be casted that are known by the player
2. run a check on all the spells that the player can use in the spell book script and only list those spells that the player has the storage values for
3. modify getPlayerInstantSpellInfo & getPlayerInstantSpellCount to work with this new script where it prints the spells the player can use but does not currently own when they level up, letting them know these spells are currently available.
4. when the player purchases the spell set the storage accordingly so that they may use the new spell(s).

5. all this could be beneficial as you can turn on and off spells due to whatever factors.

Or maybe someone else can suggest something simpler
 
A way you could handle this is a few step process,
1. set a storage value in all your spells and only allow those spells to be casted that are known by the player
2. run a check on all the spells that the player can use in the spell book script and only list those spells that the player has the storage values for
3. modify getPlayerInstantSpellInfo & getPlayerInstantSpellCount to work with this new script where it prints the spells the player can use but does not currently own when they level up, letting them know these spells are currently available.
4. when the player purchases the spell set the storage accordingly so that they may use the new spell(s).

5. all this could be beneficial as you can turn on and off spells due to whatever factors.

Or maybe someone else can suggest something simpler

This would give a tremendous job, I think there are easier ways to do it
 
If you want to do the work you can do this.... Not the best way but effective.

Code:
local spells = {
["sorcerer", "master sorcerer"] = { -- SORCERER
level = {
[1] = "spell", "spell", --spells for level 1
[5] = "spell", "spell"}}, --spells for level 5

["druid", "elder druid"] = { -- DRUID
level = {
[1] = "spell", "spell", --spells for level 1
[5] = "spell", "spell"}}, --spells for level 5
["paladin", "royal paladin"] = { -- PALADIN
level = {
[1] = "spell", "spell", --spells for level 1
[5] = "spell", "spell"}}, --spells for level 5

["knight", "elite knight"] = { -- KNIGHT
level = {
[1] = "spell", "spell", --spells for level 1
[5] = "spell", "spell"}} --spells for level 5
}




function onAdvance(cid, skill, oldLevel, newLevel)
    player = Player(cid)
    CONFIG = spells[player:getVocation()]
   
   if not CONFIG return false end
   
   EVENT = CONFIG.level[player:getMagLevel()]
   
   if not EVENT return false end
   
   player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "New spells: "..EVENT..)
   
   return true
end
 
I try it:
Code:
local spells = {
   ["sorcerer", "master sorcerer", "epic sorcerer"] = {
     level = {
       [10] = "1spell", "spell1",
       [20] = "2spell", "spell2"
     }
   },

   ["druid", "elder druid", "epic druid"] = {
     level = {
       [1] = "spell", "spell",
       [5] = "spell", "spell"
     }
   },
   
   ["paladin", "royal paladin", "epic paladin"] = {
     level = {
       [1] = "spell", "spell",
       [5] = "spell", "spell"
     }
   },

   ["knight", "elite knight", "epic knight"] = {
     level = {
       [1] = "1spell", "spell1",
       [5] = "2spell", "spell2"
     }
   }
}


function onAdvance(cid, skill, oldLevel, newLevel)
   player = Player(cid)
   CONFIG = spells[player:getVocation()]
   if not CONFIG return false end
   EVENT = CONFIG.level[player:getMagLevel()]
   if not EVENT return false end
   player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "New spells: "..EVENT..)
   return true
end

Error:
LXJOuZE.png
 
Code:
local spells = {
   [1] = { --sorcerer
     level = {
       [10] = "1spell", "spell1",
       [20] = "2spell", "spell2"
     }
   },

   [2] = { --druid
     level = {
       [1] = "spell", "spell",
       [5] = "spell", "spell"
     }
   },
   
   [3] = { --paladin
     level = {
       [1] = "spell", "spell",
       [5] = "spell", "spell"
     }
   },

   [4] = { --knight
     level = {
       [1] = "1spell", "spell1",
       [5] = "2spell", "spell2"
     }
   }
}
local array_sorc = {"Sorcerer", "Master Sorcerer"}
local array_druid = {"Druid", "Elder Druid"}
local array_paladin = {"Paladin", "Royal Paladin"}
local array_knight = {"Knight", "Elite Knight"}
local text = ""
function onAdvance(cid, skill, oldLevel, newLevel)
if skill == SKILL__MAGLEVEL then  
   player = Player(cid)
   if isInArray(array_sorc, player:getVocation()) then
   CONFIG = spells[1]
   elseif isInArray(array_druid, player:getVocation()) then
   CONFIG = spells[2]
   elseif isInArray(array_paladin, player:getVocation()) then
   CONFIG = spells[3]
   elseif isInArray(array_knight, player:getVocation()) then
   CONFIG = spells[4]
   end
   if not CONFIG return false end
   EVENT = CONFIG.level[player:getMagLevel()]
   if not EVENT return false end
   for i, v in ipairs(EVENT) do
   text = text..""..i..", "
   end
   player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "New spells: "..text..)
 end
   return true
end
 
Code:
local spells = {
   [1] = { --sorcerer
     level = {
       [10] = "1spell", "spell1",
       [20] = "2spell", "spell2"
     }
   },

   [2] = { --druid
     level = {
       [1] = "spell", "spell",
       [5] = "spell", "spell"
     }
   },
  
   [3] = { --paladin
     level = {
       [1] = "spell", "spell",
       [5] = "spell", "spell"
     }
   },

   [4] = { --knight
     level = {
       [1] = "1spell", "spell1",
       [5] = "2spell", "spell2"
     }
   }
}
local array_sorc = {"Sorcerer", "Master Sorcerer"}
local array_druid = {"Druid", "Elder Druid"}
local array_paladin = {"Paladin", "Royal Paladin"}
local array_knight = {"Knight", "Elite Knight"}
local text = ""
function onAdvance(cid, skill, oldLevel, newLevel)
if skill == SKILL__MAGLEVEL then 
   player = Player(cid)
   if isInArray(array_sorc, player:getVocation()) then
   CONFIG = spells[1]
   elseif isInArray(array_druid, player:getVocation()) then
   CONFIG = spells[2]
   elseif isInArray(array_paladin, player:getVocation()) then
   CONFIG = spells[3]
   elseif isInArray(array_knight, player:getVocation()) then
   CONFIG = spells[4]
   end
   if not CONFIG return false end
   EVENT = CONFIG.level[player:getMagLevel()]
   if not EVENT return false end
   for i, v in ipairs(EVENT) do
   text = text..""..i..", "
   end
   player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "New spells: "..text..)
end
   return true
end
hhkoI74.png
 
Damn man how are you trying to make a server when you can't fix a little problem like that? I am going to have to let you figure it out on your own.
 
Damn man how are you trying to make a server when you can't fix a little problem like that? I am going to have to let you figure it out on your own.
Your the one who caused the error but you won't correct it?
Also your code won't work because these metamethods don't exist in 0.4

I have an idea how you could solve this issue but I have to go to sleep, I'll setup a server on my computer tomorrow after work :)
 
Code:
local spells = {
   [1] = { --sorcerer
     level = {
       [10] = "1spell", "spell1",
       [20] = "2spell", "spell2"
     }
   },

   [2] = { --druid
     level = {
       [1] = "spell", "spell",
       [5] = "spell", "spell"
     }
   },
  
   [3] = { --paladin
     level = {
       [1] = "spell", "spell",
       [5] = "spell", "spell"
     }
   },

   [4] = { --knight
     level = {
       [1] = "1spell", "spell1",
       [5] = "2spell", "spell2"
     }
   }
}
local array_sorc = {"Sorcerer", "Master Sorcerer"}
local array_druid = {"Druid", "Elder Druid"}
local array_paladin = {"Paladin", "Royal Paladin"}
local array_knight = {"Knight", "Elite Knight"}
local text = ""
function onAdvance(cid, skill, oldLevel, newLevel)
if skill == SKILL__MAGLEVEL then 
    player = Player(cid)
        if isInArray(array_sorc, player:getVocation()) then
            CONFIG = spells[1]
        elseif isInArray(array_druid, player:getVocation()) then
            CONFIG = spells[2]
        elseif isInArray(array_paladin, player:getVocation()) then
            CONFIG = spells[3]
        elseif isInArray(array_knight, player:getVocation()) then
            CONFIG = spells[4]
    end
        if not CONFIG return false end
            EVENT = CONFIG.level[player:getMagLevel()]
        if not EVENT then
    return false
    end
        for i, v in ipairs(EVENT) do
            text = text..""..i..", "
        end
            player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "New spells: "..text..)
        end
    return true
end
Feels wrong but think i made it xD
 
I just found out I don't have to work today (because of holiday) so I am compiling 0.4 sources and will start to work on a solution in a few minutes :)
 
Well I did my best, your gonna have to live without the vocations for now :p
Place this in same directory where your config.lua is, it will create a spells.lua file
You can execute this script using a lua interpreter
Code:
https://code.google.com/p/luaforwindows/downloads/detail?name=LuaForWindows_v5.1.4-46.exe&can=2&q=
Or you can execute it as a talkaction and generate the code that way
Then you can copy the spells.lua file to where you need it.
Code:
-- Credits to zbizu for using the code from his item parser
-- https://otland.net/threads/tfs-1-1-items-parser-useful-for-searching-ids.228705/

-- And to Me :) Codex NG for making the the changes in this script to extract the spells names,
-- words, levels and eventually the vocations
-- vocation isn't quite finished yet

function isInArray(table_, value)
    for k, v in pairs(table_) do
        if v == value then
            return false
        end
    end
    return true
end


function findType(table_, value)
    for k, v in pairs(table_) do
        if v == value then
            return true
        end
    end
    return false
end


function parseSpells()
    local file = 'data/spells/spells.xml'
    local fileEx = 'spells.lua'
    local outputFile = fileEx

    local types = {'instant', 'conjure'}
    local typeOf, name, words, level, mana, voc, spells = '', '', '', 0, 0, {}, {}

    for line in io.lines(file) do
        for type_, n, w, l, m in line:gmatch('<(%a-)%s* name="(.-)" words="(.-)" lvl="(%d+)" mana="(%d+)"') do
            if findType(types, type_) then
                typeOf = type_
                name = n
                words = w
                level = l
                mana = m
            end
        end

        -- this section is still a work in progress
        --------------------------------------
        for id, _ in line:gmatch('<vocation id="(%d+)"') do
                if id ~= nil then
                    voc[#voc] = id
                end
        end
        -- ------------------------------------
        table.insert(spells, {typeOf = typeOf, name = name, words = words, level = level, mana = mana , voc = voc})


    end
    local temp = {}
    fileEx = io.open(fileEx, "w+")
    fileEx:write("\tspells = {\n")
    for x = 1, #spells do
        if x > 1 then
            temp[x] = spells[x-1].name
            if isInArray(temp, spells[x].name) and spells[x].name ~= "" then
                fileEx:write("\t\t{ type = \""..spells[x].typeOf.."\", name = \""..spells[x].name.."\",  words = \""..spells[x].words.."\", level = "..spells[x].level..", mana = "..spells[x].mana.." },\n")
            end
        end
    end
    fileEx:write("\t}")
    fileEx:close()
end

parseSpells()
 
Last edited:
Back
Top