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

Delusion

Divine Intellect
Support Team
Joined
Feb 14, 2015
Messages
5,046
Best answers
471
Reaction score
2,677
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.
 
OP
runsicky

runsicky

Member
Joined
Apr 19, 2018
Messages
68
Best answers
0
Reaction score
11
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?
 

Delusion

Divine Intellect
Support Team
Joined
Feb 14, 2015
Messages
5,046
Best answers
471
Reaction score
2,677
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.
 
OP
runsicky

runsicky

Member
Joined
Apr 19, 2018
Messages
68
Best answers
0
Reaction score
11
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
 
OP
runsicky

runsicky

Member
Joined
Apr 19, 2018
Messages
68
Best answers
0
Reaction score
11
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
 
OP
runsicky

runsicky

Member
Joined
Apr 19, 2018
Messages
68
Best answers
0
Reaction score
11
you think it is impossible to change damage in lua? or do i doing something wrong?
 

Delusion

Divine Intellect
Support Team
Joined
Feb 14, 2015
Messages
5,046
Best answers
471
Reaction score
2,677
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.
 

StreamSide

Joseluis Gonzalez
Support Team
Joined
Aug 31, 2007
Messages
3,317
Best answers
32
Reaction score
830
Location
Arica - Chile
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.
does someone gives support for 0.x servers?
 
OP
runsicky

runsicky

Member
Joined
Apr 19, 2018
Messages
68
Best answers
0
Reaction score
11
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)
 
Top