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

Il Knight

Veteran OT User
Joined
Dec 1, 2014
Messages
676
Solutions
7
Reaction score
350
Location
Spain
Hi otland, today im stucked with this script..

what i need?

if you kill this monsters (on the script) you get xxx exp and xxx gold.
and if you kill this monsters on (party) the exp and gold is divided.
all is working good.. But have one problem.

problem = rat (HP 20)

player 1 = deal 5 hp // < win money and exp. (this is not good) <
player 2 = deal 15 hp // < win money and exp. (its ok)

i dont know why this happen because im using this =

if not player == mostDamageKiller then
return true
end

so if you are not the most damage killer, why the script is giving exp to all the player who attack the monster?

help please..

maybe is better function on death?

Code:
local monsters = {
    {name = "rat",      min_gold = 1,    max_gold = 10,   exp = 1000 },
    {name = "cave rat", min_gold = 100,  max_gold = 200,  exp = 10000 },
    {name = "rotworm",  min_gold = 2000, max_gold = 3000, exp = 100000 }
}
function onKill(creature, target, mostDamageKiller)

        local player = creature:getPlayer()
       
    if not player then
        return true
    end
   
    if not player == mostDamageKiller then
        return true
    end
   
    if target:getMaster() then
        return true
    end
   
        local party = player:getParty()
       
    if not party then
   
    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)
        local exp = monsters[i].exp
        local lev = player:getLevel()
               
            player:addExperience(round(exp/lev))
            player:setBankBalance(round(player:getBankBalance() + value))
            player:sendTextMessage(MESSAGE_STATUS_DEFAULT, "You have gained ".. round(value) .." coins in this battle.")
           
            end
        end
    return true
    end
       
    if party and party:isSharedExperienceActive() then
       
        local rate = (party:getMemberCount() + 1)
        local members = party:getMembers()
    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)
        local gold = value/rate
        local exp = monsters[i].exp
        local div = exp/rate
        local leader = party:getLeader()
        local lev = leader:getLevel()
               
            leader:addExperience(round(div/lev))
            leader:setBankBalance(round(leader:getBankBalance() + gold))
            leader:sendTextMessage(MESSAGE_STATUS_DEFAULT, "You have gained ".. round(gold) .." coins in this battle.")
                   
    for i = 1, #members do
   
            members[i]:addExperience(round(div/members[i]:getLevel()))                   
            members[i]:setBankBalance(round(members[i]:getBankBalance() + gold))                   
            members[i]:sendTextMessage(MESSAGE_STATUS_DEFAULT, "You have gained ".. round(gold) .." coins in this battle.")
           
                end
            end
        end
    end

    return true
end
 
In TFS 1.x, there is no "mostDamageKiller" paramater in this event:
Lua:
onKill(creature, target)

What you can do is use creature:getDamageMap() and check if the most damage was from the player that you are currently running.
 
In TFS 1.x, there is no "mostDamageKiller" paramater in this event:
Lua:
onKill(creature, target)

What you can do is use creature:getDamageMap() and check if the most damage was from the player that you are currently running.
so, if you deal the 80% of the damage to this monster and go to the dp (and other kill the monster dealing the 20% left of hp) the first player who deal the 80% of hp can't run the script?
 
so, if you deal the 80% of the damage to this monster and go to the dp (and other kill the monster dealing the 20% left of hp) the first player who deal the 80% of hp can't run the script?
It will probably run for this guy that deal 80% of the damage too. You can use the onDeath event if you don't wanna care about that as you have:
Lua:
onDeath(creature, corpse, lasthitkiller, mostdamagekiller, lasthitunjustified, mostdamageunjustified)
 
It will probably run for this guy that deal 80% of the damage too. You can use the onDeath event if you don't wanna care about that as you have:
Lua:
onDeath(creature, corpse, lasthitkiller, mostdamagekiller, lasthitunjustified, mostdamageunjustified)
so, with on death i can do this=

1= if you are killing alone and you deal the 51% of the hp you going to win the monster. (not care if you are far away)

with on death how i can get the most damage killer to run all?
 
Back
Top