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

Solved Capacity is reset to 0

Berciq

Veteran OT User
Joined
Aug 7, 2018
Messages
254
Reaction score
333
Location
Poland
Hey! I made some statues to change vocation when you "use" them.
It is working, they change vocations, set new max health, set new mana, but they reset capacity to 0.
Even when I level up capacity remains 0.
I asked chat to help and it said to add some debug output.
In game server console it says it has changed cap to new (correct value) on level 10 (for me it should be 400+10*20=600) but I hardly have anything on and cap is 0
Do You have any clue?


Lua:
local config = {
    removelevel = 0, -- Amount of level taken away.
    skilafter = 10, -- What skill will the player have after change.
    minimumlevel = 1, -- What will be min level required?
    magafter = 1, -- What magic level will he receive after change?
}


local vocationChange = {
    [55550] = {vocationId = 0, hp = 10, mana = 10, cap = 20}, -- Unique ID 55550 changes to No vocation     (vocation ID 0)
    [55551] = {vocationId = 1, hp = 10, mana = 30, cap = 20}, -- Unique ID 55551 changes to Sorcerer         (vocation ID 1)
    [55552] = {vocationId = 2, hp = 10, mana = 30, cap = 20}, -- Unique ID 55552 changes to Druid             (vocation ID 2)
    [55553] = {vocationId = 3, hp = 20, mana = 15, cap = 20}, -- Unique ID 55553 changes to Paladin         (vocation ID 3)
    [55554] = {vocationId = 4, hp = 30, mana = 10, cap = 20}, -- Unique ID 55554 changes to Knight             (vocation ID 4)
    -- Add more unique IDs and corresponding vocation IDs as needed
}


function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    local changeInfo = vocationChange[item:getUniqueId()]
    if changeInfo then
        if player:getLevel() >= config.minimumlevel then
            local currentVocation = player:getVocation()
            local newVocationId = changeInfo.vocationId
            
            -- Change vocation
            player:setVocation(newVocationId)


            -- Set new hp, mana, and capacity
            local newLevel = player:getLevel()
            local newHealth = 100 + (newLevel * changeInfo.hp)
            local newMana = 0 + (newLevel * changeInfo.mana)
            local newCapacity = 400 + (newLevel * changeInfo.cap)


            -- Debug output
            print("New Level: " .. newLevel)
            print("New Health: " .. newHealth)
            print("New Mana: " .. newMana)
            print("New Capacity: " .. newCapacity)
            
            player:setMaxHealth(newHealth)
            player:setMaxMana(newMana)
            player:setCapacity(newCapacity)


            -- Send confirmation message
            player:sendTextMessage(MESSAGE_INFO_DESCR, "Your vocation has been changed to " .. currentVocation:getName() .. ".")
            return true
        else
            player:sendTextMessage(MESSAGE_STATUS_CONSOLE_RED, "You need to be at least level " .. config.minimumlevel .. " to use this item.")
            return false
        end
    else
        player:sendTextMessage(MESSAGE_STATUS_CONSOLE_RED, "This item cannot change your vocation.")
        return false
    end
end
 
Lua:
function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    local vocation = player:getVocation():getId()
    if vocation >= 5 and vocation <= 8 then
        vocation = vocation + 4
        player:setVocation(vocation)
        player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You've been promoted! Congratulations!")
        item:remove()
    else
        player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You're already at the maximum promotion level. Unable to utilize this item.")
    end
    return true
end
XML:
<action itemid="2349" script="promotion note.lua"/>
XML:
<vocation id="9" clientid="3" name="Dark Wizard" description="a Dark Wizard" gaincap="25" gainhp="5" gainmana="30" gainhpticks="4" gainhpamount="10" gainmanaticks="2" gainmanaamount="10" manamultiplier="1.1" attackspeed="600" basespeed="220" soulmax="200" gainsoulticks="15" fromvoc="5" noPongKickTime="40">
        <formula meleeDamage="1.0" distDamage="1.0" defense="1.0" armor="1.0" />
        <skill id="0" multiplier="1.5" />
        <skill id="1" multiplier="2.0" />
        <skill id="2" multiplier="2.0" />
        <skill id="3" multiplier="2.0" />
        <skill id="4" multiplier="2.0" />
        <skill id="5" multiplier="1.5" />
        <skill id="6" multiplier="1.1" />
    </vocation>
XML:
<vocation id="10" clientid="4" name="Holy Priest" description="an Holy Priest" gaincap="25" gainhp="5" gainmana="30" gainhpticks="4" gainhpamount="10" gainmanaticks="2" gainmanaamount="10" manamultiplier="1.1" attackspeed="600" basespeed="220" soulmax="200" gainsoulticks="15" fromvoc="6" noPongKickTime="40">
        <formula meleeDamage="1.0" distDamage="1.0" defense="1.0" armor="1.0" />
        <skill id="0" multiplier="1.5" />
        <skill id="1" multiplier="1.8" />
        <skill id="2" multiplier="1.8" />
        <skill id="3" multiplier="1.8" />
        <skill id="4" multiplier="1.8" />
        <skill id="5" multiplier="1.5" />
        <skill id="6" multiplier="1.1" />
    </vocation>
XML:
<vocation id="11" clientid="2" name="Nobleman" description="a Nobleman" gaincap="35" gainhp="10" gainmana="15" gainhpticks="3" gainhpamount="10" gainmanaticks="3" gainmanaamount="10" manamultiplier="1.4" attackspeed="600" basespeed="220" soulmax="200" gainsoulticks="15" fromvoc="7" noPongKickTime="50">
        <formula meleeDamage="1.0" distDamage="1.0" defense="1.0" armor="1.0" />
        <skill id="0" multiplier="1.2" />
        <skill id="1" multiplier="1.2" />
        <skill id="2" multiplier="1.2" />
        <skill id="3" multiplier="1.2" />
        <skill id="4" multiplier="1.1" />
        <skill id="5" multiplier="1.1" />
        <skill id="6" multiplier="1.1" />
    </vocation>
XML:
<vocation id="12" clientid="1" name="Barbarian" description="an Barbarian" gaincap="40" gainhp="15" gainmana="5" gainhpticks="2" gainhpamount="10" gainmanaticks="4" gainmanaamount="10" manamultiplier="3.0" attackspeed="600" basespeed="220" soulmax="200" gainsoulticks="15" fromvoc="8">
        <formula meleeDamage="1.0" distDamage="1.0" defense="1.0" armor="1.0" />
        <skill id="0" multiplier="1.1" />
        <skill id="1" multiplier="1.1" />
        <skill id="2" multiplier="1.1" />
        <skill id="3" multiplier="1.1" />
        <skill id="4" multiplier="1.4" />
        <skill id="5" multiplier="1.1" />
        <skill id="6" multiplier="1.1" />
    </vocation>
Post automatically merged:

also test
Lua:
local config = {
    removelevel = 0, -- Amount of level taken away.
    skilafter = 10, -- What skill will the player have after change.
    minimumlevel = 1, -- What will be min level required?
    magafter = 1, -- What magic level will he receive after change?
}

local vocationChange = {
    [55550] = {vocationId = 0, hp = 10, mana = 10, cap = 10}, -- Unique ID 55550 changes to No vocation (vocation ID 0)
    [55551] = {vocationId = 1, hp = 10, mana = 30, cap = 10}, -- Unique ID 55551 changes to Sorcerer (vocation ID 1)
    [55552] = {vocationId = 2, hp = 10, mana = 30, cap = 10}, -- Unique ID 55552 changes to Druid (vocation ID 2)
    [55553] = {vocationId = 3, hp = 20, mana = 15, cap = 20}, -- Unique ID 55553 changes to Paladin (vocation ID 3)
    [55554] = {vocationId = 4, hp = 30, mana = 10, cap = 25}, -- Unique ID 55554 changes to Knight (vocation ID 4)
    -- Add more unique IDs and corresponding vocation IDs as needed
}

function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    local changeInfo = vocationChange[item:getUniqueId()]
    if changeInfo then
        if player:getLevel() >= config.minimumlevel then
            local newVocationId = changeInfo.vocationId
            
            -- Adjust player's level if removelevel is greater than 0
            if config.removelevel > 0 then
                player:removeExperience(player:getExperienceForLevel(player:getLevel() - config.removelevel))
            end
            
            -- Change vocation
            player:setVocation(newVocationId)

            -- Set new hp, mana, and capacity
            local newLevel = player:getLevel()
            local newHealth = 100 + (newLevel * changeInfo.hp)
            local newMana = 0 + (newLevel * changeInfo.mana)
            local newCapacity = 400 + (newLevel * changeInfo.cap)
            
            player:setMaxHealth(newHealth)
            player:setMaxMana(newMana)
            player:setCapacity(newCapacity)

            -- Set skills and magic level after vocation change
            player:setSkillLevel(SKILL_CLUB, config.skilafter)
            player:setSkillLevel(SKILL_SWORD, config.skilafter)
            player:setSkillLevel(SKILL_AXE, config.skilafter)
            player:setSkillLevel(SKILL_DISTANCE, config.skilafter)
            player:setSkillLevel(SKILL_SHIELD, config.skilafter)
            player:setSkillLevel(SKILL_FISHING, config.skilafter)
            player:setMagicLevel(config.magafter)
            
            -- Send confirmation message
            player:sendTextMessage(MESSAGE_INFO_DESCR, "Your vocation has been changed to " .. player:getVocation():getName() .. ".")
            return true
        else
            player:sendTextMessage(MESSAGE_STATUS_CONSOLE_RED, "You need to be at least level " .. config.minimumlevel .. " to use this item.")
            return false
        end
    else
        player:sendTextMessage(MESSAGE_STATUS_CONSOLE_RED, "This item cannot change your vocation.")
        return false
    end
end
 
Still same result ;S
did you test my script?
function onUse(player, item, fromPosition, target, toPosition, isHotkey) local vocation = player:getVocation():getId() if vocation >= 5 and vocation <= 8 then vocation = vocation + 4 player:setVocation(vocation) player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You've been promoted! Congratulations!") item:remove() else player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You're already at the maximum promotion level. Unable to utilize this item.") end return true end
 
did you test my script?
I did, it set my cap to 0, and shown in console error in setskill attempt to call method (a nil value),

MOG... I forgot to take off shoes which weights 9,00oz.
after it has shown that i have 6 cap!
means that instead of 600 cap it gave me 6,00cap
I just multiplied numbers by 100 so I should have ((400+(10*20))*100) = 60000 means 600,00cap... i'm dumbaf ;D

After multiplying cap by 100 it works fine,
here maybe somoene will need it:

Lua:
local config = {
    removelevel = 0, -- Amount of level taken away.
    skilafter = 10, -- What skill will the player have after change.
    minimumlevel = 1, -- What will be min level required?
    magafter = 1, -- What magic level will he receive after change?
}


local vocationChange = {
    [55550] = {vocationId = 0, hp = 10, mana = 10, cap = 20}, -- Unique ID 55550 changes to No vocation     (vocation ID 0)
    [55551] = {vocationId = 1, hp = 10, mana = 30, cap = 20}, -- Unique ID 55551 changes to Sorcerer         (vocation ID 1)
    [55552] = {vocationId = 2, hp = 10, mana = 30, cap = 20}, -- Unique ID 55552 changes to Druid             (vocation ID 2)
    [55553] = {vocationId = 3, hp = 20, mana = 15, cap = 20}, -- Unique ID 55553 changes to Paladin         (vocation ID 3)
    [55554] = {vocationId = 4, hp = 30, mana = 10, cap = 20}, -- Unique ID 55554 changes to Knight             (vocation ID 4)
    -- Add more unique IDs and corresponding vocation IDs as needed
}


function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    local changeInfo = vocationChange[item:getUniqueId()]
    if changeInfo then
        if player:getLevel() >= config.minimumlevel then
            local currentVocation = player:getVocation()
            local newVocationId = changeInfo.vocationId
           
            -- Change vocation
            player:setVocation(newVocationId)


            -- Set new hp, mana, and capacity
            local newLevel = player:getLevel()
            local newHealth = 100 + (newLevel * changeInfo.hp)                     --    player:setMaxHealth(185 + ((newLevel - 8) * changeInfo.hp))
            local newMana = 0 + (newLevel * changeInfo.mana)                     --    player:setMaxMana(35 + ((newLevel - 8) * changeInfo.mana))
            local newCapacity = ((400 + (newLevel * changeInfo.cap)) * 100)     --    player:setCapacity(470 + ((newLevel - 8) * changeInfo.cap))


            -- Debug output
            print("New Level: " .. newLevel)
            print("New Health: " .. newHealth)
            print("New Mana: " .. newMana)
            print("New Capacity: " .. newCapacity)
           
            player:setMaxHealth(newHealth)
            player:setMaxMana(newMana)
            player:setCapacity(newCapacity)


            -- Send confirmation message
            player:sendTextMessage(MESSAGE_INFO_DESCR, "Your vocation has been changed to " .. currentVocation:getName() .. ".")
            return true
        else
            player:sendTextMessage(MESSAGE_STATUS_CONSOLE_RED, "You need to be at least level " .. config.minimumlevel .. " to use this item.")
            return false
        end
    else
        player:sendTextMessage(MESSAGE_STATUS_CONSOLE_RED, "This item cannot change your vocation.")
        return false
    end
end
 
Last edited:
Back
Top