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

TFS 0.X Convert SKILLS/ML when change vocation Dawnport

samandriel

Active Member
Joined
Oct 19, 2016
Messages
242
Solutions
1
Reaction score
46
I'm trying to bring Dawnport to 8.6 on my 0.4 (https://github.com/Fir3element/3777/blob/master/src/luascript.cpp)

It's already changing vocation, give items...

But there is only one thing it not working:
When players change vocation i want to convert skills, i mean a mage ml 10, change to knight he cant still with ml 10, same to knight shielding 40, cant be mage shielding 40

What i tried so far? zxmatzx gave me the idea to use:
getPlayerSkillTries(cid, skill) and getPlayerRequiredSkillTries(cid, skillId, skillLevel)
Code:
    -- | skills convert |
    -- get skill points
    local SKILL_SHIELD_POINTS = getPlayerSkillTries(cid, SKILL_SHIELD)
    local SKILL_DISTANCE_POINTS = getPlayerSkillTries(cid, SKILL_DISTANCE)
    local SKILL_AXE_POINTS = getPlayerSkillTries(cid, SKILL_AXE)
    local SKILL_SWORD_POINTS = getPlayerSkillTries(cid, SKILL_SWORD)
    local SKILL_CLUB_POINTS = getPlayerSkillTries(cid, SKILL_CLUB)
    -- reset skills
    doPlayerSetMagicLevel(cid, 0)
    doPlayerSetSkillLevel(cid, SKILL_SHIELD, 10)
    doPlayerSetSkillLevel(cid, SKILL_DISTANCE, 10)
    doPlayerSetSkillLevel(cid, SKILL_AXE, 10)
    doPlayerSetSkillLevel(cid, SKILL_SWORD, 10)
    doPlayerSetSkillLevel(cid, SKILL_CLUB, 10)
    -- set skill points back
    doPlayerAddSkillTry(cid, SKILL_SHIELD, SKILL_SHIELD_POINTS)
    doPlayerAddSkillTry(cid, SKILL_DISTANCE, SKILL_DISTANCE_POINTS)
    doPlayerAddSkillTry(cid, SKILL_AXE, SKILL_AXE_POINTS)
    doPlayerAddSkillTry(cid, SKILL_SWORD, SKILL_SWORD_POINTS)
    doPlayerAddSkillTry(cid, SKILL_CLUB, SKILL_CLUB_POINTS)

But its not working at all, when players change vocation it always reseting skills to the start
Why?

Full code:
Code:
-- olhar o cap changing

local tile = {
   --[actionid] = {vocation id}
   [65530] = {
        vocid = 1,
        weaponID = 2190, -- wand of vortex
        extraItems = {
            {itemID = 2260, count = 50}, -- blank rune
            {itemID = 2287, count = 30}, -- lmm
            {itemID = 2302, count = 15} -- FIREBALL
        }
   },
   [65529] = {
        vocid = 2,
        weaponID = 2182, -- snakebite rod
        extraItems = {
            {itemID = 2260, count = 50}, -- blank rune
            {itemID = 2287, count = 30}, -- lmm
            {itemID = 2265, count = 5}, -- IH
            {itemID = 2302, count = 10} -- FIREBALL
        }
   },
   [65528] = {
        vocid = 3,
        weaponID = 2456, -- bow
        extraItems = {
            {itemID = 2260, count = 10}, -- blank rune
            {itemID = 2544, count = 100}, -- arrows
            {itemID = 2389, count = 3}, -- spear
            {itemID = 2265, count = 5}, -- IH
            {itemID = 2287, count = 5}, -- LMM
            {itemID = 2302, count = 5} -- FIREBALL
        }
   },
   [65527] = {
        vocid = 4,
        extraItems = {
            {itemID = 2379, count = 1}, -- sword
            {itemID = 2382, count = 1}, -- axe
            {itemID = 2380, count = 1}, -- club
            {itemID = 2265, count = 10}, -- IH
            {itemID = 2287, count = 5}, -- LMM
            {itemID = 2302, count = 3} -- FIREBALL
        }
   }
}

function onStepIn(cid, item, position, fromPosition)
    local r = tile[item.actionid]
    if not r then
        return true
    end
    local townid = 7
    local pos = {x= 392, y=929, z=6}
    local needcap
    local extralvls = getPlayerLevel(cid) - 1
    local vocation
    local cap
    local hp
    local mp
    -- get skill points in current vocation
    local SKILL_SHIELD_POINTS = getPlayerRequiredSkillTries(cid, SKILL_SHIELD, getPlayerSkillLevel(cid, SKILL_SHIELD, true))
    local SKILL_DISTANCE_POINTS = getPlayerRequiredSkillTries(cid, SKILL_DISTANCE, getPlayerSkillLevel(cid, SKILL_DISTANCE, true))
    local SKILL_AXE_POINTS = getPlayerRequiredSkillTries(cid, SKILL_AXE, getPlayerSkillLevel(cid, SKILL_AXE, true))
    local SKILL_SWORD_POINTS = getPlayerRequiredSkillTries(cid, SKILL_SWORD, getPlayerSkillLevel(cid, SKILL_SWORD, true))
    local SKILL_CLUB_POINTS = getPlayerRequiredSkillTries(cid, SKILL_CLUB, getPlayerSkillLevel(cid, SKILL_CLUB, true))
    if item.actionid == 65530 then -- sorc
        if getPlayerVocation(cid) == 1 then --already sorc
            doTeleportThing(cid, fromPosition)
            doSendMagicEffect(getThingPos(cid), CONST_ME_POFF)
            return true
        end
        doPlayerSetVocation(cid, 1)
        needcap = 88
        hp = (185) + (extralvls * 5)
        mp = (35) + (extralvls * 30)
        cap = (400) + (extralvls * 10)
        ---
    elseif item.actionid == 65529 then -- druid
        if getPlayerVocation(cid) == 2 then --already druid
            doTeleportThing(cid, fromPosition)
            doSendMagicEffect(getThingPos(cid), CONST_ME_POFF)
            return true
        end
        doPlayerSetVocation(cid, 2)
        needcap = 91
        hp = (185) + (extralvls * 5)
        mp = (35) + (extralvls * 30)
        cap = (400) + (extralvls * 10)
        ---
    elseif item.actionid == 65528 then -- pally
        if getPlayerVocation(cid) == 3 then --already pally
            doTeleportThing(cid, fromPosition)
            doSendMagicEffect(getThingPos(cid), CONST_ME_POFF)
            return true
        end
        doPlayerSetVocation(cid, 3)
        needcap = 122
        hp = (185) + (extralvls * 10)
        mp = (35) + (extralvls * 15)
        cap = (400) + (extralvls * 20)
        ---
    elseif item.actionid == 65527 then -- kina
        if getPlayerVocation(cid) == 4 then --already knight
            doTeleportThing(cid, fromPosition)
            doSendMagicEffect(getThingPos(cid), CONST_ME_POFF)
            return true
        end
        doPlayerSetVocation(cid, 4)
        needcap = 44
        hp = (185) + (extralvls * 15)
        mp = (35) + (extralvls * 5)
        cap = (400) + (extralvls * 25)
        ---
    end

    -- add stuff
    setCreatureMaxHealth(cid, hp)
    setCreatureMaxMana(cid, mp)
    doCreatureAddHealth(cid, getCreatureMaxHealth(cid), false)
    doCreatureAddMana(cid, getCreatureMaxMana(cid), false)
    doTeleportThing(cid, pos)
    doSendMagicEffect(getThingPos(cid), CONST_ME_MAGIC_BLUE)
    doPlayerSetTown(cid, townid)
    -- cap convert
    doPlayerSetMaxCapacity(cid, cap)
    -- | skills convert |
    -- reset skills
    doPlayerSetMagicLevel(cid, 0)
    doPlayerSetSkillLevel(cid, SKILL_SHIELD, 10)
    doPlayerSetSkillLevel(cid, SKILL_DISTANCE, 10)
    doPlayerSetSkillLevel(cid, SKILL_AXE, 10)
    doPlayerSetSkillLevel(cid, SKILL_SWORD, 10)
    doPlayerSetSkillLevel(cid, SKILL_CLUB, 10)
    -- set skill points back
    doPlayerAddSkillTry(cid, SKILL_SHIELD, SKILL_SHIELD_POINTS)
    doPlayerAddSkillTry(cid, SKILL_DISTANCE, SKILL_DISTANCE_POINTS)
    doPlayerAddSkillTry(cid, SKILL_AXE, SKILL_AXE_POINTS)
    doPlayerAddSkillTry(cid, SKILL_SWORD, SKILL_SWORD_POINTS)
    doPlayerAddSkillTry(cid, SKILL_CLUB, SKILL_CLUB_POINTS)
    -- | add items |
    -- already recived
    local queststatus = getPlayerStorageValue(cid, item.actionid)
    if queststatus ~= -1 then
        return true
    end
    -- dont have cap
    if getPlayerFreeCap(cid) < needcap then
        doTeleportThing(cid, fromPosition, false)
        doSendMagicEffect(position, CONST_ME_MAGIC_BLUE)
        doPlayerPopupFYI(cid, 'You need '.. needcap ..' OZ CAP to recive the items!')
        return true
    end
    -- add items
    -- weapon first
    if r.weaponID then
        doPlayerAddItem(cid, r.weaponID, 1)
    end
    -- other stuffs
    if r.extraItems then
        for i=1,#r.extraItems do
            local item,count = r.extraItems[i].itemID, r.extraItems[i].count
            doPlayerAddItem(cid, item, count)
        end
    end
    setPlayerStorageValue(cid,item.actionid,1)
    return true
end
 
Solution
I'll try it one last time.

Lua:
local vocation_stats = {
    [1] = {hp = 5, mp = 30, cap = 10},
    [2] = {hp = 5, mp = 30, cap = 10},
    [3] = {hp = 10, mp = 15, cap = 20},
    [4] = {hp = 15, mp = 5, cap = 25}
}

local tiles = {
   --[actionid] = {vocation id}
   [65530] = {
        vocid = 1,
        extraItems = {
            {itemID = 2190, count = 1}, -- wand of vortex
            {itemID = 2260, count = 50}, -- blank rune
            {itemID = 2287, count = 30}, -- lmm
            {itemID = 2302, count = 15} -- FIREBALL
        }
   },
   [65529] = {
        vocid = 2,
        extraItems = {
            {itemID = 2182, count = 1}, -- snakebite rod
            {itemID = 2260, count = 50}, -- blank rune
            {itemID = 2287, count = 30}...
Code:
local vocation_stats = {
    [1] = {hp = 5, mp = 30, cap = 10},
    [2] = {hp = 5, mp = 30, cap = 10},
    [3] = {hp = 10, mp = 15, cap = 20},
    [4] = {hp = 15, mp = 5, cap = 25}
}

local tiles = {
   --[actionid] = {vocation id}
   [65530] = {
        vocid = 1,
        extraItems = {
            {itemID = 2190, count = 1}, -- wand of vortex
            {itemID = 2260, count = 50}, -- blank rune
            {itemID = 2287, count = 30}, -- lmm
            {itemID = 2302, count = 15} -- FIREBALL
        }
   },
   [65529] = {
        vocid = 2,
        extraItems = {
            {itemID = 2182, count = 1}, -- snakebite rod
            {itemID = 2260, count = 50}, -- blank rune
            {itemID = 2287, count = 30}, -- lmm
            {itemID = 2265, count = 5}, -- IH
            {itemID = 2302, count = 10} -- FIREBALL
        }
   },
   [65528] = {
        vocid = 3,
        extraItems = {
            {itemID = 2456, count = 1}, -- bow
            {itemID = 2260, count = 10}, -- blank rune
            {itemID = 2544, count = 100}, -- arrows
            {itemID = 2389, count = 3}, -- spear
            {itemID = 2265, count = 5}, -- IH
            {itemID = 2287, count = 5}, -- LMM
            {itemID = 2302, count = 5} -- FIREBALL
        }
   },
   [65527] = {
        vocid = 4,
        extraItems = {
            {itemID = 2379, count = 1}, -- sword
            {itemID = 2382, count = 1}, -- axe
            {itemID = 2380, count = 1}, -- club
            {itemID = 2265, count = 10}, -- IH
            {itemID = 2287, count = 5}, -- LMM
            {itemID = 2302, count = 3} -- FIREBALL
        }
   }
}

local townId = 7
local pos = {x = 392, y = 929, z = 6}

local skills = {
    SKILL_FIST,
    SKILL_CLUB,
    SKILL_AXE,
    SKILL_SWORD,
    SKILL_SHIELDING,
    SKILL_DISTANCE
}

function onStepIn(cid, item, position, fromPosition)
    local TILE = tiles[item.actionid]

    if not TILE then return false end
    -- Check Vocation
    if getPlayerVocation(cid) == TILE.vocid then
        doTeleportThing(cid, fromPosition)
        doSendMagicEffect(fromPosition, CONST_ME_POFF)
    return false
    end
    -- Give items if never recieved before
    if getPlayerStorageValue(cid, item.actionid) == -1 then
    -- dont have cap
    if getPlayerFreeCap(cid) < TILE.needcap then
        doTeleportThing(cid, fromPosition, false)
        doSendMagicEffect(position, CONST_ME_MAGIC_BLUE)
        doPlayerPopupFYI(cid, 'You need '.. TILE.needcap ..' OZ CAP to recive the items!')
        return false
    end
        for i = 1, #TILE.extraItems do
            doPlayerAddItem(cid, TILE.extraItems[i].itemID, TILE.extraItems[i].count)
        end
        setPlayerStorageValue(cid, item.actionid, 1)
    end

    --Create a table to hold player skills information
    local playerSkillTries = {}
    for i = 1, #skills do
        local currentSkill = getPlayerSkillLevel(cid, skills[i])
        playerSkillTries[i] = getPlayerSkillTries(cid, skills[i])
        for j = 11, currentSkill do
            playerSkillTries[i] = (playerSkillTries[i] or 0) + getPlayerRequiredSkillTries(cid, skills[i], j)
        end
    end

    -- calculate the same for magic level
    local playerManaSpent = getPlayerSpentMana(cid)
    local currentMagic = getPlayerMagLevel(cid, true)
    for i = 0, currentMagic do
        playerManaSpent = playerManaSpent + getPlayerRequiredMana(cid, i)
    end

    doPlayerSetVocation(cid, TILE.vocid)
    --Set players skills to 10
    for i = 1, #skills do
        doPlayerSetSkillLevel(cid, skills[i], 10)
    end
    doPlayerSetMagicLevel(cid, 0)

    --Add skill tries back to player--
    for i = 1, #skills do
        doPlayerAddSkillTry(cid, skills[i], playerSkillTries[i])
    end
    doPlayerAddSpentMana(cid, playerManaSpent)

    local extraLevels = getPlayerLevel(cid) - 1
    local STATS = vocation_stats[TILE.vocid]
 
    setCreatureMaxHealth(cid, 185 + (STATS.hp * extraLevels))
    setCreatureMaxMana(cid, 40 + (STATS.hp * extraLevels))
    doCreatureAddHealth(cid, getCreatureMaxHealth(cid), false)
    doCreatureAddMana(cid, getCreatureMaxMana(cid), false)
    doPlayerSetMaxCapacity(cid, 400 + (STATS.cap * extraLevels))
    doPlayerAddItem(cid, TILE.weaponID, 1)
    doTeleportThing(cid, pos)
    doSendMagicEffect(getThingPos(cid), CONST_ME_MAGIC_BLUE)
    doPlayerSetTown(cid, townid)
return true
end

i fix some easy things i know how to, but there is something wrong...

on tests:

starts with
knight:
sword 20, 35% to next
shield 22, 59% to next


change to
paladin
sword 13, 97% to next
shield 22, 59% to next


change back to
knight
sword 31, 13% to next
shield 22, 59% to next





And i dont think its relevant, but its printing this error
Code:
[9:59:58.784] [Error - MoveEvents Interface]
[9:59:58.784] data/movements/scripts/dawnport_tiles.lua:onStepIn
[9:59:58.784] Description:
[9:59:58.784] (luaDoPlayerAddItem) Item not found


[10:0:55.252] [Error - MoveEvents Interface]
[10:0:55.252] data/movements/scripts/dawnport_tiles.lua:onStepIn
[10:0:55.252] Description:
[10:0:55.253] (luaDoPlayerAddItem) Item not found
 
replace this part of the code with this

Code:
--Create a table to hold player skills information
    local playerSkillTries = {}
    for i = 1, #skills do
        local currentSkill = getPlayerSkillLevel(cid, skills[i])
        playerSkillTries[i] = getPlayerSkillTries(cid, skills[i])
        if getPlayerSkillLevel(cid, skill[i]) > 10 then
            local countTries = 0
            for j = 11, currentSkill do
                countTries = getPlayerRequiredSkillTries(cid, skills[i], j)
            end
            playerSkillTries[i] = playerSkillTries[i] + countTries
        end
    end
 
Code:
local vocation_stats = {
    [1] = {hp = 5, mp = 30, cap = 10},
    [2] = {hp = 5, mp = 30, cap = 10},
    [3] = {hp = 10, mp = 15, cap = 20},
    [4] = {hp = 15, mp = 5, cap = 25}
}

local tiles = {
   --[actionid] = {vocation id}
   [65530] = {
        vocid = 1,
        extraItems = {
            {itemID = 2190, count = 1}, -- wand of vortex
            {itemID = 2260, count = 50}, -- blank rune
            {itemID = 2287, count = 30}, -- lmm
            {itemID = 2302, count = 15} -- FIREBALL
        }
   },
   [65529] = {
        vocid = 2,
        extraItems = {
            {itemID = 2182, count = 1}, -- snakebite rod
            {itemID = 2260, count = 50}, -- blank rune
            {itemID = 2287, count = 30}, -- lmm
            {itemID = 2265, count = 5}, -- IH
            {itemID = 2302, count = 10} -- FIREBALL
        }
   },
   [65528] = {
        vocid = 3,
        extraItems = {
            {itemID = 2456, count = 1}, -- bow
            {itemID = 2260, count = 10}, -- blank rune
            {itemID = 2544, count = 100}, -- arrows
            {itemID = 2389, count = 3}, -- spear
            {itemID = 2265, count = 5}, -- IH
            {itemID = 2287, count = 5}, -- LMM
            {itemID = 2302, count = 5} -- FIREBALL
        }
   },
   [65527] = {
        vocid = 4,
        extraItems = {
            {itemID = 2379, count = 1}, -- sword
            {itemID = 2382, count = 1}, -- axe
            {itemID = 2380, count = 1}, -- club
            {itemID = 2265, count = 10}, -- IH
            {itemID = 2287, count = 5}, -- LMM
            {itemID = 2302, count = 3} -- FIREBALL
        }
   }
}

local townId = 7
local pos = {x = 392, y = 929, z = 6}

local skills = {
    SKILL_FIST,
    SKILL_CLUB,
    SKILL_AXE,
    SKILL_SWORD,
    SKILL_SHIELDING,
    SKILL_DISTANCE
}

function onStepIn(cid, item, position, fromPosition)
    local TILE = tiles[item.actionid]
  
    if not TILE then return false end
    -- Check Vocation
    if getPlayerVocation(cid) == TILE.vocid then
        doTeleportThing(cid, fromPosition)
        doSendMagicEffect(fromPosition, CONST_ME_POFF)
    return false
    end
    -- Give items if never recieved before
    if getPlayerStorageValue(cid, item.actionid) == -1 then
    -- dont have cap
    if getPlayerFreeCap(cid) < TILE.needcap then
        doTeleportThing(cid, fromPosition, false)
        doSendMagicEffect(position, CONST_ME_MAGIC_BLUE)
        doPlayerPopupFYI(cid, 'You need '.. TILE.needcap ..' OZ CAP to recive the items!')
        return false
    end
        for i = 1, #TILE.extraItems do
            doPlayerAddItem(cid, TILE.extraItems[i].itemID, TILE.extraItems[i].count)
        end
        setPlayerStorageValue(cid, item.actionid, 1)
    end

    --Create a table to hold player skills information
    local playerSkillTries = {}
    for i = 1, #skills do
        local currentSkill = getPlayerSkillLevel(cid, skills[i])
        playerSkillTries[i] = getPlayerSkillTries(cid, skills[i])
        if getPlayerSkillLevel(cid, skill[i]) > 10 then
            local countTries = 0
            for j = 11, currentSkill do
                countTries = getPlayerRequiredSkillTries(cid, skills[i], j)
            end
            playerSkillTries[i] = playerSkillTries[i] + countTries
        end
    end

    -- calculate the same for magic level
    local playerManaSpent = getPlayerSpentMana(cid)
    local currentMagic = getPlayerMagLevel(cid, true)
    for i = 0, currentMagic do
        playerManaSpent = playerManaSpent + getPlayerRequiredMana(cid, i)
    end

    doPlayerSetVocation(cid, TILE.vocid)
    --Set players skills to 10
    for i = 1, #skills do
        doPlayerSetSkillLevel(cid, skills[i], 10)
    end
    doPlayerSetMagicLevel(cid, 0)

    --Add skill tries back to player--
    for i = 1, #skills do
        doPlayerAddSkillTry(cid, skills[i], playerSkillTries[i])
    end
    doPlayerAddSpentMana(cid, playerManaSpent)
  
    local extraLevels = getPlayerLevel(cid) - 1
    local STATS = vocation_stats[TILE.vocid]
   
    setCreatureMaxHealth(cid, 185 + (STATS.hp * extraLevels))
    setCreatureMaxMana(cid, 40 + (STATS.hp * extraLevels))
    doCreatureAddHealth(cid, getCreatureMaxHealth(cid), false)
    doCreatureAddMana(cid, getCreatureMaxMana(cid), false)
    doPlayerSetMaxCapacity(cid, 400 + (STATS.cap * extraLevels))
    doTeleportThing(cid, pos)
    doSendMagicEffect(getThingPos(cid), CONST_ME_MAGIC_BLUE)
    doPlayerSetTown(cid, townid)
return true
end

Code:
[11:51:07.262] [Error - MoveEvents Interface] 
[11:51:07.262] data/movements/scripts/dawnport_tiles.lua:onStepIn
[11:51:07.262] Description: 
[11:51:07.263] data/movements/scripts/dawnport_tiles.lua:96: attempt to index global 'skill' (a nil value)
[11:51:07.263] stack traceback:
[11:51:07.263]     data/movements/scripts/dawnport_tiles.lua:96: in function <data/movements/scripts/dawnport_tiles.lua:66>
 
Code:
local vocation_stats = {
    [1] = {hp = 5, mp = 30, cap = 10},
    [2] = {hp = 5, mp = 30, cap = 10},
    [3] = {hp = 10, mp = 15, cap = 20},
    [4] = {hp = 15, mp = 5, cap = 25}
}

local tiles = {
   --[actionid] = {vocation id}
   [65530] = {
        vocid = 1,
        extraItems = {
            {itemID = 2190, count = 1}, -- wand of vortex
            {itemID = 2260, count = 50}, -- blank rune
            {itemID = 2287, count = 30}, -- lmm
            {itemID = 2302, count = 15} -- FIREBALL
        }
   },
   [65529] = {
        vocid = 2,
        extraItems = {
            {itemID = 2182, count = 1}, -- snakebite rod
            {itemID = 2260, count = 50}, -- blank rune
            {itemID = 2287, count = 30}, -- lmm
            {itemID = 2265, count = 5}, -- IH
            {itemID = 2302, count = 10} -- FIREBALL
        }
   },
   [65528] = {
        vocid = 3,
        extraItems = {
            {itemID = 2456, count = 1}, -- bow
            {itemID = 2260, count = 10}, -- blank rune
            {itemID = 2544, count = 100}, -- arrows
            {itemID = 2389, count = 3}, -- spear
            {itemID = 2265, count = 5}, -- IH
            {itemID = 2287, count = 5}, -- LMM
            {itemID = 2302, count = 5} -- FIREBALL
        }
   },
   [65527] = {
        vocid = 4,
        extraItems = {
            {itemID = 2379, count = 1}, -- sword
            {itemID = 2382, count = 1}, -- axe
            {itemID = 2380, count = 1}, -- club
            {itemID = 2265, count = 10}, -- IH
            {itemID = 2287, count = 5}, -- LMM
            {itemID = 2302, count = 3} -- FIREBALL
        }
   }
}

local townId = 7
local pos = {x = 392, y = 929, z = 6}

local skills = {
    SKILL_FIST,
    SKILL_CLUB,
    SKILL_AXE,
    SKILL_SWORD,
    SKILL_SHIELDING,
    SKILL_DISTANCE
}

function onStepIn(cid, item, position, fromPosition)
    local TILE = tiles[item.actionid]
  
    if not TILE then return false end
    -- Check Vocation
    if getPlayerVocation(cid) == TILE.vocid then
        doTeleportThing(cid, fromPosition)
        doSendMagicEffect(fromPosition, CONST_ME_POFF)
    return false
    end
    -- Give items if never recieved before
    if getPlayerStorageValue(cid, item.actionid) == -1 then
    -- dont have cap
    if getPlayerFreeCap(cid) < TILE.needcap then
        doTeleportThing(cid, fromPosition, false)
        doSendMagicEffect(position, CONST_ME_MAGIC_BLUE)
        doPlayerPopupFYI(cid, 'You need '.. TILE.needcap ..' OZ CAP to recive the items!')
        return false
    end
        for i = 1, #TILE.extraItems do
            doPlayerAddItem(cid, TILE.extraItems[i].itemID, TILE.extraItems[i].count)
        end
        setPlayerStorageValue(cid, item.actionid, 1)
    end

    --Create a table to hold player skills information
    local playerSkillTries = {}
    for i = 1, #skills do
        local currentSkill = getPlayerSkillLevel(cid, skills[i])
        playerSkillTries[i] = getPlayerSkillTries(cid, skills[i])
        if getPlayerSkillLevel(cid, skills[i]) > 10 then
            local countTries = 0
            for j = 11, currentSkill do
                countTries = getPlayerRequiredSkillTries(cid, skills[i], j)
            end
            playerSkillTries[i] = playerSkillTries[i] + countTries
        end
    end

    -- calculate the same for magic level
    local playerManaSpent = getPlayerSpentMana(cid)
    local currentMagic = getPlayerMagLevel(cid, true)
    for i = 0, currentMagic do
        playerManaSpent = playerManaSpent + getPlayerRequiredMana(cid, i)
    end

    doPlayerSetVocation(cid, TILE.vocid)
    --Set players skills to 10
    for i = 1, #skills do
        doPlayerSetSkillLevel(cid, skills[i], 10)
    end
    doPlayerSetMagicLevel(cid, 0)

    --Add skill tries back to player--
    for i = 1, #skills do
        doPlayerAddSkillTry(cid, skills[i], playerSkillTries[i])
    end
    doPlayerAddSpentMana(cid, playerManaSpent)
  
    local extraLevels = getPlayerLevel(cid) - 1
    local STATS = vocation_stats[TILE.vocid]
   
    setCreatureMaxHealth(cid, 185 + (STATS.hp * extraLevels))
    setCreatureMaxMana(cid, 40 + (STATS.hp * extraLevels))
    doCreatureAddHealth(cid, getCreatureMaxHealth(cid), false)
    doCreatureAddMana(cid, getCreatureMaxMana(cid), false)
    doPlayerSetMaxCapacity(cid, 400 + (STATS.cap * extraLevels))
    doTeleportThing(cid, pos)
    doSendMagicEffect(getThingPos(cid), CONST_ME_MAGIC_BLUE)
    doPlayerSetTown(cid, townid)
return true
end

0 errors on console

on tests wont work

tests:
start as knight
sword 31, 13% to advance
shield 22, 59% to advance


become paladin
sword 12, 19% to advance
shield 22, 59% to advance

become back knight
sword 28, 3% to advance
shield 22, 59% to advance
 
I'll try it one last time.

Lua:
local vocation_stats = {
    [1] = {hp = 5, mp = 30, cap = 10},
    [2] = {hp = 5, mp = 30, cap = 10},
    [3] = {hp = 10, mp = 15, cap = 20},
    [4] = {hp = 15, mp = 5, cap = 25}
}

local tiles = {
   --[actionid] = {vocation id}
   [65530] = {
        vocid = 1,
        extraItems = {
            {itemID = 2190, count = 1}, -- wand of vortex
            {itemID = 2260, count = 50}, -- blank rune
            {itemID = 2287, count = 30}, -- lmm
            {itemID = 2302, count = 15} -- FIREBALL
        }
   },
   [65529] = {
        vocid = 2,
        extraItems = {
            {itemID = 2182, count = 1}, -- snakebite rod
            {itemID = 2260, count = 50}, -- blank rune
            {itemID = 2287, count = 30}, -- lmm
            {itemID = 2265, count = 5}, -- IH
            {itemID = 2302, count = 10} -- FIREBALL
        }
   },
   [65528] = {
        vocid = 3,
        extraItems = {
            {itemID = 2456, count = 1}, -- bow
            {itemID = 2260, count = 10}, -- blank rune
            {itemID = 2544, count = 100}, -- arrows
            {itemID = 2389, count = 3}, -- spear
            {itemID = 2265, count = 5}, -- IH
            {itemID = 2287, count = 5}, -- LMM
            {itemID = 2302, count = 5} -- FIREBALL
        }
   },
   [65527] = {
        vocid = 4,
        extraItems = {
            {itemID = 2379, count = 1}, -- sword
            {itemID = 2382, count = 1}, -- axe
            {itemID = 2380, count = 1}, -- club
            {itemID = 2265, count = 10}, -- IH
            {itemID = 2287, count = 5}, -- LMM
            {itemID = 2302, count = 3} -- FIREBALL
        }
   }
}

local townId = 7
local pos = {x = 392, y = 929, z = 6}

local skills = {
    SKILL_FIST,
    SKILL_CLUB,
    SKILL_AXE,
    SKILL_SWORD,
    SKILL_SHIELD,
    SKILL_DISTANCE
}

function onStepIn(cid, item, position, fromPosition)
    local TILE = tiles[item.actionid]

    if not TILE then return false end
    -- Check Vocation
    if getPlayerVocation(cid) == TILE.vocid then
        doTeleportThing(cid, fromPosition)
        doSendMagicEffect(fromPosition, CONST_ME_POFF)
    return false
    end
    -- Give items if never recieved before
    if getPlayerStorageValue(cid, item.actionid) == -1 then
    -- dont have cap
    if getPlayerFreeCap(cid) < TILE.needcap then
        doTeleportThing(cid, fromPosition, false)
        doSendMagicEffect(position, CONST_ME_MAGIC_BLUE)
        doPlayerPopupFYI(cid, 'You need '.. TILE.needcap ..' OZ CAP to recive the items!')
        return false
    end
        for i = 1, #TILE.extraItems do
            doPlayerAddItem(cid, TILE.extraItems[i].itemID, TILE.extraItems[i].count)
        end
        setPlayerStorageValue(cid, item.actionid, 1)
    end

    --Create a table to hold player skills information
    local playerSkillTries = {}
    for i = 1, #skills do
        local currentSkill = getPlayerSkillLevel(cid, skills[i])
        playerSkillTries[i] = getPlayerSkillTries(cid, skills[i])
        for j = 11, currentSkill do
            playerSkillTries[i] = playerSkillTries[i] + getPlayerRequiredSkillTries(cid, skills[i], j)
        end
    end

    -- calculate the same for magic level
    local playerManaSpent = getPlayerSpentMana(cid)
    local currentMagic = getPlayerMagLevel(cid, true)
    for i = 1, currentMagic do
        playerManaSpent = playerManaSpent + getPlayerRequiredMana(cid, i)
    end

    doPlayerSetVocation(cid, TILE.vocid)
    --Set players skills to 10
    for i = 1, #skills do
        doPlayerSetSkillLevel(cid, skills[i], 10)
    end
    doPlayerSetMagicLevel(cid, 0)

    --Add skill tries back to player--
    for i = 1, #skills do
        doPlayerAddSkillTry(cid, skills[i], playerSkillTries[i], false)
    end
    doPlayerAddSpentMana(cid, playerManaSpent, false)

    local extraLevels = getPlayerLevel(cid) - 1
    local STATS = vocation_stats[TILE.vocid]
 
    setCreatureMaxHealth(cid, 185 + (STATS.hp * extraLevels))
    setCreatureMaxMana(cid, 40 + (STATS.hp * extraLevels))
    doCreatureAddHealth(cid, getCreatureMaxHealth(cid), false)
    doCreatureAddMana(cid, getCreatureMaxMana(cid), false)
    doPlayerSetMaxCapacity(cid, 400 + (STATS.cap * extraLevels))
    doTeleportThing(cid, pos)
    doSendMagicEffect(getThingPos(cid), CONST_ME_MAGIC_BLUE)
    doPlayerSetTown(cid, townid)
return true
end

what did I do?

1- changed back to my loop, since it doesn't make a difference if the skill is <= 10
Lua:
local currentSkill = getPlayerSkillLevel(cid, skills[i])
playerSkillTries[i] = getPlayerSkillTries(cid, skills[i])
for j = 11, currentSkill do
    playerSkillTries[i] = playerSkillTries[i] + getPlayerRequiredSkillTries(cid, skills[i], j)
end

2- changed doPlayerAddSkillTry and doPlayerAddSpentMana
Lua:
doPlayerAddSkillTry(cid, skills[i], playerSkillTries[i], false)
doPlayerAddSpentMana(cid, playerManaSpent, false)
I've added false argument because we don't want multipliers to be taken into account, we just want to throw the raw amounts in there

3- fixed magic level loop
Lua:
for i = 1, currentMagic do
    playerManaSpent = playerManaSpent + getPlayerRequiredMana(cid, i)
end
it was starting at 0 but it should start at 1

I really hope it works now, because I checked death script and all the sums seem right, probably the multipliers could be fucking it up

reference for if somebody wants to read the death function:
 
Last edited:
Solution
I'll try it one last time.

Lua:
local vocation_stats = {
    [1] = {hp = 5, mp = 30, cap = 10},
    [2] = {hp = 5, mp = 30, cap = 10},
    [3] = {hp = 10, mp = 15, cap = 20},
    [4] = {hp = 15, mp = 5, cap = 25}
}

local tiles = {
   --[actionid] = {vocation id}
   [65530] = {
        vocid = 1,
        extraItems = {
            {itemID = 2190, count = 1}, -- wand of vortex
            {itemID = 2260, count = 50}, -- blank rune
            {itemID = 2287, count = 30}, -- lmm
            {itemID = 2302, count = 15} -- FIREBALL
        }
   },
   [65529] = {
        vocid = 2,
        extraItems = {
            {itemID = 2182, count = 1}, -- snakebite rod
            {itemID = 2260, count = 50}, -- blank rune
            {itemID = 2287, count = 30}, -- lmm
            {itemID = 2265, count = 5}, -- IH
            {itemID = 2302, count = 10} -- FIREBALL
        }
   },
   [65528] = {
        vocid = 3,
        extraItems = {
            {itemID = 2456, count = 1}, -- bow
            {itemID = 2260, count = 10}, -- blank rune
            {itemID = 2544, count = 100}, -- arrows
            {itemID = 2389, count = 3}, -- spear
            {itemID = 2265, count = 5}, -- IH
            {itemID = 2287, count = 5}, -- LMM
            {itemID = 2302, count = 5} -- FIREBALL
        }
   },
   [65527] = {
        vocid = 4,
        extraItems = {
            {itemID = 2379, count = 1}, -- sword
            {itemID = 2382, count = 1}, -- axe
            {itemID = 2380, count = 1}, -- club
            {itemID = 2265, count = 10}, -- IH
            {itemID = 2287, count = 5}, -- LMM
            {itemID = 2302, count = 3} -- FIREBALL
        }
   }
}

local townId = 7
local pos = {x = 392, y = 929, z = 6}

local skills = {
    SKILL_FIST,
    SKILL_CLUB,
    SKILL_AXE,
    SKILL_SWORD,
    SKILL_SHIELDING,
    SKILL_DISTANCE
}

function onStepIn(cid, item, position, fromPosition)
    local TILE = tiles[item.actionid]

    if not TILE then return false end
    -- Check Vocation
    if getPlayerVocation(cid) == TILE.vocid then
        doTeleportThing(cid, fromPosition)
        doSendMagicEffect(fromPosition, CONST_ME_POFF)
    return false
    end
    -- Give items if never recieved before
    if getPlayerStorageValue(cid, item.actionid) == -1 then
    -- dont have cap
    if getPlayerFreeCap(cid) < TILE.needcap then
        doTeleportThing(cid, fromPosition, false)
        doSendMagicEffect(position, CONST_ME_MAGIC_BLUE)
        doPlayerPopupFYI(cid, 'You need '.. TILE.needcap ..' OZ CAP to recive the items!')
        return false
    end
        for i = 1, #TILE.extraItems do
            doPlayerAddItem(cid, TILE.extraItems[i].itemID, TILE.extraItems[i].count)
        end
        setPlayerStorageValue(cid, item.actionid, 1)
    end

    --Create a table to hold player skills information
    local playerSkillTries = {}
    for i = 1, #skills do
        local currentSkill = getPlayerSkillLevel(cid, skills[i])
        playerSkillTries[i] = getPlayerSkillTries(cid, skills[i])
        for j = 11, currentSkill do
            playerSkillTries[i] = playerSkillTries[i] + getPlayerRequiredSkillTries(cid, skills[i], j)
        end
    end

    -- calculate the same for magic level
    local playerManaSpent = getPlayerSpentMana(cid)
    local currentMagic = getPlayerMagLevel(cid, true)
    for i = 1, currentMagic do
        playerManaSpent = playerManaSpent + getPlayerRequiredMana(cid, i)
    end

    doPlayerSetVocation(cid, TILE.vocid)
    --Set players skills to 10
    for i = 1, #skills do
        doPlayerSetSkillLevel(cid, skills[i], 10)
    end
    doPlayerSetMagicLevel(cid, 0)

    --Add skill tries back to player--
    for i = 1, #skills do
        doPlayerAddSkillTry(cid, skills[i], playerSkillTries[i], false)
    end
    doPlayerAddSpentMana(cid, playerManaSpent, false)

    local extraLevels = getPlayerLevel(cid) - 1
    local STATS = vocation_stats[TILE.vocid]
 
    setCreatureMaxHealth(cid, 185 + (STATS.hp * extraLevels))
    setCreatureMaxMana(cid, 40 + (STATS.hp * extraLevels))
    doCreatureAddHealth(cid, getCreatureMaxHealth(cid), false)
    doCreatureAddMana(cid, getCreatureMaxMana(cid), false)
    doPlayerSetMaxCapacity(cid, 400 + (STATS.cap * extraLevels))
    doTeleportThing(cid, pos)
    doSendMagicEffect(getThingPos(cid), CONST_ME_MAGIC_BLUE)
    doPlayerSetTown(cid, townid)
return true
end

what did I do?

1- changed back to my loop, since it doesn't make a difference if the skill is <= 10
Lua:
local currentSkill = getPlayerSkillLevel(cid, skills[i])
playerSkillTries[i] = getPlayerSkillTries(cid, skills[i])
for j = 11, currentSkill do
    playerSkillTries[i] = playerSkillTries[i] + getPlayerRequiredSkillTries(cid, skills[i], j)
end

2- changed doPlayerAddSkillTry and doPlayerAddSpentMana
Lua:
doPlayerAddSkillTry(cid, skills[i], playerSkillTries[i], false)
doPlayerAddSpentMana(cid, playerManaSpent, false)
I've added false argument because we don't want multipliers to be taken into account, we just want to throw the raw amounts in there

3- fixed magic level loop
Lua:
for i = 1, currentMagic do
    playerManaSpent = playerManaSpent + getPlayerRequiredMana(cid, i)
end
it was starting at 0 but it should start at 1

I really hope it works now, because I checked death script and all the sums seem right, probably the multipliers could be fucking it up

reference for if somebody wants to read the death function:

start as knight:
sword 28 %3 to advance
shield 22 59% to advance

change to paladin:
sword 13 85% to advance
shield 22 59% to advance

change back to knight:
skill 28 3% to advance
shield 22 59% to advance




---

so change to sorcerer:
sword 13 85% to advance
shield 22 59% to advance

change back to knight:
skill 28 3% to advance
shield 22 59% to advance


so sword fight is working !!!!!!!!!!!!!!!!!!!!!!!!
but shield not


testing magic stuff now
change back to sorcerer and train magic level and fist fight

after train as a sorcerer
i got
magic 21 95% to advance
fist 14 60% to advance
shield 24 64% to advance

change to knight
magic 4 70% to advance
fist 15 99% to advance
shield 24 64% to advance

change back to sorcerer
magic 21 95% to advance
fist 15 73% to advance
shield 24 64% to advance

so far:
shielding is not changing, never
sword/ml is working perfect
there is something wrong with fist fighting
 
another test with distance fight and multiple vocations changes...

paladin
ml 9... 27% to advance
fist 16... 84% to advance
sword 13... 85% to advance
dist 32... 30% to advance
shield 25... 87% to advance

change to
knight
ml 4... 70% to advance
fist 16... 42% to advance
sword 28... 3% to advance
dist 13... 64% to advance
shield 25... 87% to advance


change to
sorcerer
ml 21... 95% to advance
fist 17... 92% to advance
sword 13... 85% to advance
dist 13... 64% to advance
shield 25... 87% to advance


back to
paladin
ml 9... 27% to advance
fist 17... 59% to advance
sword 13... 85% to advance
dist 32... 30% to advance
shield 25... 87% to advance

final test assumes:
fist fighting is always growing
sword/dist/ml is working perfect
shield skill is not changing never
 
great! so we have progress.

shield doesn't work because we put the wrong value, it's SKILL_SHIELD not SKILL_SHIELDING.

Lua:
local skills = {
    SKILL_FIST,
    SKILL_CLUB,
    SKILL_AXE,
    SKILL_SWORD,
    SKILL_SHIELD,
    SKILL_DISTANCE
}

but no idea what's happening to fist, I'll have to investigate later
 
change

Code:
local skills = {
    SKILL_FIST,
    SKILL_CLUB,
    SKILL_AXE,
    SKILL_SWORD,
    SKILL_SHIELDING,
    SKILL_DISTANCE
}

for

Code:
local skills = {
    SKILL_FIST,
    SKILL_CLUB,
    SKILL_AXE,
    SKILL_SWORD,
    SKILL_SHIELD,
    SKILL_DISTANCE
}

see if shielding changes now.
 
i think that is it guys, thank you all to help to make it work

everybody who wants dawnport to 8.6 go to the best aswer

---

is it normal a 3~4 seconds lag everytime when i change the vocation?
 
i think that is it guys, thank you all to help to make it work

everybody who wants dawnport to 8.6 go to the best aswer

---

is it normal a 3~4 seconds lag everytime when i change the vocation?
does it happen every time or only the first time you change to each vocation?
example: 1 start as knight -> 2 go to sorcerer (lags) -> 3 go to knight (lags) -> 4 go to sorcerer again (does it lag again?) -> 5 go to knight again (does it lag again?)
if that's what happens, it's probably due to calculating all required skill tries/mana spent to advance your skills for the first time (since it's then cached)

otherwise, you can also test what's causing the lag
1- remove the magic level part of the code (calculating/reseting/adding). does it lag less?
2- remove the skill tries part of the code also. no lag?
3- put mana back, did lag increase?

remove some of the skills (have only shield in the table or something)
you can try stuff out to find out what's going on
 
1) TEST
No calc skills/ml
No convert skills/ml

Code:
local vocation_stats = {
    [1] = {hp = 5, mp = 30, cap = 10},
    [2] = {hp = 5, mp = 30, cap = 10},
    [3] = {hp = 10, mp = 15, cap = 20},
    [4] = {hp = 15, mp = 5, cap = 25}
}

local tiles = {
   --[actionid] = {vocation id}
   [65530] = {
        vocid = 1,
        extraItems = {
            {itemID = 2190, count = 1}, -- wand of vortex
            {itemID = 2260, count = 50}, -- blank rune
            {itemID = 2287, count = 30}, -- lmm
            {itemID = 2302, count = 15} -- FIREBALL
        }
   },
   [65529] = {
        vocid = 2,
        extraItems = {
            {itemID = 2182, count = 1}, -- snakebite rod
            {itemID = 2260, count = 50}, -- blank rune
            {itemID = 2287, count = 30}, -- lmm
            {itemID = 2265, count = 5}, -- IH
            {itemID = 2302, count = 10} -- FIREBALL
        }
   },
   [65528] = {
        vocid = 3,
        extraItems = {
            {itemID = 2456, count = 1}, -- bow
            {itemID = 2260, count = 10}, -- blank rune
            {itemID = 2544, count = 100}, -- arrows
            {itemID = 2389, count = 3}, -- spear
            {itemID = 2265, count = 5}, -- IH
            {itemID = 2287, count = 5}, -- LMM
            {itemID = 2302, count = 5} -- FIREBALL
        }
   },
   [65527] = {
        vocid = 4,
        extraItems = {
            {itemID = 2379, count = 1}, -- sword
            {itemID = 2382, count = 1}, -- axe
            {itemID = 2380, count = 1}, -- club
            {itemID = 2265, count = 10}, -- IH
            {itemID = 2287, count = 5}, -- LMM
            {itemID = 2302, count = 3} -- FIREBALL
        }
   }
}

local townId = 7
local pos = {x = 392, y = 929, z = 6}

local skills = {
    SKILL_FIST,
    SKILL_CLUB,
    SKILL_AXE,
    SKILL_SWORD,
    SKILL_SHIELD,
    SKILL_DISTANCE
}

function onStepIn(cid, item, position, fromPosition)
    local TILE = tiles[item.actionid]
 
    if not TILE then return false end
    -- Check Vocation
    if getPlayerVocation(cid) == TILE.vocid then
        doTeleportThing(cid, fromPosition)
        doSendMagicEffect(fromPosition, CONST_ME_POFF)
    return false
    end
    -- Give items if never recieved before
    if getPlayerStorageValue(cid, item.actionid) == -1 then
    -- dont have cap
    if getPlayerFreeCap(cid) < TILE.needcap then
        doTeleportThing(cid, fromPosition, false)
        doSendMagicEffect(position, CONST_ME_MAGIC_BLUE)
        doPlayerPopupFYI(cid, 'You need '.. TILE.needcap ..' OZ CAP to recive the items!')
        return false
    end
        for i = 1, #TILE.extraItems do
            doPlayerAddItem(cid, TILE.extraItems[i].itemID, TILE.extraItems[i].count)
        end
        setPlayerStorageValue(cid, item.actionid, 1)
    end

    --Create a table to hold player skills information
    --local playerSkillTries = {}
    --for i = 1, #skills do
    --    local currentSkill = getPlayerSkillLevel(cid, skills[i])
    --    playerSkillTries[i] = getPlayerSkillTries(cid, skills[i])
    --    for j = 11, currentSkill do
    --        playerSkillTries[i] = playerSkillTries[i] + getPlayerRequiredSkillTries(cid, skills[i], j)
    --    end
    --end

    -- calculate the same for magic level
    --local playerManaSpent = getPlayerSpentMana(cid)
    --local currentMagic = getPlayerMagLevel(cid, true)
    --for i = 1, currentMagic do
    --    playerManaSpent = playerManaSpent + getPlayerRequiredMana(cid, i)
    --end

    doPlayerSetVocation(cid, TILE.vocid)
    --Set players skills to 10
    --for i = 1, #skills do
    --    doPlayerSetSkillLevel(cid, skills[i], 10)
    --end
    --doPlayerSetMagicLevel(cid, 0)

    --Add skill tries back to player--
    --for i = 1, #skills do
    --    doPlayerAddSkillTry(cid, skills[i], playerSkillTries[i], false)
    --end
    --doPlayerAddSpentMana(cid, playerManaSpent, false)
 
    local extraLevels = getPlayerLevel(cid) - 1
    local STATS = vocation_stats[TILE.vocid]
  
    setCreatureMaxHealth(cid, 185 + (STATS.hp * extraLevels))
    setCreatureMaxMana(cid, 40 + (STATS.hp * extraLevels))
    doCreatureAddHealth(cid, getCreatureMaxHealth(cid), false)
    doCreatureAddMana(cid, getCreatureMaxMana(cid), false)
    doPlayerSetMaxCapacity(cid, 400 + (STATS.cap * extraLevels))
    doTeleportThing(cid, pos)
    doSendMagicEffect(getThingPos(cid), CONST_ME_MAGIC_BLUE)
    doPlayerSetTown(cid, townid)
return true
end

0 lag


2) TEST
Only calc skills/ml
No convert

Code:
local vocation_stats = {
    [1] = {hp = 5, mp = 30, cap = 10},
    [2] = {hp = 5, mp = 30, cap = 10},
    [3] = {hp = 10, mp = 15, cap = 20},
    [4] = {hp = 15, mp = 5, cap = 25}
}

local tiles = {
   --[actionid] = {vocation id}
   [65530] = {
        vocid = 1,
        extraItems = {
            {itemID = 2190, count = 1}, -- wand of vortex
            {itemID = 2260, count = 50}, -- blank rune
            {itemID = 2287, count = 30}, -- lmm
            {itemID = 2302, count = 15} -- FIREBALL
        }
   },
   [65529] = {
        vocid = 2,
        extraItems = {
            {itemID = 2182, count = 1}, -- snakebite rod
            {itemID = 2260, count = 50}, -- blank rune
            {itemID = 2287, count = 30}, -- lmm
            {itemID = 2265, count = 5}, -- IH
            {itemID = 2302, count = 10} -- FIREBALL
        }
   },
   [65528] = {
        vocid = 3,
        extraItems = {
            {itemID = 2456, count = 1}, -- bow
            {itemID = 2260, count = 10}, -- blank rune
            {itemID = 2544, count = 100}, -- arrows
            {itemID = 2389, count = 3}, -- spear
            {itemID = 2265, count = 5}, -- IH
            {itemID = 2287, count = 5}, -- LMM
            {itemID = 2302, count = 5} -- FIREBALL
        }
   },
   [65527] = {
        vocid = 4,
        extraItems = {
            {itemID = 2379, count = 1}, -- sword
            {itemID = 2382, count = 1}, -- axe
            {itemID = 2380, count = 1}, -- club
            {itemID = 2265, count = 10}, -- IH
            {itemID = 2287, count = 5}, -- LMM
            {itemID = 2302, count = 3} -- FIREBALL
        }
   }
}

local townId = 7
local pos = {x = 392, y = 929, z = 6}

local skills = {
    SKILL_FIST,
    SKILL_CLUB,
    SKILL_AXE,
    SKILL_SWORD,
    SKILL_SHIELD,
    SKILL_DISTANCE
}

function onStepIn(cid, item, position, fromPosition)
    local TILE = tiles[item.actionid]
 
    if not TILE then return false end
    -- Check Vocation
    if getPlayerVocation(cid) == TILE.vocid then
        doTeleportThing(cid, fromPosition)
        doSendMagicEffect(fromPosition, CONST_ME_POFF)
    return false
    end
    -- Give items if never recieved before
    if getPlayerStorageValue(cid, item.actionid) == -1 then
    -- dont have cap
    if getPlayerFreeCap(cid) < TILE.needcap then
        doTeleportThing(cid, fromPosition, false)
        doSendMagicEffect(position, CONST_ME_MAGIC_BLUE)
        doPlayerPopupFYI(cid, 'You need '.. TILE.needcap ..' OZ CAP to recive the items!')
        return false
    end
        for i = 1, #TILE.extraItems do
            doPlayerAddItem(cid, TILE.extraItems[i].itemID, TILE.extraItems[i].count)
        end
        setPlayerStorageValue(cid, item.actionid, 1)
    end

    --Create a table to hold player skills information
    local playerSkillTries = {}
    for i = 1, #skills do
        local currentSkill = getPlayerSkillLevel(cid, skills[i])
        playerSkillTries[i] = getPlayerSkillTries(cid, skills[i])
        for j = 11, currentSkill do
            playerSkillTries[i] = playerSkillTries[i] + getPlayerRequiredSkillTries(cid, skills[i], j)
        end
    end

    -- calculate the same for magic level
    local playerManaSpent = getPlayerSpentMana(cid)
    local currentMagic = getPlayerMagLevel(cid, true)
    for i = 1, currentMagic do
        playerManaSpent = playerManaSpent + getPlayerRequiredMana(cid, i)
    end

    doPlayerSetVocation(cid, TILE.vocid)
    --Set players skills to 10
    --for i = 1, #skills do
    --    doPlayerSetSkillLevel(cid, skills[i], 10)
    --end
    --doPlayerSetMagicLevel(cid, 0)

    --Add skill tries back to player--
    --for i = 1, #skills do
    --    doPlayerAddSkillTry(cid, skills[i], playerSkillTries[i], false)
    --end
    --doPlayerAddSpentMana(cid, playerManaSpent, false)
 
    local extraLevels = getPlayerLevel(cid) - 1
    local STATS = vocation_stats[TILE.vocid]
  
    setCreatureMaxHealth(cid, 185 + (STATS.hp * extraLevels))
    setCreatureMaxMana(cid, 40 + (STATS.hp * extraLevels))
    doCreatureAddHealth(cid, getCreatureMaxHealth(cid), false)
    doCreatureAddMana(cid, getCreatureMaxMana(cid), false)
    doPlayerSetMaxCapacity(cid, 400 + (STATS.cap * extraLevels))
    doTeleportThing(cid, pos)
    doSendMagicEffect(getThingPos(cid), CONST_ME_MAGIC_BLUE)
    doPlayerSetTown(cid, townid)
return true
end

0 lag
 
3)
Calc SKILLS & ML
Set only ML
Code:
local vocation_stats = {
    [1] = {hp = 5, mp = 30, cap = 10},
    [2] = {hp = 5, mp = 30, cap = 10},
    [3] = {hp = 10, mp = 15, cap = 20},
    [4] = {hp = 15, mp = 5, cap = 25}
}

local tiles = {
   --[actionid] = {vocation id}
   [65530] = {
        vocid = 1,
        extraItems = {
            {itemID = 2190, count = 1}, -- wand of vortex
            {itemID = 2260, count = 50}, -- blank rune
            {itemID = 2287, count = 30}, -- lmm
            {itemID = 2302, count = 15} -- FIREBALL
        }
   },
   [65529] = {
        vocid = 2,
        extraItems = {
            {itemID = 2182, count = 1}, -- snakebite rod
            {itemID = 2260, count = 50}, -- blank rune
            {itemID = 2287, count = 30}, -- lmm
            {itemID = 2265, count = 5}, -- IH
            {itemID = 2302, count = 10} -- FIREBALL
        }
   },
   [65528] = {
        vocid = 3,
        extraItems = {
            {itemID = 2456, count = 1}, -- bow
            {itemID = 2260, count = 10}, -- blank rune
            {itemID = 2544, count = 100}, -- arrows
            {itemID = 2389, count = 3}, -- spear
            {itemID = 2265, count = 5}, -- IH
            {itemID = 2287, count = 5}, -- LMM
            {itemID = 2302, count = 5} -- FIREBALL
        }
   },
   [65527] = {
        vocid = 4,
        extraItems = {
            {itemID = 2379, count = 1}, -- sword
            {itemID = 2382, count = 1}, -- axe
            {itemID = 2380, count = 1}, -- club
            {itemID = 2265, count = 10}, -- IH
            {itemID = 2287, count = 5}, -- LMM
            {itemID = 2302, count = 3} -- FIREBALL
        }
   }
}

local townId = 7
local pos = {x = 392, y = 929, z = 6}

local skills = {
    SKILL_FIST,
    SKILL_CLUB,
    SKILL_AXE,
    SKILL_SWORD,
    SKILL_SHIELD,
    SKILL_DISTANCE
}

function onStepIn(cid, item, position, fromPosition)
    local TILE = tiles[item.actionid]

    if not TILE then return false end
    -- Check Vocation
    if getPlayerVocation(cid) == TILE.vocid then
        doTeleportThing(cid, fromPosition)
        doSendMagicEffect(fromPosition, CONST_ME_POFF)
    return false
    end
    -- Give items if never recieved before
    if getPlayerStorageValue(cid, item.actionid) == -1 then
    -- dont have cap
    if getPlayerFreeCap(cid) < TILE.needcap then
        doTeleportThing(cid, fromPosition, false)
        doSendMagicEffect(position, CONST_ME_MAGIC_BLUE)
        doPlayerPopupFYI(cid, 'You need '.. TILE.needcap ..' OZ CAP to recive the items!')
        return false
    end
        for i = 1, #TILE.extraItems do
            doPlayerAddItem(cid, TILE.extraItems[i].itemID, TILE.extraItems[i].count)
        end
        setPlayerStorageValue(cid, item.actionid, 1)
    end

    --Create a table to hold player skills information
    local playerSkillTries = {}
    for i = 1, #skills do
        local currentSkill = getPlayerSkillLevel(cid, skills[i])
        playerSkillTries[i] = getPlayerSkillTries(cid, skills[i])
        for j = 11, currentSkill do
            playerSkillTries[i] = playerSkillTries[i] + getPlayerRequiredSkillTries(cid, skills[i], j)
        end
    end

    -- calculate the same for magic level
    local playerManaSpent = getPlayerSpentMana(cid)
    local currentMagic = getPlayerMagLevel(cid, true)
    for i = 1, currentMagic do
        playerManaSpent = playerManaSpent + getPlayerRequiredMana(cid, i)
    end

    doPlayerSetVocation(cid, TILE.vocid)
    --Set players skills to 10
    --for i = 1, #skills do
    --    doPlayerSetSkillLevel(cid, skills[i], 10)
    --end
    doPlayerSetMagicLevel(cid, 0)

    --Add skill tries back to player--
    --for i = 1, #skills do
    --    doPlayerAddSkillTry(cid, skills[i], playerSkillTries[i], false)
    --end
    doPlayerAddSpentMana(cid, playerManaSpent, false)

    local extraLevels = getPlayerLevel(cid) - 1
    local STATS = vocation_stats[TILE.vocid]
 
    setCreatureMaxHealth(cid, 185 + (STATS.hp * extraLevels))
    setCreatureMaxMana(cid, 40 + (STATS.hp * extraLevels))
    doCreatureAddHealth(cid, getCreatureMaxHealth(cid), false)
    doCreatureAddMana(cid, getCreatureMaxMana(cid), false)
    doPlayerSetMaxCapacity(cid, 400 + (STATS.cap * extraLevels))
    doTeleportThing(cid, pos)
    doSendMagicEffect(getThingPos(cid), CONST_ME_MAGIC_BLUE)
    doPlayerSetTown(cid, townid)
return true
end

5+ seconds LAG

4)
Calc SKILLS & ML
Set only SKILL

Code:
local vocation_stats = {
    [1] = {hp = 5, mp = 30, cap = 10},
    [2] = {hp = 5, mp = 30, cap = 10},
    [3] = {hp = 10, mp = 15, cap = 20},
    [4] = {hp = 15, mp = 5, cap = 25}
}

local tiles = {
   --[actionid] = {vocation id}
   [65530] = {
        vocid = 1,
        extraItems = {
            {itemID = 2190, count = 1}, -- wand of vortex
            {itemID = 2260, count = 50}, -- blank rune
            {itemID = 2287, count = 30}, -- lmm
            {itemID = 2302, count = 15} -- FIREBALL
        }
   },
   [65529] = {
        vocid = 2,
        extraItems = {
            {itemID = 2182, count = 1}, -- snakebite rod
            {itemID = 2260, count = 50}, -- blank rune
            {itemID = 2287, count = 30}, -- lmm
            {itemID = 2265, count = 5}, -- IH
            {itemID = 2302, count = 10} -- FIREBALL
        }
   },
   [65528] = {
        vocid = 3,
        extraItems = {
            {itemID = 2456, count = 1}, -- bow
            {itemID = 2260, count = 10}, -- blank rune
            {itemID = 2544, count = 100}, -- arrows
            {itemID = 2389, count = 3}, -- spear
            {itemID = 2265, count = 5}, -- IH
            {itemID = 2287, count = 5}, -- LMM
            {itemID = 2302, count = 5} -- FIREBALL
        }
   },
   [65527] = {
        vocid = 4,
        extraItems = {
            {itemID = 2379, count = 1}, -- sword
            {itemID = 2382, count = 1}, -- axe
            {itemID = 2380, count = 1}, -- club
            {itemID = 2265, count = 10}, -- IH
            {itemID = 2287, count = 5}, -- LMM
            {itemID = 2302, count = 3} -- FIREBALL
        }
   }
}

local townId = 7
local pos = {x = 392, y = 929, z = 6}

local skills = {
    SKILL_FIST,
    SKILL_CLUB,
    SKILL_AXE,
    SKILL_SWORD,
    SKILL_SHIELD,
    SKILL_DISTANCE
}

function onStepIn(cid, item, position, fromPosition)
    local TILE = tiles[item.actionid]
 
    if not TILE then return false end
    -- Check Vocation
    if getPlayerVocation(cid) == TILE.vocid then
        doTeleportThing(cid, fromPosition)
        doSendMagicEffect(fromPosition, CONST_ME_POFF)
    return false
    end
    -- Give items if never recieved before
    if getPlayerStorageValue(cid, item.actionid) == -1 then
    -- dont have cap
    if getPlayerFreeCap(cid) < TILE.needcap then
        doTeleportThing(cid, fromPosition, false)
        doSendMagicEffect(position, CONST_ME_MAGIC_BLUE)
        doPlayerPopupFYI(cid, 'You need '.. TILE.needcap ..' OZ CAP to recive the items!')
        return false
    end
        for i = 1, #TILE.extraItems do
            doPlayerAddItem(cid, TILE.extraItems[i].itemID, TILE.extraItems[i].count)
        end
        setPlayerStorageValue(cid, item.actionid, 1)
    end

    --Create a table to hold player skills information
    local playerSkillTries = {}
    for i = 1, #skills do
        local currentSkill = getPlayerSkillLevel(cid, skills[i])
        playerSkillTries[i] = getPlayerSkillTries(cid, skills[i])
        for j = 11, currentSkill do
            playerSkillTries[i] = playerSkillTries[i] + getPlayerRequiredSkillTries(cid, skills[i], j)
        end
    end

    -- calculate the same for magic level
    local playerManaSpent = getPlayerSpentMana(cid)
    local currentMagic = getPlayerMagLevel(cid, true)
    for i = 1, currentMagic do
        playerManaSpent = playerManaSpent + getPlayerRequiredMana(cid, i)
    end

    doPlayerSetVocation(cid, TILE.vocid)
    --Set players skills to 10
    for i = 1, #skills do
        doPlayerSetSkillLevel(cid, skills[i], 10)
    end
    --doPlayerSetMagicLevel(cid, 0)

    --Add skill tries back to player--
    for i = 1, #skills do
        doPlayerAddSkillTry(cid, skills[i], playerSkillTries[i], false)
    end
    --doPlayerAddSpentMana(cid, playerManaSpent, false)
 
    local extraLevels = getPlayerLevel(cid) - 1
    local STATS = vocation_stats[TILE.vocid]
  
    setCreatureMaxHealth(cid, 185 + (STATS.hp * extraLevels))
    setCreatureMaxMana(cid, 40 + (STATS.hp * extraLevels))
    doCreatureAddHealth(cid, getCreatureMaxHealth(cid), false)
    doCreatureAddMana(cid, getCreatureMaxMana(cid), false)
    doPlayerSetMaxCapacity(cid, 400 + (STATS.cap * extraLevels))
    doTeleportThing(cid, pos)
    doSendMagicEffect(getThingPos(cid), CONST_ME_MAGIC_BLUE)
    doPlayerSetTown(cid, townid)
return true
end

10+ seconds LAG
 
Is that because how higher is the skills or ml it lag more?
Cause in this tests for example

3) knight ml 11
so got ml 95 when change to sorcerer

4) i was sorcerer sword 40
so got 174/125 when change to knight

I'm scare to when i put my server online it lag the server
 
i'm starting to think that could be something on creaturescript onadvance

i desative every "advance" script and it don't lag again

i think i found the major responsible for the lag
i'm right?
Code:
<event type="advance" name="AdvanceSave" event="script" value="advancesave.lua"/>

Code:
local config = {
    savePlayersOnAdvance = true
}

function onAdvance(cid, skill, oldLevel, newLevel)
    if(config.savePlayersOnAdvance) then
        doPlayerSave(cid, true)
    end

    return true
end

removing it, the server isnt even lagging more then 1 sec
but its a very important script

what should i do?
there is a way to revert it?

i think it is saving in every skill advance
then if i got skill 20 to 100, it save the player 80 times, i'm right?
 
i'm starting to think that could be something on creaturescript onadvance

i desative every "advance" script and it don't lag again

i think i found the major responsible for the lag
i'm right?
Code:
<event type="advance" name="AdvanceSave" event="script" value="advancesave.lua"/>

Code:
local config = {
    savePlayersOnAdvance = true
}

function onAdvance(cid, skill, oldLevel, newLevel)
    if(config.savePlayersOnAdvance) then
        doPlayerSave(cid, true)
    end

    return true
end

removing it, the server isnt even lagging more then 1 sec
but its a very important script

what should i do?
there is a way to revert it?

i think it is saving in every skill advance
then if i got skill 20 to 100, it save the player 80 times, i'm right?
you're probably right

this happens due to this part of player's addSkillAdvance
C++:
CreatureEventList advanceEvents = getCreatureEvents(CREATURE_EVENT_ADVANCE);
for(CreatureEventList::iterator it = advanceEvents.begin(); it != advanceEvents.end(); ++it)
    (*it)->executeAdvance(this, skill, (skills[skill][SKILL_LEVEL] - 1), skills[skill][SKILL_LEVEL]);

every time a skill goes up, it executes all creatureScript events
I think a fix would be to take this out of the loop, but I'm not sure if it'll have effects on other things
either way, here's my recommendation:

C++:
void Player::addSkillAdvance(skills_t skill, uint32_t count, bool useMultiplier/* = true*/)
{
    if(!count)
        return;

    uint32_t previousSkill = skills[skill][SKILL_LEVEL];

    //player has reached max skill
    uint32_t currReqTries = vocation->getReqSkillTries(skill, skills[skill][SKILL_LEVEL]),
        nextReqTries = vocation->getReqSkillTries(skill, skills[skill][SKILL_LEVEL] + 1);
    if(currReqTries > nextReqTries)
        return;

    if(useMultiplier)
        count = uint32_t((double)count * rates[skill] * g_config.getDouble(ConfigManager::RATE_SKILL));

    std::stringstream s;
    while(skills[skill][SKILL_TRIES] + count >= nextReqTries)
    {
        count -= nextReqTries - skills[skill][SKILL_TRIES];
        skills[skill][SKILL_TRIES] = skills[skill][SKILL_PERCENT] = 0;
        skills[skill][SKILL_LEVEL]++;

        s.str("");
        s << "You advanced in " << getSkillName(skill);
        if(g_config.getBool(ConfigManager::ADVANCING_SKILL_LEVEL))
            s << " [" << skills[skill][SKILL_LEVEL] << "]";

        s << ".";
        sendTextMessage(MSG_EVENT_ADVANCE, s.str().c_str());

        currReqTries = nextReqTries;
        nextReqTries = vocation->getReqSkillTries(skill, skills[skill][SKILL_LEVEL] + 1);
        if(currReqTries > nextReqTries)
        {
            count = 0;
            break;
        }
    }

    if(skills[skill][SKILL_LEVEL] > previousSkill) {
        CreatureEventList advanceEvents = getCreatureEvents(CREATURE_EVENT_ADVANCE);
        for(CreatureEventList::iterator it = advanceEvents.begin(); it != advanceEvents.end(); ++it)
            (*it)->executeAdvance(this, skill, previousSkill, skills[skill][SKILL_LEVEL]);
    }

    if(count)
        skills[skill][SKILL_TRIES] += count;

    //update percent
    uint32_t newPercent = Player::getPercentLevel(skills[skill][SKILL_TRIES], nextReqTries);
    if(skills[skill][SKILL_PERCENT] != newPercent)
    {
        skills[skill][SKILL_PERCENT] = newPercent;
        sendSkills();
    }
    else if(!s.str().empty())
        sendSkills();
}
I've changed lines 6 and 41, so it compares the previous player skill and, if it has changed since then, it'll execute creatureScripts
therefore if it goes from 1 to 100 at once it'll only execute creatureScripts once, while it was executing 99 times

again, be careful! I don't know if it'll affect your other creatureScripts. check them out and think if there's any difference between running them each time a player's skill goes up or if it only matters the end result

--edit

I forgot to say: the same is valid for magic level!


C++:
void Player::addManaSpent(uint64_t amount, bool useMultiplier/* = true*/)
{
    if(!amount)
        return;

    uint32_t previousMagLevel = magLevel;

    uint64_t currReqMana = vocation->getReqMana(magLevel), nextReqMana = vocation->getReqMana(magLevel + 1);
    if(currReqMana > nextReqMana) //player has reached max magic level
        return;

    if(useMultiplier)
        amount = uint64_t((double)amount * rates[SKILL__MAGLEVEL] * g_config.getDouble(ConfigManager::RATE_MAGIC));

    bool advance = false;
    while(manaSpent + amount >= nextReqMana)
    {
        amount -= nextReqMana - manaSpent;
        manaSpent = 0;
        magLevel++;

        char advMsg[50];
        sprintf(advMsg, "You advanced to magic level %d.", magLevel);
        sendTextMessage(MSG_EVENT_ADVANCE, advMsg);

        advance = true;

        currReqMana = nextReqMana;
        nextReqMana = vocation->getReqMana(magLevel + 1);
        if(currReqMana > nextReqMana)
        {
            amount = 0;
            break;
        }
    }

    if(magLevel > previousMagLevel) {
        CreatureEventList advanceEvents = getCreatureEvents(CREATURE_EVENT_ADVANCE);
        for(CreatureEventList::iterator it = advanceEvents.begin(); it != advanceEvents.end(); ++it)
            (*it)->executeAdvance(this, SKILL__MAGLEVEL, previousMagLevel, magLevel);
    }

    if(amount)
        manaSpent += amount;

    uint32_t newPercent = Player::getPercentLevel(manaSpent, nextReqMana);
    if(magLevelPercent != newPercent)
    {
        magLevelPercent = newPercent;
        sendStats();
    }
    else if(advance)
        sendStats();
}
 
Last edited:
you're probably right

this happens due to this part of player's addSkillAdvance
C++:
CreatureEventList advanceEvents = getCreatureEvents(CREATURE_EVENT_ADVANCE);
for(CreatureEventList::iterator it = advanceEvents.begin(); it != advanceEvents.end(); ++it)
    (*it)->executeAdvance(this, skill, (skills[skill][SKILL_LEVEL] - 1), skills[skill][SKILL_LEVEL]);

every time a skill goes up, it executes all creatureScript events
I think a fix would be to take this out of the loop, but I'm not sure if it'll have effects on other things
either way, here's my recommendation:

C++:
void Player::addSkillAdvance(skills_t skill, uint32_t count, bool useMultiplier/* = true*/)
{
    if(!count)
        return;

    uint32_t previousSkill = skills[skill][SKILL_LEVEL];

    //player has reached max skill
    uint32_t currReqTries = vocation->getReqSkillTries(skill, skills[skill][SKILL_LEVEL]),
        nextReqTries = vocation->getReqSkillTries(skill, skills[skill][SKILL_LEVEL] + 1);
    if(currReqTries > nextReqTries)
        return;

    if(useMultiplier)
        count = uint32_t((double)count * rates[skill] * g_config.getDouble(ConfigManager::RATE_SKILL));

    std::stringstream s;
    while(skills[skill][SKILL_TRIES] + count >= nextReqTries)
    {
        count -= nextReqTries - skills[skill][SKILL_TRIES];
        skills[skill][SKILL_TRIES] = skills[skill][SKILL_PERCENT] = 0;
        skills[skill][SKILL_LEVEL]++;

        s.str("");
        s << "You advanced in " << getSkillName(skill);
        if(g_config.getBool(ConfigManager::ADVANCING_SKILL_LEVEL))
            s << " [" << skills[skill][SKILL_LEVEL] << "]";

        s << ".";
        sendTextMessage(MSG_EVENT_ADVANCE, s.str().c_str());

        currReqTries = nextReqTries;
        nextReqTries = vocation->getReqSkillTries(skill, skills[skill][SKILL_LEVEL] + 1);
        if(currReqTries > nextReqTries)
        {
            count = 0;
            break;
        }
    }

    if(skills[skill][SKILL_LEVEL] > previousSkill) {
        CreatureEventList advanceEvents = getCreatureEvents(CREATURE_EVENT_ADVANCE);
        for(CreatureEventList::iterator it = advanceEvents.begin(); it != advanceEvents.end(); ++it)
            (*it)->executeAdvance(this, skill, previousSkill, skills[skill][SKILL_LEVEL]);
    }

    if(count)
        skills[skill][SKILL_TRIES] += count;

    //update percent
    uint32_t newPercent = Player::getPercentLevel(skills[skill][SKILL_TRIES], nextReqTries);
    if(skills[skill][SKILL_PERCENT] != newPercent)
    {
        skills[skill][SKILL_PERCENT] = newPercent;
        sendSkills();
    }
    else if(!s.str().empty())
        sendSkills();
}
I've changed lines 6 and 41, so it compares the previous player skill and, if it has changed since then, it'll execute creatureScripts
therefore if it goes from 1 to 100 at once it'll only execute creatureScripts once, while it was executing 99 times

again, be careful! I don't know if it'll affect your other creatureScripts. check them out and think if there's any difference between running them each time a player's skill goes up or if it only matters the end result

--edit

I forgot to say: the same is valid for magic level!


C++:
void Player::addManaSpent(uint64_t amount, bool useMultiplier/* = true*/)
{
    if(!amount)
        return;

    uint32_t previousMagLevel = magLevel;

    uint64_t currReqMana = vocation->getReqMana(magLevel), nextReqMana = vocation->getReqMana(magLevel + 1);
    if(currReqMana > nextReqMana) //player has reached max magic level
        return;

    if(useMultiplier)
        amount = uint64_t((double)amount * rates[SKILL__MAGLEVEL] * g_config.getDouble(ConfigManager::RATE_MAGIC));

    bool advance = false;
    while(manaSpent + amount >= nextReqMana)
    {
        amount -= nextReqMana - manaSpent;
        manaSpent = 0;
        magLevel++;

        char advMsg[50];
        sprintf(advMsg, "You advanced to magic level %d.", magLevel);
        sendTextMessage(MSG_EVENT_ADVANCE, advMsg);

        advance = true;

        currReqMana = nextReqMana;
        nextReqMana = vocation->getReqMana(magLevel + 1);
        if(currReqMana > nextReqMana)
        {
            amount = 0;
            break;
        }
    }

    if(magLevel > previousMagLevel) {
        CreatureEventList advanceEvents = getCreatureEvents(CREATURE_EVENT_ADVANCE);
        for(CreatureEventList::iterator it = advanceEvents.begin(); it != advanceEvents.end(); ++it)
            (*it)->executeAdvance(this, SKILL__MAGLEVEL, previousMagLevel, magLevel);
    }

    if(amount)
        manaSpent += amount;

    uint32_t newPercent = Player::getPercentLevel(manaSpent, nextReqMana);
    if(magLevelPercent != newPercent)
    {
        magLevelPercent = newPercent;
        sendStats();
    }
    else if(advance)
        sendStats();
}

working perfectly
thank you
 
Back
Top