• 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!

Lua Getting the primaryType from onManaChange

Glecko

Veteran OT User
Joined
Aug 21, 2007
Messages
1,054
Reaction score
270
Location
Spain
So I'm trying to migrate a onStatsChange creaturescript that I was using in TFS 0.4 to TFS 1.1.

Basically what the script did was that, under some circumstances, a player get increased damage (let's say, 20% increased damage from all sources). In TFS 0.4 I did that registering an onStatsEvent that, if the circumstances were met, executed the following:

doTargetCombatHealth(attacker, cid, combat, -value*0.2, -value*0.2, CONST_ME_NONE, false)

And returned TRUE at the end, so the player would get 2 damage rounds (the original one and another one with only 20% damage, 120% in total).

My problem in TFS 1.1: While the above can be done with the onHealthChange function that comes with the same parameters, no problem with that, I have the problem when the player is using a manashield. As far as I have read, the function function onManaChange(cid, attacker, manaChange) does not provide the type of damage that was done to the player (basically the primaryType parameter from onHealthChange).

I need to know what type of damage was done to the player (physical, fire, earth...) in the onManaChange. Both because it's related to the circumstances that call the damage amplification, and because it only makes sense for the second round of damage the player gets to have the same type as the original one.

I hope I have explained myself properly :) If anybody could help me out with this I would be very thankful :D
 
As far as I can tell, there's no way to do it without source edits, since the event doesn't pass any information about the combat except the origin, which is not helpful. If you're cool with doing a source edit, I can try to write up the code for you.
 
Well, my idea was not to do any source edits since I was switching to 1.1 exactly for stability. I guess I'll have to work my way around with this. :P

Thanks anyway! :)
 
a "solution" would be using a custom manashield, (for example with blue square around player) so everything calls onhealthchange, then you just return false and do mana "damage" if they have manashield on
not the best solution but doesnt require source edits
 
Code:
local combat = Combat()
combat:setParameter(COMBAT_PARAM_EFFECT, CONST_ME_MAGIC_BLUE)
combat:setParameter(COMBAT_PARAM_AGGRESSIVE, false)

local condition = Condition(CONDITION_ATTRIBUTES)
condition:setParameter(CONDITION_PARAM_TICKS, 200000)
condition:setParameter(CONDITION_PARAM_SUBID, 2000)
condition:setParameter(CONDITION_PARAM_BUFF_SPELL, 1)
combat:setCondition(condition)

function onCastSpell(creature, variant)
    return combat:execute(creature, variant)
end

Code:
function onHealthChange(creature, attacker, primaryDamage, primaryType, secondaryDamage, secondaryType, origin)
    if creature:isPlayer() then
        if primaryType == COMBAT_HEALING then
            return primaryDamage, primaryType, secondaryDamage, secondaryType
        end
        if creature:getCondition(CONDITION_ATTRIBUTES, CONDITIONID_COMBAT, 2000) then
            if primaryDamage > 0 then
                doTargetCombatMana(attacker:getId(), creature:getId(), -primaryDamage, CONST_ME_LOSEENERGY, origin)
            end
            if secondaryDamage > 0 then
                doTargetCombatMana(attacker:getId(), creature:getId(), -secondaryDamage, CONST_ME_LOSEENERGY, origin)
            end
            primaryDamage = 0
            secondaryDamage = 0
        end
    end
    return primaryDamage, primaryType, secondaryDamage, secondaryType
end

something like this should work, in regards to above suggestion. Would just have to tweak it to modify damage as you see fit before doing the checks for primary and secondary being > 0

edit: changed creature:addMana to doTargetCombatMana
 
Last edited:
:)
all i have to say is creature:addMana -> doTargetCombatMana so it actually shows up as dmg for the people involved in the combat, looks good though
 
:)
all i have to say is creature:addMana -> doTargetCombatMana so it actually shows up as dmg for the people involved in the combat, looks good though
creature:addMana(manaChange[, animationOnLoss = false])

Edit: oh I see what you mean now, edited code
 
Last edited:
Code:
local combat = Combat()
combat:setParameter(COMBAT_PARAM_EFFECT, CONST_ME_MAGIC_BLUE)
combat:setParameter(COMBAT_PARAM_AGGRESSIVE, false)

local condition = Condition(CONDITION_ATTRIBUTES)
condition:setParameter(CONDITION_PARAM_TICKS, 200000)
condition:setParameter(CONDITION_PARAM_SUBID, 2000)
condition:setParameter(CONDITION_PARAM_BUFF_SPELL, 1)
combat:setCondition(condition)

function onCastSpell(creature, variant)
    return combat:execute(creature, variant)
end

Code:
function onHealthChange(creature, attacker, primaryDamage, primaryType, secondaryDamage, secondaryType, origin)
    if creature:isPlayer() then
        if primaryType == COMBAT_HEALING then
            return primaryDamage, primaryType, secondaryDamage, secondaryType
        end
        if creature:getCondition(CONDITION_ATTRIBUTES, CONDITIONID_COMBAT, 2000) then
            if primaryDamage > 0 then
                doTargetCombatMana(attacker:getId(), creature:getId(), -primaryDamage, CONST_ME_LOSEENERGY, origin)
            end
            if secondaryDamage > 0 then
                doTargetCombatMana(attacker:getId(), creature:getId(), -secondaryDamage, CONST_ME_LOSEENERGY, origin)
            end
            primaryDamage = 0
            secondaryDamage = 0
        end
    end
    return primaryDamage, primaryType, secondaryDamage, secondaryType
end

something like this should work, in regards to above suggestion. Would just have to tweak it to modify damage as you see fit before doing the checks for primary and secondary being > 0

edit: changed creature:addMana to doTargetCombatMana

That's actually pretty awesome! The only problem I see with this, as far as I can tell, it converts all damage done to a player while using mana shield to manadrain right? So using mana shield while wearing bronze amulet and depth ocrea would grant the player a damage reduction of 32% against any type of damage.
 
That's actually pretty awesome! The only problem I see with this, as far as I can tell, it converts all damage done to a player while using mana shield to manadrain right? So using mana shield while wearing bronze amulet and depth ocrea would grant the player a damage reduction of 32% against any type of damage.
that, I'm not sure about. I don't typically test my code since I don't typically have a server running xD
In the source, when magic shield intervenes, it executes a manaChange through creaturescript, so combating mana instead could definitely convert to manadrain but I don't know for sure. honestly, the easiest way to do all this would be to just recode onManaChange in the source to pass combat information xD
 
Back
Top