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

DPS script TFS 1.2

Fantasma24

New Member
Joined
Feb 15, 2018
Messages
43
Solutions
1
Reaction score
0
Hello so iam really bad at programming. Could anyone make a script that would calculate player's dps? Basically what would i want is to player attack a dummy or something w/e for like 10 seconds for example and that code could print out my dps(damage per second).
Thanks in advance.
 
Solution
Got it! Mods have to edit my post so before they do that, here it is. Original thread updated.
Make sure you change everything, even .xml for that dummy, removed few lines there.

  1. Open data/creaturescripts/creaturescripts.xml
  2. Add <event type="healthchange" name="EventDPS" script="dps.lua" />
  3. Open data/events/events.xml
  4. Enable onTargetCombat
  5. Open data/events/scripts/creature.lua
  6. Find function Creature:onTargetCombat(target)
  7. Add before return RETURNVALUE_NOERROR
    Lua:
    if target:getName() == "Training Dummy" then
        target:registerEvent("EventDPS")
    end
  8. Create file data/creaturescripts/scripts/dps.lua with this code
    Lua:
    DPS_STORAGE = 50392...
nvm the script works but its not good i think. i made a test basically i hit 500k like 2 times a sec but it says i only have 300k dps kinda weird. could u check that script again?
 
Last edited:
yeah i just counted basically i got 30 hits in 10 sec. which means 3 hits in 1 sec sooo if i hit on average lets say 400k cuz its depends sometimes i hit 350k sometimes 500k+ so lets say 400k soo i hit 3 times 400k in one sec it means my dps should be arounds 1.2m but the dps meter shows only 300k.
 
yeah i just counted basically i got 30 hits in 10 sec. which means 3 hits in 1 sec sooo if i hit on average lets say 400k cuz its depends sometimes i hit 350k sometimes 500k+ so lets say 400k soo i hit 3 times 400k in one sec it means my dps should be arounds 1.2m but the dps meter shows only 300k.
It does work, I can even record it for you.
 
well it works but as i said the calculations are inaccurate. cuz if i hit 3times x 400k in 1 sec it means my dps should be around 1.2m and it shows me 300k
 
well it works but as i said the calculations are inaccurate. cuz if i hit 3times x 400k in 1 sec it means my dps should be around 1.2m and it shows me 300k
Maybe you have different script that changes your DMG and it changes damage after my script.
 
Not sure if that changes order of events execution but do you have this line in creaturescripts.xml set <event type="healthchange" name="EventDPS" script="dps.lua" /> at the end (or after different healthchange events)?
 
Yea i have one which is ringdmg but it based on energydamage not physical and activates only when you wear it, so we can assume that eventdps is the last healthchange on creaturescript
 
Give this one a whirl.

Creaturescripts\scripts\dpsCheck.lua
Lua:
local dps = {}

local ms = 5000 -- time between dps checks


local function sayDPS(cid, guid)

    local player = Player(cid)

    if player then

        local dps = math.floor((dps[guid].damage / (ms / 1000)) + 0.5)

        player:say("DPS: ".. dps, TALKTYPE_MONSTER_SAY, false, player)

        player:sendTextMessage(MESSAGE_STATUS_CONSOLE_ORANGE, "Your damage per second is "..dps)

    end

    dps[guid] = {damage = 0, event = false}

end



function onHealthChange(creature, attacker, primaryDamage, primaryType, secondaryDamage, secondaryType, origin)

    if not attacker then

        return primaryDamage, primaryType, secondaryDamage, secondaryType

    end

    if creature:getName() ~= 'Training Monk' then

        return primaryDamage, primaryType, secondaryDamage, secondaryType

    end

    local player = attacker:getPlayer()

    if player then

        local guid = player:getGuid()

        local cid = player:getId()

        if not dps[guid] or not dps[guid].event then

            dps[guid] = {damage = 0, event = true}

            addEvent(sayDPS, ms, cid, guid)

        end

        dps[guid].damage = dps[guid].damage + (primaryDamage + secondaryDamage)

    end

    return primaryDamage, primaryType, secondaryDamage, secondaryType

end

heres my training monk too.
XML:
<?xml version="1.0" encoding="UTF-8"?>

<monster name="Training Monk" nameDescription="a training monk" race="blood" experience="0" speed="210" manacost="0">

    <health now="240000" max="240000" />

    <look type="57" head="20" body="30" legs="40" feet="50" corpse="3128" />

    <targetchange interval="60000" chance="0" />

    <strategy attack="100" defense="0" />

    <script>

        <event name="dpsCheck"/>

    </script>

    <flags>

        <flag summonable="0" />

        <flag attackable="1" />

        <flag hostile="1" />

        <flag illusionable="0" />

        <flag convinceable="0" />

          <flag pushable="0" />

          <flag canpushitems="1" />

          <flag staticattack="50" />

          <flag lightlevel="0" />

          <flag lightcolor="0" />

          <flag targetdistance="1" />

          <flag runonhealth="0" />

    </flags>

    <attacks>

        <attack name="melee" interval="2000" min="0" max="-1" />

    </attacks>

    <defenses armor="0" defense="0">

        <defense name="healing" interval="10000" chance="100" min="240000" max="240000" />

    </defenses>

    <immunities>

        <immunity physical="0" />

        <immunity energy="0" />

        <immunity fire="0" />

        <immunity poison="0" />

        <immunity lifedrain="0" />

        <immunity paralyze="0" />

        <immunity outfit="0" />

        <immunity drunk="0" />

        <immunity invisible="1" />

    </immunities>

    <elements>

    </elements>

    <voices interval="5000" chance="10">

        <voice sentence="You need protein shakes, boy!"/>

        <voice sentence="Do you even lift?"/>

        <voice sentence="Whens smokeo?!"/>

    </voices>

    <loot>

    </loot>

</monster>

Edit: Fix code tags. Been awhile..
 
yeah same problem just like with oen's script. something does not pick up. Probably the script doesnt pick up some of the other systems like dual wielding ,transforms? idk
 
Got it! Mods have to edit my post so before they do that, here it is. Original thread updated.
Make sure you change everything, even .xml for that dummy, removed few lines there.

  1. Open data/creaturescripts/creaturescripts.xml
  2. Add <event type="healthchange" name="EventDPS" script="dps.lua" />
  3. Open data/events/events.xml
  4. Enable onTargetCombat
  5. Open data/events/scripts/creature.lua
  6. Find function Creature:onTargetCombat(target)
  7. Add before return RETURNVALUE_NOERROR
    Lua:
    if target:getName() == "Training Dummy" then
        target:registerEvent("EventDPS")
    end
  8. Create file data/creaturescripts/scripts/dps.lua with this code
    Lua:
    DPS_STORAGE = 50392
    PLAYER_DPS = {}
    PLAYER_EVENTS = {}
    
    function ReadDPS(pid, cid)
        local player = Player(pid)
        local target = Monster(cid)
        if player and target then
            PLAYER_DPS[pid] = PLAYER_DPS[pid] * -1
            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 Dummy" 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
  9. Create new monster
    XML:
    <?xml version="1.0" encoding="UTF-8"?>
        <monster name="Training Dummy" nameDescription="a training dummy" race="undead" experience="0" speed="0">
        <health now="100000000" max="100000000" />
        <look typeex="5787" />
        <flags>
            <flag summonable="0" />
            <flag attackable="1" />
            <flag hostile="1" />
            <flag illusionable="0" />
            <flag convinceable="0" />
            <flag pushable="0" />
            <flag canpushitems="0" />
            <flag canpushcreatures="0" />
            <flag targetdistance="1" />
            <flag staticattack="100" />
            <flag runonhealth="0" />
            <flag canwalkonenergy="0" />
            <flag canwalkonfire="0" />
            <flag canwalkonpoison="0" />
        </flags>
        <attacks>
            <attack name="melee" interval="2000" min="0" max="-1" />
        </attacks>
        <defenses armor="0" defense="0">
            <defense name="healing" interval="5000" chance="100" min="100000000" max="100000000">
                <attribute key="areaEffect" value="blueshimmer" />
            </defense>
        </defenses>
        <immunities>
            <immunity invisible="1" />
        </immunities>
    </monster>
 
Last edited:
Solution
Got it! Mods have to edit my post so before they do that, here it is. Original thread updated.
Make sure you change everything, even .xml for that dummy, removed few lines there.

  1. Open data/creaturescripts/creaturescripts.xml
  2. Add <event type="healthchange" name="EventDPS" script="dps.lua" />
  3. Open data/events/events.xml
  4. Enable onTargetCombat
  5. Open data/events/scripts/creature.lua
  6. Find function Creature:onTargetCombat(target)
  7. Add before return RETURNVALUE_NOERROR
    Lua:
    if target:getName() == "Training Dummy" then
    target:registerEvent("EventDPS")
    end
  8. Create file data/creaturescripts/scripts/dps.lua with this code
    Lua:
    DPS_STORAGE = 50392
    PLAYER_DPS = {}
    PLAYER_EVENTS = {}
    
    function ReadDPS(pid, cid)
    local player = Player(pid)
    local target = Monster(cid)
    if player and target then
    PLAYER_DPS[pid] = PLAYER_DPS[pid] * -1
    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 Dummy" 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
  9. Create new monster
    XML:
    <?xml version="1.0" encoding="UTF-8"?>
    <monster name="Training Dummy" nameDescription="a training dummy" race="undead" experience="0" speed="0">
    <health now="100000000" max="100000000" />
    <look typeex="5787" />
    <flags>
    <flag summonable="0" />
    <flag attackable="1" />
    <flag hostile="1" />
    <flag illusionable="0" />
    <flag convinceable="0" />
    <flag pushable="0" />
    <flag canpushitems="0" />
    <flag canpushcreatures="0" />
    <flag targetdistance="1" />
    <flag staticattack="100" />
    <flag runonhealth="0" />
    <flag canwalkonenergy="0" />
    <flag canwalkonfire="0" />
    <flag canwalkonpoison="0" />
    </flags>
    <attacks>
    <attack name="melee" interval="2000" min="0" max="-1" />
    </attacks>
    <defenses armor="0" defense="0">
    <defense name="healing" interval="5000" chance="100" min="100000000" max="100000000">
    <attribute key="areaEffect" value="blueshimmer" />
    </defense>
    </defenses>
    <immunities>
    <immunity invisible="1" />
    </immunities>
    </monster>

Hello guys!

Im using TFS 1.3 and i get this error:
Lua:
Lua Script Error: [Event Interface]
data/events/scripts/creature.lua:Creature@onTargetCombat
data/events/scripts/creature.lua:10: attempt to index global 'creature' (a nil value)
stack traceback:
        [C]: in function '__index'
        data/events/scripts/creature.lua:10: in function <data/events/scripts/creature.lua:9>

This is my: data/events/scripts/creature.lua:10: in function <data/events/scripts/creature.lua:9>
Lua:
function Creature:onChangeOutfit(outfit)
    return true
end

function Creature:onAreaCombat(tile, isAggressive)
    return RETURNVALUE_NOERROR
end

function Creature:onTargetCombat(target)
    if creature:getStorageValue(STORAGEVALUE_WAR_GREENPLAYER_BOOL) == 1 then
    if target:getStorageValue(STORAGEVALUE_WAR_REDPLAYER_BOOL) == 1 then
    if target:getName() == "Training Dummy" then
    target:registerEvent("EventDPS")
        end
        return RETURNVALUE_NOERROR
        elseif target:getStorageValue(STORAGEVALUE_WAR_REDPLAYER_BOOL) == 0 then
            creature:sendCancelMessage("You cannot attack someone that is on your team.")
            return false
        end
    elseif creature:getStorageValue(STORAGEVALUE_WAR_REDPLAYER_BOOL) == 1 then
        if target:getStorageValue(STORAGEVALUE_WAR_GREENPLAYER_BOOL) == 1 then
            return RETURNVALUE_NOERROR
        elseif target:getStorageValue(STORAGEVALUE_WAR_GREENPLAYER_BOOL) == 0 then
            creature:sendCancelMessage("You cannot attack someone that is on your team.")
            return false
        end
    end
end
 
Hello guys!

Im using TFS 1.3 and i get this error:
Lua:
Lua Script Error: [Event Interface]
data/events/scripts/creature.lua:Creature@onTargetCombat
data/events/scripts/creature.lua:10: attempt to index global 'creature' (a nil value)
stack traceback:
        [C]: in function '__index'
        data/events/scripts/creature.lua:10: in function <data/events/scripts/creature.lua:9>

This is my: data/events/scripts/creature.lua:10: in function <data/events/scripts/creature.lua:9>
Lua:
function Creature:onChangeOutfit(outfit)
    return true
end

function Creature:onAreaCombat(tile, isAggressive)
    return RETURNVALUE_NOERROR
end

function Creature:onTargetCombat(target)
    if creature:getStorageValue(STORAGEVALUE_WAR_GREENPLAYER_BOOL) == 1 then
    if target:getStorageValue(STORAGEVALUE_WAR_REDPLAYER_BOOL) == 1 then
    if target:getName() == "Training Dummy" then
    target:registerEvent("EventDPS")
        end
        return RETURNVALUE_NOERROR
        elseif target:getStorageValue(STORAGEVALUE_WAR_REDPLAYER_BOOL) == 0 then
            creature:sendCancelMessage("You cannot attack someone that is on your team.")
            return false
        end
    elseif creature:getStorageValue(STORAGEVALUE_WAR_REDPLAYER_BOOL) == 1 then
        if target:getStorageValue(STORAGEVALUE_WAR_GREENPLAYER_BOOL) == 1 then
            return RETURNVALUE_NOERROR
        elseif target:getStorageValue(STORAGEVALUE_WAR_GREENPLAYER_BOOL) == 0 then
            creature:sendCancelMessage("You cannot attack someone that is on your team.")
            return false
        end
    end
end



oen432
Have solved it with:

Lua:
function Creature:onTargetCombat(target)
    if self:isPlayer() then
        if self:getStorageValue(STORAGEVALUE_WAR_GREENPLAYER_BOOL) == 1 then
            if target:getStorageValue(STORAGEVALUE_WAR_REDPLAYER_BOOL) == 1 then
                return RETURNVALUE_NOERROR
            elseif target:getStorageValue(STORAGEVALUE_WAR_REDPLAYER_BOOL) == 0 then
                self:sendCancelMessage("You cannot attack someone that is on your team.")
                return false
            end
        elseif self:getStorageValue(STORAGEVALUE_WAR_REDPLAYER_BOOL) == 1 then
            if target:getStorageValue(STORAGEVALUE_WAR_GREENPLAYER_BOOL) == 1 then
                return RETURNVALUE_NOERROR
            elseif target:getStorageValue(STORAGEVALUE_WAR_GREENPLAYER_BOOL) == 0 then
                self:sendCancelMessage("You cannot attack someone that is on your team.")
                return false
            end
        end
    end
    
    if target:getName() == "Training Dummy" then
        target:registerEvent("EventDPS")
 
oen432
Have solved it with:

Lua:
function Creature:onTargetCombat(target)
    if self:isPlayer() then
        if self:getStorageValue(STORAGEVALUE_WAR_GREENPLAYER_BOOL) == 1 then
            if target:getStorageValue(STORAGEVALUE_WAR_REDPLAYER_BOOL) == 1 then
                return RETURNVALUE_NOERROR
            elseif target:getStorageValue(STORAGEVALUE_WAR_REDPLAYER_BOOL) == 0 then
                self:sendCancelMessage("You cannot attack someone that is on your team.")
                return false
            end
        elseif self:getStorageValue(STORAGEVALUE_WAR_REDPLAYER_BOOL) == 1 then
            if target:getStorageValue(STORAGEVALUE_WAR_GREENPLAYER_BOOL) == 1 then
                return RETURNVALUE_NOERROR
            elseif target:getStorageValue(STORAGEVALUE_WAR_GREENPLAYER_BOOL) == 0 then
                self:sendCancelMessage("You cannot attack someone that is on your team.")
                return false
            end
        end
    end
   
    if target:getName() == "Training Dummy" then
        target:registerEvent("EventDPS")
Half the script is missing.
 
Back
Top