function getHand(player)
local _ALLOWEDS = {2187} -- example {2723, 8329, 8921}
local slotRight = getPlayerSlotItem(player, 5)
local slotLeft = getPlayerSlotItem(player, 6)
if isInArray(_ALLOWEDS, slotRight.itemid) then
return "right"
elseif isInArray(_ALLOWEDS, slotLeft.itemid) then
return "left"
end
return nil
end
function getWandDmg(itemId)
local file = io.open("data/weapons/weapons.xml", "r")
for info in string.gmatch(file:read("*a"), "<weapons(.-)</weapons>") do
if info:match("wand id=\"(.-)\"") == itemId then
local min = info:match("min=(.-)")
local max = info:match("max=(.-)")
return math.random(min, max)
end
end
file:close()
return nil
end
function getWandDmgType(itemId)
local file = io.open("data/weapons/weapons.xml", "r")
for info in string.gmatch(file:read("*a"), "<weapons(.-)</weapons>") do
if info:match("wand id=\"(.-)\"") == itemId then
local type = info:match("type=(.-)")
return tostring(type)
end
end
file:close()
return nil
end
function setWandExtraDmg(wand, extra)
local value = tonumber(getWandExtraDmg(wand))
return doItemSetAttribute(wand.uid, "extraDmg", value + extra)
end
function getWandExtraDmg(wand)
if getItemAttribute(wand.uid, "extraDmg") == nil then
doItemSetAttribute(wand.uid, "extraDmg", 0)
end
return getItemAttribute(wand.uid, "extraDmg")
end
function onUse(cid, item, fromPosition, itemEx, toPosition)
local _VAL = 100 -- value of upgrade, example damage is 100 boost + 5 = damage 150
local _ALLOWEDS = {2187} -- example {2723, 8329, 8921}
if isInArray(_ALLOWEDS, itemEx.itemid) then
setWandExtraDmg(itemEx, _VAL)
doSendMagicEffect(fromPosition, 28)
--doRemoveItem(item.uid, 1)
--doSendAnimatedText(fromPosition, "+ 1", math.random(210, 250))
end
return true
end
function onStatsChange(cid, attacker, type, combat, value)
local _TYPES = {
["fire"] = {efect = 36, dmg = COMBAT_FIREDAMAGE},
["ice"] = {efect = 42, dmg = COMBAT_ICEDAMAGE},
["earth"] = {efect = 45, dmg = COMBAT_POISONDAMAGE},
["death"] = {efect = 17, dmg = COMBAT_DEATHDAMAGE},
["energy"] = {efect = 11, dmg = COMBAT_ENERGYDAMAGE},
["holy"] = {efect = 49, dmg = COMBAT_HOLYDAMAGE}
}
local slotRight = getPlayerSlotItem(attacker, 5)
local slotLeft = getPlayerSlotItem(attacker, 6)
local _HAND = getHand(attacker) == "right" and slotRight or slotLeft
local _TYPE = _TYPES[getWandDmgType(_HAND.itemid)]
local _EXTRA = getWandExtraDmg(_HAND)
local _MIN, _MAX = getWandDmg(_HAND.itemid) + _EXTRA, getWandDmg(_HAND.itemid) + _EXTRA
if _MIN > _MAX then
_MIN = _MAX
end
if _EXTRA > 0 then
if getCreatureCondition(cid, CONDITION_MANASHIELD) then
doTargetCombatMana(attacker, cid, _MIN, _MAX, _TYPE.efect)
else
doTargetCombatHealth(attacker, cid, _TYPE.dmg, - _MIN, - _MAX, _TYPE.efect)
end
end
return true
end