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

Help with..Interactive Trainer updating script to tfs 1.2

Joined
Jun 22, 2010
Messages
268
Solutions
1
Reaction score
5
Location
Usa, Utah
Thanks for looking.

I'm trying to update this training monk script that displays your dps to tfs 1.2 Original link below:
https://otland.net/threads/interactive-training-monk.145227/#post-1396476.

What I have so far gives no errors but it make it so the monk takes no visible damage even though the weapons make contact and I get a dps reading that is accurate. It has also made it so regular players can't be attacked. Any ideas?



Code:
local exhaust = createConditionObject(CONDITION_EXHAUST)
setConditionParam(exhaust, CONDITION_PARAM_SUBID, 82936)
setConditionParam(exhaust, CONDITION_PARAM_TICKS, 10000)

function getDamageDone(cid, targetpos)
targetpos.x = targetpos.x - 1
if(isPlayer(cid)) then
doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Average DPS: ".. getPlayerStorageValue(cid, 82936) / 10 .."")
doCreatureSay(cid, "You are currently dealing an average of ".. getPlayerStorageValue(cid, 82936) / 10 .." damage per second.", TALKTYPE_ORANGE_1, false, 0, targetpos)
return setPlayerStorageValue(cid, 82936, 0)
end
return true
end

function onHealthChange(creature, attacker, primaryDamage, primaryType, secondaryDamage, secondaryType, origin)
if(primaryDamage >= 0) then
if(not isPlayer(attacker.uid)) then
return true
end

setPlayerStorageValue(attacker.uid, 82936, getPlayerStorageValue(attacker.uid, 82936) + primaryDamage)

if(getCreatureCondition(attacker.uid, CONDITION_EXHAUST, 82936) == false) then
setPlayerStorageValue(attacker.uid, 82936, 0)
addEvent(getDamageDone, 9900, attacker.uid, creature:getPosition())
doAddCondition(attacker.uid, exhaust)
end
end
return true
end
 
Try this:
creaturescripts/scripts/dpscounter.lua:
Code:
function onHealthChange(creature, attacker, primaryDamage, primaryType, secondaryDamage, secondaryType, origin)
    local cid = creature:getId()
    local cur = os.time()
    if primaryType ~= COMBAT_HEALING then
        DPS[cid] = DPS[cid] or {0, cur, cur, cur}
        DPS[cid][3] = os.time()
        DPS[cid][1] = DPS[cid][1] + primaryDamage
    end
    return primaryDamage, primaryType, secondaryDamage, secondaryType
end

function onDeath(creature)
    DPS[creature:getId()] = nil
    return true
end

--[[
  <event type="death" name="DPSDeath" script="dpscounter.lua" />
   <event type="healthchange" name="DPSHealth" script="dpscounter.lua" />
]]
(onDeath optional only in case of monk death, doesn't really makes much difference you may not put it there :3)

Register both events in the monster xml and add this script to the monster:
Something like:
<monster name="Training Monk" nameDescription="a training monk" race="blood" experience="200" speed="200" script="DPS.lua">

(Create scripts folder in monster folder, tfs doesnt come with it for some reason.)
Code:
function onThink(self, interval)
    local cid = self:getId()
    if DPS[cid] then
        local cur = os.time()
        if DPS[cid][1] > 0 and cur > DPS[cid][4] + MSGINTERVAL then
            self:say(DPSMSG:format(DPS[cid][1] / (cur - DPS[cid][2] > 0 and cur - DPS[cid][2] or 1)), TALKTYPE_MONSTER_SAY)
            DPS[cid][4] = cur
        end
        if cur - DPS[cid][3] > DPSCLEAR and DPS[cid][1] > 0 then
            self:say(("Total Damage: %d"):format(DPS[cid][1]), TALKTYPE_MONSTER_SAY) -- If you want, remove it :3
            DPS[cid] = nil
        end
    end
    return false
end

And put this in global.lua:
Code:
DPS = {}
DPSCLEAR = 10 -- seconds to clear dps (if monk is not hitted for 10 seconds it clears the dps and stops saying shit.)
MSGINTERVAL = 5 -- seconds to say dps message
DPSMSG = "You did %d damage per second."

Not tested, should work tho.

EDIT: oops fixed an error in onThink monster.
 
Last edited:
Not sure what you fixed cause both ways worked! Thanks man, that is a big help. I tried to have it send myself a status message but it debugs the client. Is it because its in the monster script and not possible?
 
Not sure what you fixed cause both ways worked! Thanks man, that is a big help. I tried to have it send myself a status message but it debugs the client. Is it because its in the monster script and not possible?
It was not properly cleaning the damage information. I don't know what "status message" you tried but this is not linked in anyway to the player that is doing the damage so if you are trying to send a message to creature or self its not going to work cause its not a player
 
Back
Top