• 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,
        needcap = 88,
        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,
        needcap = 91,
        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,
        needcap = 91,
        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,
        needcap = 122,
        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}

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

    if not TILE then return true 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

    local clubTries = getPlayerSkillTries(cid, SKILL_CLUB)
    local axeTries = getPlayerSkillTries(cid, SKILL_AXE)
    local swordTries = getPlayerSkillTries(cid, SKILL_SWORD)
    local shieldingTries = getPlayerSkillTries(cid, SKILL_SHIELD)
    local distanceTries = getPlayerSkillTries(cid, SKILL_DISTANCE)

    print("shield tries:")
    print(shieldingTries)

    --doPlayerSetSkillLevel(cid, SKILL_CLUB, 10)
    --doPlayerSetSkillLevel(cid, SKILL_AXE, 10)
    --doPlayerSetSkillLevel(cid, SKILL_SWORD, 10)

    --doPlayerSetSkillLevel(cid, SKILL_SHIELD, 10)

    --doPlayerSetSkillLevel(cid, SKILL_DISTANCE, 10)

    local extraLevels = getPlayerLevel(cid) - 1

    doPlayerSetVocation(cid, TILE.vocid)

    --Add skill tries back to player--
    --doPlayerAddSkillTry(cid, SKILL_CLUB, clubTries)
    --doPlayerAddSkillTry(cid, SKILL_AXE, axeTries)
    --doPlayerAddSkillTry(cid, SKILL_SWORD, swordTries)

    --doPlayerAddSkillTry(cid, SKILL_SHIELD, shieldingTries)

    --doPlayerAddSkillTry(cid, SKILL_DISTANCE, distanceTries)

    local STATS = vocation_stats[TILE.vocid]
    setCreatureMaxHealth(cid, 185 + (STATS.hp * extraLevels))
    setCreatureMaxMana(cid, 40 + (STATS.mp * 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


How getPlayerSkillTries works?
Code:
shield 17 - 100% to 18

shield tries:
0
shield tries:
0
shield tries:
0



shield 22 - 71% to 23
shield tries:
93
shield tries:
93
shield tries:
93
 
you can just do something like this
Code:
local ml = getPlayerMagicLevel(cid)
function onSay(cid, words, param)
if (getPlayerVocation(cid) == 1) then -- Sorcerer to knight so i have to change magic level to sword fighting for example.
setPlayerVocation(cid, 4)
setPlayerSkillLevel(cid, 1, ml*0.5) -- iam not good at all in 0.4 so idk the functions just showing you the way to do it by % 0.5*ml = 50% of his ml will be sword fighting.
setPlayerMagicLevel(cid) == 4
end
return true
end
Looks like you need to bind it to a storage value or collect the skilltries from db i guess 😣
i can't remember but if it needs the required skill tries or not but if it needs then you can use this function
getRequiredSkillTries
( This code will not work its just a sample )
 
It is a short fix, the calc will not be perfect, players would change vocation to grow up theirs skills...

All the 0.4 functions are here:

Looking on 0.4 functions i got an idea to try in some other way:
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,
        needcap = 88,
        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,
        needcap = 91,
        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,
        needcap = 91,
        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,
        needcap = 122,
        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}

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

    if not TILE then return true 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

    local clubTries = getPlayerSkillTries(cid, SKILL_CLUB)
    local axeTries = getPlayerSkillTries(cid, SKILL_AXE)
    local swordTries = getPlayerSkillTries(cid, SKILL_SWORD)

    local shieldingTries = getPlayerRequiredSkillTries(cid, SKILL_SHIELD, getPlayerSkillLevel(cid, SKILL_SHIELD))

    local distanceTries = getPlayerSkillTries(cid, SKILL_DISTANCE)

    print("shield tries:")
    print(shieldingTries)

    --doPlayerSetSkillLevel(cid, SKILL_CLUB, 10)
    --doPlayerSetSkillLevel(cid, SKILL_AXE, 10)
    --doPlayerSetSkillLevel(cid, SKILL_SWORD, 10)

    doPlayerSetSkillLevel(cid, SKILL_SHIELD, 10)

    --doPlayerSetSkillLevel(cid, SKILL_DISTANCE, 10)

    local extraLevels = getPlayerLevel(cid) - 1

    doPlayerSetVocation(cid, TILE.vocid)

    --Add skill tries back to player--
    --doPlayerAddSkillTry(cid, SKILL_CLUB, clubTries)
    --doPlayerAddSkillTry(cid, SKILL_AXE, axeTries)
    --doPlayerAddSkillTry(cid, SKILL_SWORD, swordTries)

    doPlayerAddSkillTry(cid, SKILL_SHIELD, shieldingTries)

    --doPlayerAddSkillTry(cid, SKILL_DISTANCE, distanceTries)

    local STATS = vocation_stats[TILE.vocid]
    setCreatureMaxHealth(cid, 185 + (STATS.hp * extraLevels))
    setCreatureMaxMana(cid, 40 + (STATS.mp * 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

But on test it wont work too :(

knight shield skills 17, 87% to 18
become sorcerer

prints it:
Code:
shield tries:
177
skills gone to 12, 54% to 13

so i've come back to knight again
print it:
Code:
shield tries:
150
skills gone to 12, 26% to 13

Is anyone could pls help me? I have no idea to what to do
What i'm doing wrong?
 
Last edited:
It is a short fix, the calc will not be perfect, players would change vocation to grow up theirs skills...

All the 0.4 functions are here:

Looking on 0.4 functions i got an idea to try in some other way:
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,
        needcap = 88,
        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,
        needcap = 91,
        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,
        needcap = 91,
        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,
        needcap = 122,
        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}

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

    if not TILE then return true 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

    local clubTries = getPlayerSkillTries(cid, SKILL_CLUB)
    local axeTries = getPlayerSkillTries(cid, SKILL_AXE)
    local swordTries = getPlayerSkillTries(cid, SKILL_SWORD)

    local shieldingTries = getPlayerRequiredSkillTries(cid, SKILL_SHIELD, getPlayerSkillLevel(cid, SKILL_SHIELD))

    local distanceTries = getPlayerSkillTries(cid, SKILL_DISTANCE)

    print("shield tries:")
    print(shieldingTries)

    --doPlayerSetSkillLevel(cid, SKILL_CLUB, 10)
    --doPlayerSetSkillLevel(cid, SKILL_AXE, 10)
    --doPlayerSetSkillLevel(cid, SKILL_SWORD, 10)

    doPlayerSetSkillLevel(cid, SKILL_SHIELD, 10)

    --doPlayerSetSkillLevel(cid, SKILL_DISTANCE, 10)

    local extraLevels = getPlayerLevel(cid) - 1

    doPlayerSetVocation(cid, TILE.vocid)

    --Add skill tries back to player--
    --doPlayerAddSkillTry(cid, SKILL_CLUB, clubTries)
    --doPlayerAddSkillTry(cid, SKILL_AXE, axeTries)
    --doPlayerAddSkillTry(cid, SKILL_SWORD, swordTries)

    doPlayerAddSkillTry(cid, SKILL_SHIELD, shieldingTries)

    --doPlayerAddSkillTry(cid, SKILL_DISTANCE, distanceTries)

    local STATS = vocation_stats[TILE.vocid]
    setCreatureMaxHealth(cid, 185 + (STATS.hp * extraLevels))
    setCreatureMaxMana(cid, 40 + (STATS.mp * 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

But on test it wont work too :(

knight shield skills 17, 87% to 18
become sorcerer

prints it:
Code:
shield tries:
177
skills gone to 12, 54% to 13

so i've come back to knight again
print it:
Code:
shield tries:
150
skills gone to 12, 26% to 13

Is anyone could pls help me? I have no idea to what to do
What i'm doing wrong?
Line 102:
Code:
    doPlayerSetSkillLevel(cid, SKILL_SHIELD, 10) -- why it is 10? and wy do you even use playersetskilllevel?
if you want it to be like before it have to be by % for example 50% (50% = 0.5) of shielding level 60 at sorc player will be 30 to get it back to 60 when he is knight it should be local shieldingTries = getPlayerRequiredSkillTries(cid, SKILL_SHIELD, getPlayerSkillLevel(cid, SKILL_SHIELD)) then doPlayerAddSkillTry(cid, SKILL_SHIELD, shieldingTries * 2)-- Line 115 if he is going to be EK if the player going to be Sorc it should be doPlayerAddSkillTry(cid, SKILL_SHIELD, shieldingTries * 0.5) iam sure it should do what i want if i got correctly what you need
 
Line 102:
Code:
    doPlayerSetSkillLevel(cid, SKILL_SHIELD, 10) -- why it is 10? and wy do you even use playersetskilllevel?
if you want it to be like before it have to be by % for example 50% (50% = 0.5) of shielding level 60 at sorc player will be 30 to get it back to 60 when he is knight it should be local shieldingTries = getPlayerRequiredSkillTries(cid, SKILL_SHIELD, getPlayerSkillLevel(cid, SKILL_SHIELD)) then doPlayerAddSkillTry(cid, SKILL_SHIELD, shieldingTries * 2)-- Line 115 if he is going to be EK if the player going to be Sorc it should be doPlayerAddSkillTry(cid, SKILL_SHIELD, shieldingTries * 0.5) iam sure it should do what i want if i got correctly what you need

The line 104 is to reset skills before add tries again

It is not how the doPlayerAddSkillTry, i dont know how it works, but its not like that...
i could use your idea to setplayerskill, but anyways it still wouldnt be like tibia formula works, and maybe could be something OP

I have this dawnport movement for 8.60 (0.4)

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,
        needcap = 88,
        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,
        needcap = 91,
        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,
        needcap = 91,
        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,
        needcap = 122,
        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}

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

    if not TILE then return true 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

    local clubTries = getPlayerSkillTries(cid, SKILL_CLUB)
    local axeTries = getPlayerSkillTries(cid, SKILL_AXE)
    local swordTries = getPlayerSkillTries(cid, SKILL_SWORD)

    local shieldingTries = getPlayerRequiredSkillTries(cid, SKILL_SHIELD, getPlayerSkillLevel(cid, SKILL_SHIELD))

    local distanceTries = getPlayerSkillTries(cid, SKILL_DISTANCE)

    print("shield tries:")
    print(shieldingTries)

    --doPlayerSetSkillLevel(cid, SKILL_CLUB, 10)
    --doPlayerSetSkillLevel(cid, SKILL_AXE, 10)
    --doPlayerSetSkillLevel(cid, SKILL_SWORD, 10)

    doPlayerSetSkillLevel(cid, SKILL_SHIELD, 10)

    --doPlayerSetSkillLevel(cid, SKILL_DISTANCE, 10)

    local extraLevels = getPlayerLevel(cid) - 1

    doPlayerSetVocation(cid, TILE.vocid)

    --Add skill tries back to player--
    --doPlayerAddSkillTry(cid, SKILL_CLUB, clubTries)
    --doPlayerAddSkillTry(cid, SKILL_AXE, axeTries)
    --doPlayerAddSkillTry(cid, SKILL_SWORD, swordTries)

    doPlayerAddSkillTry(cid, SKILL_SHIELD, shieldingTries)

    --doPlayerAddSkillTry(cid, SKILL_DISTANCE, distanceTries)

    local STATS = vocation_stats[TILE.vocid]
    setCreatureMaxHealth(cid, 185 + (STATS.hp * extraLevels))
    setCreatureMaxMana(cid, 40 + (STATS.mp * 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

But on test it wont work


knight shield skills 17 (87% to 18)
become sorcerer

prints it:
{
shield tries:
177
}

skills gone to 12 (54% to 13)

so i've come back to knight again
print it:
{
shield tries:
150
}

skills gone to 12 (26% to 13)

Is anyone could pls help me? I have no idea to what to do
What i'm doing wrong?
[/code]
 
I have this dawnport movement for 8.60 (0.4)

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,
        needcap = 88,
        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,
        needcap = 91,
        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,
        needcap = 91,
        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,
        needcap = 122,
        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}

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

    if not TILE then return true 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

    local clubTries = getPlayerSkillTries(cid, SKILL_CLUB)
    local axeTries = getPlayerSkillTries(cid, SKILL_AXE)
    local swordTries = getPlayerSkillTries(cid, SKILL_SWORD)

    local shieldingTries = getPlayerRequiredSkillTries(cid, SKILL_SHIELD, getPlayerSkillLevel(cid, SKILL_SHIELD))

    local distanceTries = getPlayerSkillTries(cid, SKILL_DISTANCE)

    print("shield tries:")
    print(shieldingTries)

    --doPlayerSetSkillLevel(cid, SKILL_CLUB, 10)
    --doPlayerSetSkillLevel(cid, SKILL_AXE, 10)
    --doPlayerSetSkillLevel(cid, SKILL_SWORD, 10)

    doPlayerSetSkillLevel(cid, SKILL_SHIELD, 10)

    --doPlayerSetSkillLevel(cid, SKILL_DISTANCE, 10)

    local extraLevels = getPlayerLevel(cid) - 1

    doPlayerSetVocation(cid, TILE.vocid)

    --Add skill tries back to player--
    --doPlayerAddSkillTry(cid, SKILL_CLUB, clubTries)
    --doPlayerAddSkillTry(cid, SKILL_AXE, axeTries)
    --doPlayerAddSkillTry(cid, SKILL_SWORD, swordTries)

    doPlayerAddSkillTry(cid, SKILL_SHIELD, shieldingTries)

    --doPlayerAddSkillTry(cid, SKILL_DISTANCE, distanceTries)

    local STATS = vocation_stats[TILE.vocid]
    setCreatureMaxHealth(cid, 185 + (STATS.hp * extraLevels))
    setCreatureMaxMana(cid, 40 + (STATS.mp * 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

But on test it wont work


knight shield skills 17 (87% to 18)
become sorcerer

prints it:
{
shield tries:
177
}

skills gone to 12 (54% to 13)

so i've come back to knight again
print it:
{
shield tries:
150
}

skills gone to 12 (26% to 13)

Is anyone could pls help me? I have no idea to what to do
What i'm doing wrong?
[/code]

So its no possible to do on 8.6?
 
hey buddy, I'm not sure if this is it, but judging from previous posts, "skillTries" might have two meanings:
1- getPlayerRequiredSkillTries: defines how many skill tries are needed to reach that skill
2- getPlayerSkillTries: gets how many skill tries the player has (for the current skill)

C++:
void Player::setSkillLevel(skills_t skill, uint32_t value)
{
    // stuff
    skills[skill][SKILL_LEVEL] = value;
    skills[skill][SKILL_TRIES] = 0;
    skills[skill][SKILL_PERCENT] = 0;
    // stuff
}

as you can see in setSkillLevel, it resets the skill tries (so it is set to 100% to next skill)

my guess is that you need this:

Lua:
local shieldingTries = getPlayerRequiredSkillTries(cid, SKILL_SHIELD, getPlayerSkillLevel(cid, SKILL_SHIELD)) + getPlayerSkillTries(cid, SKILL_SHIELD)
which, from what I understood, should mean "how many skill tries he needed to get to that skill + how many skill tries he has on that skill"
 
hey buddy, I'm not sure if this is it, but judging from previous posts, "skillTries" might have two meanings:
1- getPlayerRequiredSkillTries: defines how many skill tries are needed to reach that skill
2- getPlayerSkillTries: gets how many skill tries the player has (for the current skill)

C++:
void Player::setSkillLevel(skills_t skill, uint32_t value)
{
    // stuff
    skills[skill][SKILL_LEVEL] = value;
    skills[skill][SKILL_TRIES] = 0;
    skills[skill][SKILL_PERCENT] = 0;
    // stuff
}

as you can see in setSkillLevel, it resets the skill tries (so it is set to 100% to next skill)

my guess is that you need this:

Lua:
local shieldingTries = getPlayerRequiredSkillTries(cid, SKILL_SHIELD, getPlayerSkillLevel(cid, SKILL_SHIELD)) + getPlayerSkillTries(cid, SKILL_SHIELD)
which, from what I understood, should mean "how many skill tries he needed to get to that skill + how many skill tries he has on that skill"

But i'm not using setSkillLevel, just to reset...

You mean this?
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,
        needcap = 88,
        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,
        needcap = 91,
        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,
        needcap = 91,
        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,
        needcap = 122,
        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}

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

    if not TILE then return true 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

    local clubTries = getPlayerSkillTries(cid, SKILL_CLUB)
    local axeTries = getPlayerSkillTries(cid, SKILL_AXE)
    local swordTries = getPlayerSkillTries(cid, SKILL_SWORD)

    local shieldingTries = getPlayerRequiredSkillTries(cid, SKILL_SHIELD, getPlayerSkillLevel(cid, SKILL_SHIELD)) + getPlayerSkillTries(cid, SKILL_SHIELD)

    local distanceTries = getPlayerSkillTries(cid, SKILL_DISTANCE)

    print("shield tries:")
    print(shieldingTries)

    --doPlayerSetSkillLevel(cid, SKILL_CLUB, 10)
    --doPlayerSetSkillLevel(cid, SKILL_AXE, 10)
    --doPlayerSetSkillLevel(cid, SKILL_SWORD, 10)

    doPlayerSetSkillLevel(cid, SKILL_SHIELD, 10)

    --doPlayerSetSkillLevel(cid, SKILL_DISTANCE, 10)

    local extraLevels = getPlayerLevel(cid) - 1

    doPlayerSetVocation(cid, TILE.vocid)

    --Add skill tries back to player--
    --doPlayerAddSkillTry(cid, SKILL_CLUB, clubTries)
    --doPlayerAddSkillTry(cid, SKILL_AXE, axeTries)
    --doPlayerAddSkillTry(cid, SKILL_SWORD, swordTries)

    doPlayerAddSkillTry(cid, SKILL_SHIELD, shieldingTries)

    --doPlayerAddSkillTry(cid, SKILL_DISTANCE, distanceTries)

    local STATS = vocation_stats[TILE.vocid]
    setCreatureMaxHealth(cid, 185 + (STATS.hp * extraLevels))
    setCreatureMaxMana(cid, 40 + (STATS.mp * 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


knight shielding 20 89% to 21

become mage
shielding 13 85% to 14

become knight
shielding 14 37% to 15



it prints:
Code:
shield tries:
264

shield tries:
278
 
But i'm not using setSkillLevel, just to reset...

You mean this?
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,
        needcap = 88,
        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,
        needcap = 91,
        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,
        needcap = 91,
        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,
        needcap = 122,
        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}

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

    if not TILE then return true 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

    local clubTries = getPlayerSkillTries(cid, SKILL_CLUB)
    local axeTries = getPlayerSkillTries(cid, SKILL_AXE)
    local swordTries = getPlayerSkillTries(cid, SKILL_SWORD)

    local shieldingTries = getPlayerRequiredSkillTries(cid, SKILL_SHIELD, getPlayerSkillLevel(cid, SKILL_SHIELD)) + getPlayerSkillTries(cid, SKILL_SHIELD)

    local distanceTries = getPlayerSkillTries(cid, SKILL_DISTANCE)

    print("shield tries:")
    print(shieldingTries)

    --doPlayerSetSkillLevel(cid, SKILL_CLUB, 10)
    --doPlayerSetSkillLevel(cid, SKILL_AXE, 10)
    --doPlayerSetSkillLevel(cid, SKILL_SWORD, 10)

    doPlayerSetSkillLevel(cid, SKILL_SHIELD, 10)

    --doPlayerSetSkillLevel(cid, SKILL_DISTANCE, 10)

    local extraLevels = getPlayerLevel(cid) - 1

    doPlayerSetVocation(cid, TILE.vocid)

    --Add skill tries back to player--
    --doPlayerAddSkillTry(cid, SKILL_CLUB, clubTries)
    --doPlayerAddSkillTry(cid, SKILL_AXE, axeTries)
    --doPlayerAddSkillTry(cid, SKILL_SWORD, swordTries)

    doPlayerAddSkillTry(cid, SKILL_SHIELD, shieldingTries)

    --doPlayerAddSkillTry(cid, SKILL_DISTANCE, distanceTries)

    local STATS = vocation_stats[TILE.vocid]
    setCreatureMaxHealth(cid, 185 + (STATS.hp * extraLevels))
    setCreatureMaxMana(cid, 40 + (STATS.mp * 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


knight shielding 20 89% to 21

become mage
shielding 13 85% to 14

become knight
shielding 14 37% to 15



it prints:
Code:
shield tries:
264

shield tries:
278

let's try calculating stuff then
taking formulas from the source code you linked, we have that:
C++:
skillMap[level] = (uint32_t)(skillBase[skill] * std::pow(skillMultipliers[skill], (level - 11)));
is the formula for required skill tries to reach (level) skill

skillBase and skillMultipliers are taken from vocations.xml, which I'm gonna assume is the same as from github.
skillBase for shielding is not declared, so I'm gonna assume it is default (100, as per vocation.cpp line 478)
skillMultiplier for shield is 1.1 for knight and 1.5 for mages

therefore we have:
Lua:
local function knightRequiredTries(level)
  return 100 * (1.1 ^ (level - 11))
end
local function mageRequiredTries(level)
  return 100 * (1.5 ^ (level - 11))
end

this way we can see that, for skill 10, knights require 90 tries while mages only 66
we should then account for this difference, instead of just adding skill tries on top of each other

Lua:
-- total skill tries the player has as the current vocation
local oldSkillTries = getPlayerRequiredSkillTries(cid, SKILL_SHIELD, getPlayerSkillLevel(cid, SKILL_SHIELD)) + getPlayerSkillTries(cid, SKILL_SHIELD)
-- how many skill tries we'll need to add
local skillTriesToAdd = oldSkillTries - getPlayerRequiredSkillTries(cid, SKILL_SHIELD, 10)
-- now we have how many tries the player has above the start skill (10 with 100% to 11)
-- do stuff to change player vocation
-- set player's skill to 10
doPlayerAddSkillTry(cid, SKILL_SHIELD, skillTriesToAdd)

final code should be something like
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,
        needcap = 88,
        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,
        needcap = 91,
        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,
        needcap = 91,
        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,
        needcap = 122,
        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}

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

    if not TILE then return true 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

    local clubTries = getPlayerSkillTries(cid, SKILL_CLUB)
    local axeTries = getPlayerSkillTries(cid, SKILL_AXE)
    local swordTries = getPlayerSkillTries(cid, SKILL_SWORD)

    print('hey, you needed ' .. tonumber(getPlayerRequiredSkillTries(cid, SKILL_SHIELD, getPlayerSkillLevel(cid, SKILL_SHIELD))) .. ' tries to reach skill ' ..  tonumber(getPlayerSkillLevel(cid, SKILL_SHIELD)))
    local shieldingTries = getPlayerRequiredSkillTries(cid, SKILL_SHIELD, getPlayerSkillLevel(cid, SKILL_SHIELD)) + getPlayerSkillTries(cid, SKILL_SHIELD)
    print('in total, you had ' .. tonumber(shieldingTries) .. ' tries to reach your percentage')
    shieldingTries = shieldingTries - getPlayerRequiredSkillTries(cid, SKILL_SHIELD, 10)

    local distanceTries = getPlayerSkillTries(cid, SKILL_DISTANCE)

    print('we only need to add ' .. tonumber(shieldingTries) .. ' tries to your count because the rest are from your skill 10 base')

    local extraLevels = getPlayerLevel(cid) - 1

    doPlayerSetVocation(cid, TILE.vocid)

    --doPlayerSetSkillLevel(cid, SKILL_CLUB, 10)
    --doPlayerSetSkillLevel(cid, SKILL_AXE, 10)
    --doPlayerSetSkillLevel(cid, SKILL_SWORD, 10)

    doPlayerSetSkillLevel(cid, SKILL_SHIELD, 10)

    --doPlayerSetSkillLevel(cid, SKILL_DISTANCE, 10)

    --Add skill tries back to player--
    --doPlayerAddSkillTry(cid, SKILL_CLUB, clubTries)
    --doPlayerAddSkillTry(cid, SKILL_AXE, axeTries)
    --doPlayerAddSkillTry(cid, SKILL_SWORD, swordTries)

    doPlayerAddSkillTry(cid, SKILL_SHIELD, shieldingTries)
    print('we added back your tries and now you have ' .. getPlayerRequiredSkillTries(cid, SKILL_SHIELD, getPlayerSkillLevel(cid, SKILL_SHIELD)) + getPlayerSkillTries(cid, SKILL_SHIELD) .. ' from which ' .. tonumber(getPlayerRequiredSkillTries(cid, SKILL_SHIELD, 10)) .. ' are from skill 10 base')

    --doPlayerAddSkillTry(cid, SKILL_DISTANCE, distanceTries)

    local STATS = vocation_stats[TILE.vocid]
    setCreatureMaxHealth(cid, 185 + (STATS.hp * extraLevels))
    setCreatureMaxMana(cid, 40 + (STATS.mp * 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

can you try this? I don't have anywhere to test it.
I've also added a few more prints to it, so we can understand what's going on
if possible, use a simple example (knight shielding 20 (100% to 21) -> mage 12 something -> knight 20)
 
This code should be what you want. I cleaned it up more with some loops and tables. Let me know.

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 = {
    [1] = SKILL_CLUB,
    [2] = SKILL_AXE,
    [3] = SKILL_SWORD,
    [4] = SKILL_SHIELDING,
    [5] = 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) < 88 then
        doTeleportThing(cid, fromPosition, false)
        doSendMagicEffect(position, CONST_ME_MAGIC_BLUE)
        doPlayerPopupFYI(cid, 'You need 88 OZ CAP to recive the items!')
        return false
    end
    --Give player items
    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 playerSkills = {}
    for i = 1, #skills do
        playerSkills[i] = getPlayerRequiredSkillTries(cid, skills[i], getPlayerSkillLevel(cid, skills[i])) + getPlayerSkillTries(cid, skills[i])
    end
    --Set players skills to 10
    for i = 1, #skills do
        doPlayerSetSkillLevel(cid, skills[i], 10)
    end
    --Add skill tries back to player--
    for i = 1, #skills do
        doPlayerAddSkillTries(cid, skills[i], playerSkills[i], true)
    end
  
    local extraLevels = getPlayerLevel(cid) - 1
    local STATS = vocation_stats[TILE.vocid]
   
    setPlayerVocation(cid, 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, cap + (STATS.cap * extraLevels))
    doPlayerAddItem(cid, TILE.weaponID, 1)
    doTeleportThing(cid, pos)
    doSendMagicEffect(getThingPos(cid), CONST_ME_MAGIC_BLUE)
    doPlayerSetTown(cid, townid)
return true
end
 
Last edited:
I'm back. I checked how it works better and noticed that I had a wrong assumption.
Required skill tries actually returns how many tries are needed to advance, not total, so we need to sum all values to know how many skill tries we should give him back.
I took itutorial's code as base and added magic level/fist that were missing.

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) < 88 then
        doTeleportThing(cid, fromPosition, false)
        doSendMagicEffect(position, CONST_ME_MAGIC_BLUE)
        doPlayerPopupFYI(cid, 'You need 88 OZ CAP to recive the items!')
        return false
    end
    --Give player items
    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])
        for j = 11, currentSkill do
            playerSkillTries[i] = (playerSkillTries[i] or 0) + getPlayerRequiredSkillTries(cid, skills[i], j)
        end
        playerSkillTries[i] = playerSkillTries + getPlayerSkillTries(cid, skills[i])
    end

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

    setPlayerVocation(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
        doPlayerAddSkillTries(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, cap + (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 hope this works, otherwise I don't know what to do.
 
Oh guys think you so much
I was thinking no one would help me...

---

error using this final script

I'm back. I checked how it works better and noticed that I had a wrong assumption.
Required skill tries actually returns how many tries are needed to advance, not total, so we need to sum all values to know how many skill tries we should give him back.
I took itutorial's code as base and added magic level/fist that were missing.

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) < 88 then
        doTeleportThing(cid, fromPosition, false)
        doSendMagicEffect(position, CONST_ME_MAGIC_BLUE)
        doPlayerPopupFYI(cid, 'You need 88 OZ CAP to recive the items!')
        return false
    end
    --Give player items
    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])
        for j = 11, currentSkill do
            playerSkillTries[i] = (playerSkillTries[i] or 0) + getPlayerRequiredSkillTries(cid, skills[i], j)
        end
        playerSkillTries[i] = playerSkillTries + getPlayerSkillTries(cid, skills[i])
    end

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

    setPlayerVocation(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
        doPlayerAddSkillTries(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, cap + (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 hope this works, otherwise I don't know what to do.

Code:
[6:9:56.048] [Error - MoveEvents Interface] 
[6:9:56.048] data/movements/scripts/dawnport_tiles.lua:onStepIn
[6:9:56.048] Description: 
[6:9:56.048] data/movements/scripts/dawnport_tiles.lua:99: attempt to perform arithmetic on local 'playerSkillTries' (a table value)
[6:9:56.048] stack traceback:
[6:9:56.048]     data/movements/scripts/dawnport_tiles.lua:99: in function <data/movements/scripts/dawnport_tiles.lua:66>

line 99
Code:
playerSkillTries[i] = playerSkillTries + getPlayerSkillTries(cid, skills[i])
 
Thanks for the update on my code @leleco95 Was tired and didn't remember I needed to run a loop for each skill level to grab the total skill tries needed.

Change this on line 99 should fix it

Code:
playerSkillTries[i] = playerSkillTries[i] + getPlayerSkillTries(cid, skills[i])
 
Thanks for the update on my code @leleco95 Was tired and didn't remember I needed to run a loop for each skill level to grab the total skill tries needed.

Change this on line 99 should fix it

Code:
playerSkillTries[i] = playerSkillTries[i] + getPlayerSkillTries(cid, skills[i])

Still that:
Code:
[7:13:39.106] [Error - MoveEvents Interface] 
[7:13:39.106] data/movements/scripts/dawnport_tiles.lua:onStepIn
[7:13:39.106] Description: 
[7:13:39.106] data/movements/scripts/dawnport_tiles.lua:99: attempt to perform arithmetic on field '?' (a nil value)
[7:13:39.106] stack traceback:
[7:13:39.106]     data/movements/scripts/dawnport_tiles.lua:99: in function <data/movements/scripts/dawnport_tiles.lua:66>
 
can't believe I missed that...
you probably have a skill on 10 so no it didn't enter the loop and wasn't initialized
fixed that and also noticed I fucked up magic level cus I was replacing instead of adding

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) < 88 then
        doTeleportThing(cid, fromPosition, false)
        doSendMagicEffect(position, CONST_ME_MAGIC_BLUE)
        doPlayerPopupFYI(cid, 'You need 88 OZ CAP to recive the items!')
        return false
    end
    --Give player items
    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

    setPlayerVocation(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
        doPlayerAddSkillTries(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, cap + (STATS.cap * extraLevels))
    doPlayerAddItem(cid, TILE.weaponID, 1)
    doTeleportThing(cid, pos)
    doSendMagicEffect(getThingPos(cid), CONST_ME_MAGIC_BLUE)
    doPlayerSetTown(cid, townid)
return true
end
 
Last edited:
can't believe I missed that...
you probably have a skill on 10 so no it didn't enter the loop and wasn't initialized
fixed that and also noticed I fucked up magic level cus I was replacing instead of adding

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) < 88 then
        doTeleportThing(cid, fromPosition, false)
        doSendMagicEffect(position, CONST_ME_MAGIC_BLUE)
        doPlayerPopupFYI(cid, 'You need 88 OZ CAP to recive the items!')
        return false
    end
    --Give player items
    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

    setPlayerVocation(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
        doPlayerAddSkillTries(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, cap + (STATS.cap * extraLevels))
    doPlayerAddItem(cid, TILE.weaponID, 1)
    doTeleportThing(cid, pos)
    doSendMagicEffect(getThingPos(cid), CONST_ME_MAGIC_BLUE)
    doPlayerSetTown(cid, townid)
return true
end

There is something wrong with set player vocation
Was a knight, if i enter on knight tile works:
Code:
        doTeleportThing(cid, fromPosition)
        doSendMagicEffect(fromPosition, CONST_ME_POFF)

But it i try to become paladin for example:
Code:
[7:30:21.050] [Error - MoveEvents Interface] 
[7:30:21.050] data/movements/scripts/dawnport_tiles.lua:onStepIn
[7:30:21.050] Description: 
[7:30:21.050] data/movements/scripts/dawnport_tiles.lua:109: attempt to call global 'setPlayerVocation' (a nil value)
[7:30:21.050] stack traceback:
[7:30:21.050]     data/movements/scripts/dawnport_tiles.lua:109: in function <data/movements/scripts/dawnport_tiles.lua:66>
 
There is something wrong with set player vocation
Was a knight, if i enter on knight tile works:
Code:
        doTeleportThing(cid, fromPosition)
        doSendMagicEffect(fromPosition, CONST_ME_POFF)

But it i try to become paladin for example:
Code:
[7:30:21.050] [Error - MoveEvents Interface]
[7:30:21.050] data/movements/scripts/dawnport_tiles.lua:onStepIn
[7:30:21.050] Description:
[7:30:21.050] data/movements/scripts/dawnport_tiles.lua:109: attempt to call global 'setPlayerVocation' (a nil value)
[7:30:21.050] stack traceback:
[7:30:21.050]     data/movements/scripts/dawnport_tiles.lua:109: in function <data/movements/scripts/dawnport_tiles.lua:66>
replace those lines with doPlayerSetVocation
 
replace those lines with doPlayerSetVocation

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) < 88 then
        doTeleportThing(cid, fromPosition, false)
        doSendMagicEffect(position, CONST_ME_MAGIC_BLUE)
        doPlayerPopupFYI(cid, 'You need 88 OZ CAP to recive the items!')
        return false
    end
    --Give player items
    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
        doPlayerAddSkillTries(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, cap + (STATS.cap * extraLevels))
    doPlayerAddItem(cid, TILE.weaponID, 1)
    doTeleportThing(cid, pos)
    doSendMagicEffect(getThingPos(cid), CONST_ME_MAGIC_BLUE)
    doPlayerSetTown(cid, townid)
return true
end

Code:
[9:18:16.837] [Error - MoveEvents Interface] 
[9:18:16.837] data/movements/scripts/dawnport_tiles.lua:onStepIn
[9:18:16.837] Description: 
[9:18:16.837] data/movements/scripts/dawnport_tiles.lua:118: attempt to call global 'doPlayerAddSkillTries' (a nil value)
[9:18:16.837] stack traceback:
[9:18:16.837]     data/movements/scripts/dawnport_tiles.lua:118: in function <data/movements/scripts/dawnport_tiles.lua:66>

It just reset my sword skill
 
Back
Top