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

Il Knight

Veteran OT User
Joined
Dec 1, 2014
Messages
678
Solutions
7
Reaction score
352
Location
Spain
SOLVED!

Hellouuu
i have 3 hours triying get work this script

Code:
function onKill(player, target, mostDamageKiller)

local damageMap = Creature(target):getDamageMap()
for CreatureId, damage in pairs(damageMap) do
local player = Player(id)

if not mostDamageKiller(Player) or isSummon(target)
    then
    end
        return true
    end

    local monsters = {
  [1] = { name = "rat",      min_gold = 1, max_gold = 100 },
  [2] = { name = "cave rat", min_gold = 100, max_gold = 1000 },
  [3] = { name = "rotworm",  min_gold = 1000, max_gold = 10000 }

}

    for i = 1, #monsters do
        if monsters[i].name == target:getName():lower() then
            local value = math.random(monsters[i].min_gold, monsters[i].max_gold)
            player:setBankBalance(player:getBankBalance() + value)
            player:sendTextMessage(MESSAGE_STATUS_DEFAULT, value)
            break
        end
    end

    return true
end

it work (give a random value when you kill the monsters but its givin to all people! i need only give to who deal most damage


here the script without damage get
Code:
function onKill(player, target, mostDamageKiller)
    if not target:isMonster() or isSummon(target) then
        return true
    end

    local monsters = {
  [1] = { name = "rat",      min_gold = 1, max_gold = 100 },
  [2] = { name = "cave rat", min_gold = 100, max_gold = 1000 },
  [3] = { name = "rotworm",  min_gold = 1000, max_gold = 10000 }

}

    for i = 1, #monsters do
        if monsters[i].name == target:getName():lower() then
            local value = math.random(monsters[i].min_gold, monsters[i].max_gold)
            player:setBankBalance(player:getBankBalance() + value)
            player:sendTextMessage(MESSAGE_STATUS_DEFAULT, value)
            break
        end
    end

    return true
end
 
Last edited:
how i can use that?

function onKill(player, target, mostDamageKiller)
print( mostDamageKiller, type(mostDamageKiller))
 
You use print to find information from your script, and print it to console.

I would assume you could just use it directly though.
Code:
function onKill(player, target, mostDamageKiller)
    if not target:isMonster() or isSummon(target) then
        return true
    end

    if player ~= mostDamageKiller then
        return true
    end

    local monsters = {
        [1] = { name = "rat",      min_gold = 1, max_gold = 100 },
        [2] = { name = "cave rat", min_gold = 100, max_gold = 1000 },
        [3] = { name = "rotworm",  min_gold = 1000, max_gold = 10000 }
    }

    for i = 1, #monsters do
        if monsters[i].name == target:getName():lower() then
            local value = math.random(monsters[i].min_gold, monsters[i].max_gold)
            player:setBankBalance(player:getBankBalance() + value)
            player:sendTextMessage(MESSAGE_STATUS_DEFAULT, value)
            break
        end
    end

    return true
end

If this doesn't work, start using "print(value)" and checking the console to find more information.

Omni posted this in another thread, however I think it would be useful to you.
To see what is going on in the script we (or you do at least) need to know what value is being returned.

Most things in lua return a value, even variables, this is how we are able to compare or assign values to something else.
Code:
local status = obj:refine(cid, item)
if status == "success" then
obj:refine returns a value and stores it in status, that in-turn compares its return value with a string "success".
To determine what status holds, lets see the return value and its type, this is where print comes in.
Code:
print(status)
If we want to see the data-type the value it returns, we would use type.
Code:
print(type(status))
We can also combine the two, if you are printing a value it is always called after the value is assigned.
Code:
local status = obj:refine(cid, item)
print(status, type(status))
Let us know what you get, you will see something printed in the console window when this script is executed.
 
You use print to find information from your script, and print it to console.

I would assume you could just use it directly though.
Code:
function onKill(player, target, mostDamageKiller)
    if not target:isMonster() or isSummon(target) then
        return true
    end

    if player ~= mostDamageKiller then
        return true
    end

    local monsters = {
        [1] = { name = "rat",      min_gold = 1, max_gold = 100 },
        [2] = { name = "cave rat", min_gold = 100, max_gold = 1000 },
        [3] = { name = "rotworm",  min_gold = 1000, max_gold = 10000 }
    }

    for i = 1, #monsters do
        if monsters[i].name == target:getName():lower() then
            local value = math.random(monsters[i].min_gold, monsters[i].max_gold)
            player:setBankBalance(player:getBankBalance() + value)
            player:sendTextMessage(MESSAGE_STATUS_DEFAULT, value)
            break
        end
    end

    return true
end

If this doesn't work, start using "print(value)" and checking the console to find more information.

Omni posted this in another thread, however I think it would be useful to you.

hey bro it work (but some times not)
what mean if player ~= <<<< (~=) ?
 
SOLVED WITH
function onKill(player, target, mostDamageKiller)

if not player == mostDamageKiller or isSummon(target) then
return true
end

Xikini
how i can add a nice message here?
player:sendTextMessage(MESSAGE_STATUS_DEFAULT, value)

like you win "value" in this battle?
 
Maybe something like this? Sorry if I did something wrong but I'm in mobile :p

Code:
player:sendTextMessage(MESSAGE_STATUS_DEFAULT, string.format('You recived %d extra gold for killing %s.', value, target:getName()))
 
its done, now in mi server you dont need loot gold/platinums etc jejeje
thanks

Xikini
president vankk



(Speed attack on weapon by %) DONE
(Critical hit system by % (only hits(weapons) DONE
(only work with gold coins and send it to bank automatically) DONE
(remove platinum coins, and crystal coins) DONE
(remove withdraw and deposit on npc) DONE

Bank Channel (to transfer money, and see account balance) Not done
npc(take money from bank directly) Not done
Purse slot (client 10.76) to send the loot gained in battles to this virtual slot. )) Not done < very hard?
 
Back
Top