abdala ragab
Veteran OT User
I need a Dodge&Critical system i use tfs 1.5
For the player, not the items
Thanks in advance
For the player, not the items
Thanks in advance
--[[
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
--[[
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"/>
--[[
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"/>
player:registerEvent("DodgeCritical")
player:registerEvent("DodgeMana")
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()
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
add on login.luaCode:player:registerEvent("DodgeCritical") player:registerEvent("DodgeMana")
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()
[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'
this is not talkactions, this is revscripts: data/scriptsI encountered that errorLua:[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'
this is not talkactions, this is revscripts: data/scripts
> dodgeCritical.lua [error]
^ ...top\Edited Abdala Tfs 1.5\data\scripts\dodgeCritical.lua:14: invalid escape sequence near '"CRITICAL SYSTEM'
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()
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 fineI edited the corrected post... check it out.
about onLook: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
make this quick change and seeIf I'm attacking a player the Critical works well
If I'm attacking monsters it doesn't work
what is the reason
if (attacker:isPlayer() and (attacker:getCriticalLevel() * 3) >= math.random (0, 1000)) then
if (creature:isPlayer() and (creature:getCriticalLevel() * 3) >= math.random (0, 1000)) then
attacker:say("CRITICAL!", TALKTYPE_MONSTER_SAY)
creature:say("CRITICAL!", TALKTYPE_MONSTER_SAY)
It no longer works at allmake this quick change and see
onHealthChange
is triggered by the creature receiving the damage.onSpawn
would be a good place to register it for all monsters.