Svira
Banned User
- Joined
- Jan 27, 2008
- Messages
- 361
- Solutions
- 13
- Reaction score
- 105
Hello everyone,
I have a problem with my movement script for a ring. Everything seems correct, there are no errors in the console, but the script is not working at all – even the print statements are not showing up. The ring should give health/mana bonuses depending on the player's vocation when equipped and remove them when unequipped. However, equipping or unequipping the ring does nothing.
code:
and register:
I have checked everything, and there are no errors in the console. However, the print messages are not showing, and the effects are not applied to the player.
Does anyone know what could be wrong? Is there something missing in movements.xml, or is there an issue with how onEquip and onDeEquip are handled?
Thanks in advance for your help!
#edit:
Yes, I know I can do it in items.xml but I want to check vocation...
I have a problem with my movement script for a ring. Everything seems correct, there are no errors in the console, but the script is not working at all – even the print statements are not showing up. The ring should give health/mana bonuses depending on the player's vocation when equipped and remove them when unequipped. However, equipping or unequipping the ring does nothing.
code:
LUA:
local ringStorage = 790528
local vocationBonuses = {
[4] = {health = 1500, mana = -500, storage = 1}, -- Knight
[8] = {health = 1500, mana = -500, storage = 1}, -- Elite Knight
[5] = {health = 1500, mana = -500, storage = 1}, -- Paladin
[9] = {health = 1500, mana = -500, storage = 1}, -- Royal Paladin
[2] = {health = -400, mana = 1300, storage = 2}, -- Druid
[6] = {health = -400, mana = 1300, storage = 2}, -- Elder Druid
[1] = {health = -400, mana = 1300, storage = 2}, -- Sorcerer
[7] = {health = -400, mana = 1300, storage = 2} -- Master Sorcerer
}
function onEquip(player, item, slot)
local vocation = player:getVocation():getId()
local bonus = vocationBonuses[vocation]
if bonus then
print("Ring equipped")
player:setHealth(math.max(1, player:getHealth() + bonus.health))
player:setMana(math.max(0, player:getMana() + bonus.mana))
player:setStorageValue(ringStorage, bonus.storage)
local message = (bonus.storage == 1) and
"You feel a surge of vitality, but your magical energy diminishes." or
"You feel a surge of magical energy, but your vitality diminishes."
player:sendTextMessage(MESSAGE_EVENT_ADVANCE, message)
else
player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "This ring seems to have no effect on you.")
end
return true
end
function onDeEquip(player, item, slot)
local storageValue = player:getStorageValue(ringStorage)
if storageValue == 1 then
print("Ring unequipped (Knight/Paladin)")
player:setHealth(math.max(1, player:getHealth() - 1500))
player:setMana(math.max(0, player:getMana() + 500))
player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "The surge of vitality fades, and your magical energy returns.")
elseif storageValue == 2 then
print("Ring unequipped (Druid/Sorcerer)")
player:setMana(math.max(0, player:getMana() - 1300))
player:setHealth(math.max(1, player:getHealth() + 400))
player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "The surge of magical energy fades, and your vitality returns.")
end
player:setStorageValue(ringStorage, -1) -- Reset the storage value
return true
end
XML:
<!-- Tier EQ -->
<movement type="Equip" itemid="13825" slot="ring" script="ring_tier_1.lua">
<vocation name="Knight" />
<vocation name="Elite Knight" showInDescription="0" />
<vocation name="Paladin" />
<vocation name="Royal Paladin" showInDescription="0" />
<vocation name="Sorcerer" />
<vocation name="Master Sorcerer" showInDescription="0" />
<vocation name="Druid" />
<vocation name="Elder Druid" showInDescription="0" />
</movement>
<movement type="DeEquip" itemid="13825" slot="ring" script="ring_tier_1.lua" />
I have checked everything, and there are no errors in the console. However, the print messages are not showing, and the effects are not applied to the player.
Does anyone know what could be wrong? Is there something missing in movements.xml, or is there an issue with how onEquip and onDeEquip are handled?
Thanks in advance for your help!
#edit:
Yes, I know I can do it in items.xml but I want to check vocation...
Last edited: