• 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+ Making two-handed weapons give bleeding condition

Togu

Advanced OT User
Joined
Jun 22, 2018
Messages
308
Solutions
1
Reaction score
178
Location
Brazil
How am I suppose to do that?

I was looking on movements folder, I couldn't understand how it works.

I don't know if I should do that in C++, in Lua or in both.

Is there some way of adding bleeding condition in C++ (I just found it in the lua file for the bleeding spell)? Cause I know I can create an "invisible" special random skill called Bleeding Hit Chance and then use it in the same way Critical Hit Chance is used.

SOLVED: Working two-handed melee weapon giving bonus bleeding damage:
After player hits another creature wielding a two-handed melee weapon. He has 50% of chance of giving extras bleeding hit based on his skill.

data/weapons/weapons.xml:
XML:
<melee id="2413" script="two_handed_melee.lua" />

data/weapons/scripts/two_handed_melee.lua:
Lua:
local combat = Combat()
combat:setParameter(COMBAT_PARAM_TYPE, COMBAT_PHYSICALDAMAGE)
combat:setParameter(COMBAT_PARAM_BLOCKARMOR, true)
combat:setParameter(COMBAT_PARAM_BLOCKSHIELD, true)
combat:setFormula(COMBAT_FORMULA_SKILL, 0, 0, 1, 0)

function onUseWeapon(player, variant)
   if not combat:execute(player, variant) then
       return false
   end

   if math.random(1, 100) <= 50 then
       return false
   end

   local damage = math.floor((player:getEffectiveSkillLevel(SKILL_STRENGHT) * 0.02) + 1)
   player:addDamageCondition(Creature(variant:getNumber()), CONDITION_BLEEDING, DAMAGELIST_CONSTANT_PERIOD, damage, 1, 4)
   return true
end
 
Last edited:
Solution
one way could be through a onHealthChange creaturescript

there you can check if the origin is from a melee attack, and then you can also check if the player doing the attack is holding a two handed weapon, and then you can apply the bleeding condition

but you can also just simply do it through registering all two handed weapons in weapons.xml and then linking them to a script that applies the bleeding condition
one way could be through a onHealthChange creaturescript

there you can check if the origin is from a melee attack, and then you can also check if the player doing the attack is holding a two handed weapon, and then you can apply the bleeding condition

but you can also just simply do it through registering all two handed weapons in weapons.xml and then linking them to a script that applies the bleeding condition
 
Solution
one way could be through a onHealthChange creaturescript

there you can check if the origin is from a melee attack, and then you can also check if the player doing the attack is holding a two handed weapon, and then you can apply the bleeding condition
Thaaaanks a lot for these tips!
but you can also just simply do it through registering all two handed weapons in weapons.xml and then linking them to a script that applies the bleeding condition
I'll have to register them all anyway because I've put all two-handed weapons giving critical hit chance and critical hit amount.

Edit:
Now I understood how to edit items effect properly. Thanks a lot.

But how do I solve this? It is printing message three times when equiping:

00:10 Bleeding effect test
00:10 Bleeding effect test
00:10 Bleeding effect test
Code:
function onEquip(creature, item)
   creature:sendTextMessage(MESSAGE_EVENT_ORANGE, 'Bleeding effect test')
   return true
end

Tryied to change to MESSAGE_EVENT_ADVANCE but still three times.
 
Last edited:
XML:
<movevent event="Equip" itemid="2161" slot="necklace" script="bleedingeffect.lua" />
<movevent event="DeEquip" itemid="2161" slot="necklace" script="bleedingeffect.lua" />
I think you do it like this
Yeah I did that. Didn't know it was possible cause I didn't found any script with "onEquip" function linked to an item.
But it really is possible :D

Gonna try to implement the bleeding effect tomorrow.
 
Yeah I did that. Didn't know it was possible cause I didn't found any script with "onEquip" function linked to an item.
But it really is possible :D

Gonna try to implement the bleeding effect tomorrow.
Sorry, try this.
Lua:
function onEquip(player, item, slot, isCheck)
    if isCheck == false then
        -- script here
    end
    return true
end
That should fix the multiple onEquip bug thing.
[Fix] [0.3.7 / 0.4 / 0.3.6] Multiple onEquip bug.
I think it's the same problem that's been around forever, and looking int he source, it looks like they've added the same thing probably? Just renamed it to isCheck.
Worth a try anyway.
 
Sorry, try this.
Lua:
function onEquip(player, item, slot, isCheck)
    if isCheck == false then
        -- script here
    end
    return true
end
That should fix the multiple onEquip bug thing.
[Fix] [0.3.7 / 0.4 / 0.3.6] Multiple onEquip bug.
I think it's the same problem that's been around forever, and looking int he source, it looks like they've added the same thing probably? Just renamed it to isCheck.
Worth a try anyway.
Thaaaaanks, worked!

Edit:
I don't know how to recognize the combat situation and the target through movements so I'm trying to do it through creaturescripts.

XML:
<!-- Bleeding Effect -->
   <event type="healthchange" name="BleedingEffect" script="bleedingeffect.lua" />
Lua:
function onHealthChange(creature, attacker, primaryDamage, primaryType, secondaryDamage, secondaryType, origin)
   creature:sendTextMessage(MESSAGE_EVENT_ORANGE, 'Bleeding effect test')
   local min = (creature:getLevel() / 80) + (100 * 0.2) + 2
   local max = (creature:getLevel() / 80) + (100 * 0.4) + 2
   local damage = math.random(math.floor(min) * 1000, math.floor(max) * 1000) / 1000
   creature:addDamageCondition(creature, CONDITION_BLEEDING, DAMAGELIST_LOGARITHMIC_DAMAGE, creature:isPlayer() and damage / 4 or damage)
   creature:unregisterEvent("BleedingEffect")
   return true
end
Just have to make the two-handed restriction.

Edit:
Using onHealthChange gives too many bugs =/
One time the bleeding heals, other time healing spells stops working, other attacks don't work.

Edit:
Lua:
function onEquip(player, item, slot, isCheck)
   if isCheck == false then
       player:sendTextMessage(MESSAGE_STATUS_CONSOLE_ORANGE, "TESTE1")
       local min = (player:getLevel() / 80) + (50 * 0.2) + 2
       local max = (player:getLevel() / 80) + (50 * 0.4) + 2
       local damage = math.random(math.floor(10) * 1000, math.floor(10) * 1000) / 1000
       if (player:getTarget()) then
           target = player:getTarget()
           target:addDamageCondition(target, CONDITION_BLEEDING, DAMAGELIST_LOGARITHMIC_DAMAGE, target:isPlayer() and damage / 4 or damage)
       end
   end
   return true
end
Working only if equiping item after selecting target :/
Don't know how to solve this.
 
Last edited:
Working two-handed melee weapon giving bonus bleeding damage:
After player hits another player wielding a two-handed melee weapon. He has 50% of chance of giving an extra bleeding hit based on his skill (you will have to make a change on this part cause my server just have one melee skill - strenght).
Lua:
function onHealthChange(creature, attacker, primaryDamage, primaryType, secondaryDamage, secondaryType, origin)
   if math.random(1, 100) > 50 then
       local leftItem = attacker:getSlotItem(CONST_SLOT_LEFT)
       local rightItem = attacker:getSlotItem(CONST_SLOT_RIGHT)
       local two_handed_melee = {
           2377, -- two handed sword
           2378, -- battle axe
           2381, -- halberd
           2387, -- double axe
           2390, -- magic longsword
           2391, -- war hammer
           2393, -- giant sword
           2401, -- staff
           2408, -- warlord sword
           2413, -- broadsword
           2414, -- dragon lance
           2415, -- great axe
           2425, -- obsidian lance
           2426, -- naginata
           2427, -- guardian halberd
           2433, -- enchanted staff
           2440, -- daramian waraxe
           2443, -- ravager's axe
           2444, -- hammer of wrath
           2447, -- twin axe
           2452, -- heavy mace
           2453, -- arcane staff
           2454, -- war axe
           2455, -- crossbow
           2456, -- bow
           2550, -- scythe
           3964, -- ripper lance
           5803, -- arbalest
           6528, -- the avenger
           6553, -- ruthless axe
           7379, -- brutetamer's staff
           7382, -- demonrage sword
           7386, -- mercenary sword
           7391, -- thaian sword
           7392, -- orcish maul
           7402, -- dragon slayer
           7403, -- berserker
           7405, -- havoc blade
           7406, -- blacksteel sword
           7407, -- haunted blade
           7413, -- titan axe
           7414, -- abyss hammer
           7423, -- skullcrusher
           7424, -- lunar staff
           7425, -- taurus mace
           7426, -- amber staff
           7427, -- chaos mace
           7428, -- bonebreaker
           7436, -- angelic axe
           7449, -- crystal sword
           7450, -- hammer of prophecy
           7452, -- spiked squelcher
           7453, -- executioner
           7454, -- glorious axe
           7747, -- fiery blacksteel sword
           7748, -- fiery dragon slayer
           7752, -- fiery headchopper
           7753, -- fiery war axe
           7757, -- fiery orcish maul
           7758, -- fiery war hammer
           7766, -- icy blacksteel sword
           7767, -- icy dragon slayer
           7771, -- icy headchopper
           7772, -- icy war axe
           7776, -- icy orcish maul
           7777, -- icy war hammer
           7857, -- earth blacksteel sword
           7858, -- earth dragon slayer
           7862, -- earth headchopper
           7863, -- earth war axe
           7867, -- earth orcish maul
           7868, -- earth war hammer
           7872, -- energy blacksteel sword
           7873, -- energy dragon slayer
           7877, -- energy headchopper
           7878, -- energy war axe
           7882, -- energy orcish maul
           7883, -- energy war hammer
           8926, -- demonwing axe
           8929, -- the stomper
           8932, -- the calamity
           10301, -- scythe of the reaper
           10303, -- farmer's avenger
           11305, -- drakinata
           11306, -- sai
           11308, -- drachaku
           11309, -- twin hooks
           11323, -- Zaoan halberd
           12613, -- twiceslicer
           13838, -- heavy trident
           13873, -- shimmer bow
           15400, -- deepling staff
           15454, -- guardian axe
           20108, -- pair of iron fists
           22401, -- crude umbral slayer
           22402, -- umbral slayer
           22403, -- umbral master slayer
           22407, -- crude umbral chopper
           22408, -- umbral chopper
           22409, -- umbral master chopper
           22413, -- crude umbral hammer
           22414, -- umbral hammer
           22415 -- umbral master hammer
       }
   
       local function isItemTwoHanded(itemid)
           return isInArray(two_handed_melee, itemid)
       end

       if leftItem then
           if isItemTwoHanded(leftItem:getId()) then
               local damage = math.floor((attacker:getEffectiveSkillLevel(SKILL_STRENGHT) * 0.2) + 2)
               attacker:addDamageCondition(creature, CONDITION_BLEEDING, DAMAGELIST_CONSTANT_PERIOD, creature:isPlayer() and damage / 4 or damage, 1, 1)
           end
       elseif rightItem then
           if isItemTwoHanded(rightItem:getId()) then
               local damage = math.floor((attacker:getEffectiveSkillLevel(SKILL_STRENGHT) * 0.2) + 2)
               attacker:addDamageCondition(creature, CONDITION_BLEEDING, DAMAGELIST_CONSTANT_PERIOD, creature:isPlayer() and damage / 4 or damage, 1, 1)
           end
       end
   end
   return primaryDamage, primaryType, secondaryDamage, secondaryType
end
 
Working two-handed melee weapon giving bonus bleeding damage:
After player hits another player wielding a two-handed melee weapon. He has 50% of chance of giving an extra bleeding hit based on his skill (you will have to make a change on this part cause my server just have one melee skill - strenght).
Lua:
function onHealthChange(creature, attacker, primaryDamage, primaryType, secondaryDamage, secondaryType, origin)
   if math.random(1, 100) > 50 then
       local leftItem = attacker:getSlotItem(CONST_SLOT_LEFT)
       local rightItem = attacker:getSlotItem(CONST_SLOT_RIGHT)
       local two_handed_melee = {
           2377, -- two handed sword
           2378, -- battle axe
           2381, -- halberd
           2387, -- double axe
           2390, -- magic longsword
           2391, -- war hammer
           2393, -- giant sword
           2401, -- staff
           2408, -- warlord sword
           2413, -- broadsword
           2414, -- dragon lance
           2415, -- great axe
           2425, -- obsidian lance
           2426, -- naginata
           2427, -- guardian halberd
           2433, -- enchanted staff
           2440, -- daramian waraxe
           2443, -- ravager's axe
           2444, -- hammer of wrath
           2447, -- twin axe
           2452, -- heavy mace
           2453, -- arcane staff
           2454, -- war axe
           2455, -- crossbow
           2456, -- bow
           2550, -- scythe
           3964, -- ripper lance
           5803, -- arbalest
           6528, -- the avenger
           6553, -- ruthless axe
           7379, -- brutetamer's staff
           7382, -- demonrage sword
           7386, -- mercenary sword
           7391, -- thaian sword
           7392, -- orcish maul
           7402, -- dragon slayer
           7403, -- berserker
           7405, -- havoc blade
           7406, -- blacksteel sword
           7407, -- haunted blade
           7413, -- titan axe
           7414, -- abyss hammer
           7423, -- skullcrusher
           7424, -- lunar staff
           7425, -- taurus mace
           7426, -- amber staff
           7427, -- chaos mace
           7428, -- bonebreaker
           7436, -- angelic axe
           7449, -- crystal sword
           7450, -- hammer of prophecy
           7452, -- spiked squelcher
           7453, -- executioner
           7454, -- glorious axe
           7747, -- fiery blacksteel sword
           7748, -- fiery dragon slayer
           7752, -- fiery headchopper
           7753, -- fiery war axe
           7757, -- fiery orcish maul
           7758, -- fiery war hammer
           7766, -- icy blacksteel sword
           7767, -- icy dragon slayer
           7771, -- icy headchopper
           7772, -- icy war axe
           7776, -- icy orcish maul
           7777, -- icy war hammer
           7857, -- earth blacksteel sword
           7858, -- earth dragon slayer
           7862, -- earth headchopper
           7863, -- earth war axe
           7867, -- earth orcish maul
           7868, -- earth war hammer
           7872, -- energy blacksteel sword
           7873, -- energy dragon slayer
           7877, -- energy headchopper
           7878, -- energy war axe
           7882, -- energy orcish maul
           7883, -- energy war hammer
           8926, -- demonwing axe
           8929, -- the stomper
           8932, -- the calamity
           10301, -- scythe of the reaper
           10303, -- farmer's avenger
           11305, -- drakinata
           11306, -- sai
           11308, -- drachaku
           11309, -- twin hooks
           11323, -- Zaoan halberd
           12613, -- twiceslicer
           13838, -- heavy trident
           13873, -- shimmer bow
           15400, -- deepling staff
           15454, -- guardian axe
           20108, -- pair of iron fists
           22401, -- crude umbral slayer
           22402, -- umbral slayer
           22403, -- umbral master slayer
           22407, -- crude umbral chopper
           22408, -- umbral chopper
           22409, -- umbral master chopper
           22413, -- crude umbral hammer
           22414, -- umbral hammer
           22415 -- umbral master hammer
       }
 
       local function isItemTwoHanded(itemid)
           return isInArray(two_handed_melee, itemid)
       end

       if leftItem then
           if isItemTwoHanded(leftItem:getId()) then
               local damage = math.floor((attacker:getEffectiveSkillLevel(SKILL_STRENGHT) * 0.2) + 2)
               attacker:addDamageCondition(creature, CONDITION_BLEEDING, DAMAGELIST_CONSTANT_PERIOD, creature:isPlayer() and damage / 4 or damage, 1, 1)
           end
       elseif rightItem then
           if isItemTwoHanded(rightItem:getId()) then
               local damage = math.floor((attacker:getEffectiveSkillLevel(SKILL_STRENGHT) * 0.2) + 2)
               attacker:addDamageCondition(creature, CONDITION_BLEEDING, DAMAGELIST_CONSTANT_PERIOD, creature:isPlayer() and damage / 4 or damage, 1, 1)
           end
       end
   end
   return primaryDamage, primaryType, secondaryDamage, secondaryType
end
Weapons table should be moved outside a function, creating new local function just for this table is overkill, i can see 2 possible errors in the code: while being hit by no attacker; while bleeding hit occurs on last hit.
Check this out.
Also why not scripting this in onUseWeapon function?

//
healing also stands for health change
 
Weapons table should be moved outside a function, creating new local function just for this table is overkill, i can see 2 possible errors in the code: while being hit by no attacker; while bleeding hit occurs on last hit.
Check this out.
Also why not scripting this in onUseWeapon function?

//


healing also stands for health change
Thats the kind of tip I was needing. Thanks!
Gonna try it and then come back later to give feedback.

Edit:
but you can also just simply do it through registering all two handed weapons in weapons.xml and then linking them to a script that applies the bleeding condition
LoL I saw that and somehow I've read movements.xml. The best tip was in the first comment since the beginning.

Edit: FINISHED
Code:
local combat = Combat()
combat:setParameter(COMBAT_PARAM_TYPE, COMBAT_PHYSICALDAMAGE)
combat:setParameter(COMBAT_PARAM_BLOCKARMOR, true)
combat:setParameter(COMBAT_PARAM_BLOCKSHIELD, true)
combat:setFormula(COMBAT_FORMULA_SKILL, 0, 0, 1, 0)

function onUseWeapon(player, variant)
   if not combat:execute(player, variant) then
       return false
   end

   if math.random(1, 100) <= 50 then
       return false
   end

   local damage = math.floor((player:getEffectiveSkillLevel(SKILL_STRENGHT) * 0.02) + 1)
   player:addDamageCondition(Creature(variant:getNumber()), CONDITION_BLEEDING, DAMAGELIST_CONSTANT_PERIOD, damage, 1, 4)
   return true
end

Edit:
Anyone know how to recognize when its a hit blocked by armor and a hit blocked by shield?
Cause the bleeding condition is being added even when player blocks hit. And I don't want that.
 
Last edited:
Back
Top