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

TFS 1.2 onDeath reward after killing monster

Lopaskurwa

Active Member
Joined
Oct 6, 2017
Messages
873
Solutions
2
Reaction score
49
Hello, i found this script in otland trying to figure it out why nothing happens. How i understand this code should work like this if you deal 50% damage to this monster you will get reward so lets say i do 51(gets reward) and other player 49(doesnt get reward). So code looks like this. Though the issue is because its not registered in login.lua but nothing changed

Creaturescript
XML:
<event type="death" name="monsterEvent" script="monsterevent.lua" />
Lua:
function onDeath(creature, corpse, killer, mostDamage, unjustified, mostDamage_unjustified)
    local percent = creature:getMaxHealth() * 0.50
    for k, v in pairs(monstersSystem) do
            if v.name:lower() == creature:getName():lower() then
            for pid, info in pairs(creature:getDamageMap()) do
                local player = Player(pid)
                if player and info.total >= percent then
                    player:addExperience(v.expReward, true)
                    player:addMoney(v.goldReward)
                    player:addItem(v.itemReward, v.itemCount) -- this adds items 
                    player:addEventPoints(v.pointsReward) -- So this is event points
                    if math.random(1,100) <= v.chance then
                    player:addItem(v.RandomitemReward, v.RandomitemCount) -- this is adds items too
                    end
                end
            end
        end
    end
    return true
end

Global.lua
Lua:
monstersSystem = {
    [1] = {name = "Ornstein Lvl 1", chance = 5, expReward = 15000000, pointsReward = 100, goldReward = 1000000, RandomitemReward = 8373, RandomitemCount = 1, itemReward = 16857, itemCount = 15},
    [2] = {name = "Ornstein Lvl 2", chance = 5, expReward = 15000000, pointsReward = 10, goldReward = 1000000, RandomitemReward = 8373, RandomitemCount = 1, itemReward = 16857, itemCount = 15},
    [3] = {name = "Wizpig", chance = 5, expReward = 15000000, pointsReward = 10, goldReward = 1000000, RandomitemReward = 8373, RandomitemCount = 1, itemReward = 16857, itemCount = 15},
    [4] = {name = "Dracula", chance = 5, expReward = 15000000, pointsReward = 10, goldReward = 1000000, RandomitemReward = 8373, RandomitemCount = 1, itemReward = 16857, itemCount = 15}
}
 
Solution
You must register the event monsterEvent in the monster!
Usually they usually do the registration within data/events/scripts/creature.lua ok the function: function Creature:onTargetCombat(target)

example:
Lua:
function Creature:onTargetCombat(target)
    if target and target:isMonster() then
        target:registerevent("monsterEvent")
    end
    return RETURNVALUE_NOERROR
end
You must register the event monsterEvent in the monster!
Usually they usually do the registration within data/events/scripts/creature.lua ok the function: function Creature:onTargetCombat(target)

example:
Lua:
function Creature:onTargetCombat(target)
    if target and target:isMonster() then
        target:registerevent("monsterEvent")
    end
    return RETURNVALUE_NOERROR
end
 
Solution
You must register the event monsterEvent in the monster!
Usually they usually do the registration within data/events/scripts/creature.lua ok the function: function Creature:onTargetCombat(target)

example:
Lua:
function Creature:onTargetCombat(target)
    if target and target:isMonster() then
        target:registerevent("monsterEvent")
    end
    return RETURNVALUE_NOERROR
end
Works, thanks
 
Back
Top