• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!
  • 2026 staff recruitment is open! Check it out and consider applying!

Solved Mana Rune Problem

X X X

Newb
Joined
Jul 26, 2015
Messages
153
Reaction score
13
Okay, so I can't get my mana rune to work. I'm using TFS 0.2.15, and I've been looking at a lot of threads to try to solve my problem. I have two separate scripts that I can get to work without error, when I mess with either, the rune doesn't work. I basically want it like a UH rune but for mana.

With this one, my mana gets healed, but I don't have the sparkle effect on my character.
Code:
local combat = createCombatObject()
setCombatParam(combat, COMBAT_PARAM_EFFECT, CONST_ME_MAGIC_BLUE)
setCombatParam(combat, COMBAT_PARAM_TARGETCASTERORTOPMOST, 1)
setCombatParam(combat, COMBAT_PARAM_AGGRESSIVE, 0)


function onCastSpell(cid, item, fromPosition, toPosition)
    local level = getPlayerLevel(cid)
    local mlevel = getPlayerMagLevel(cid)
    local mana_minimum = (level * 1) + (mlevel * 4) * 2.08
    local mana_maximum = (level * 1) + (mlevel * 4) * 2.7
    local mana_add = math.random(mana_minimum, mana_maximum)
  
    doPlayerAddMana(cid, mana_add)
    return TRUE
end

With this one, I get a sparkle effect but no mana.
Code:
local combat = createCombatObject()
setCombatParam(combat, COMBAT_PARAM_TYPE, COMBAT_MANADRAIN)
setCombatParam(combat, COMBAT_PARAM_EFFECT, CONST_ME_MAGIC_BLUE)
setCombatParam(combat, COMBAT_PARAM_AGGRESSIVE, false)
setCombatParam(combat, COMBAT_PARAM_TARGETCASTERORTOPMOST, true)
setCombatParam(combat, COMBAT_PARAM_DISPEL, CONDITION_PARALYZE)

function onGetFormulaValues(cid)
    local level = getPlayerLevel(cid)
    local mlevel = getPlayerMagLevel(cid)
    local mana_minimum = (level * 1) + (mlevel * 4) * 2.08
    local mana_maximum = (level * 1) + (mlevel * 4) * 2.7
    local mana_add = math.random(mana_minimum, mana_maximum)
end

setCombatCallback(combat, CALLBACK_PARAM_LEVELMAGICVALUE, "onGetFormulaValues")

function onCastSpell(cid, var)
     return doCombat(cid, combat, var)
end

Anyone have a solution? Thanks :D
 
In second script.

Under
Code:
local mana_add = math.random(mana_minimum, mana_maximum)

add this line
Code:
doPlayerAddMana(cid, mana_add)
 
No need to use onGetFormulaValues or create a combat if you are going to do it this way. You can simply remove everything but onCastSpell and put doPlayerAddMana(cid, amount) in there. Change it to aggresive="0" in the xml to allow it in pz. This should also remove the black box as well. (You get a black box because attacking yourself)
 
No need to use onGetFormulaValues or create a combat if you are going to do it this way. You can simply remove everything but onCastSpell and put doPlayerAddMana(cid, amount) in there. Change it to aggresive="0" in the xml to allow it in pz. This should also remove the black box as well. (You get a black box because attacking yourself)
So I did the xml part, and now I can use it in pz, but I still get the black box.
Also, I don't exactly understand the script part. I see what you're trying to say, but idk how to delete the FormulaValues part and still have the same healing formula.
Code:
local combat = createCombatObject()
setCombatParam(combat, COMBAT_PARAM_TYPE, COMBAT_MANADRAIN)
setCombatParam(combat, COMBAT_PARAM_EFFECT, CONST_ME_MAGIC_RED)
setCombatParam(combat, COMBAT_PARAM_AGGRESSIVE, false)
setCombatParam(combat, COMBAT_PARAM_TARGETCASTERORTOPMOST, true)
setCombatParam(combat, COMBAT_PARAM_DISPEL, CONDITION_PARALYZE)

function onGetFormulaValues(cid)
    local level = getPlayerLevel(cid)
    local mlevel = getPlayerMagLevel(cid)
    local mana_minimum = (level * 1) + (mlevel * 4) * 2.08
    local mana_maximum = (level * 1) + (mlevel * 4) * 2.7
    local mana_add = math.random(mana_minimum, mana_maximum)
    doPlayerAddMana(cid, mana_add)
end

setCombatCallback(combat, CALLBACK_PARAM_LEVELMAGICVALUE, "onGetFormulaValues")

function onCastSpell(cid, var)
     return doCombat(cid, combat, var)
end
What exactly should I do?
Thanks a lot btw :P
 
Test It Too

In Action.xml
Code:
<action itemid="2300" script="manarune.lua" />


Action/Scripts/ And Create New Lua Name manarune.lua
Code:
local MIN = 1500
local MAX = 2400
local EMPTY_POTION = 2300 //<< Id OF THe Rune
local exhaust = createConditionObject(CONDITION_EXHAUST)
setConditionParam(exhaust, CONDITION_PARAM_TICKS, (getConfigInfo('timeBetweenExActions') - 200))
function onUse(cid, item, fromPosition, itemEx, toPosition)
if isPlayer(itemEx.uid) == FALSE then
return FALSE
end
if hasCondition(cid, CONDITION_EXHAUST_HEAL) == true then
doPlayerSendDefaultCancel(cid, RETURNVALUE_YOUAREEXHAUSTED)
return TRUE
end
if doPlayerAddMana(itemEx.uid, math.random(MIN, MAX)) == LUA_ERROR then
return FALSE
end
doAddCondition(cid, exhaust)
doSendMagicEffect(getThingPos(itemEx.uid), CONST_ME_MAGIC_BLUE)
doSendAnimatedText(getThingPos(cid), "MR Ahhh!", TEXTCOLOR_RED)
doTransformItem(item.uid, EMPTY_POTION)
return TRUE
end
 
Last edited by a moderator:
Test It Too

In Action.xml
Code:
<action itemid="2300" script="manarune.lua" />


Action/Scripts/ And Create New Lua Name manarune.lua
Code:
local MIN = 1500
local MAX = 2400
local EMPTY_POTION = 2300 //<< Id OF THe Rune
local exhaust = createConditionObject(CONDITION_EXHAUST)
setConditionParam(exhaust, CONDITION_PARAM_TICKS, (getConfigInfo('timeBetweenExActions') - 200))
function onUse(cid, item, fromPosition, itemEx, toPosition)
if isPlayer(itemEx.uid) == FALSE then
return FALSE
end
if hasCondition(cid, CONDITION_EXHAUST_HEAL) == true then
doPlayerSendDefaultCancel(cid, RETURNVALUE_YOUAREEXHAUSTED)
return TRUE
end
if doPlayerAddMana(itemEx.uid, math.random(MIN, MAX)) == LUA_ERROR then
return FALSE
end
doAddCondition(cid, exhaust)
doSendMagicEffect(getThingPos(itemEx.uid), CONST_ME_MAGIC_BLUE)
doSendAnimatedText(getThingPos(cid), "MR Ahhh!", TEXTCOLOR_RED)
doTransformItem(item.uid, EMPTY_POTION)
return TRUE
end
That looks like the code of a mana potion...
Also the min/max there is 1500-2400, I want it to be based on level/magic level as I had it
 
Ok this is getting confusing. Basically what I need it to by like UH but for mana.

This, but giving mana instead of health.
Code:
local combat = createCombatObject()
setCombatParam(combat, COMBAT_PARAM_TYPE, COMBAT_HEALING)
setCombatParam(combat, COMBAT_PARAM_EFFECT, CONST_ME_MAGIC_BLUE)
setCombatParam(combat, COMBAT_PARAM_AGGRESSIVE, FALSE)
setCombatParam(combat, COMBAT_PARAM_TARGETCASTERORTOPMOST, TRUE)
setCombatParam(combat, COMBAT_PARAM_DISPEL, CONDITION_PARALYZE)

function onGetFormulaValues(cid, level, maglevel)
    min = (level * 1 + maglevel * 4) * 2.08
    max = (level * 1 + maglevel * 4) * 2.7
    if min < 250 then
        min = 250
    end
    return min, max
end

setCombatCallback(combat, CALLBACK_PARAM_LEVELMAGICVALUE, "onGetFormulaValues")

function onCastSpell(cid, var)
    return doCombat(cid, combat, var)
end
 
Your original script was fine, you just needed to add the magic effect.

Code:
--[[ REMOVE ALL OF THIS
local combat = createCombatObject()
setCombatParam(combat, COMBAT_PARAM_EFFECT, CONST_ME_MAGIC_BLUE)
setCombatParam(combat, COMBAT_PARAM_TARGETCASTERORTOPMOST, 1)
setCombatParam(combat, COMBAT_PARAM_AGGRESSIVE, 0)
]]--

function onCastSpell(cid, item, fromPosition, toPosition)
    local level = getPlayerLevel(cid)
    local mlevel = getPlayerMagLevel(cid)
    local mana_minimum = (level * 1) + (mlevel * 4) * 2.08
    local mana_maximum = (level * 1) + (mlevel * 4) * 2.7
    -- local mana_add = math.random(mana_minimum, mana_maximum) no need for this either

    doPlayerAddMana(cid, math.random(mana_minimum, mana_maximum)) -- we can put it here
    doSendMagicEffect(getCreaturePosition(cid), CONST_ME_MAGIC_BLUE) -- add this for sparkles
    return true -- no need for uppercase true
end
 
Your original script was fine, you just needed to add the magic effect.

Code:
--[[ REMOVE ALL OF THIS
local combat = createCombatObject()
setCombatParam(combat, COMBAT_PARAM_EFFECT, CONST_ME_MAGIC_BLUE)
setCombatParam(combat, COMBAT_PARAM_TARGETCASTERORTOPMOST, 1)
setCombatParam(combat, COMBAT_PARAM_AGGRESSIVE, 0)
]]--

function onCastSpell(cid, item, fromPosition, toPosition)
    local level = getPlayerLevel(cid)
    local mlevel = getPlayerMagLevel(cid)
    local mana_minimum = (level * 1) + (mlevel * 4) * 2.08
    local mana_maximum = (level * 1) + (mlevel * 4) * 2.7
    -- local mana_add = math.random(mana_minimum, mana_maximum) no need for this either

    doPlayerAddMana(cid, math.random(mana_minimum, mana_maximum)) -- we can put it here
    doSendMagicEffect(getCreaturePosition(cid), CONST_ME_MAGIC_BLUE) -- add this for sparkles
    return true -- no need for uppercase true
end
Hey thanks man!
 
Back
Top