Is it possible to add a critical attribute to a weapon via setAttribute ?TFS 1.4.2 has the critical effect by default
Just add it to your items.xml, and any weapons you desire, add and save. Then, you should register it in movements.xml... there you go, the weapon will react to critical hits (Critical Hit Animation). Done!Is it possible to add a critical attribute to a weapon via setAttribute ?
<attribute key="criticalhitchance" value="100" />
<attribute key="criticalhitamount" value="100" />
Ok, this i now.Just add it to your items.xml, and any weapons you desire, add and save. Then, you should register it in movements.xml... there you go, the weapon will react to critical hits (Critical Hit Animation). Done!
XML:<attribute key="criticalhitchance" value="100" /> <attribute key="criticalhitamount" value="100" />
-- Creation of Combat objects and setting the damage type as physical for combat1
local combat1 = Combat()
combat1:setParameter(COMBAT_PARAM_TYPE, COMBAT_PHYSICALDAMAGE)
-- Function to determine formula values for combat1
function onGetFormulaValues1(cid, level, maglevel)
local player = Player(cid)
local skill = player:getSkillLevel(3) --This skill number 3 is for Axe. 0 is for Fist, 1 for Club, 2 for Sword, 3 for Axe, 4 for Distance, 5 for Shield, 6 for SKILL_FISHING, and 7 for Magic Level (ml).
level = player:getLevel()
local min = -((skill * 15) + level * 6) --This is based on the level. You can adjust the numbers to make the damage stronger or weaker, etc. If it's too much damage, just decrease the numbers,
local max = -((skill * 21) + level * 6)
return min, max
end
-- Set the callback function to get formula values for combat1
combat1:setCallback(CALLBACK_PARAM_LEVELMAGICVALUE, "onGetFormulaValues1")
-- Creation of Combat objects with effect 173 and setting the damage type as physical for combat2
local combat2 = Combat()
combat2:setParameter(COMBAT_PARAM_EFFECT, 173) --in this case, the effect with ID 173 is being set.
combat2:setParameter(COMBAT_PARAM_TYPE, COMBAT_PHYSICALDAMAGE)
-- Function to determine formula values for combat2
function onGetFormulaValues2(cid, level, maglevel)
local player = Player(cid)
local skill = player:getSkillLevel(3)
level = player:getLevel()
local min = -((skill * 39) + level * 9)
local max = -((skill * 42) + level * 9)
return min, max
end
-- Set the callback function to get formula values for combat2
combat2:setCallback(CALLBACK_PARAM_LEVELMAGICVALUE, "onGetFormulaValues2")
-- Creation of Combat objects with effect 173 and setting the damage type as physical for combat3
local combat3 = Combat()
combat3:setParameter(COMBAT_PARAM_EFFECT, 173) --in this case, the effect with ID 173 is being set.
combat3:setParameter(COMBAT_PARAM_TYPE, COMBAT_PHYSICALDAMAGE)
-- Function to determine formula values for combat3
function onGetFormulaValues3(cid, level, maglevel)
local player = Player(cid)
local skill = player:getSkillLevel(3)
level = player:getLevel()
local min = -((skill * 48) + level * 11)
local max = -((skill * 55) + level * 15)
return min, max
end
-- Set the callback function to get formula values for combat3
combat3:setCallback(CALLBACK_PARAM_LEVELMAGICVALUE, "onGetFormulaValues3")
-- Function called when the player uses the weapon
function onUseWeapon(cid, var)
local player = Player(cid)
local critical = math.random(1, 100) --This is the percentage that triggers the critical hit. You can increase or decrease it to make it happen more quickly or take longer, depending on your preference.
local life = 10 * player:getMaxHealth() / 100 --This is the one that will give life according to the critical, gaining random life.
local position = player:getPosition()
-- If the attack is critical, send animated text "Critical!" and execute combat2
if critical > 90 then
--Game.sendAnimatedText("Critical!", position, 215) --If you want an animated text in white or your preferred colors, simply uncomment it. If you don't want it, leave it commented, okay?
player:addHealth(life)
combat2:execute(cid, var)
-- If the attack is critical (less than 10%), send animated text "Critical!" and execute combat3
elseif critical < 10 then
--Game.sendAnimatedText("Critical!", position, 215) --If you want an animated text in white or your preferred colors, simply uncomment it. If you don't want it, leave it commented, okay?
player:addHealth(life)
combat3:execute(cid, var)
-- Otherwise, execute combat1
else
combat1:execute(cid, var)
end
end
Ok thanks, but I have problem with this.Okay, let's talk about how it works in weapons.xml... this 'combat1' that targets regular hits won't trigger a critical hit, only normal hits.
In 'combat2,' which triggers the critical hit, yes, there's a percentage based on the level. You can increase it to make it stronger or decrease it to adjust the critical hit chance.
weapons.xml
Lua:-- Creation of Combat objects and setting the damage type as physical for combat1 local combat1 = Combat() combat1:setParameter(COMBAT_PARAM_TYPE, COMBAT_PHYSICALDAMAGE) -- Function to determine formula values for combat1 function onGetFormulaValues1(cid, level, maglevel) local player = Player(cid) local skill = player:getSkillLevel(3) --This skill number 3 is for Axe. 0 is for Fist, 1 for Club, 2 for Sword, 3 for Axe, 4 for Distance, 5 for Shield, 6 for SKILL_FISHING, and 7 for Magic Level (ml). level = player:getLevel() local min = -((skill * 15) + level * 6) --This is based on the level. You can adjust the numbers to make the damage stronger or weaker, etc. If it's too much damage, just decrease the numbers, local max = -((skill * 21) + level * 6) return min, max end -- Set the callback function to get formula values for combat1 combat1:setCallback(CALLBACK_PARAM_LEVELMAGICVALUE, "onGetFormulaValues1") -- Creation of Combat objects with effect 173 and setting the damage type as physical for combat2 local combat2 = Combat() combat2:setParameter(COMBAT_PARAM_EFFECT, 173) --in this case, the effect with ID 173 is being set. combat2:setParameter(COMBAT_PARAM_TYPE, COMBAT_PHYSICALDAMAGE) -- Function to determine formula values for combat2 function onGetFormulaValues2(cid, level, maglevel) local player = Player(cid) local skill = player:getSkillLevel(3) level = player:getLevel() local min = -((skill * 39) + level * 9) local max = -((skill * 42) + level * 9) return min, max end -- Set the callback function to get formula values for combat2 combat2:setCallback(CALLBACK_PARAM_LEVELMAGICVALUE, "onGetFormulaValues2") -- Creation of Combat objects with effect 173 and setting the damage type as physical for combat3 local combat3 = Combat() combat3:setParameter(COMBAT_PARAM_EFFECT, 173) --in this case, the effect with ID 173 is being set. combat3:setParameter(COMBAT_PARAM_TYPE, COMBAT_PHYSICALDAMAGE) -- Function to determine formula values for combat3 function onGetFormulaValues3(cid, level, maglevel) local player = Player(cid) local skill = player:getSkillLevel(3) level = player:getLevel() local min = -((skill * 48) + level * 11) local max = -((skill * 55) + level * 15) return min, max end -- Set the callback function to get formula values for combat3 combat3:setCallback(CALLBACK_PARAM_LEVELMAGICVALUE, "onGetFormulaValues3") -- Function called when the player uses the weapon function onUseWeapon(cid, var) local player = Player(cid) local critical = math.random(1, 100) --This is the percentage that triggers the critical hit. You can increase or decrease it to make it happen more quickly or take longer, depending on your preference. local life = 10 * player:getMaxHealth() / 100 --This is the one that will give life according to the critical, gaining random life. local position = player:getPosition() -- If the attack is critical, send animated text "Critical!" and execute combat2 if critical > 90 then --Game.sendAnimatedText("Critical!", position, 215) --If you want an animated text in white or your preferred colors, simply uncomment it. If you don't want it, leave it commented, okay? player:addHealth(life) combat2:execute(cid, var) -- If the attack is critical (less than 10%), send animated text "Critical!" and execute combat3 elseif critical < 10 then --Game.sendAnimatedText("Critical!", position, 215) --If you want an animated text in white or your preferred colors, simply uncomment it. If you don't want it, leave it commented, okay? player:addHealth(life) combat3:execute(cid, var) -- Otherwise, execute combat1 else combat1:execute(cid, var) end end
<attribute key="criticalhitchance" value="100" />
<attribute key="criticalhitamount" value="100" />
Have you already registered it in movements? Without registering, of course, it won't work. That's why.Ok thanks, but I have problem with this.
I add ths to Royal Axe, and when I use critical not working.
The only thing that changed was the description of the weapon that it has a % crit, but that doesn't work.
XML:<attribute key="criticalhitchance" value="100" /> <attribute key="criticalhitamount" value="100" />
<movevent event="Equip" slot="hand" itemid="xxx" level="80" function="onEquipItem" />
<movevent event="DeEquip" slot="hand" itemid="xxx" function="onDeEquipItem" />