• 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 onDeath or onKill?

Il Knight

Veteran OT User
Joined
Dec 1, 2014
Messages
678
Solutions
7
Reaction score
352
Location
Spain
hi, i am triying to make this script work

Lua:
_____________________________
local chance = math.random(100)
local send = "asd"

function onDeath(creature, target, mostDamageKiller)

if getCreatureName(target) == "rat" then
player:setBankBalance(player:getBankBalance() + chance)
player:sendTextMessage(MESSAGE_STATUS_DEFAULT, send)

end
return true
end
______________________________

i need when you kill a "rat" in this case you get 0-100 gold coins in your bank balance but nothing happend :/
its possible to add more monsters in one script? like local monsters "rat", "rotworm" etc?
 
SOLVED


Just going to put this out there, that I'm not a great scripter. :p
But this is how I would personally do it.
Code:
function onKill(creature, target)
    if not target:isMonster() then
        return true
    end

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

    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


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

i add

function onKill(player, target, mostDamageKiller)
isSummon(target) then

now summon not give money and only the most damage player get the reward money, thanks to
Omni Cloud
and
Xikini

now i going to add correct message

player:sendTextMessage(MESSAGE_STATUS_DEFAULT, value)

ops sorry! of course thanks
president vankk
 
Last edited by a moderator:
Back
Top