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

Item that deals 5% more

Lopaskurwa

Active Member
Joined
Oct 6, 2017
Messages
873
Solutions
2
Reaction score
49
Hello,
how to make that ring deals 5% more COMBAT_ENERGYDAMAGE
TFS 1.2
 
I was reading it and I think there are two problems, I do not know if this function should return true, and I you should check if the attacker is a monster (if attacker:isMonster() then) and return the expected parameters earlier if it is true (primaryDamage, etc). I am on my celphone so can not do much, maybe later I can edit it if you did not understand
 
I was reading it and I think there are two problems, I do not know if this function should return true, and I you should check if the attacker is a monster (if attacker:isMonster() then) and return the expected parameters earlier if it is true (primaryDamage, etc). I am on my celphone so can not do much, maybe later I can edit it if you did not understand
like this?
Lua:
local specialRings = {1526}

function onHealthChange(creature, attacker, primaryDamage, primaryType, secondaryDamage, secondaryType, origin)
  if not attacker then return true end
  local ring = attacker:getSlotItem(CONST_SLOT_RING)
  if ring and creature then
  if attacker:isMonster() then
    return true
  end
    if primaryType == COMBAT_ENERGYDAMAGE then
      if table.contains(specialRings, ring.itemid) then
        primaryDamage = primaryDamage * 1.05
      end
    end
  end
  return primaryDamage, primaryType, secondaryDamage, secondaryType
end
?
 
Not tested but it should work

Save this script as damage_ring.lua in data/creaturescripts/scripts/
Lua:
-- consolidate the code into a table to easily reference
local x = {
    specialRings = {1526},
    multiplier = 1.05,
    combatType = COMBAT_ENERGYDAMAGE,
    slot = CONST_SLOT_RING
}

function onHealthChange(creature, attacker, primaryDamage, primaryType, secondaryDamage, secondaryType, origin)
    -- is there an attacker and a creature, is the attacker a player and is creature a creature? (Monster, Player or NPC)
    if (attacker and creature) and (attacker:isPlayer() and creature:isCreature()) then
        -- if the attacker is a player get the slot item (ring)
        local ring = attacker:getSlotItem(x.slot)
        if ring then
            -- are they wearing a ring & is it the correct one?
            if table.contains(x.specialRings, ring.itemid) then
                -- determine if the combat type is the correct one for both primary & secondary types
                -- if it is for either apply the damage multiplier
                if primaryType == x.combatType then
                    primaryDamage = primaryDamage * x.multiplier
                end
                if secondaryType == x.combatType then
                    secondaryDamage = secondaryDamage * x.multiplier
                end
            end
        end
    end
    -- return the values whether they have been changed or not
      return primaryDamage, primaryType, secondaryDamage, secondaryType
end

Open creaturescripts.xml and add this
XML:
<event type="healthchange" name="ringDamage" script="damage_ring.lua" />

Open login.lua and add this just above the line where it says return true
Lua:
player:registerEvent("ringDamage")

This will allow you to register the event with every monster without having to edit every xml file.
Open creature.lua in data/events/scripts/ and replace or modify the existing method Creature:eek:nTargetCombat
Lua:
function Creature:onTargetCombat(target)
    if self and self:isMonster() then
        self:registerEvent("ringDamage")
    end
    return true
end

In events.xml located in data/events make sure that onTargetCombat is enabled like it is in the code below
XML:
<event class="Creature" method="onTargetCombat" enabled="1" />
 
Not tested but it should work

Save this script as damage_ring.lua in data/creaturescripts/scripts/
Lua:
-- consolidate the code into a table to easily reference
local x = {
    specialRings = {1526},
    multiplier = 1.05,
    combatType = COMBAT_ENERGYDAMAGE,
    slot = CONST_SLOT_RING
}

function onHealthChange(creature, attacker, primaryDamage, primaryType, secondaryDamage, secondaryType, origin)
    -- is there an attacker and a creature, is the attacker a player and is creature a creature? (Monster, Player or NPC)
    if (attacker and creature) and (attacker:isPlayer() and creature:isCreature()) then
        -- if the attacker is a player get the slot item (ring)
        local ring = attacker:getSlotItem(x.slot)
        if ring then
            -- are they wearing a ring & is it the correct one?
            if table.contains(x.specialRings, ring.itemid) then
                -- determine if the combat type is the correct one for both primary & secondary types
                -- if it is for either apply the damage multiplier
                if primaryType == x.combatType then
                    primaryDamage = primaryDamage * x.multiplier
                end
                if secondaryType == x.combatType then
                    secondaryDamage = secondaryDamage * x.multiplier
                end
            end
        end
    end
    -- return the values whether they have been changed or not
      return primaryDamage, primaryType, secondaryDamage, secondaryType
end

Open creaturescripts.xml and add this
XML:
<event type="healthchange" name="ringDamage" script="damage_ring.lua" />

Open login.lua and add this just above the line where it says return true
Lua:
player:registerEvent("ringDamage")

This will allow you to register the event with every monster without having to edit every xml file.
Open creature.lua in data/events/scripts/ and replace or modify the existing method Creature:eek:nTargetCombat
Lua:
function Creature:onTargetCombat(target)
    if self and self:isMonster() then
        self:registerEvent("ringDamage")
    end
    return true
end

In events.xml located in data/events make sure that onTargetCombat is enabled like it is in the code below
XML:
<event class="Creature" method="onTargetCombat" enabled="1" />
Wow :eek: no errors but it doesnt increase dmg at all register in events.xml but noting
 
Wow :eek: no errors but it doesnt increase dmg at all register in events.xml but noting
change the code from damage_ring to this one

Lua:
-- consolidate the code into a table to easily reference
local x = {
    specialRings = {2121},
    multiplier = 1.05,
    combatType = COMBAT_ENERGYDAMAGE,
    slot = CONST_SLOT_RING
}

function onHealthChange(creature, attacker, primaryDamage, primaryType, secondaryDamage, secondaryType, origin)
    -- is there an attacker and a creature, is the attacker a player and is creature a creature? (Monster, Player or NPC)
    if (attacker and creature) and (attacker:isPlayer() and creature:isCreature()) then
        -- if the attacker is a player get the slot item (ring)
        local ring = attacker:getSlotItem(x.slot)
        if ring then
            -- are they wearing a ring & is it the correct one?
            if table.contains(tostring(ring.itemid), x.specialRings) then
                -- determine if the combat type is the correct one for both primary & secondary types
                -- if it is for either apply the damage multiplier
                if primaryType == x.combatType then
                    primaryDamage = primaryDamage * x.multiplier
                end
                if secondaryType == x.combatType then
                    secondaryDamage = secondaryDamage * x.multiplier
                end
            end
        end
    end
    -- return the values whether they have been changed or not
      return primaryDamage, primaryType, secondaryDamage, secondaryType
end

and the part from creature.lua should be like this

Lua:
if self and target and target:isMonster() then
    target:registerEvent("ringDamage")
end

Note: used 2121 (wedding ring) while was testing.

Code:
15:41 A demon loses 73 hitpoints due to your attack.
15:41 A demon loses 720 hitpoints due to your attack.
 
change the code from damage_ring to this one

Lua:
-- consolidate the code into a table to easily reference
local x = {
    specialRings = {2121},
    multiplier = 1.05,
    combatType = COMBAT_ENERGYDAMAGE,
    slot = CONST_SLOT_RING
}

function onHealthChange(creature, attacker, primaryDamage, primaryType, secondaryDamage, secondaryType, origin)
    -- is there an attacker and a creature, is the attacker a player and is creature a creature? (Monster, Player or NPC)
    if (attacker and creature) and (attacker:isPlayer() and creature:isCreature()) then
        -- if the attacker is a player get the slot item (ring)
        local ring = attacker:getSlotItem(x.slot)
        if ring then
            -- are they wearing a ring & is it the correct one?
            if table.contains(tostring(ring.itemid), x.specialRings) then
                -- determine if the combat type is the correct one for both primary & secondary types
                -- if it is for either apply the damage multiplier
                if primaryType == x.combatType then
                    primaryDamage = primaryDamage * x.multiplier
                end
                if secondaryType == x.combatType then
                    secondaryDamage = secondaryDamage * x.multiplier
                end
            end
        end
    end
    -- return the values whether they have been changed or not
      return primaryDamage, primaryType, secondaryDamage, secondaryType
end

and the part from creature.lua should be like this

Lua:
if self and target and target:isMonster() then
    target:registerEvent("ringDamage")
end

Note: used 2121 (wedding ring) while was testing.

Code:
15:41 A demon loses 73 hitpoints due to your attack.
15:41 A demon loses 720 hitpoints due to your attack.
I swear to god its still same. Everything is registered properly
 
you didnt changed what I told to you or didnt enabled the event, try adding some prints in onTargetCombat because its working for me.
 
change this to
Lua:
function Creature:onTargetCombat(target)
    if self and target and target:isMonster() then
        print("Attacker name: " .. self:getName())
        print("Monster target name: " .. target:getName())
        target:registerEvent("ringDamage")
    end
    return RETURNVALUE_NOERROR
end

and this to
Code:
<event class="Creature" method="onTargetCombat" enabled="1" />
edit:
btw
7nBFibH.png


kt4wy7R.png
 
Last edited:
change this to
Lua:
function Creature:onTargetCombat(target)
    if self and target and target:isMonster() then
        print("Attacker name: " .. self:getName())
        print("Monster target name: " .. target:getName())
        target:registerEvent("ringDamage")
    end
    return RETURNVALUE_NOERROR
end

and this to
Code:
<event class="Creature" method="onTargetCombat" enabled="1" />
Yea i enabled ontargetcombat when Steve said.
34522
 
So you missing something cus its working flawless here.
Lua:
-- consolidate the code into a table to easily reference
local x = {
    specialRings = {2121},
    multiplier = 1.05,
    combatType = COMBAT_ENERGYDAMAGE,
    slot = CONST_SLOT_RING
}

function onHealthChange(creature, attacker, primaryDamage, primaryType, secondaryDamage, secondaryType, origin)
    -- is there an attacker and a creature, is the attacker a player and is creature a creature? (Monster, Player or NPC)
    if (attacker and creature) and (attacker:isPlayer() and creature:isCreature()) then
        -- if the attacker is a player get the slot item (ring)
        local ring = attacker:getSlotItem(x.slot)
        if ring then
            -- are they wearing a ring & is it the correct one?
            if table.contains(tostring(ring.itemid), x.specialRings) then
                -- determine if the combat type is the correct one for both primary & secondary types
                -- if it is for either apply the damage multiplier
                attacker:say("OMG SO MUCH DAMAGE", TALKTYPE_MONSTER_SAY)
                creature:say("PLS NO HIT ME PAPA", TALKTYPE_MONSTER_SAY)
                if primaryType == x.combatType then
                    primaryDamage = primaryDamage * x.multiplier
                end
                if secondaryType == x.combatType then
                    secondaryDamage = secondaryDamage * x.multiplier
                end
            end
        end
    end
    -- return the values whether they have been changed or not
      return primaryDamage, primaryType, secondaryDamage, secondaryType
end


XQ8JHiK.png
 
So you missing something cus its working flawless here.
I dont understand what i checked multiple times.
created dmgRing.lua in data/creaturescripts/scripts/
Lua:
-- consolidate the code into a table to easily reference
local x = {
    specialRings = {1526},
    multiplier = 1.05,
    combatType = COMBAT_ENERGYDAMAGE,
    slot = CONST_SLOT_RING
}

function onHealthChange(creature, attacker, primaryDamage, primaryType, secondaryDamage, secondaryType, origin)
    -- is there an attacker and a creature, is the attacker a player and is creature a creature? (Monster, Player or NPC)
    if (attacker and creature) and (attacker:isPlayer() and creature:isCreature()) then
        -- if the attacker is a player get the slot item (ring)
        local ring = attacker:getSlotItem(x.slot)
        if ring then
            -- are they wearing a ring & is it the correct one?
            if table.contains(tostring(ring.itemid), x.specialRings) then
                -- determine if the combat type is the correct one for both primary & secondary types
                -- if it is for either apply the damage multiplier
                if primaryType == x.combatType then
                    primaryDamage = primaryDamage * x.multiplier
                end
                if secondaryType == x.combatType then
                    secondaryDamage = secondaryDamage * x.multiplier
                end
            end
        end
    end
    -- return the values whether they have been changed or not
      return primaryDamage, primaryType, secondaryDamage, secondaryType
end
1526 my ring id.
then in creaturescipt.xml
XML:
    <event type="healthchange" name="ringDamage" script="dmgRing.lua" />
then creaturescripts\scripts\login.lua
Lua:
    player:registerEvent("ringDamage")

then data\events\scripts\creature.lua

Lua:
function Creature:onChangeOutfit(outfit)
    return true
end

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

function Creature:onTargetCombat(target)
     if self and target and target:isMonster() then
    target:registerEvent("ringDamage")
    end
    return true
end

then enabled events.xml
XML:
<?xml version="1.0" encoding="UTF-8"?>
<events>
    <!-- Creature methods -->
    <event class="Creature" method="onChangeOutfit" enabled="0" />
    <event class="Creature" method="onAreaCombat" enabled="0" />
    <event class="Creature" method="onTargetCombat" enabled="1" />

    <!-- Party methods -->
    <event class="Party" method="onJoin" enabled="0" />
    <event class="Party" method="onLeave" enabled="0" />
    <event class="Party" method="onDisband" enabled="0" />

    <!-- Player methods -->
    <event class="Player" method="onLook" enabled="1" />
    <event class="Player" method="onLookInBattleList" enabled="1" />
    <event class="Player" method="onLookInTrade" enabled="1" />
    <event class="Player" method="onLookInShop" enabled="0" />
    <event class="Player" method="onMoveItem" enabled="0" />
    <event class="Player" method="onMoveCreature" enabled="0" />
    <event class="Player" method="onTurn" enabled="0" />
    <event class="Player" method="onTradeRequest" enabled="0" />
    <event class="Player" method="onTradeAccept" enabled="0" />
    <event class="Player" method="onGainExperience" enabled="1" />
    <event class="Player" method="onLoseExperience" enabled="0" />
    <event class="Player" method="onGainSkillTries" enabled="1" />
    <event class="Player" method="onMoveItem" enabled="1" />

   
    <!-- Monster methods -->
    <event class="Monster" method="onSpawn" enabled="1" />
</events>
Everything is added how it should be
 
I dont understand what i checked multiple times.
created dmgRing.lua in data/creaturescripts/scripts/
Lua:
-- consolidate the code into a table to easily reference
local x = {
    specialRings = {1526},
    multiplier = 1.05,
    combatType = COMBAT_ENERGYDAMAGE,
    slot = CONST_SLOT_RING
}

function onHealthChange(creature, attacker, primaryDamage, primaryType, secondaryDamage, secondaryType, origin)
    -- is there an attacker and a creature, is the attacker a player and is creature a creature? (Monster, Player or NPC)
    if (attacker and creature) and (attacker:isPlayer() and creature:isCreature()) then
        -- if the attacker is a player get the slot item (ring)
        local ring = attacker:getSlotItem(x.slot)
        if ring then
            -- are they wearing a ring & is it the correct one?
            if table.contains(tostring(ring.itemid), x.specialRings) then
                -- determine if the combat type is the correct one for both primary & secondary types
                -- if it is for either apply the damage multiplier
                if primaryType == x.combatType then
                    primaryDamage = primaryDamage * x.multiplier
                end
                if secondaryType == x.combatType then
                    secondaryDamage = secondaryDamage * x.multiplier
                end
            end
        end
    end
    -- return the values whether they have been changed or not
      return primaryDamage, primaryType, secondaryDamage, secondaryType
end
1526 my ring id.
then in creaturescipt.xml
XML:
    <event type="healthchange" name="ringDamage" script="dmgRing.lua" />
then creaturescripts\scripts\login.lua
Lua:
    player:registerEvent("ringDamage")

then data\events\scripts\creature.lua

Lua:
function Creature:onChangeOutfit(outfit)
    return true
end

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

function Creature:onTargetCombat(target)
     if self and target and target:isMonster() then
    target:registerEvent("ringDamage")
    end
    return true
end

then enabled events.xml
XML:
<?xml version="1.0" encoding="UTF-8"?>
<events>
    <!-- Creature methods -->
    <event class="Creature" method="onChangeOutfit" enabled="0" />
    <event class="Creature" method="onAreaCombat" enabled="0" />
    <event class="Creature" method="onTargetCombat" enabled="1" />

    <!-- Party methods -->
    <event class="Party" method="onJoin" enabled="0" />
    <event class="Party" method="onLeave" enabled="0" />
    <event class="Party" method="onDisband" enabled="0" />

    <!-- Player methods -->
    <event class="Player" method="onLook" enabled="1" />
    <event class="Player" method="onLookInBattleList" enabled="1" />
    <event class="Player" method="onLookInTrade" enabled="1" />
    <event class="Player" method="onLookInShop" enabled="0" />
    <event class="Player" method="onMoveItem" enabled="0" />
    <event class="Player" method="onMoveCreature" enabled="0" />
    <event class="Player" method="onTurn" enabled="0" />
    <event class="Player" method="onTradeRequest" enabled="0" />
    <event class="Player" method="onTradeAccept" enabled="0" />
    <event class="Player" method="onGainExperience" enabled="1" />
    <event class="Player" method="onLoseExperience" enabled="0" />
    <event class="Player" method="onGainSkillTries" enabled="1" />
    <event class="Player" method="onMoveItem" enabled="1" />

  
    <!-- Monster methods -->
    <event class="Monster" method="onSpawn" enabled="1" />
</events>
Everything is added how it should be

So if you do this
Lua:
function Creature:onTargetCombat(target)
    if self and target and target:isCreature() then
        self:say(self:getName(), TALKTYPE_MONSTER_SAY)
        target:say(target:getName(), TALKTYPE_MONSTER_SAY)
    end
    return true
end

I also changed isMonster to isCreature (because we want monsters and players, or nay?)
 
Back
Top