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

Monster Training Dummy with DPS calculation

Doesn't seem to be the issue, I am using fresh tfs database and tried with different characters, Also cleared the storages at player_storage but still doesn't show damage record.
Is it showing current DPS?
 
Yeah it shows the current DPS but not any record.
 
Put print(player:getStorageValue(DPS_STORAGE)) before line 10 and check output in console.
 
Lua:
Moustafa has logged in.
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
 
Yeah now it works , Thank you.
 
Great script, thank you.

Just a doubt, because shouldn't a DPS calculator split the damage on lets say 30 seconds and during that past time calculate the damage per second?

because now it prints every 1 second and the last damage during that time, right?
 
Great script, thank you.

Just a doubt, because shouldn't a DPS calculator split the damage on lets say 30 seconds and during that past time calculate the damage per second?

because now it prints every 1 second and the last damage during that time, right?
As long as you deal damage in 1 second duration, it's included in your DPS (for whatever combo you just used) because you just dealt X damage in 1 second, no matter at which point of that second. If you want to calculate DPS for your weapon damage or spell damage, then it would be calculated differently ((minDamage + maxDamage) / 2 / speed, where speed is Attack Speed or Spells cooldown).
 
It works but it doesn't show new DPS record, I didn't edit it at all just copied everything to latest TFS, will never get new record for negative values it your issue like mine this should work proberly.
had the same issue the values was written in negative even he added player_dps * -1 but it should be added like this
Lua:
DPS_STORAGE = 26545
PLAYER_DPS = {}
PLAYER_EVENTS = {}

function ReadDPS(pid, cid)
    local player = Player(pid)
    local target = Monster(cid)
    if player and target then
        if PLAYER_DPS[pid] < 1 then
        PLAYER_DPS[pid] = PLAYER_DPS[pid] * -1
        end
        if PLAYER_DPS[pid] > player:getStorageValue(DPS_STORAGE) then
            player:setStorageValue(DPS_STORAGE, PLAYER_DPS[pid])
            target:say(string.format("New Record! DPS: %d", PLAYER_DPS[pid]), TALKTYPE_MONSTER_SAY, false, player, target:getPosition())
        else
            target:say(string.format("DPS: %d", PLAYER_DPS[pid]), TALKTYPE_MONSTER_SAY, false, player, target:getPosition())
        end
        PLAYER_DPS[pid] = 0
        PLAYER_EVENTS[pid] = nil
    end
end

function onHealthChange(creature, attacker, primaryDamage, primaryType, secondaryDamage, secondaryType, origin)
    if not creature then return primaryDamage, primaryType, secondaryDamage, secondaryType end
    if not attacker then return primaryDamage, primaryType, secondaryDamage, secondaryType end

    if creature:isMonster() and attacker:isPlayer() then
        if creature:getName() == "Training Monk" then
            local damage = primaryDamage + secondaryDamage
            local pid = attacker:getId()
            if not PLAYER_DPS[pid] then PLAYER_DPS[pid] = 0 end
            PLAYER_DPS[pid] = PLAYER_DPS[pid] + damage
            if not PLAYER_EVENTS[pid] then
                PLAYER_EVENTS[pid] = addEvent(ReadDPS, 1000, pid, creature:getId())
            end
        end
    end

    return primaryDamage, primaryType, secondaryDamage, secondaryType
end
thank you tho ^^ just changed line 9 added if PLAYER_DPS[pid] < 1 then PLAYER_DPS[pid] = PLAYER_DPS[pid] * -1 end
Remove this line PLAYER_DPS[pid] = PLAYER_DPS[pid] * -1
tried to do that worked till server restarted and values came negative again, i didn't understand the reason but with this if statement worked well.
 
Last edited by a moderator:
I don't get what
Lua:
if PLAYER_DPS[pid] < 1 then PLAYER_DPS[pid] = PLAYER_DPS[pid] * -1 end
would do here @Shadow_,
so if player_dps is 0, you multiple it with -1? and its value becomes 0? ...
or if the player_dps is -1, and you multiple it with -1 it will become +1 because double negatives becomes positive.

its all confusing, what is that line doing?
 
I don't get what
Lua:
if PLAYER_DPS[pid] < 1 then PLAYER_DPS[pid] = PLAYER_DPS[pid] * -1 end
would do here @Shadow_,
so if player_dps is 0, you multiple it with -1? and its value becomes 0? ...
or if the player_dps is -1, and you multiple it with -1 it will become +1 because double negatives becomes positive.

its all confusing, what is that line doing?
The thing is, TFS is using negative values when you deal damage, that's why I had dps * -1 so it won't be throwing DPS text with negative values. For me it was always working, maybe some TFS versions have a bug or someone made spells damage calculation not returning negative values which is causing damage to be positive values.
 
Last edited:
Hey, ive done this by 1:1 step and dps wont appear.
Any suggestions? (otservBR TFS 1.3)
Change PLAYER_DPS[pid] = PLAYER_DPS[pid] * -1 to
Lua:
if PLAYER_DPS[pid] < 1 then
    PLAYER_DPS[pid] = PLAYER_DPS[pid] * -1
end
 
where do I exactly set the step 7?

6. Find function Creature: onTargetCombat(target) (found already)
7. Add before return RETURNVALUE_NOERROR
 

Attachments

Back
Top