Monster Training Dummy with DPS calculation

oen432

Veteran OT User
Joined
Oct 3, 2014
Messages
482
Best answers
11
Reaction score
446
Location
Poland
Simple training dummy that is showing players DPS (Damage Per Second). The highest DPS is stored in storage and can be used for different things, like rewards or requirements for items or something, I don't know, use your brain.

  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 by a moderator:

Walox

Member
Joined
Jul 31, 2017
Messages
18
Best answers
0
Reaction score
15
Oii, can you do that for version 8.54? I really liked the system but I do not think it will work on my server.
 
Top