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

CreatureEvent Critical/Dodge System based on weaponSkill/speed TFS 1.2

Lubinho Fit

Member
Joined
May 10, 2017
Messages
37
Reaction score
8
Updated 05/08/2017
So this is my first "contribuition" it's a critical system based on the weapon that you use and a dodge system based on the player speed and free cap.
It has effects and texts for melee and ranged attacks. Wands/spells have only texts.

Monsters can crit/dodge and everything is based on the monster speed.
If something go wrong maybe i can help, but its my first script so don't expect much support.

It couldn't be done without the help of @WibbenZ and @Static_ thx again !

+ Fixed fields/damage over time causing attacker nil values
+ Fixed dodge on healing spells
+ Fixed dodge calculation


Register in creatureScript:

XML:
<event type="HealthChange" name="criticoMonstros" script="criticoMonstros.lua" />

Register in login.lua
Lua:
player:registerEvent("criticoMonstros")

And for every monster (sorry i don't know how to make it work for every monster without this)
XML:
<script>
<event name="criticoMonstros"/>
</script>

Create a script in creature scripts:
Lua:
--Config crit chance PS: Values are in % of skill level and using a range 0 to 1
	local critChance = {
		Sword	= 0.75,
		Axe		= 0.6,
		Club	= 0.5,
		Dist	= 0.75,
		Magic	= 0.75
	}

	--Config crit damage by weapon type
	
	local critDmg = {
		Sword	= 0.3,
		Axe		= 0.3,
		Club	= 0.3,
		Dist	= 0.3,
		Magic	= 0.5
	}

function onHealthChange(creature, attacker, primaryDamage, primaryType, secondaryDamage, secondaryType, origin)
	--If its a field or damage over time
	if Tile(creature:getPosition()):hasFlag(TILESTATE_MAGICFIELD) == TRUE or attacker == nil then
		return primaryDamage, primaryType, secondaryDamage, secondaryType	
	end

	--If its not a player or monster attacking
	if not attacker:isPlayer() and not attacker:isMonster() then
		return primaryDamage, primaryType, secondaryDamage, secondaryType		
	end

	local pDam, pCap = 0, 0
	local dodge = false
	
	--Calculate Crit chance of monsters
    if attacker:isMonster() and not creature:isMonster() then		
		if attacker:getSpeed() * 0.08 > math.random(100) then
			pDam = primaryDamage * 0.5
		end		
    end

	--Calculate DODGE chance of monsters
	if creature:isMonster() and attacker:isPlayer() and primaryType ~= COMBAT_HEALING then
		if creature:getSpeed() * 0.08 > math.random(100) then
			dodge = true
			creature:say("DODGE".. pDam, TALKTYPE_MONSTER_SAY)
		end
	end

	--Calculate CRIT chance of players
    if attacker:isPlayer() then 
		--The chance of critical is based on the weapon type, the same for crit damage
		if attacker:getWeaponType() == WEAPON_SWORD and math.random(100) <= attacker:getSkillLevel(SKILL_SWORD) * critChance.Sword then
			pDam = ((attacker:getSkillLevel(SKILL_SWORD) * critDmg.Sword)		/ 100) * primaryDamage		
		elseif attacker:getWeaponType() == WEAPON_AXE and math.random(100) <= attacker:getSkillLevel(SKILL_AXE) * critChance.Axe then
			pDam = ((attacker:getSkillLevel(SKILL_AXE) * critDmg.Axe)			/ 100) * primaryDamage		
		elseif attacker:getWeaponType() == WEAPON_CLUB and math.random(100) <= attacker:getSkillLevel(SKILL_CLUB) * critChance.Club then
			pDam = ((attacker:getSkillLevel(SKILL_CLUB) * critDmg.Club)			/ 100) * primaryDamage		
		elseif attacker:getWeaponType() == WEAPON_DISTANCE and math.random(100) <= attacker:getSkillLevel(SKILL_DISTANCE) * critChance.Dist then
			pDam = ((attacker:getSkillLevel(SKILL_DISTANCE) * critDmg.Dist)		/ 100) * primaryDamage		
		elseif attacker:getWeaponType() == WEAPON_WAND and math.random(100) <= attacker:getMagicLevel(SKILL_MAGLEVEL) * critChance.Magic then
			pDam = ((attacker:getMagicLevel(SKILL_MAGLEVEL) * critDmg.Magic)	/ 100) * primaryDamage
		end
    end

	--Calculate DODGE chance of players
	if creature:isPlayer() and primaryType ~= COMBAT_HEALING then
		--Get's the free % of the capacity
		pCap = getPlayerFreeCap(creature) / (creature:getCapacity() / 100)

		--The calculation is based on speed and % of free capacity (cap)
		if ((creature:getSpeed() / 2) * 0.05) * (pCap * 1.5/1) > math.random(100)  then			
			dodge = true
			creature:say("DODGE", TALKTYPE_MONSTER_SAY)
		end
	end

	--If its a Critical show message
	if pDam ~= 0 then
		if origin == ORIGIN_RANGED then
			creature:say("HEADSHOT!", TALKTYPE_MONSTER_SAY)
			creature:getPosition():sendMagicEffect(CONST_ME_EXPLOSIONAREA)        
        elseif origin == ORIGIN_MELEE then
            attacker:say("CRITICAL!", TALKTYPE_MONSTER_SAY)
			creature:getPosition():sendMagicEffect(CONST_ME_HITAREA)
		elseif origin == ORIGIN_SPELL then
			if primaryType == 2 then
					attacker:say("ELECTROCUTE!", TALKTYPE_MONSTER_SAY)
				elseif primaryType == 512 then
					attacker:say("FREEZE!", TALKTYPE_MONSTER_SAY)
				elseif primaryType == 8 then
					attacker:say("BURN!", TALKTYPE_MONSTER_SAY)
				elseif primaryType == 2048 then
					attacker:say("EMBRACE!", TALKTYPE_MONSTER_SAY)
				elseif primaryType == 1024 then
					attacker:say("PURIFY!", TALKTYPE_MONSTER_SAY)
				elseif primaryType == 128 then
					attacker:say("REVIVE!", TALKTYPE_MONSTER_SAY)
				elseif primaryType == 1 then
					attacker:say("CRITICAL!", TALKTYPE_MONSTER_SAY)
				elseif primaryType == 4 then
					attacker:say("THORN!", TALKTYPE_MONSTER_SAY)
			end
        end
	end

	--If dodged
	if dodge then
		return primaryDamage - primaryDamage, primaryType, secondaryDamage - secondaryDamage, secondaryType
	else
		--If critted
		if pDam ~= 0 then
			if attacker:isPlayer() then
				attacker:sendTextMessage((MESSAGE_DAMAGE_DEALT), "Critical Hit: +".. pDam .." DMG")
				return primaryDamage + pDam, primaryType, secondaryDamage, secondaryType
			else
				attacker:say("Crit: ".. pDam, TALKTYPE_MONSTER_SAY)
				return primaryDamage + pDam, primaryType, secondaryDamage, secondaryType
			end
		end
		
		--Normal damage
		return primaryDamage, primaryType, secondaryDamage, secondaryType		
	end
	
end
 
Last edited by a moderator:
So this is my first "contribuition" it's a critical system based on the weapon that you use and a dodge system based on the player speed and free cap.
It has effects and texts for melee and ranged attacks. Wands/spells have only texts.

Monsters can crit/dodge and everything is based on the monster speed.
If something go wrong maybe i can help, but its my first script so don't expect much support.

It couldn't be done without the help of @WibbenZ and @Static_ thx again !

Register in creatureScript:

Code:
<event type="HealthChange" name="criticoMonstros" script="criticoMonstros.lua" />

Register in login.lua
Code:
player:registerEvent("criticoMonstros")

And for every monster (sorry i don't know how to make it work for every monster without this)
Code:
<script>
<event name="criticoMonstros"/>
</script>

Create a script in creature scripts:
Lua:
function onHealthChange(creature, attacker, primaryDamage, primaryType, secondaryDamage, secondaryType, origin)

    --If its not a player or monster attacking
    if not attacker:isPlayer() and not attacker:isMonster() then
        return primaryDamage, primaryType, secondaryDamage, secondaryType      
    end

    local pDam, pCap = 0, 0
    local dodge = false

    --Config crit chance PS: Values are in % of skill level and using a range 0 to 1
    local critChance = {
        Sword    = 0.75,
        Axe        = 0.6,
        Club    = 0.5,
        Dist    = 0.75,
        Magic    = 0.75
    }

    --Config crit damage by weapon type
  
    local critDmg = {
        Sword    = 0.3,
        Axe        = 0.3,
        Club    = 0.3,
        Dist    = 0.3,
        Magic    = 0.5
    }
  
    --Calculate Crit chance of monsters
    if attacker:isMonster() and not creature:isMonster() then      
        if attacker:getSpeed() * 0.08 > math.random(100) then
            pDam = primaryDamage * 0.5
            attacker:say("Crit: ".. pDam, TALKTYPE_MONSTER_SAY)
        end      
    end

    --Calculate DODGE chance of monsters
    if creature:isMonster() and attacker:isPlayer() then
        if creature:getSpeed() * 0.08 > math.random(100) then
            dodge = true
            creature:say("DODGE".. pDam, TALKTYPE_MONSTER_SAY)
        end
    end

    --Calculate CRIT chance of players
    if attacker:isPlayer() then
        --The chance of critical is based on the weapon type, the same for crit damage
        if attacker:getWeaponType() == WEAPON_SWORD and math.random(100) <= attacker:getSkillLevel(SKILL_SWORD) * critChance.Sword then
            pDam = ((attacker:getSkillLevel(SKILL_SWORD) * critDmg.Sword)        / 100) * primaryDamage      
        elseif attacker:getWeaponType() == WEAPON_AXE and math.random(100) <= attacker:getSkillLevel(SKILL_AXE) * critChance.Axe then
            pDam = ((attacker:getSkillLevel(SKILL_AXE) * critDmg.Axe)            / 100) * primaryDamage      
        elseif attacker:getWeaponType() == WEAPON_CLUB and math.random(100) <= attacker:getSkillLevel(SKILL_CLUB) * critChance.Club then
            pDam = ((attacker:getSkillLevel(SKILL_CLUB) * critDmg.Club)            / 100) * primaryDamage      
        elseif attacker:getWeaponType() == WEAPON_DISTANCE and math.random(100) <= attacker:getSkillLevel(SKILL_DISTANCE) * critChance.Dist then
            pDam = ((attacker:getSkillLevel(SKILL_DISTANCE) * critDmg.Dist)        / 100) * primaryDamage      
        elseif attacker:getWeaponType() == WEAPON_WAND and math.random(100) <= attacker:getMagicLevel(SKILL_MAGLEVEL) * critChance.Magic then
            pDam = ((attacker:getMagicLevel(SKILL_MAGLEVEL) * critDmg.Magic)    / 100) * primaryDamage
        end
    end

    --Calculate DODGE chance of players
    if creature:isPlayer() then
        --Get's the free % of the capacity
        pCap = (getPlayerFreeCap(creature) * 100)  / (creature:getCapacity() / 100)

        --The calculation is based on speed and % of free capacity (cap)
        if ((creature:getSpeed() / 2) * 0.05) * (pCap * 0.5) > math.random(100)  then          
            dodge = true
            creature:say("DODGE", TALKTYPE_MONSTER_SAY)
        end
    end

    --If its a Critical show message
    if pDam ~= 0 then
        if origin == ORIGIN_RANGED then
            creature:say("HEADSHOT!", TALKTYPE_MONSTER_SAY)
            creature:getPosition():sendMagicEffect(CONST_ME_EXPLOSIONAREA)      
        elseif origin == ORIGIN_MELEE then
            attacker:say("CRITICAL!", TALKTYPE_MONSTER_SAY)
            creature:getPosition():sendMagicEffect(CONST_ME_HITAREA)
        elseif origin == ORIGIN_SPELL then
            if primaryType == 2 then
                    attacker:say("ELECTROCUTE!", TALKTYPE_MONSTER_SAY)
                elseif primaryType == 512 then
                    attacker:say("FREEZE!", TALKTYPE_MONSTER_SAY)
                elseif primaryType == 8 then
                    attacker:say("BURN!", TALKTYPE_MONSTER_SAY)
                elseif primaryType == 2048 then
                    attacker:say("EMBRACE!", TALKTYPE_MONSTER_SAY)
                elseif primaryType == 1024 then
                    attacker:say("PURIFY!", TALKTYPE_MONSTER_SAY)
                elseif primaryType == 128 then
                    attacker:say("REVIVE!", TALKTYPE_MONSTER_SAY)
                elseif primaryType == 1 then
                    attacker:say("CRITICAL!", TALKTYPE_MONSTER_SAY)
                elseif primaryType == 4 then
                    attacker:say("THORN!", TALKTYPE_MONSTER_SAY)
            end
        end
    end

    --If dodged
    if dodge then
        return primaryDamage - primaryDamage, primaryType, secondaryDamage - secondaryDamage, secondaryType
    else
        --If critted
        if pDam ~= 0 then
            attacker:sendTextMessage((MESSAGE_DAMAGE_DEALT), "Critical Hit: +".. pDam .." DMG")
            return primaryDamage + pDam, primaryType, secondaryDamage, secondaryType      
        end
      
        --Normal damage
        return primaryDamage, primaryType, secondaryDamage, secondaryType      
    end
  
end

--[[
VIS     2
FRIGO     512
FLAM     8
MORT     2048
HOLY     1024
HEAL    128
PHYS    1
TERA    4
]]--

--print(getPlayerFreeCap(attacker))
--print(attacker:getCapacity())

A tip is to move these from the scope;
Lua:
    local pDam, pCap = 0, 0
    local dodge = false

    --Config crit chance PS: Values are in % of skill level and using a range 0 to 1
    local critChance = {
        Sword    = 0.75,
        Axe        = 0.6,
        Club    = 0.5,
        Dist    = 0.75,
        Magic    = 0.75
    }

    --Config crit damage by weapon type
   
    local critDmg = {
        Sword    = 0.3,
        Axe        = 0.3,
        Club    = 0.3,
        Dist    = 0.3,
        Magic    = 0.5
    }

Above this line;
Lua:
function onHealthChange(creature, attacker, primaryDamage, primaryType, secondaryDamage, secondaryType, origin)
 
Lua:
    --If its not a player or monster attacking
    if not attacker:isPlayer() or not attacker:isMonster() then
        return primaryDamage, primaryType, secondaryDamage, secondaryType
    end

Why this part do not work? Fields on map are broken and console searching for arttackers when some1 step on ;o
 
A tip is to move these from the scope;
Lua:
    local pDam, pCap = 0, 0
    local dodge = false

    --Config crit chance PS: Values are in % of skill level and using a range 0 to 1
    local critChance = {
        Sword    = 0.75,
        Axe        = 0.6,
        Club    = 0.5,
        Dist    = 0.75,
        Magic    = 0.75
    }

    --Config crit damage by weapon type
  
    local critDmg = {
        Sword    = 0.3,
        Axe        = 0.3,
        Club    = 0.3,
        Dist    = 0.3,
        Magic    = 0.5
    }

Above this line;
Lua:
function onHealthChange(creature, attacker, primaryDamage, primaryType, secondaryDamage, secondaryType, origin)

Thx but how can i edit the thread? I already made the modification

Lua:
    --If its not a player or monster attacking
    if not attacker:isPlayer() or not attacker:isMonster() then
        return primaryDamage, primaryType, secondaryDamage, secondaryType
    end

Why this part do not work? Fields on map are broken and console searching for arttackers when some1 step on ;o

Right now idk cause i forgot to test it! But tonight im going to try to fix it thx for the bug report ! :D

Lua:
    --If its not a player or monster attacking
    if not attacker:isPlayer() or not attacker:isMonster() then
        return primaryDamage, primaryType, secondaryDamage, secondaryType
    end

Why this part do not work? Fields on map are broken and console searching for arttackers when some1 step on ;o

Ok i managed to make it work!

Right after the function paste this

Lua:
if ORIGIN_CONDITION then
        return primaryDamage, primaryType, secondaryDamage, secondaryType   
    end

it should look like this
Code:
function onHealthChange(creature, attacker, primaryDamage, primaryType, secondaryDamage, secondaryType, origin)
    if ORIGIN_CONDITION then
        return primaryDamage, primaryType, secondaryDamage, secondaryType   
    end

i already contacted a mod to edit the thread, because the Dodge calculation is wrong

Replace the old one with this!

Lua:
--Calculate DODGE chance of players
    if creature:isPlayer() then
        --Get's the free % of the capacity
        pCap = getPlayerFreeCap(creature) / (creature:getCapacity() / 100)

        --The calculation is based on speed and % of free capacity (cap)
        if ((creature:getSpeed() / 2) * 0.05) * (pCap * 1.5/1) > math.random(100)  then           
            dodge = true
            creature:say("DODGE", TALKTYPE_MONSTER_SAY)
        end
    end

Lua:
    --If its not a player or monster attacking
    if not attacker:isPlayer() or not attacker:isMonster() then
        return primaryDamage, primaryType, secondaryDamage, secondaryType
    end

Why this part do not work? Fields on map are broken and console searching for arttackers when some1 step on ;o

Ok sorry like I said I don't know alot about scripting my last fix got all the crits with magic to be removed but i managed to make it work with everything just replace your main script with this:

Lua:
--Config crit chance PS: Values are in % of skill level and using a range 0 to 1
    local critChance = {
        Sword    = 0.75,
        Axe        = 0.6,
        Club    = 0.5,
        Dist    = 0.75,
        Magic    = 0.75
    }

    --Config crit damage by weapon type
   
    local critDmg = {
        Sword    = 0.3,
        Axe        = 0.3,
        Club    = 0.3,
        Dist    = 0.3,
        Magic    = 0.5
    }

function onHealthChange(creature, attacker, primaryDamage, primaryType, secondaryDamage, secondaryType, origin)
    --If its a field or damage over time
    if Tile(creature:getPosition()):hasFlag(TILESTATE_MAGICFIELD) == TRUE or attacker == nil then
        return primaryDamage, primaryType, secondaryDamage, secondaryType   
    end

    --If its not a player or monster attacking
    if not attacker:isPlayer() and not attacker:isMonster() then
        return primaryDamage, primaryType, secondaryDamage, secondaryType       
    end

    local pDam, pCap = 0, 0
    local dodge = false
   
    --Calculate Crit chance of monsters
    if attacker:isMonster() and not creature:isMonster() then       
        if attacker:getSpeed() * 0.08 > math.random(100) then
            pDam = primaryDamage * 0.5
        end       
    end

    --Calculate DODGE chance of monsters
    if creature:isMonster() and attacker:isPlayer() then
        if creature:getSpeed() * 0.08 > math.random(100) then
            dodge = true
            creature:say("DODGE".. pDam, TALKTYPE_MONSTER_SAY)
        end
    end

    --Calculate CRIT chance of players
    if attacker:isPlayer() then
        --The chance of critical is based on the weapon type, the same for crit damage
        if attacker:getWeaponType() == WEAPON_SWORD and math.random(100) <= attacker:getSkillLevel(SKILL_SWORD) * critChance.Sword then
            pDam = ((attacker:getSkillLevel(SKILL_SWORD) * critDmg.Sword)        / 100) * primaryDamage       
        elseif attacker:getWeaponType() == WEAPON_AXE and math.random(100) <= attacker:getSkillLevel(SKILL_AXE) * critChance.Axe then
            pDam = ((attacker:getSkillLevel(SKILL_AXE) * critDmg.Axe)            / 100) * primaryDamage       
        elseif attacker:getWeaponType() == WEAPON_CLUB and math.random(100) <= attacker:getSkillLevel(SKILL_CLUB) * critChance.Club then
            pDam = ((attacker:getSkillLevel(SKILL_CLUB) * critDmg.Club)            / 100) * primaryDamage       
        elseif attacker:getWeaponType() == WEAPON_DISTANCE and math.random(100) <= attacker:getSkillLevel(SKILL_DISTANCE) * critChance.Dist then
            pDam = ((attacker:getSkillLevel(SKILL_DISTANCE) * critDmg.Dist)        / 100) * primaryDamage       
        elseif attacker:getWeaponType() == WEAPON_WAND and math.random(100) <= attacker:getMagicLevel(SKILL_MAGLEVEL) * critChance.Magic then
            pDam = ((attacker:getMagicLevel(SKILL_MAGLEVEL) * critDmg.Magic)    / 100) * primaryDamage
        end
    end

    --Calculate DODGE chance of players
    if creature:isPlayer() then
        --Get's the free % of the capacity
        pCap = getPlayerFreeCap(creature) / (creature:getCapacity() / 100)

        --The calculation is based on speed and % of free capacity (cap)
        if ((creature:getSpeed() / 2) * 0.05) * (pCap * 1.5/1) > math.random(100)  then           
            dodge = true
            creature:say("DODGE", TALKTYPE_MONSTER_SAY)
        end
    end

    --If its a Critical show message
    if pDam ~= 0 then
        if origin == ORIGIN_RANGED then
            creature:say("HEADSHOT!", TALKTYPE_MONSTER_SAY)
            creature:getPosition():sendMagicEffect(CONST_ME_EXPLOSIONAREA)       
        elseif origin == ORIGIN_MELEE then
            attacker:say("CRITICAL!", TALKTYPE_MONSTER_SAY)
            creature:getPosition():sendMagicEffect(CONST_ME_HITAREA)
        elseif origin == ORIGIN_SPELL then
            if primaryType == 2 then
                    attacker:say("ELECTROCUTE!", TALKTYPE_MONSTER_SAY)
                elseif primaryType == 512 then
                    attacker:say("FREEZE!", TALKTYPE_MONSTER_SAY)
                elseif primaryType == 8 then
                    attacker:say("BURN!", TALKTYPE_MONSTER_SAY)
                elseif primaryType == 2048 then
                    attacker:say("EMBRACE!", TALKTYPE_MONSTER_SAY)
                elseif primaryType == 1024 then
                    attacker:say("PURIFY!", TALKTYPE_MONSTER_SAY)
                elseif primaryType == 128 then
                    attacker:say("REVIVE!", TALKTYPE_MONSTER_SAY)
                elseif primaryType == 1 then
                    attacker:say("CRITICAL!", TALKTYPE_MONSTER_SAY)
                elseif primaryType == 4 then
                    attacker:say("THORN!", TALKTYPE_MONSTER_SAY)
            end
        end
    end

    --If dodged
    if dodge then
        return primaryDamage - primaryDamage, primaryType, secondaryDamage - secondaryDamage, secondaryType
    else
        --If critted
        if pDam ~= 0 then
            if attacker:isPlayer() then
                attacker:sendTextMessage((MESSAGE_DAMAGE_DEALT), "Critical Hit: +".. pDam .." DMG")
                return primaryDamage + pDam, primaryType, secondaryDamage, secondaryType
            else
                attacker:say("Crit: ".. pDam, TALKTYPE_MONSTER_SAY)
                return primaryDamage + pDam, primaryType, secondaryDamage, secondaryType
            end
        end
       
        --Normal damage
        return primaryDamage, primaryType, secondaryDamage, secondaryType       
    end
   
end

--[[
VIS     2
FRIGO     512
FLAM     8
MORT     2048
HOLY     1024
HEAL    128
PHYS    1
TERA    4
]]--

--print(getPlayerFreeCap(attacker))
--print(attacker:getCapacity())

If someone comes up with a new feature let me know i would love to improve the script and my knowledge thx and sorry for the triple post :S
 
Last edited by a moderator:
i have 1 erro in console :(

ngvei0.png
 
Hi, this don't work. Why?

Lua:
    --Calculate DODGE chance of monsters
    if creature:isMonster() and attacker:isPlayer() and primaryType ~= COMBAT_HEALING then
        if creature:getSpeed() * 0.08 > math.random(100) then
            dodge = true
            creature:say("DODGE".. pDam, TALKTYPE_MONSTER_SAY)
        end
    end

I change to test and it does not show anything:

Lua:
    --Calculate DODGE chance of monsters
    if creature:isMonster() and attacker:isPlayer() and primaryType ~= COMBAT_HEALING then
            dodge = true
            creature:say("DODGE".. pDam, TALKTYPE_MONSTER_SAY)
            print("Dodge!!!")
    end

Sorry I cant edit IDK.

But my problem is in:
Lua:
    --Calculate CRIT chance of players
    if attacker:isPlayer() then
        --The chance of critical is based on the weapon type, the same for crit damage
        if attacker:getWeaponType() == WEAPON_SWORD and math.random(100) <= attacker:getSkillLevel(SKILL_SWORD) * critChance.Sword then
            pDam = ((attacker:getSkillLevel(SKILL_SWORD) * critDmg.Sword)       / 100) * primaryDamage    
        elseif attacker:getWeaponType() == WEAPON_AXE and math.random(100) <= attacker:getSkillLevel(SKILL_AXE) * critChance.Axe then
            pDam = ((attacker:getSkillLevel(SKILL_AXE) * critDmg.Axe)           / 100) * primaryDamage    
        elseif attacker:getWeaponType() == WEAPON_CLUB and math.random(100) <= attacker:getSkillLevel(SKILL_CLUB) * critChance.Club then
            pDam = ((attacker:getSkillLevel(SKILL_CLUB) * critDmg.Club)         / 100) * primaryDamage    
        elseif attacker:getWeaponType() == WEAPON_DISTANCE and math.random(100) <= attacker:getSkillLevel(SKILL_DISTANCE) * critChance.Dist then
            pDam = ((attacker:getSkillLevel(SKILL_DISTANCE) * critDmg.Dist)     / 100) * primaryDamage    
        elseif attacker:getWeaponType() == WEAPON_WAND and math.random(100) <= attacker:getMagicLevel(SKILL_MAGLEVEL) * critChance.Magic then
            pDam = ((attacker:getMagicLevel(SKILL_MAGLEVEL) * critDmg.Magic)    / 100) * primaryDamage
        end
    end

I change to see and dont work:
Code:
    if attacker:isPlayer() then
        pDam = 100
    end
 
Last edited by a moderator:
how to work in mana too?
i try it:
Code:
function onManaChange(creature, attacker, manaChange, origin)
if not isPlayer(creature) then return false end
    if (creature:getDodgeLevel() * 3) >= math.random (0, 1000) and isCreature(attacker) then
        if isInArray({ORIGIN_MELEE, ORIGIN_RANGED, ORIGIN_SPELL}, origin) and primaryType ~= COMBAT_HEALING then
            primaryDamage = primaryDamage - math.ceil(primaryDamage * DODGE.PERCENT)
            creature:say("DODGE!", TALKTYPE_MONSTER_SAY)
            creature:getPosition():sendMagicEffect(CONST_ME_BLOCKHIT)
        end
    end
    return primaryDamage, primaryType, secondaryDamage, secondaryType
end

but not work =/
 
Back
Top