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

TFS 0.X Is it possible to change things on receive damage in LUA?

runsicky

Member
Joined
Apr 19, 2018
Messages
80
Reaction score
12
It is possible to change attack formula in weapons, like i did on this example:

Code:
local combat = createCombatObject()
setCombatParam(combat, COMBAT_PARAM_BLOCKARMOR, 1)
setCombatParam(combat, COMBAT_PARAM_TYPE, COMBAT_PHYSICALDAMAGE)

function onGetFormulaValues(cid, level, skill, attack, factor)
    -- get attack mode
    local damagebase_min = wbdmg_melee_min
    local damagebase_max = wbdmg_melee_min
    min = ((damagebase_min) * (attack * 12) * (skill * 3)) * -0.10
    max = ((damagebase_max) * (attack * 12) * (skill * 3)) * -1.00
    return min, max
end
setCombatCallback(combat, CALLBACK_PARAM_SKILLVALUE, "onGetFormulaValues")

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

But what about defense?
Is it possible to change things on receive damage in LUA?


I mean, something like:
reduce death/fire/ice/energy/holy damage depending if player got a storage X
also reflect some dmg % if player got a storage Y
dont recive any dmg if player got a storage Z
paralyze who attacks the player if player got the storage C
 
Where the value is changed, you need to set the storage value & send the new damage from value again, since he didn't add that when he looped through the combat types.
 
i didn't understand, i'm sorry, what are u mean?
Lua:
                setPlayerStorageValue(cid, stackOverflow, 1)
                doTargetCombatHealth(cid, attacker, combat, -value, -value, CONST_ME_NONE)
You need to do this same thing when it checks for combats, and where it sets value to / 2.
 
Lua:
                setPlayerStorageValue(cid, stackOverflow, 1)
                doTargetCombatHealth(cid, attacker, combat, -value, -value, CONST_ME_NONE)
You need to do this same thing when it checks for combats, and where it sets value to / 2.

like this?
Code:
local combatTypes = {
    [1] = {storage = 1000, type = COMBAT_FIREDAMAGE, text = "Fire Protect"},
    [2] = {storage = 1001, type = COMBAT_DEATHDAMAGE, text = "Death Protect"},
    [3] = {storage = 1002, type = COMBAT_ICEDAMAGE, text = "Ice Protect"},
    [4] = {storage = 1003, type = COMBAT_ENERGYDAMAGE, text = "Energy Protect"},
    [5] = {storage = 1004, type = COMBAT_HOLYDAMAGE, text = "Holy Protect"},
    [6] = {storage = 1005, type = COMBAT_EARTHDAMAGE, text = "Earth Protect"}

}

local stackOverflow = 65111

function onStatsChange(cid, attacker, type, combat, value)
    if isPlayer(cid) then
   
        if getPlayerStorageValue(cid, stackOverflow) == 1 then
            setPlayerStorageValue(cid, stackOverflow, -1)
            return true
        end
   
        -- Handle all of the protections at once in a loop for efficientcy. --
        for i = 1, #combatTypes do
            if combat == combatTypes[i].type then
                if getPlayerStorageValue(cid, combatTypes[i].storage) > 0 then
                    doSendAnimatedText(getThingPos(cid), combatTypes[i].text, TEXTCOLOR_WHITE)
                    value = value / 2
                    setPlayerStorageValue(cid, stackOverflow, 1)
                    doTargetCombatHealth(cid, attacker, combat, -value, -value, CONST_ME_NONE)
                    break
                end
            end
        end
       
    if attacker ~= nil then
        if getPlayerStorageValue(cid, 1006) > 0 then
            if math.random(1, 10) == 1 then -- If you don't add a random it will reflect everytime.
                doSendAnimatedText(getThingPos(cid), "REFLECT!", TEXTCOLOR_WHITE)
                -- Changed this so the reflected damage will be the same damage as recieved and also will count as the player hitting him and not the server hitting him. --
                setPlayerStorageValue(cid, stackOverflow, 1)
                doTargetCombatHealth(cid, attacker, combat, -value, -value, CONST_ME_NONE)
                return false
            else -- You have to base dodge off of reflect's math.random so they both don't happen.
            if getPlayerStorageValue(cid, 1007) > 0 then
                if math.random(1, 10) == 1 then
                    doSendAnimatedText(getThingPos(cid), "DODGE!", TEXTCOLOR_WHITE)
                    value = 0
                    setPlayerStorageValue(cid, stackOverflow, 1)
                    doTargetCombatHealth(cid, attacker, combat, -value, -value, CONST_ME_NONE)
                else -- You have to base paralize off of dodge do they both don't happen. --
                if getPlayerStorageValue(cid, 1008) > 0 then
                    doSendAnimatedText(getThingPos(cid), "PARALYZE!", TEXTCOLOR_WHITE)
                    if not getCreatureCondition(attacker, CONDITION_PARALYZE) then
                        local condition = createConditionObject(CONDITION_PARALYZE)
                        setConditionParam(condition, CONDITION_PARAM_TICKS, 1000)
                        setConditionFormula(condition, -0.5, 0, -0.5, 0)
                        doAddCondition(attacker, condition)
                    end
                end
                end
            end
            end
        end
    end
    end
return true
end
 
like this?
Code:
local combatTypes = {
    [1] = {storage = 1000, type = COMBAT_FIREDAMAGE, text = "Fire Protect"},
    [2] = {storage = 1001, type = COMBAT_DEATHDAMAGE, text = "Death Protect"},
    [3] = {storage = 1002, type = COMBAT_ICEDAMAGE, text = "Ice Protect"},
    [4] = {storage = 1003, type = COMBAT_ENERGYDAMAGE, text = "Energy Protect"},
    [5] = {storage = 1004, type = COMBAT_HOLYDAMAGE, text = "Holy Protect"},
    [6] = {storage = 1005, type = COMBAT_EARTHDAMAGE, text = "Earth Protect"}

}

local stackOverflow = 65111

function onStatsChange(cid, attacker, type, combat, value)
    if isPlayer(cid) then
  
        if getPlayerStorageValue(cid, stackOverflow) == 1 then
            setPlayerStorageValue(cid, stackOverflow, -1)
            return true
        end
  
        -- Handle all of the protections at once in a loop for efficientcy. --
        for i = 1, #combatTypes do
            if combat == combatTypes[i].type then
                if getPlayerStorageValue(cid, combatTypes[i].storage) > 0 then
                    doSendAnimatedText(getThingPos(cid), combatTypes[i].text, TEXTCOLOR_WHITE)
                    value = value / 2
                    setPlayerStorageValue(cid, stackOverflow, 1)
                    doTargetCombatHealth(cid, attacker, combat, -value, -value, CONST_ME_NONE)
                    break
                end
            end
        end
      
    if attacker ~= nil then
        if getPlayerStorageValue(cid, 1006) > 0 then
            if math.random(1, 10) == 1 then -- If you don't add a random it will reflect everytime.
                doSendAnimatedText(getThingPos(cid), "REFLECT!", TEXTCOLOR_WHITE)
                -- Changed this so the reflected damage will be the same damage as recieved and also will count as the player hitting him and not the server hitting him. --
                setPlayerStorageValue(cid, stackOverflow, 1)
                doTargetCombatHealth(cid, attacker, combat, -value, -value, CONST_ME_NONE)
                return false
            else -- You have to base dodge off of reflect's math.random so they both don't happen.
            if getPlayerStorageValue(cid, 1007) > 0 then
                if math.random(1, 10) == 1 then
                    doSendAnimatedText(getThingPos(cid), "DODGE!", TEXTCOLOR_WHITE)
                    value = 0
                    setPlayerStorageValue(cid, stackOverflow, 1)
                    doTargetCombatHealth(cid, attacker, combat, -value, -value, CONST_ME_NONE)
                else -- You have to base paralize off of dodge do they both don't happen. --
                if getPlayerStorageValue(cid, 1008) > 0 then
                    doSendAnimatedText(getThingPos(cid), "PARALYZE!", TEXTCOLOR_WHITE)
                    if not getCreatureCondition(attacker, CONDITION_PARALYZE) then
                        local condition = createConditionObject(CONDITION_PARALYZE)
                        setConditionParam(condition, CONDITION_PARAM_TICKS, 1000)
                        setConditionFormula(condition, -0.5, 0, -0.5, 0)
                        doAddCondition(attacker, condition)
                    end
                end
                end
            end
            end
        end
    end
    end
return true
end

using this, 2 insane things are happen...

1- earth protection is only call after 1 hit
for example, if i do 1 dmg, it dont call earth protection
but next one calls

2- when call the earth prootection
if i damage 8 and player target says earth protection
i recive -2 damage in my character


i dmg 7
i rcv 1
 
Yeah but I don't know why it's acting weird. But I don't support 0.X anymore, so I'm not writing any code or testing anything, someone else can do that for you, or you could just learn and try things yourself.
 
Yeah but I don't know why it's acting weird. But I don't support 0.X anymore, so I'm not writing any code or testing anything, someone else can do that for you, or you could just learn and try things yourself.

Hmmm okey, anyways thank you for your try then...

Do u have a tip for what search, what to do to do it on my own?
I will not use your script like it is now, just want a base to change recive damage on LUA (if it is possible ofc)
 
Back
Top