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

errorvwith my creature.lua

wafuboe

Member
Joined
Dec 24, 2010
Messages
881
Solutions
2
Reaction score
22
hello well i was trying to install in my server CreatureEvent - [TFS 1.1] Ultimate item stat system (elements, skills, exp, loot and more) (https://otland.net/threads/tfs-1-1-ultimate-item-stat-system-elements-skills-exp-loot-and-more.229771/page-15)
and i think i messup at the creature.lua part because mine is slighty diferent, im not familiar with eof

i got this error con console

35018

here is my creature.lua
Code:
__picif = {}
function Creature:onChangeOutfit(outfit)
    return true
end

function Creature:onAreaCombat(tile, isAggressive)
    return true
end

local function removeCombatProtection(cid)
    local player = Player(cid)
    if not player then
        return true
    end

    local time = 0
    if player:isMage() then
        time = 10
    elseif player:isPaladin() then
        time = 20
    else
        time = 30
    end

    player:setStorageValue(Storage.combatProtectionStorage, 2)
    addEvent(function(cid)
        local player = Player(cid)
        if not player then
            return
        end

        player:setStorageValue(Storage.combatProtectionStorage, 0)
        player:remove()
    end, time * 1000, cid)
end

-- Increase Stamina when Attacking Trainer
local staminaBonus = {
    target = 'Training Monk',
    period = 120000, -- time on miliseconds
    bonus = 1, -- gain stamina
    events = {}
}

local function addStamina(name)
    local player = Player(name)
    if not player then
        staminaBonus.events[name] = nil
    else
        local target = player:getTarget()
        if not target or target:getName() ~= staminaBonus.target then
            staminaBonus.events[name] = nil
        else
            player:setStamina(player:getStamina() + staminaBonus.bonus)
            staminaBonus.events[name] = addEvent(addStamina, staminaBonus.period, name)
        end
    end
end

function Creature:onTargetCombat(target)
  return stat_onTargetCombat(self, target)
  end
if not self then return true end
    if self:isPlayer() and target:isMonster() then
        target:registerEvent("extra_loot_d")
    end
    if not self then
        return true
    end

    if not __picif[target.uid] then
        if target:isMonster() then
            target:registerEvent("RewardSystemSlogan")
            __picif[target.uid] = {}
        end
    end

    if target:isPlayer() then
        if self:isMonster() then
            local protectionStorage = target:getStorageValue(Storage.combatProtectionStorage)

            if target:getIp() == 0 then -- If player is disconnected, monster shall ignore to attack the player
                if protectionStorage <= 0 then
                    addEvent(removeCombatProtection, 30 * 1000, target.uid)
                    target:setStorageValue(Storage.combatProtectionStorage, 1)
                elseif protectionStorage == 1 then
                    self:searchTarget()
                    return RETURNVALUE_YOUMAYNOTATTACKTHISPLAYER
                end

                return true
            end

            if protectionStorage >= os.time() then
                return RETURNVALUE_YOUMAYNOTATTACKTHISPLAYER
            end
        end
    end

    if ((target:isMonster() and self:isPlayer() and target:getType():isPet() and target:getMaster() == self) or (self:isMonster() and target:isPlayer() and self:getType():isPet() and self:getMaster() == target)) then
        return RETURNVALUE_YOUMAYNOTATTACKTHISCREATURE
    end

    if PARTY_PROTECTION ~= 0 then
        if self:isPlayer() and target:isPlayer() then
            local party = self:getParty()
            if party then
                local targetParty = target:getParty()
                if targetParty and targetParty == party then
                    return RETURNVALUE_YOUMAYNOTATTACKTHISPLAYER
                end
            end
        end
    end

    if ADVANCED_SECURE_MODE ~= 0 then
        if self:isPlayer() and target:isPlayer() then
            if self:hasSecureMode() then
                return RETURNVALUE_YOUMAYNOTATTACKTHISPLAYER
            end
        end
    end

        if self:isPlayer() then
        if target and target:getName() == staminaBonus.target then
            local name = self:getName()
            if not staminaBonus.events[name] then
                staminaBonus.events[name] = addEvent(addStamina, staminaBonus.period, name)
            end
        end
    end

    return true
end

function Creature:onDrainHealth(attacker, typePrimary, damagePrimary, typeSecondary, damageSecondary, colorPrimary, colorSecondary)
    if (not self) then
        return typePrimary, damagePrimary, typeSecondary, damageSecondary, colorPrimary, colorSecondary
    end

    if (not attacker) then
        return typePrimary, damagePrimary, typeSecondary, damageSecondary, colorPrimary, colorSecondary
    end

    -- Imbuement Defense
    if self:isPlayer() then
        for slot = 1, 10 do
            local item = self:getSlotItem(slot)
            if item and item:getType():getImbuingSlots() > 0 then
                for i = 1, item:getType():getImbuingSlots() do
                    local slotEnchant = item:getSpecialAttribute(i)
                    if (slotEnchant and type(slotEnchant) == 'string') then
                        local percentDamage, enchantPercent = 0, item:getImbuementPercent(slotEnchant)
                        local typeEnchant = item:getImbuementType(i) or ""

                        reductPrimary, reductSecondary = false, false
                        if (typeEnchant == "absorbPercentFire") then
                            -- reduct fire damage
                            if typePrimary == COMBAT_FIREDAMAGE then
                                reductPrimary = true
                            end

                            if typeSecondary == COMBAT_FIREDAMAGE then
                                reductSecondary = true
                            end
                        elseif (typeEnchant == "absorbPercentEarth" and typePrimary == COMBAT_EARTHDAMAGE) then
                            -- reduct earth damage
                            if typePrimary == COMBAT_EARTHDAMAGE then
                                reductPrimary = true
                            end

                            if typeSecondary == COMBAT_EARTHDAMAGE then
                                reductSecondary = true
                            end
                        elseif (typeEnchant == "absorbPercentIce" and typePrimary == COMBAT_ICEDAMAGE) then
                            -- reduct ice damage
                            if typePrimary == COMBAT_ICEDAMAGE then
                                reductPrimary = true
                            end

                            if typeSecondary == COMBAT_ICEDAMAGE then
                                reductSecondary = true
                            end
                        elseif (typeEnchant == "absorbPercentEnergy" and typePrimary == COMBAT_ENERGYDAMAGE) then
                            -- reduct energy damage
                            if typePrimary == COMBAT_ENERGYDAMAGE then
                                reductPrimary = true
                            end

                            if typeSecondary == COMBAT_ENERGYDAMAGE then
                                reductSecondary = true
                            end
                        elseif (typeEnchant == "absorbPercentDeath" and typePrimary == COMBAT_DEATHDAMAGE) then
                            -- reduct death damage
                            if typePrimary == COMBAT_DEATHDAMAGE then
                                reductPrimary = true
                            end

                            if typeSecondary == COMBAT_DEATHDAMAGE then
                                reductSecondary = true
                            end
                        end

                        if reductPrimary then
                            damagePrimary = damagePrimary - (damagePrimary * enchantPercent/100)
                        end

                        if reductSecondary then
                            damageSecondary = damageSecondary - (damageSecondary * enchantPercent/100)
                        end

                        if (typeEnchant ~= "" and typeEnchant == "skillShield" or typeEnchant:find("absorb") and (reductPrimary or reductSecondary)) then
                            useStaminaImbuing(self:getId(), item:getUniqueId())
                        end
                    end
                end
            end
        end
    end

    if (attacker:isPlayer()) then
        if (self:isMonster() and not self:getMaster()) then
            for i = 1, 3 do
                if (attacker:isActive(i-1)) then
                    local bonusInfo = attacker:getBonusInfo(i-1)
                    if (bonusInfo.Type == 0 and bonusInfo.Name == self:getName()) then
                        damagePrimary = damagePrimary + math.floor(damagePrimary * (bonusInfo.Value/100))
                        break
                    end
                end
            end
        end
    elseif (attacker:isMonster()) then
        if (self:isPlayer()) then
            for i = 1, 3 do
                if (self:isActive(i-1)) then
                    local bonusInfo = self:getBonusInfo(i-1)
                    if (bonusInfo.Type == 1 and bonusInfo.Name == attacker:getName()) then
                        damagePrimary = damagePrimary - math.floor(damagePrimary * (bonusInfo.Value/100))
                        return typePrimary, damagePrimary, typeSecondary, damageSecondary, colorPrimary, colorSecondary
                    end
                end
            end
        end
    end

    return typePrimary, damagePrimary, typeSecondary, damageSecondary, colorPrimary, colorSecondary
end

thanks you so much!
 
Last edited:
Solution
problem must be because i changed this part of the scipt
Code:
function Creature:onTargetCombat(target)
   return stat_onTargetCombat(self, target)
end

imsure this part mess up but dont know how the error is on line 134 to much lines away
Yes it is messed up. Remove this from that part of the code you posted
Lua:
return stat_onTargetCombat(self, target)
end
Idk where you got this code from but the way lua works is if it encounters a return statement then it immediately ends whatever executed it. The end below the return breaks the body of the remaining function definition. This will cause an error as we have already seen but also prevents the script from loading properly or loading at all.
eof means End Of File
Look on line 134 for the error or even the previous line. The reason the code is indented isn't just for aesthetics its to show code execution & scope.
 
eof means End Of File
Look on line 134 for the error or even the previous line. The reason the code is indented isn't just for aesthetics its to show code execution & scope.
problem must be because i changed this part of the scipt
Code:
function Creature:onTargetCombat(target)
   return stat_onTargetCombat(self, target)
end

imsure this part mess up but dont know how the error is on line 134 to much lines away
 
problem must be because i changed this part of the scipt
Code:
function Creature:onTargetCombat(target)
   return stat_onTargetCombat(self, target)
end

imsure this part mess up but dont know how the error is on line 134 to much lines away
Yes it is messed up. Remove this from that part of the code you posted
Lua:
return stat_onTargetCombat(self, target)
end
Idk where you got this code from but the way lua works is if it encounters a return statement then it immediately ends whatever executed it. The end below the return breaks the body of the remaining function definition. This will cause an error as we have already seen but also prevents the script from loading properly or loading at all.
 
Last edited:
Solution
901 is the line the error gives. Whats on or above line 901 in global.lua?

global only have 250+- lines the error comes from the lib file here it is im using tfs 1.3
Code:
    stat_conditions[2]['hp'][i] = createConditionObject(CONDITION_ATTRIBUTES)
 
stat_conditions[2]['hp']:setParameter(CONDITION_PARAM_SUBID, 50)
now
Code:
 if rares > 0 then
                                if STATS_SYSTEM_CONFIG.rare_popup then
                                        local spectators = Game.getSpectators(pos, false, true, 7, 7, 5, 5)
                                        for i = 1, #spectators do
                                                spectators[i]:say(STATS_SYSTEM_CONFIG.rare_text, TALKTYPE_MONSTER_SAY, false, spectators:setParameter( pos)
                                        end
                                end
this is line 2326
Code:
   spectators[i]:say(STATS_SYSTEM_CONFIG.rare_text, TALKTYPE_MONSTER_SAY, false, spectators:setParameter( pos)
35022
 
There error says you're missing a closing parentheses ")" it's also pretty obvious by just looking at the code, don't add the quotes.
 
im so sorry this whole time i was installing wrong the system. i needed to add to on data and global.lua instead of libs

its working!

but when i look at any object it goes x3 x2 double description
Example"
10:19 You see a common royal helmet -1 (Arm:7).
Imbuements: (Empty Slot, Empty Slot).
It weighs 48.00 oz.
An excellent masterpiece of a smith.a common royal helmet -1 (Arm:7).
Imbuements: (Empty Slot, Empty Slot).
It weighs 48.00 oz.
An excellent masterpiece of a smith.

Any idea mate?
 
Player: onLook handles descriptions that is found in data/events/scripts in player.lua

Post that method
It isn't the only method but we can just from there.
 
meanwhile ill check the movements that i made before the bug, ill post it here thank btw C:

I did this changes

player.lua event
replace

Code:
function Player:onLook(thing, position, distance)
   local description = "You see " .. thing:getDescription(distance)
to

Code:
function Player:onLook(thing, position, distance)
   local description = "You see " .. thing:getDescription(distance)
   description = stat_onLook(thing, description)

replace

Code:
function Player:onLookInTrade(partner, item, distance)
self:sendTextMessage(MESSAGE_INFO_DESCR, "You see " .. item:getDescription(distance))
end

to

Code:
function Player:onLookInTrade(partner, item, distance)
   local description = item:getDescription(distance)
   description = stat_onLook(item, description)
   self:sendTextMessage(MESSAGE_INFO_DESCR, "You see " .. description)
   end
 
Last edited:
Back
Top