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

Lua Tables damage map

Il Knight

Veteran OT User
Joined
Dec 1, 2014
Messages
676
Solutions
7
Reaction score
350
Location
Spain
what i need? create a table players
{} insert in the table all the players who have storage value 10000 + 10001 (damage map saved on storages)
then the first player on the table (with more storage values win xxx item)
the second player of the table win xxx item, the third win xxx item.
players from 4 to 10, win xxx item.
players from 11 + win xxx item.

tfs 1.3 / 10.98

Code:
local Bosses = {
    {name = "ferumbras"}
}
function onDeath(creature, corpse, lasthitkiller, mostdamagekiller, lasthitunjustified, mostdamageunjustified)

    for i = 1, #Bosses do
 
    if Bosses[i].name == creature:getName():lower() then
    creature:setDropLoot(false)
 
    for id in pairs(creature:getDamageMap()) do
 
    local player = Player(id)

    local chanceatk = player:getStorageValue(10000)
    local chancedef = player:getStorageValue(10001)
 
do stuff here =

    player:setStorageValue(10000, -1)
    player:setStorageValue(10001, -1)
 
            end
        end
    end
 
    return true
end

thanks in advance
 
you want players with the most storage values from the damage map to win better rewards if i understand correctly?
 
yes @Xeraphus here is the other script =
Code:
function onHealthChange(creature, attacker, primaryDamage, primaryType, secondaryDamage, secondaryType, origin)

    if creature:getName() == "Ferumbras" then
    local value = attacker:getStorageValue(10000)
    local hp = creature:getHealth()
    local damage = (primaryDamage + secondaryDamage)
    if damage > hp then
    attacker:setStorageValue(10000, (value + hp))
    return hp , primaryType, hp, secondaryType
    end
    attacker:setStorageValue(10000, (value + damage))
    end
  
    if attacker:getName() == "Ferumbras" then
    local value = creature:getStorageValue(10001)
    local hp = creature:getHealth()
    local damage = (primaryDamage + secondaryDamage)
    if damage > hp then
    creature:setStorageValue(10001, (value + hp))
    return hp , primaryType, hp, secondaryType
    end
    creature:setStorageValue(10001, (value + damage))
    end

return primaryDamage , primaryType, secondaryDamage, secondaryType
end

the damage dealed to the boss and the damage that you take is saved in the storages 10000 and 10001.

i do on healthchange because damageMap only save the last hit of each attacker. not all the hits.
what im trying to do is storage 10000 + storage 10001 = xx value < "chance" to get xxx items.
the best way is using tables?
 
Lua:
local bosses = {"Ferumbras"}

local rewards = {
    [1] = {itemid = 2160, subType = 5},
    [2] = {itemid = 2160, subType = 10},
    [3] = {itemid = 2160, subType = 15},
    [4] = {itemid = 2160, subType = 30},
    [11] = {itemid = 2160, subType = 100}
}

local playerRewards = {}

function onDeath(creature, corpse, lasthitkiller, mostdamagekiller, lasthitunjustified, mostdamageunjustified)

    if isInArray(bosses, creature:getName()) then
        creature:setDropLoot(false)
        for damage, cid in pairs(creature:getDamageMap()) do
            local player = Player(cid)
            local chanceatk = player:getStorageValue(10000)
            local chancedef = player:getStorageValue(10001)
            playerRewards[#playerRewards+1] = {player = player, storage = chanceatk + chancedef}
            player:setStorageValue(10000, -1)
            player:setStorageValue(10001, -1)
        end
    end
    table.sort(playerRewards, function(a, b) return a[2] < b[2] end)
    local lastIndex = 1
    for i = 1, table.maxn(playerRewards) do
        local index = i
        if not rewards[i] then
            index = lastIndex
        end
        lastIndex = index
        playerRewards[i].player:addItem(rewards[index].itemid, rewards[index].subType)
    end
    playerRewards = {}
    return true
end
 
Lua:
local bosses = {"Ferumbras"}

local rewards = {
    [1] = {itemid = 2160, subType = 5},
    [2] = {itemid = 2160, subType = 10},
    [3] = {itemid = 2160, subType = 15},
    [4] = {itemid = 2160, subType = 30},
    [11] = {itemid = 2160, subType = 100}
}

local playerRewards = {}

function onDeath(creature, corpse, lasthitkiller, mostdamagekiller, lasthitunjustified, mostdamageunjustified)

    if isInArray(bosses, creature:getName()) then
        creature:setDropLoot(false)
        for damage, cid in pairs(creature:getDamageMap()) do
            local player = Player(cid)
            local chanceatk = player:getStorageValue(10000)
            local chancedef = player:getStorageValue(10001)
            playerRewards[#playerRewards+1] = {player = player, storage = chanceatk + chancedef}
            player:setStorageValue(10000, -1)
            player:setStorageValue(10001, -1)
        end
    end
    table.sort(playerRewards, function(a, b) return a[2] < b[2] end)
    local lastIndex = 1
    for i = 1, table.maxn(playerRewards) do
        local index = i
        if not rewards[i] then
            index = lastIndex
        end
        lastIndex = index
        playerRewards[i].player:addItem(rewards[index].itemid, rewards[index].subType)
    end
    playerRewards = {}
    return true
end

table.sort(playerRewards, function(a, b) return a[2] < b[2] end)

attemp to compare two nill values. line 26

only work when only 1 player kill the boss
 
i need to sort something like =

player 0 = lasthitkiller

if player = 0 then
reward
if player = 1 then
reward
if player = 2 then
reward
if player = 3 then
reward
if player = 4 then
reward
if player = 5 then
reward
if player >= 6 then
reward

where player number (storage value 10000 (ferumbras hits)
 
i looking some script here on otland but im still stucked ajaja

i going to explain it again for furthers readers =

Here in this script if you deal damage or block damage from ferumbras you gain "points" in the storage 10000 (attack) and 10001 defense.

Code:
function onHealthChange(creature, attacker, primaryDamage, primaryType, secondaryDamage, secondaryType, origin)

    if creature:getName() == "Ferumbras" then
    local value = attacker:getStorageValue(10000)
    local hp = creature:getHealth()
    local damage = (primaryDamage + secondaryDamage)
    if damage > hp then
    attacker:setStorageValue(10000, (value + hp))
    return hp , primaryType, hp, secondaryType
    end
    attacker:setStorageValue(10000, (value + damage))
    end
   
    if attacker:getName() == "Ferumbras" then
    local value = creature:getStorageValue(10001)
    local hp = creature:getHealth()
    local damage = (primaryDamage + secondaryDamage)
    if damage > hp then
    creature:setStorageValue(10001, (value + hp))
    return hp , primaryType, hp, secondaryType
    end
    creature:setStorageValue(10001, (value + damage))
    end

return primaryDamage , primaryType, secondaryDamage, secondaryType
end

and here is the second script on Death (check the mostdamagekiller and the lasthitkiller) corpse and creature (ferumbras)
Code:
local Bosses = {
    {name = "ferumbras"}  
}

function onDeath(creature, corpse, lasthitkiller, mostdamagekiller, lasthitunjustified, mostdamageunjustified)

     local winner1 = lasthitkiller:getPlayer()
    local winner2 = mostdamagekiller:getPlayer()
       
    for i = 1, #Bosses do
   
    if Bosses[i].name == creature:getName():lower() then
   
    creature:setDropLoot(false)
   
    for id in pairs(creature:getDamageMap()) do
   
    local player = Player(id)
   
    local chanceatk = (player:getStorageValue(10000) / 1000)
    local chancedef = (player:getStorageValue(10001) / 1000)
       
    player:setStorageValue(10000, -1)
    player:setStorageValue(10001, -1)
   
            end
        end
    end
   
    return true
end

here the ferumbras is death then what im trying to do?
check all the PLAYERS with storage value 10000 (here its the amount of damage that you deal to the ferumbras)
then to the player with more storage (10000)
= reward
player 2 then
reward
player 3 then
reward etc etc.

How i can check the storage value 10000 of all the player who deal damage and get the most, second, third, etc?
 
Back
Top