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
how to make that ring deals 5% more COMBAT_ENERGYDAMAGE
TFS 1.2
I checked, its made like a ring... there is nothing wrong with it.check the ring in the script...
ofc there is something wrong, you not checking if a player is using the ringI checked, its made like a ring... there is nothing wrong with it.
How do i need to check it because the creator of that script didnt said anything about itofc there is something wrong, you not checking if a player is using the ring
you also should learn while you doing it, thats the point of asking for help.How do i need to check it because the creator of that script didnt said anything about it
like this?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
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
-- 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
<event type="healthchange" name="ringDamage" script="damage_ring.lua" />
player:registerEvent("ringDamage")
function Creature:onTargetCombat(target)
if self and self:isMonster() then
self:registerEvent("ringDamage")
end
return true
end
<event class="Creature" method="onTargetCombat" enabled="1" />
Wow no errors but it doesnt increase dmg at all register in events.xml but notingNot 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 CreaturenTargetCombat
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" />
change the code from damage_ring to this oneWow no errors but it doesnt increase dmg at all register in events.xml but noting
-- 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
if self and target and target:isMonster() then
target:registerEvent("ringDamage")
end
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 properlychange 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.
print like what?you didnt changed what I told to you or didnt enabled the event, try adding some prints in onTargetCombat because its working for me.
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
<event class="Creature" method="onTargetCombat" enabled="1" />
Yea i enabled ontargetcombat when Steve said.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" />
-- 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
I dont understand what i checked multiple times.So you missing something cus its working flawless here.
-- 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
<event type="healthchange" name="ringDamage" script="dmgRing.lua" />
player:registerEvent("ringDamage")
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
<?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>
I dont understand what i checked multiple times.
created dmgRing.lua in data/creaturescripts/scripts/
1526 my ring id.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
then in creaturescipt.xml
then creaturescripts\scripts\login.luaXML:<event type="healthchange" name="ringDamage" script="dmgRing.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
Everything is added how it should beXML:<?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>
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