oen432
Legendary OT User
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.
- Open
data/creaturescripts/creaturescripts.xml
- Add
<event type="healthchange" name="EventDPS" script="dps.lua" />
- Open
data/events/events.xml
- Enable
onTargetCombat
- Open
data/events/scripts/creature.lua
- Find
function Creature:onTargetCombat(target)
- Add before
return RETURNVALUE_NOERROR
Lua:if target:getName() == "Training Dummy" then target:registerEvent("EventDPS") end
- Create file
data/creaturescripts/scripts/dps.lua
with this codeLua: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
- 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: