• 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.X+ rarity items error

janes123

Member
Joined
Jun 21, 2012
Messages
114
Reaction score
7
Hello I would like to add [TFS 1.X] Rarity Rolls & Custom Attributes Library (https://otland.net/threads/tfs-1-x-rarity-rolls-custom-attributes-library.268888/) but unfortunately I get an error at the end I tried the solutions that are under the post but each ended with an error after adding according to the author an error pops up

LUA:
Lua Script Error: [Event Interface]
data/events/scripts/monster.lua:Monster@onDropLoot
data/events/scripts/monster.lua:7: attempt to index global 'hasEvent' (a nil value)
stack traceback:
        [C]: in function '__index'
        data/events/scripts/monster.lua:7: in function <data/events/scripts/monster.lua:6>
any solutions?
 
bump

LUA:
-- Rarity Animations
local rare_popup = true
local rare_effect = true
local rare_effect_id = CONST_ME_STUN

function Monster:onDropLoot(corpse)
    if hasEvent.onDropLoot then
        Event.onDropLoot(self, corpse)
    end
    local player = Player(corpse:getCorpseOwner())
    if player then
        player:updateKillTracker(self, corpse)
    end
end

function Monster:onSpawn(position, startup, artificial)
    if hasEvent.onSpawn then
        return Event.onSpawn(self, position, startup, artificial)
    end
    return true
end
-- Apply rarity chance to corpse contents and apply animation
if rollRarity(corpse) > 0 then -- If a rare item was rolled, play animation
        if rare_popup then
            local spectators = Game.getSpectators(corpse:getPosition(), false, true, 7, 7, 5, 5)
            for i = 1, #spectators do
                spectators[i]:say(rare_text, TALKTYPE_MONSTER_SAY, false, spectators[i], corpse:getPosition())
            end
        end
    if rare_effect then
        corpse:getPosition():sendMagicEffect(rare_effect_id)
    end
end

function Monster:onSpawn(position, startup, artificial)
    self:registerEvent("rollHealth")
    self:registerEvent("rollMana")
   return true
end
this is my monster.lua
 
I'm not sure if monster uses the hasEvent function but first of all you should put this:

LUA:
-- Apply rarity chance to corpse contents and apply animation

if rollRarity(corpse) > 0 then -- If a rare item was rolled, play animation

        if rare_popup then

            local spectators = Game.getSpectators(corpse:getPosition(), false, true, 7, 7, 5, 5)

            for i = 1, #spectators do

                spectators[i]:say(rare_text, TALKTYPE_MONSTER_SAY, false, spectators[i], corpse:getPosition())

            end

        end

    if rare_effect then

        corpse:getPosition():sendMagicEffect(rare_effect_id)

    end

end

In
Code:
function Monster:onDropLoot(corpse)
 
I'm not sure if monster uses the hasEvent function but first of all you should put this:

LUA:
-- Apply rarity chance to corpse contents and apply animation

if rollRarity(corpse) > 0 then -- If a rare item was rolled, play animation

        if rare_popup then

            local spectators = Game.getSpectators(corpse:getPosition(), false, true, 7, 7, 5, 5)

            for i = 1, #spectators do

                spectators[i]:say(rare_text, TALKTYPE_MONSTER_SAY, false, spectators[i], corpse:getPosition())

            end

        end

    if rare_effect then

        corpse:getPosition():sendMagicEffect(rare_effect_id)

    end

end

In
Code:
function Monster:onDropLoot(corpse)
Thanks for answer i did so :
LUA:
-- Rarity Animations
local rare_popup = true
local rare_effect = true
local rare_effect_id = CONST_ME_STUN

function Monster:onDropLoot(corpse)
    if hasEvent.onDropLoot then
        Event.onDropLoot(self, corpse)
    end
if rollRarity(corpse) > 0 then -- If a rare item was rolled, play animation

        if rare_popup then

            local spectators = Game.getSpectators(corpse:getPosition(), false, true, 7, 7, 5, 5)

            for i = 1, #spectators do

                spectators[i]:say(rare_text, TALKTYPE_MONSTER_SAY, false, spectators[i], corpse:getPosition())

            end

        end

    if rare_effect then

        corpse:getPosition():sendMagicEffect(rare_effect_id)

    end

end
    local player = Player(corpse:getCorpseOwner())
    if player then
        player:updateKillTracker(self, corpse)
    end
end

function Monster:onSpawn(position, startup, artificial)
    if hasEvent.onSpawn then
        return Event.onSpawn(self, position, startup, artificial)
    end
    return true
end


function Monster:onSpawn(position, startup, artificial)
    self:registerEvent("rollHealth")
    self:registerEvent("rollMana")
   return true
end
and the same error
i use this datapack [8.0] [TFS 1.2] - Server Global Full [Real Map] (https://otland.net/threads/8-0-tfs-1-2-server-global-full-real-map.280265/)
 
This datapack does not have EventCallback since it is very old (TFS 1.2). The correct approach is to use it without hasEvent and Event.

Do you know why hasEvent and Event exist? They were introduced in TFS 1.3+.

Instead of:
LUA:
function Monster:onSpawn(position, startup, artificial)
    self:registerEvent("rollHealth")
    self:registerEvent("rollMana")
    return true
end

It should be:
LUA:
function Monster:onSpawn(pos, forced)
    self:registerEvent("rollHealth")
    self:registerEvent("rollMana")
    return true
end

The original version is here:

If you've made changes to your source similar to the commits below:

Then I have removed HasEvent and Event. Check if it works:

LUA:
-- Rarity Animations
local rare_popup = true
local rare_effect = true
local rare_effect_id = CONST_ME_STUN

function Monster:onDropLoot(corpse)
    if rollRarity(corpse) > 0 then -- If a rare item was rolled, play animation
        if rare_popup then
            local spectators = Game.getSpectators(corpse:getPosition(), false, true, 7, 7, 5, 5)
            for i = 1, #spectators do
                spectators[i]:say(rare_text, TALKTYPE_MONSTER_SAY, false, spectators[i], corpse:getPosition())
            end
        end

        if rare_effect then
            corpse:getPosition():sendMagicEffect(rare_effect_id)
        end
    end

    local player = Player(corpse:getCorpseOwner())
    if player then
        player:updateKillTracker(self, corpse)
    end
end

function Monster:onSpawn(position, startup, artificial)
    self:registerEvent("rollHealth")
    self:registerEvent("rollMana")
    return true
end

I have a theory that this won't work on TFS 1.2 unless significant changes are made to both the source code and Lua scripts. I recommend migrating to TFS 1.5 or the latest available version, especially if you want a rarity system.
 
Back
Top