liqeen
Active Member
Hello, I'm trying to make a script that will set a certain value of storage to item from table when equipped, it "KINDA" works but not so far, by that I mean it do set the storage but every time a player gets hit it adds the storage once more and so on, also it does not remove the storage upon dequiping.
How it should work:
1. Player has already a certain value of x storage.
2. Player equips an item which gives value of "5" for example.
3. Player should have value of the storage equal to x + 5.
4. Player dequip a piece of equipment and his storage value should go back to x.
It is probably messed up and should be done in movements but I can't handle it, please help
Thanks for your time
How it should work:
1. Player has already a certain value of x storage.
2. Player equips an item which gives value of "5" for example.
3. Player should have value of the storage equal to x + 5.
4. Player dequip a piece of equipment and his storage value should go back to x.
Lua:
local gear = {
[21691] = {slot = CONST_SLOT_NECKLACE, amount = 500}
}
function onHealthChange(creature, attacker, primaryDamage, primaryType, secondaryDamage, secondaryType, origin)
if attacker then
local base = creature:getStorageValue(27452)
local storage = 0
for i = CONST_SLOT_HEAD, CONST_SLOT_AMMO do
local slot = creature:getSlotItem(i)
if slot then
local v = gear[slot:getId()]
if v then
if i == v.slot then
storage = v.amount
end
end
end
end
creature:setStorageValue(27452, base + storage) end
return
end
It is probably messed up and should be done in movements but I can't handle it, please help
Thanks for your time