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

TFS 0.X Training dummy DPS

mRefaat

Marketing and Coding
Joined
Jan 18, 2014
Messages
854
Solutions
3
Reaction score
141
Location
Egypt
Hello

i am using 0.3.7

i was trying to convert this script to work with 0.3.7 but it is not working

what i have done
Lua:
DPS_STORAGE = 50392
PLAYER_DPS = {}
PLAYER_EVENTS = {}

function onStatsChange(cid, attacker, type, combat, value)
    if not cid then
        return true
    end
    if not attacker then
        return true
    end

    local function ReadDPS(cid, attacker)
        local player = attacker
        local target = cid
        if player and target then
            PLAYER_DPS[pid] = PLAYER_DPS[pid] * -1
            if PLAYER_DPS[pid] > getPlayerStorageValue(player, DPS_STORAGE) then
                setPlayerStorageValue(player, DPS_STORAGE, PLAYER_DPS[pid])
                doCreatureSay(target, string.format("New Record! DPS: %d", PLAYER_DPS[pid]), TALKTYPE_MONSTER, nil, nil, getCreaturePosition(target))
            else
                doCreatureSay(target, string.format("DPS: %d", PLAYER_DPS[pid]), TALKTYPE_MONSTER, nil, nil, getCreaturePosition(target))
            end
            PLAYER_DPS[pid] = 0
            PLAYER_EVENTS[pid] = nil
        end
    end

    if isMonster(cid) and isPlayer(attacker) then
        local damage = value
        local pid = attacker
        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)
        end
    end

    return true
end

any help to make it work ? :)
 
Solution
Untested.

Register in the monster. directly above loot is where I normally put it.
XML:
    <script>
        <event name="whatever_you_name_it_in_creatureevents.xml" />
    </script>
Then use this as a statschange. (Do not register this to players in login.lua)
Lua:
DPS_STORAGE = 50392
PLAYER_DPS = {}
PLAYER_EVENTS = {}

local function ReadDPS(cid, attacker)
    if isCreature(cid) and isCreature(attacker) then
        if PLAYER_DPS[attacker] > getPlayerStorageValue(attacker, DPS_STORAGE) then
            setPlayerStorageValue(attacker, DPS_STORAGE, PLAYER_DPS[attacker])
            doCreatureSay(cid, string.format("New Record! DPS: %d", PLAYER_DPS[attacker]), TALKTYPE_MONSTER, nil, nil, getCreaturePosition(cid))
        else...
Untested.

Register in the monster. directly above loot is where I normally put it.
XML:
    <script>
        <event name="whatever_you_name_it_in_creatureevents.xml" />
    </script>
Then use this as a statschange. (Do not register this to players in login.lua)
Lua:
DPS_STORAGE = 50392
PLAYER_DPS = {}
PLAYER_EVENTS = {}

local function ReadDPS(cid, attacker)
    if isCreature(cid) and isCreature(attacker) then
        if PLAYER_DPS[attacker] > getPlayerStorageValue(attacker, DPS_STORAGE) then
            setPlayerStorageValue(attacker, DPS_STORAGE, PLAYER_DPS[attacker])
            doCreatureSay(cid, string.format("New Record! DPS: %d", PLAYER_DPS[attacker]), TALKTYPE_MONSTER, nil, nil, getCreaturePosition(cid))
        else
            doCreatureSay(cid, string.format("DPS: %d", PLAYER_DPS[attacker]), TALKTYPE_MONSTER, nil, nil, getCreaturePosition(cid))
        end
        PLAYER_DPS[attacker] = 0
        PLAYER_EVENTS[attacker] = nil
    end
end

function onStatsChange(cid, attacker, type, combat, value)
    if not cid then
        return true
    end
    if not attacker then
        return true
    end
 
    if isPlayer(attacker) then
        if not PLAYER_DPS[attacker] then
            PLAYER_DPS[attacker] = 0
        end
        PLAYER_DPS[attacker] = PLAYER_DPS[attacker] + value
        if not PLAYER_EVENTS[attacker] then
            PLAYER_EVENTS[attacker] = addEvent(ReadDPS, 1000, cid, attacker)
        end
    end
 
    return true
end
 
Last edited:
Solution
Untested.

Register in the monster. directly above loot is where I normally put it.
XML:
    <script>
        <event name="whatever_you_name_it_in_creatureevents.xml" />
    </script>
Then use this as a statschange. (Do not register this to players in login.lua)
Lua:
DPS_STORAGE = 50392
PLAYER_DPS = {}
PLAYER_EVENTS = {}

local function ReadDPS(cid, attacker)
    if isCreature(cid) and isCreature(attacker) then
        PLAYER_DPS[attacker] = PLAYER_DPS[attacker] * -1
        if PLAYER_DPS[attacker] > getPlayerStorageValue(attacker, DPS_STORAGE) then
            setPlayerStorageValue(attacker, DPS_STORAGE, PLAYER_DPS[attacker])
            doCreatureSay(cid, string.format("New Record! DPS: %d", PLAYER_DPS[attacker]), TALKTYPE_MONSTER, nil, nil, getCreaturePosition(cid))
        else
            doCreatureSay(cid, string.format("DPS: %d", PLAYER_DPS[attacker]), TALKTYPE_MONSTER, nil, nil, getCreaturePosition(cid))
        end
        PLAYER_DPS[attacker] = 0
        PLAYER_EVENTS[attacker] = nil
    end
end

function onStatsChange(cid, attacker, type, combat, value)
    if not cid then
        return true
    end
    if not attacker then
        return true
    end

    if isPlayer(attacker) then
        if not PLAYER_DPS[attacker] then
            PLAYER_DPS[attacker] = 0
        end
        PLAYER_DPS[attacker] = PLAYER_DPS[attacker] + value
        if not PLAYER_EVENTS[attacker] then
            PLAYER_EVENTS[attacker] = addEvent(ReadDPS, 1000, cid, attacker)
        end
    end

    return true
end
Thanks for replying, i tested it but i will show you an image

test.png

It shows the dmg with minus plus it never say new record dps.

i don't care about the new record, i just want it to show your DPS (maybe we can delete the new record part)?
Post automatically merged:

PLAYER_DPS[attacker] = PLAYER_DPS[attacker] * -1

i changed this part to be

PLAYER_DPS[attacker] = PLAYER_DPS[attacker] * 1

and it worked fine with normal DPS and new record DPS.

Thanks for help :)
 
Last edited:
Thanks for replying, i tested it but i will show you an image

View attachment 58189

It shows the dmg with minus plus it never say new record dps.

i don't care about the new record, i just want it to show your DPS (maybe we can delete the new record part)?
Post automatically merged:

PLAYER_DPS[attacker] = PLAYER_DPS[attacker] * -1

i changed this part to be

PLAYER_DPS[attacker] = PLAYER_DPS[attacker] * 1

and it worked fine with normal DPS and new record DPS.

Thanks for help :)
mmm that's leftover from tfs 1.3 I think.
tfs 1.3 has everything negative, and you need to turn it positive. xD

So in your case, you can just remove that line altogether, as it's no longer needed.

I'll edit my above post with those changes as well.
 
mmm that's leftover from tfs 1.3 I think.
tfs 1.3 has everything negative, and you need to turn it positive. xD

So in your case, you can just remove that line altogether, as it's no longer needed.

I'll edit my above post with those changes as well.
Thanks really for help! <3
 
Back
Top