Mateus Robeerto
Excellent OT User
Look, I made a script, but I know it doesn't work. Does anyone know if it's possible to put a script via CreatureScript, for example, on an item when using it and gain a magic damage bonus in percentage?
code for example
Does anyone have any ideas about this? I urgently need my server, because I'm almost finishing my project. It was the last detail, please. I already tried using magicpointsPercepent and BossPercent, but neither worked
can be creaturescript or Revscript.. Thank you
code for example
Lua:
function onCreatureAttack(creature, target, primaryDamage, primaryType, secondaryDamage, secondaryType, origin)
if not creature:isPlayer() then
return primaryDamage, primaryType, secondaryDamage, secondaryType
end
local attackerPlayer = creature:getPlayer()
for slot = CONST_SLOT_FIRST, CONST_SLOT_LAST do
if attackerPlayer:isItemAbilityEnabled(slot) then
local item = attackerPlayer:getInventoryItem(slot)
if item then
local boostPercent = item:getBoostPercent(primaryType)
if boostPercent ~= 0 then
primaryDamage = primaryDamage + math.round(primaryDamage * (boostPercent / 100))
end
end
end
end
if primaryDamage <= 0 then
primaryDamage = 0
secondaryType = BLOCK_ARMOR
end
return primaryDamage, primaryType, secondaryDamage, secondaryType
end
Lua:
local creatureEvent = CreatureEvent("MagicDamageBoost")
function creatureEvent.onUse(player, item, fromPosition, target, toPosition, isHotkey)
if not player:isPlayer() then
return false
end
local boostPercent = 0
local itemID = item:getId()
local itemNode = ItemType(itemID)
if itemNode:isStackable() or itemNode:isMultiType() then
itemNode = ItemType(itemID, item:getType())
end
if itemNode then
boostPercent = itemNode:getMagicDamagePercent()
end
if boostPercent > 0 then
local magicDamageBoost = player:getBaseMagicDamage() * boostPercent / 100
player:setBaseMagicDamage(player:getBaseMagicDamage() + magicDamageBoost)
player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You feel an increase in your magical power.")
player:getPosition():sendMagicEffect(CONST_ME_MAGIC_GREEN)
item:remove(1)
else
player:sendCancelMessage("This item doesn't provide any magical damage boost.")
end
return true
end
creatureEvent:register()
can be creaturescript or Revscript.. Thank you
Last edited: