I'm trying to make it so that when the player casts 2 runes, 1 in each hand, he consumes twice the amount of soul points. But I've tried everything and I can't :/
tfs 1,5
spells in scripts
scripts/folder/functions.lua
tfs 1,5
spells in scripts
scripts/folder/functions.lua
LUA:
function Player:conjureItem(conjureMana, reagentId, conjureId, conjureCount, effect)
local conjureFromHandsOnly = true
if not conjureCount and conjureId ~= 0 then
local itemType = ItemType(conjureId)
if itemType:getId() == 0 then
return false
end
local charges = itemType:getCharges()
if charges ~= 0 then
conjureCount = charges
end
end
if not conjureFromHandsOnly then
if reagentId ~= 0 and not self:removeItem(reagentId, 1, -1) then
self:sendCancelMessage(RETURNVALUE_YOUNEEDAMAGICITEMTOCASTSPELL)
self:getPosition():sendMagicEffect(CONST_ME_POFF)
return false
end
local item = self:addItem(conjureId, conjureCount)
if not item then
self:sendCancelMessage(RETURNVALUE_NOTPOSSIBLE)
self:getPosition():sendMagicEffect(CONST_ME_POFF)
return false
end
if item:hasAttribute(ITEM_ATTRIBUTE_DURATION) then
item:decay()
end
self:getPosition():sendMagicEffect(effect or CONST_ME_MAGIC_RED)
else
local leftItem = self:getSlotItem(CONST_SLOT_LEFT)
local rightItem = self:getSlotItem(CONST_SLOT_RIGHT)
local totalConjures = 0
if reagentId ~= 0 then
if leftItem and leftItem:getId() == reagentId then
leftItem:remove()
local item = self:addItem(conjureId, 1, true, conjureCount, CONST_SLOT_LEFT)
if not item then
self:sendCancelMessage(RETURNVALUE_NOTPOSSIBLE)
self:getPosition():sendMagicEffect(CONST_ME_POFF)
return false
end
if item:hasAttribute(ITEM_ATTRIBUTE_DURATION) then
item:decay()
end
self:getPosition():sendMagicEffect(effect or CONST_ME_MAGIC_RED)
totalConjures = 1
end
if rightItem and rightItem:getId() == reagentId then
local infiniteMana = self:getGroup():hasFlag(PlayerFlag_HasInfiniteMana)
local notEnoughMana = self:getMana() < conjureMana * 2 and not infiniteMana
if totalConjures == 1 and notEnoughMana then
-- not enough mana on second hand
return true
elseif totalConjures == 1 then
-- take mana for second hand
self:addMana(-conjureMana)
self:addManaSpent(conjureMana)
end
rightItem:remove()
local item = self:addItem(conjureId, 1, true, conjureCount, CONST_SLOT_RIGHT)
if not item then
self:sendCancelMessage(RETURNVALUE_NOTPOSSIBLE)
self:getPosition():sendMagicEffect(CONST_ME_POFF)
return false
end
if item:hasAttribute(ITEM_ATTRIBUTE_DURATION) then
item:decay()
end
self:getPosition():sendMagicEffect(effect or CONST_ME_MAGIC_RED)
totalConjures = totalConjures + 1
end
if totalConjures == 0 then
self:sendCancelMessage(RETURNVALUE_YOUNEEDAMAGICITEMTOCASTSPELL)
self:getPosition():sendMagicEffect(CONST_ME_POFF)
return false
end
else
local item = self:addItem(conjureId, conjureCount)
if not item then
self:sendCancelMessage(RETURNVALUE_NOTPOSSIBLE)
self:getPosition():sendMagicEffect(CONST_ME_POFF)
return false
end
if item:hasAttribute(ITEM_ATTRIBUTE_DURATION) then
item:decay()
end
self:getPosition():sendMagicEffect(effect or CONST_ME_MAGIC_RED)
end
end
return true
end