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

Points for all attackers

vexler222

Active Member
Joined
Apr 22, 2012
Messages
714
Solutions
15
Reaction score
46
Hi, can someone help me with damagemap? I tried add it few times, with examples from others topics, but everytime when i add it, script don't giving points for me, without any errors.
If someone can explain to me how damagemap works, I will be very grateful!

Code:
function onKill(creature, target)
    local config = {
        ["Rotworm"] = {pkt = 1, },
    }
    if player:isPlayer() and target:isMonster() then
        local monster = config[Creature(target):getName()]
        local storage_v = 367465
        local max_storage = 367466
                if monster and player:getStorageValue(storage_v) <= player:getStorageValue(max_storage) then
                    player:setStorageValue(storage_v, player:getStorageValue(storage_v) + monster.pkt)
                    player:sendTextMessage(MESSAGE_EVENT_ORANGE, "You get " .. monster.pkt .. "  points!")
                elseif monster and player:getStorageValue(storage_v) >= player:getStorageValue(max_storage) then
                    player:sendTextMessage(MESSAGE_EVENT_ORANGE, "You can\'t get more points! Just purchase something!")
                end
    return true
end

Code:
function onKill(creature, target)
    local config = {
        ["Rotworm"] = {pkt = 1, },
    }
    if player:isPlayer() and target:isMonster() then
        local player = Player(cid)
        local monster = config[Creature(target):getName()]
        local storage_v = 367465
        local max_storage = 367466
        local targetMonster = Monster(target)

        for currentPlayerId, currentDamage in pairs(targetMonster:getDamageMap()) do
            local attackerPlayer = Player(currentPlayerId)
            if attackerPlayer then
                if monster and player:getStorageValue(storage_v) <= player:getStorageValue(max_storage) then
                    player:setStorageValue(storage_v, player:getStorageValue(storage_v) + monster.pkt)
                    player:sendTextMessage(MESSAGE_EVENT_ORANGE, "You get " .. monster.pkt .. "  points!")
                elseif monster and player:getStorageValue(storage_v) >= player:getStorageValue(max_storage) then
                    player:sendTextMessage(MESSAGE_EVENT_ORANGE, "You can\'t get more points! Just purchase something!")
                end
            end
        end
    end
    return true
end
 
Last edited:
What the... Xd try to use attackerPlayer instead of player.

And use creature instead of cid.. you dont have cid declared in function.

You don't have to create userdate "Creature(target)" because tfx 1.x return userdate to function.

Try to think what you write in script.
 
This should work:
Lua:
local config = {
    ["Rotworm"] = {pkt = 1, },
}
local storage_v = 367465
local max_storage = 367466

function onKill(creature, target)
    if creature:isPlayer() and target:isMonster() then
        local monster = config[target:getName()]
        if monster then
            for currentPlayerId, currentDamage in pairs(target:getDamageMap()) do
                local attackerPlayer = Player(currentPlayerId)
                if attackerPlayer then
                    if attackerPlayer:getStorageValue(storage_v) <= attackerPlayer:getStorageValue(max_storage) then
                        attackerPlayer:setStorageValue(storage_v, attackerPlayer:getStorageValue(storage_v) + monster.pkt)
                        attackerPlayer:sendTextMessage(MESSAGE_EVENT_ORANGE, "You get " .. monster.pkt .. "  points!")
                    else -- if its not lower-equal, it must be higher, we dont need IF
                        attackerPlayer:sendTextMessage(MESSAGE_EVENT_ORANGE, "You can\'t get more points! Just purchase something!")
                    end
                end
            end
        end
    end
    return true
end
Possible problems (if it works at all):
  • add points 2 times (onKill may execute 2 times: for most damage killer and for last hit killer - if it's not same player)
  • count summons
  • starts counting from -1 (default storage value), after first kill player will have 0 kills, not 1 - is storage 367465 set to 0 in some other script?
  • attackerPlayer:getStorageValue(storage_v) <= attackerPlayer:getStorageValue(max_storage) allows player to get 101 of 100 points limit, it should be < ?

I'm not sure what these 2 storages do. Is there some other script that set 367466 to max possible points value?
 
This should work:
Lua:
local config = {
    ["Rotworm"] = {pkt = 1, },
}
local storage_v = 367465
local max_storage = 367466

function onKill(creature, target)
    if creature:isPlayer() and target:isMonster() then
        local monster = config[target:getName()]
        if monster then
            for currentPlayerId, currentDamage in pairs(target:getDamageMap()) do
                local attackerPlayer = Player(currentPlayerId)
                if attackerPlayer then
                    if attackerPlayer:getStorageValue(storage_v) <= attackerPlayer:getStorageValue(max_storage) then
                        attackerPlayer:setStorageValue(storage_v, attackerPlayer:getStorageValue(storage_v) + monster.pkt)
                        attackerPlayer:sendTextMessage(MESSAGE_EVENT_ORANGE, "You get " .. monster.pkt .. "  points!")
                    else -- if its not lower-equal, it must be higher, we dont need IF
                        attackerPlayer:sendTextMessage(MESSAGE_EVENT_ORANGE, "You can\'t get more points! Just purchase something!")
                    end
                end
            end
        end
    end
    return true
end
Possible problems (if it works at all):
  • add points 2 times (onKill may execute 2 times: for most damage killer and for last hit killer - if it's not same player)
  • count summons
  • starts counting from -1 (default storage value), after first kill player will have 0 kills, not 1 - is storage 367465 set to 0 in some other script?
  • attackerPlayer:getStorageValue(storage_v) <= attackerPlayer:getStorageValue(max_storage) allows player to get 101 of 100 points limit, it should be < ?

I'm not sure what these 2 storages do. Is there some other script that set 367466 to max possible points value?

About last question, yes. Im set max possible points in login.lua, if player has max_storage -1, then in login.lua i set him default value of max points.
Thanks, i will test it when im back to home.

What the... Xd try to use attackerPlayer instead of player.

And use creature instead of cid.. you dont have cid declared in function.

You don't have to create userdate "Creature(target)" because tfx 1.x return userdate to function.

Try to think what you write in script.

Im not a scripter ;p Fragments in code, about damagemap i copied from other script in someone else topic, but i never use a damagemap, so i don't know how to use, and i tried copy/paste ;D
 
Back
Top