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?
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