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

RevScripts I need a Dodge&Critical system

Create a File on data/lib with name : dodgeCritical.lua
Lua:
--[[
   NBsao
--]]
STORAGEVALUE_DODGE = 48900
STORAGEVALUE_CRITICAL = 48901

DODGE = {
    LEVEL_MAX = 100, -- max lvl of dodge
    PERCENT = 0.2 -- % def
}

CRITICAL = {
    LEVEL_MAX = 100, -- máxi level critical
    PERCENT = 0.2 -- % attack
}

function Player.getDodgeLevel(self)
    return self:getStorageValue(STORAGEVALUE_DODGE)
end

function Player.setDodgeLevel(self, value)
    return self:setStorageValue(STORAGEVALUE_DODGE, value)
end

function Player.getCriticalLevel(self)
    return self:getStorageValue(STORAGEVALUE_CRITICAL)
end

function Player.setCriticalLevel(self, value)
    return self:setStorageValue(STORAGEVALUE_CRITICAL, value)
end

register the event on lib.lua file too

later go to datacreaturescripts/scripts and create a file with name dodgeCritical.lua


Code:
--[[
   NBsao
--]]
  function onHealthChange(creature, attacker, primaryDamage, primaryType, secondaryDamage, secondaryType, origin)

    if (not attacker or not creature) then
        return primaryDamage, primaryType, secondaryDamage, secondaryType
    end

    if primaryType == COMBAT_HEALING then
        return primaryDamage, primaryType, secondaryDamage, secondaryType
    end

    if ((creature:getDodgeLevel() * 3) >= math.random (0, 1000) and creature:isPlayer()) then
        primaryDamage = 0
        secondaryDamage = 0
        creature:say("DODGE!", TALKTYPE_MONSTER_SAY)
        creature:getPosition():sendMagicEffect(CONST_ME_BLOCKHIT)
    end

    if (attacker:isPlayer() and (attacker:getCriticalLevel() * 3) >= math.random (0, 1000)) then
        primaryDamage = primaryDamage + math.ceil(primaryDamage * CRITICAL.PERCENT)
        attacker:say("CRITICAL!", TALKTYPE_MONSTER_SAY)
        creature:getPosition():sendMagicEffect(CONST_ME_EXPLOSIONHIT)
    end

    return primaryDamage, primaryType, secondaryDamage, secondaryType
end

<event type="healthchange" name="DodgeCritical" script="dodgeCritical.lua"/>

then create another file with name dodgeMana.lua
Code:
--[[
   NBsao
--]]
function onManaChange(creature, attacker, primaryDamage, primaryType, secondaryDamage, secondaryType, origin)
 
    if (not attacker or not creature) then
        return primaryDamage, primaryType, secondaryDamage, secondaryType
    end
 
    if ((creature:getDodgeLevel() * 3) >= math.random (0, 1000) and creature:isPlayer())  then
        primaryDamage = 0
        secondaryDamage = 0
        creature:say("DODGE!", TALKTYPE_MONSTER_SAY)
        creature:getPosition():sendMagicEffect(CONST_ME_BLOCKHIT)
    end
    return primaryDamage, primaryType, secondaryDamage, secondaryType
end
<event type="manachange" name="DodgeMana" script="dodgeMana.lua"/>

register no login.lua
Code:
player:registerEvent("DodgeCritical")
player:registerEvent("DodgeMana")
add on login.lua
if player:getDodgeLevel() == -1 then
player:setDodgeLevel(0)
end
if player:getCriticalLevel() == -1 then
player:setCriticalLevel(0)
end

finally scripts create a file with name dodgeCritical.lua
Code:
local dodge = TalkAction("!dodge")
local critical = TalkAction("!critical")

function dodge.onSay(player, words, param)
    local skill = player:getDodgeLevel()
    local message = "DODGE SYSTEM\nDodge will defend 1% of attacks.\n\nFor Example:\nEvery stone of you use will sent 0,3% of  chance.\nwith 10 stones, do you will have 3% of chance to defender 50% of attacks.\nwith 100 stones (max), do you will have 30% of chance defender 50% of attacks.\nEvery stone do you will use will upgrade 1 level of dodge.\n\n------------------\nDodge Skill: [" .. skill .. "/100]"
    doPlayerPopupFYI(player, message)
end

dodge:register()

function critical.onSay(player, words, param)
    local skill = player:getCriticalLevel()
    local message = "CRITICAL SYSTEM\.\nWith 10 stones, do you have 3% of chance to hit to oponents.\nWith 100 stones (max), do you will have a 30% of critical.\n1 stone will up 1 level of dodge.\n\n------------------\nCritical Skill: [" .. skill .. "/100]"
    doPlayerPopupFYI(player, message)
end

critical:register()
 
Last edited:
Create a File on data/lib with name : dodgeCritical.lua
Lua:
--[[
   NBsao
--]]
STORAGEVALUE_DODGE = 48900
STORAGEVALUE_CRITICAL = 48901

DODGE = {
    LEVEL_MAX = 100, -- max lvl of dodge
    PERCENT = 0.2 -- % def
}

CRITICAL = {
    LEVEL_MAX = 100, -- máxi level critical
    PERCENT = 0.2 -- % attack
}

function Player.getDodgeLevel(self)
    return self:getStorageValue(STORAGEVALUE_DODGE)
end

function Player.setDodgeLevel(self, value)
    return self:setStorageValue(STORAGEVALUE_DODGE, value)
end

function Player.getCriticalLevel(self)
    return self:getStorageValue(STORAGEVALUE_CRITICAL)
end

function Player.setCriticalLevel(self, value)
    return self:setStorageValue(STORAGEVALUE_CRITICAL, value)
end

register the event on lib.lua file too

later go to datacreaturescripts/scripts and create a file with name dodgeCritical.lua


Code:
--[[
   NBsao
--]]
  function onHealthChange(creature, attacker, primaryDamage, primaryType, secondaryDamage, secondaryType, origin)

    if (not attacker or not creature) then
        return primaryDamage, primaryType, secondaryDamage, secondaryType
    end

    if primaryType == COMBAT_HEALING then
        return primaryDamage, primaryType, secondaryDamage, secondaryType
    end

    if ((creature:getDodgeLevel() * 3) >= math.random (0, 1000) and creature:isPlayer()) then
        primaryDamage = 0
        secondaryDamage = 0
        creature:say("DODGE!", TALKTYPE_MONSTER_SAY)
        creature:getPosition():sendMagicEffect(CONST_ME_BLOCKHIT)
    end

    if (attacker:isPlayer() and (attacker:getCriticalLevel() * 3) >= math.random (0, 1000)) then
        primaryDamage = primaryDamage + math.ceil(primaryDamage * CRITICAL.PERCENT)
        attacker:say("CRITICAL!", TALKTYPE_MONSTER_SAY)
        creature:getPosition():sendMagicEffect(CONST_ME_EXPLOSIONHIT)
    end

    return primaryDamage, primaryType, secondaryDamage, secondaryType
end

<event type="healthchange" name="DodgeCritical" script="dodgeCritical.lua"/>

then create another file with name dodgeMana.lua
Code:
--[[
   NBsao
--]]
function onManaChange(creature, attacker, primaryDamage, primaryType, secondaryDamage, secondaryType, origin)
 
    if (not attacker or not creature) then
        return primaryDamage, primaryType, secondaryDamage, secondaryType
    end
 
    if ((creature:getDodgeLevel() * 3) >= math.random (0, 1000) and creature:isPlayer())  then
        primaryDamage = 0
        secondaryDamage = 0
        creature:say("DODGE!", TALKTYPE_MONSTER_SAY)
        creature:getPosition():sendMagicEffect(CONST_ME_BLOCKHIT)
    end
    return primaryDamage, primaryType, secondaryDamage, secondaryType
end
<event type="manachange" name="DodgeMana" script="dodgeMana.lua"/>

register no login.lua
Code:
player:registerEvent("DodgeCritical")
player:registerEvent("DodgeMana")
add on login.lua
if player:getDodgeLevel() == -1 then
player:setDodgeLevel(0)
end
if player:getCriticalLevel() == -1 then
player:setCriticalLevel(0)
end

finally on talkaction/scripts create a file with name dodgeCritical.lua
Code:
local dodge = TalkAction("!dodge")
local critical = TalkAction("!critical")

function dodge.onSay(player, words, param)
    local skill = player:getDodgeLevel()
    local message = "DODGE SYSTEM\nDodge will defend 1% of attacks.\n\nFor Example:\nEvery stone of you use will sent 0,3% of  chance.\nwith 10 stones, do you will have 3% of chance to defender 50% of attacks.\nwith 100 stones (max), do you will have 30% of chance defender 50% of attacks.\nEvery stone do you will use will upgrade 1 level of dodge.\n\n------------------\nDodge Skill: [" .. skill .. "/100]"
    doPlayerPopupFYI(player, message)
end

dodge:register()

function critical.onSay(player, words, param)
    local skill = player:getCriticalLevel()
    local message = "CRITICAL SYSTEM\.\nWith 10 stones, do you have 3% of chance to hit to oponents.\nWith 100 stones (max), do you will have a 30% of critical.\n1 stone will up 1 level of dodge.\n\n------------------\nCritical Skill: [" .. skill .. "/100]"
    doPlayerPopupFYI(player, message)
end

critical:register()
Lua:
[Warning - Event::checkScript] Can not load script: scripts/dodgeCritical.lua

data/talkactions/scripts/dodgeCritical.lua:13: invalid escape sequence near '"CRITICAL SYSTEM'

[Warning - Event::checkScript] Can not load script: scripts/dodgeCritical.lua

data/talkactions/scripts/dodgeCritical.lua:13: invalid escape sequence near '"CRITICAL SYSTEM'
I encountered that error
 
Lua:
[Warning - Event::checkScript] Can not load script: scripts/dodgeCritical.lua

data/talkactions/scripts/dodgeCritical.lua:13: invalid escape sequence near '"CRITICAL SYSTEM'

[Warning - Event::checkScript] Can not load script: scripts/dodgeCritical.lua

data/talkactions/scripts/dodgeCritical.lua:13: invalid escape sequence near '"CRITICAL SYSTEM'
I encountered that error
this is not talkactions, this is revscripts: data/scripts
 
try!
Lua:
local dodgeCmd = TalkAction("!dodge")
local criticalCmd = TalkAction("!critical")

function sendPopupFYI(player, message)
    player:popupFYI(message)
end

function dodgeCmd.onSay(player, words, param)
    local skill = player:getDodgeLevel()
    local message = [[
DODGE SYSTEM
Dodge will defend 1% of attacks.

For Example:
Every stone you use will add 0.3% chance.
With 10 stones, you will have 3% chance to defend against 50% of attacks.
With 100 stones (max), you will have 30% chance to defend against 50% of attacks.
Every stone you use will upgrade 1 level of dodge.

------------------
Dodge Skill: []] .. skill .. [[/100]
]]
    sendPopupFYI(player, message)
end

dodgeCmd:register()

function criticalCmd.onSay(player, words, param)
    local skill = player:getCriticalLevel()
    local message = [[
CRITICAL SYSTEM
With 10 stones, you have a 3% chance to hit opponents.
With 100 stones (max), you will have a 30% critical chance.
1 stone will increase 1 level of critical.

------------------
Critical Skill: []] .. skill .. [[/100]
]]
    sendPopupFYI(player, message)
end

criticalCmd:register()
 
Last edited:
Lua:
Lua Script Error: [Scripts Interface]
C:\Users\FOXCONN\Desktop\Edited Abdala Tfs 1.5\data\scripts\dodgeCritical.lua:callback
...top\Edited Abdala Tfs 1.5\data\scripts\dodgeCritical.lua:19: attempt to call method 'popupFY' (a nil value)
stack traceback:
        [C]: in function 'popupFY'
        ...top\Edited Abdala Tfs 1.5\data\scripts\dodgeCritical.lua:19: in function <...top\Edited Abdala Tfs 1.5\data\scripts\dodgeCritical.lua:4>

Lua Script Error: [Scripts Interface]
C:\Users\FOXCONN\Desktop\Edited Abdala Tfs 1.5\data\scripts\dodgeCritical.lua:callback
...top\Edited Abdala Tfs 1.5\data\scripts\dodgeCritical.lua:35: attempt to call method 'popupFY' (a nil value)
stack traceback:
        [C]: in function 'popupFY'
        ...top\Edited Abdala Tfs 1.5\data\scripts\dodgeCritical.lua:35: in function <...top\Edited Abdala Tfs 1.5\data\scripts\dodgeCritical.lua:24>
 
its work fine
Why doesn't it appear on players?
onlook
Also when I get 100 crictal it doesn't work
does not increase attack
Dodge Work fine
about onLook:
because u didnt requested about description editing, maybe instead of perma demands try it by doing yourself? its not a hard task since u have every function to get value from dodge / critical
 
If I'm attacking a player the Critical works well
If I'm attacking monsters it doesn't work
what is the reason
make this quick change and see
Lua:
if (attacker:isPlayer() and (attacker:getCriticalLevel() * 3) >= math.random (0, 1000)) then
to
Code:
if (creature:isPlayer() and (creature:getCriticalLevel() * 3) >= math.random (0, 1000)) then
now
Code:
attacker:say("CRITICAL!", TALKTYPE_MONSTER_SAY)
to
Code:
creature:say("CRITICAL!", TALKTYPE_MONSTER_SAY)
 
onHealthChange is triggered by the creature receiving the damage.

Thus, you need to register it to every player/monster who wants to use the specific systems.

Dodge, would be applied to players
Critical, would need to be applied to players & monsters.

onSpawn would be a good place to register it for all monsters.
 
Back
Top