• 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 How to change mana shield spell?

whitevo

Feeling good, thats what I do.
Joined
Jan 2, 2015
Messages
3,454
Solutions
1
Reaction score
627
Location
Estonia
This code is default TFS 1.0 mana shield spell in game.cpp

What i want to do with mana shield spell is:
1. All damage taken is reduced by 50% while mana shield active
2. Condition no longer has duration
3. When player looses 100mana while manashield is active, condition will wear off
(i don't mind if doing other spells will also reduce the manashield effect)
(i don't mind if mana shield condition is on, but only would block 10damange and player takes 1000dmg and it halfed by 2)
4. when player takes 210damage total (after the 50% damage reduction) i want it to take mana shield off (100mana) and rest from hp (110hp)

I have slight idea how to change player protection values trough lua script. So only the wear-off should be somehow inserted to source code.

But what would be really the best is: If i could somehow entirely manipulate the mana shield condition inside the .lua code
Attribute1: how much mana can manashield block before condition wears off
Attribute2: how much damage reduction manashield will give

I know this is some next level coding and very hard to do (at least i have no idea where to even start), but perhaps someone has already done something like this and has no problem helping me out with this kind of code.

here is the working script i made with Codinablack and Evan help

barrier.lua
Code:
local barrierStorage = 10500


function onHealthChange(creature, attacker, primaryDamage, primaryType, secondaryDamage, secondaryType, origin)
local dam1 = primaryDamage/2
local dam2 = secondaryDamage/2
local manaLoss = math.floor(dam1+dam2)
local barrier = creature:getStorageValue(barrierStorage)

if barrier >= 1 then


if manaLoss <= barrier then
doCreatureSay(creature, manaLoss.. " damage absorbed", TALKTYPE_MONSTER_SAY)
creature:setStorageValue(barrierStorage, barrier-manaLoss)
creature:sendTextMessage(TALKTYPE_MONSTER_SAY, "barrier can absorb "..barrier-manaLoss.." damage more")
return primaryDamage*0, primaryType, secondaryDamage*0, secondaryType
else
if dam1 > barrier then
primaryDamage = primaryDamage - barrier*2
blocked1 = barrier
else
primaryDamage = barrier - dam1
blocked1 = dam1
end

if dam2 > barrier then
secondaryDamage = secondaryDamage - barrier*2
blocked2 = barrier
else
secondaryDamage = barrier - dam2
blocked2 = dam2
end

doCreatureSay(creature, blocked1+blocked2.. " damage absorbed", TALKTYPE_MONSTER_SAY)
creature:setStorageValue(barrierStorage, 0)
creature:sendTextMessage(TALKTYPE_MONSTER_SAY, "BARRIER IS BROKEN")
return primaryDamage, primaryType, secondaryDamage, secondaryType
end
end
return primaryDamage, primaryType, secondaryDamage, secondaryType
end
barrier.lua (in spells now)
Code:
local barrierStorage = 10500
local amount = 110
Combat():setParameter(COMBAT_PARAM_AGGRESSIVE, 0)

function onCastSpell(creature, var)
creature:setStorageValue(barrierStorage, amount)
Combat():execute(creature, var)
creature:sendTextMessage(MESSAGE_STATUS_DEFAULT, "Mana shield Activated")
creature:sendTextMessage(TALKTYPE_MONSTER_SAY, "barrier can absorb "..amount.." damage")
return true
end
 
Last edited:
1. All damage taken is reduced by 50% while mana shield active -- Can be done with onstatschange, reduce the damage by 50% if you have manashield condition
2. Condition no longer has duration - You can do this by making the tick infinite
3. When player looses 100mana while manashield is active, condition will wear off - Can also be done by onstatschange by disabling the manashield if player lost % of mana
4. when player takes 210damage total (after the 50% damage reduction) i want it to take mana shield off (100mana) and rest from hp (110hp) - Can also be done by dividing the incoming damage on 2 and making player loose 25% health and 25% mana.
 
onstatschange is some kind of source code method or in lua scripts?

Can you bring code example?

i tried to look onstatschange word from github and sourcecode. Didn't find any functions or methods
 
1. All damage taken is reduced by 50% while mana shield active -- Can be done with onstatschange, reduce the damage by 50% if you have manashield condition
2. Condition no longer has duration - You can do this by making the tick infinite
3. When player looses 100mana while manashield is active, condition will wear off - Can also be done by onstatschange by disabling the manashield if player lost % of mana
4. when player takes 210damage total (after the 50% damage reduction) i want it to take mana shield off (100mana) and rest from hp (110hp) - Can also be done by dividing the incoming damage on 2 and making player loose 25% health and 25% mana.
onstatschange is some kind of source code method or in lua scripts?

Can you bring code example?

i tried to look onstatschange word from github and sourcecode. Didn't find any functions or methods

onstatschange is not an event in 1.x

onHealthChange would be the correct event to use...
 
onHealthChange is sourcecode method? not?

How i could use that in .lua script?

Once again, can you bring code example.. i need some visual understanding.
 

this is some nice stuff, but a bit too much information at once.

Would this work? Or im missing the point you are trying to explain me.
green text = my though process or questions or whatever

function onHealthChange(creature, attacker, primaryDamage, primaryType, secondaryDamage, secondaryType, origin)
if getCondition == MANA_SHIELD then
Don't know does something getCondition exist, but i would find something what tried to get the player conditions what he has on.
Don't know does condition MANA_Shield exist, but if i look into it i will find the correct condition. For now just trying to bring out the construction of function

Now when monster who is about to hit me, finds that i have manashield on. it will look into this and do this?:
i add here formula how much primaryDamage and secondaryDamage is changed.
Then instead of changehealth i add changemana? (change mana will also go trough some formula, if damage is higher then it will take the mana and remaining health)
also if damage exeeds the mana limit i set, it will remove the manashield condition from player.
and then i return true?
hopefully it doesn't do the original changehealth function what is written in sourcecode
 
this is some nice stuff, but a bit too much information at once.

Would this work? Or im missing the point you are trying to explain me.
green text = my though process or questions or whatever

function onHealthChange(creature, attacker, primaryDamage, primaryType, secondaryDamage, secondaryType, origin)
if getCondition == MANA_SHIELD then
Don't know does something getCondition exist, but i would find something what tried to get the player conditions what he has on.
Don't know does condition MANA_Shield exist, but if i look into it i will find the correct condition. For now just trying to bring out the construction of function

Now when monster who is about to hit me, finds that i have manashield on. it will look into this and do this?:
i add here formula how much primaryDamage and secondaryDamage is changed.
Then instead of changehealth i add changemana? (change mana will also go trough some formula, if damage is higher then it will take the mana and remaining health)
also if damage exeeds the mana limit i set, it will remove the manashield condition from player.
and then i return true?
hopefully it doesn't do the original changehealth function what is written in sourcecode

You would need it to be

creature:getCondition(conditionType[, conditionId = CONDITIONID_COMBAT[, subId = 0]])
 
i noticed instead of condition you used storage value in your script. I would love to use that (instead of conditions), did you get your idea working?
 
what are the legit options i can use for creaturescripts?

<event type="onHealthChange" name="manaShield" script="manaShield.lua"/>
<event type="onManaChange" name="manaChange" script="manachange.lua"/>

these are invalid creature events

EDIT: Found
Code:
std::string tmpStr = asLowerCaseString(typeAttribute.as_string());
    if (tmpStr == "login") {
        m_type = CREATURE_EVENT_LOGIN;
    } else if (tmpStr == "logout") {
        m_type = CREATURE_EVENT_LOGOUT;
    } else if (tmpStr == "think") {
        m_type = CREATURE_EVENT_THINK;
    } else if (tmpStr == "preparedeath") {
        m_type = CREATURE_EVENT_PREPAREDEATH;
    } else if (tmpStr == "death") {
        m_type = CREATURE_EVENT_DEATH;
    } else if (tmpStr == "kill") {
        m_type = CREATURE_EVENT_KILL;
    } else if (tmpStr == "advance") {
        m_type = CREATURE_EVENT_ADVANCE;
    } else if (tmpStr == "modalwindow") {
        m_type = CREATURE_EVENT_MODALWINDOW;
    } else if (tmpStr == "textedit") {
        m_type = CREATURE_EVENT_TEXTEDIT;
    } else if (tmpStr == "healthchange") {
        m_type = CREATURE_EVENT_HEALTHCHANGE;
    } else if (tmpStr == "manachange") {
        m_type = CREATURE_EVENT_MANACHANGE;
    } else if (tmpStr == "extendedopcode") {
        m_type = CREATURE_EVENT_EXTENDED_OPCODE;
    } else {
        std::cout << "[Error - CreatureEvent::configureEvent] Invalid type for creature event: " << m_eventName << std::endl;
        return false;
    }

    m_isLoaded = true;
    return true;
 
Last edited:
Back
Top