• 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 1.X+ Summing up the damage received

Michcol94

Member
Joined
Sep 2, 2021
Messages
105
Reaction score
18
How to load and sum the received damage such as drowndamage and distance to one variable and save in a database or other optimal solution that the sum does not disappear after restarting the server
use tfs 1.5 downgrade 8.6 by Nekiro
IS THERE A METHOD THAT READS THE INJURY RECEIVED?
 
Last edited:
When it comes to HP dmg you could use event:
Lua:
onHealthChange(creature, attacker, primaryDamage, primaryType, secondaryDamage, secondaryType, origin)

Maybe an option not to save it every single time into DB would be to store these dmgs in some map (player guid => dmg) and persist it into DB every x minutes and for script use (if needed) just use value from the global map like:

Lua:
local guid = player:getGuid()
local totalDmg = dmgMap[guid] or 0

Implementation details are up to you, such as:
  • dmg origin
  • dmg type
  • attacker type, level, whatever (condition dmgs might not have attacker if I remember correctly)

Just a POC
 
It doesn't work, I wrote something like this
Lua:
local dmgMap = {}

function loadDmgMap()
    local file = io.open("dmgMap.txt", "r")
    if file then
        for line in file:lines() do
            local guid, totalDmg = line:match("(%w+)%s+(%d+)")
            dmgMap[guid] = tonumber(totalDmg)
        end
        file:close()
    end
end

function saveDmgMap()
    local file = io.open("dmgMap.txt", "w")
    if file then
        for guid, totalDmg in pairs(dmgMap) do
            file:write(guid .. " " .. totalDmg .. "\n")
        end
        file:close()
    end
end

function onHealthChange(creature, attacker, primaryDamage, primaryType, secondaryDamage, secondaryType, origin)
    if attacker:isMonster() and creature:isPlayer() then
        local player = creature:getPlayer()
        local guid = player:getGuid()
        local totalDmg = dmgMap[guid] or 0
        
        -- Oblicz całkowite obrażenia zadane graczowi
        local damage = primaryDamage + secondaryDamage
        
        -- Dodaj obecne obrażenia do całkowitych obrażeń gracza
        totalDmg = totalDmg + damage
        
        -- Zapisz całkowite obrażenia w mapie dmgMap
        dmgMap[guid] = totalDmg
        
        -- Wyświetl informację o obrażeniach
        print("Gracz o GUID " .. guid .. " otrzymał " .. damage .. " obrażeń.")
        print("Całkowite obrażenia gracza to " .. totalDmg .. ".")
        
        -- Zapisz aktualną wersję dmgMap do pliku
        saveDmgMap()
    end
end

-- Wczytaj wcześniej zapisane dane z pliku przy uruchomieniu silnika
loadDmgMap()
 
Lua:
local cEvent = CreatureEvent("HpChange")
function cEvent.onHealthChange(creature, attacker, primaryDamage, primaryType, secondaryDamage, secondaryType, origin)
    local totalDamage = primaryDamage + secondaryDamage
    print(totalDamage)
    return primaryDamage, primaryType, secondaryDamage, secondaryType, origin
end

cEvent:register()

And register onLogin:
Lua:
local lEvent = CreatureEvent("HpLogin")

function lEvent.onLogin(player)
    player:registerEvent("HpChange")
    return true
end

lEvent:register()
 
Last edited:
Back
Top