Descrição
Serão 100 livros que você poderá comprar de um npc específico, cada livro te dá 1 ponto a mais na skill Dodge e isso acarreta em 0.3% de chance a mais de desviar de um golpe e tomar só 50% de dano. Infelizmente só funciona ao perder vida então se o mago usar utamo vita acabou os dodge’s dele. Outra coisa importante é que o player tem uma chance rara de dar Dodge no Dodge, ou seja, levando 1/4 do dano. Só vai funcionar para ataques de criaturas, tanto melee quanto spells, ou seja, se o cara passar no fogo não tem chance dele desviar do dano.

Crie um arquivo chamado dodge.lua na pasta creaturescripts\scripts e coloque isso dentro dele:


local lvldodge = 48902
local percent = 0.5

function onStatsChange(cid, attacker, type, combat, value)
if type == STATSCHANGE_HEALTHLOSS and isCreature(attacker) then
if (getPlayerStorageValue(cid, lvldodge)*3) >= math.random (0,1000) then
value = math.ceil(value*(percent))
doTargetCombatHealth(attacker, cid, combat, -value, -value, 255)
doSendAnimatedText(getCreaturePos(cid), "DODGE", 6)
return false
end
end
return true
end


 Agora adicione essa linha no creaturescripts.xml: 
<event type="statschange" name="dodge" event="script" value="dodge.lua"/>

Em creaturescripts\scripts\login.lua adicione isso antes do ultimo return true:

registerCreatureEvent(cid, “dodge”)

if getPlayerStorageValue(cid, 48902) == 1 then        

setPlayerStorageValue(cid, 48902, 0)      end

 

Agora vá em actions.xml e adicione essa linha aqui:

<action itemid="1950" script="dodgebook.lua"/>

*Note: você pode mudar o ID do livro quando desejar.

Em items.xml, procure o item com o ID que vc irá utilizar e deixe ele assim:

<item id="1950" article="a" name="Skill Book [DODGE]">
<attribute key="weight" value="1300" />
</item>

Agora crie um arquivo chamado dodgebook em actions\scripts e coloque isso dentro dele:

  local config = {
   effectonuse = 14, -- efeito que sai
   levelsdodge = 100,  --- leveis que terão
   storagedodge = 48902 -- storage que será verificado
   }
   
function onUse(cid, item, frompos, item2, topos)
    if getPlayerStorageValue(cid, config.storagedodge) < config.levelsdodge then
   doRemoveItem(item.uid, 1)
doSendMagicEffect(topos,config.effectonuse)
doPlayerSendTextMessage(cid,22,"You've Leveled your Dodge Skill to ["..(getPlayerStorageValue(cid, config.storagedodge)+1).."/100].")
setPlayerStorageValue(cid, config.storagedodge, getPlayerStorageValue(cid, config.storagedodge)+1)
elseif getPlayerStorageValue(cid, config.storagedodge) >= config.levelsdodge then
doPlayerSendTextMessage(cid,22,"You've already reached the MAX level of Dodge Skill.\nCongratulations!!!!")
    return 0
    end
return 1
end

Feito isso, seu sistema está pronto.. agora vamos criar o NPC que vai vender o livro.. vá em npc\scripts e crie um arquivo chamadobookseller.lua e adicione o seguinte:

local config = {
minlevel = 150, --- level que precisa pra comprar o livro
price = 10000, --- preço do livro
itemid = 1950 --- ID DO LIVRO
}
--- end config


function getDodgeSkill(cid)
dodgeskill = getPlayerStorageValue(cid, 48902)
return dodgeskill
end

local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)
local talkState = {}

-- OTServ event handling functions start
function onCreatureAppear(cid)              npcHandler:onCreatureAppear(cid) end
function onCreatureDisappear(cid)           npcHandler:onCreatureDisappear(cid) end
function onCreatureSay(cid, type, msg)  npcHandler:onCreatureSay(cid, type, msg) end
function onThink()                      npcHandler:onThink() end
-- OTServ event handling functions end

function creatureSayCallback(cid, type, msg)
    -- Place all your code in here. Remember that hi, bye and all that stuff is already handled by the npcsystem, so you do not have to take care of that yourself.
    if (not npcHandler:isFocused(cid)) then
        return false
    end
local talkUser = NPCHANDLER_CONVbehavior == CONVERSATION_DEFAULT and 0 or cid

if msgcontains(msg, 'skill book') then
if getDodgeSkill(cid)  == dodgeskill then
selfSay('You want to buy Skill Book [DODGE]? It will cost '..config.price..' gp\'s!', cid)
talkState[talkUser] = 1
else
selfSay('I couldnt acess your data bank!', cid)
end
elseif(msgcontains(msg, 'yes') and talkState[talkUser] == 1) then
if getPlayerMoney(cid) < config.price then
selfSay('Its necessary to have at least '..config.price..' gp\'s in order to buy the Skill Book!', cid)
elseif getPlayerLevel(cid) < config.minlevel then
selfSay('The minimum level for buying this skill book is '..config.minlevel..'!', cid)
else
doPlayerRemoveMoney(cid,config.price)
doPlayerAddItem(cid, config.itemid, 1, TRUE)
end
talkState[talkUser] = 0
elseif(msgcontains(msg, 'no')) and isInArray({1}, talkState[talkUser]) == TRUE then
talkState[talkUser] = 0
selfSay('Ok.', cid)
elseif msgcontains(msg, 'level') then
selfSay('You have Leveled your Dodge Skill to ['..getDodgeSkill(cid)..'/100].', cid)
end


return true
end

npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new()) 

lembrando que no começo vc pode editar o preço, o level que precisa pra comprar a skill e o ID do livro que será usado (USE O MESMO ID NO ITEMS.XML E NO ACTIONS.) Agora crie o npc dodgeseller.xml e coloque isso nele:

<npc name="Dodge Skill Seller" script="data/npc/scripts/bookseller.lua" access="5" lookdir="1">
<health now="1000" max="1000"/>
<look type="133" head="95" body="86" legs="86" feet="38" addons="3"/>
<parameters>
<parameter key="message_greet" value="Hello |PLAYERNAME|. I've been waiting for you to come.. Say 'skill book' or 'level'" />
<parameter key="message_farewell" value="Cya folk." />
<parameter key="message_walkaway" value="How Rude!" />
</parameters> 
</npc>

Explanações gerais: O sistema é bem simples (muito simples mesmo), ele pega o valor do storage do cara e multiplica por 3.. se isso for maior que um numero aleatório criado entre 0 e 1000 ele dá dodge e solta os efeitinhos lá do creaturescripts. Note que no nivel máximo o cara vai ter 100 de storagevalue e isso será multiplicado por 3 resultando em 300. Se 300 for maior que um valor aleatorio entre 0 e 1000 (30% de chance) você vai tomar apenas metade do dano. Vc pode editar a vontade e melhorar ele da forma que quiser, se vc quiser que todos os danos do player sejam passíveis de serem esquivados mude aqui:

if type == STATSCHANGE_HEALTHLOSS and isCreature(attacker) then

apenas retirando esse and isCreature(attacker), daí até dano de firefield vai dar pra dar dodge.

Se você quiser adicionar classes que poderão usar (só knights e paladins por exemplo) só colocar isInArray({3,4,7,8}, getPlayerVocation(cid)) como condição na action. E se vc quiser que mago possa dar dodge mesmo com utamo vita (OQUE NÃO FAZ MUITO SENTIDO JÁ QUE O ESCUDO DE MANA FICA EM VOLTA DO PLAYER TEORICAMENTE, MAS TUDO BEM) é só colocar

if type == STATSCHANGE_HEALTHLOSS or type == STATSCHANGE_MANALOSS and isCreature(attacker) then

Se você quiser que só ataques de Players sejam desviados ou só ataques de monstros é só trocar
isCreature(attacker) por isMonster(attacker) ou isPlayer(attacker).

Crédito: @xWhiteWolf

LEAVE A REPLY

Please enter your comment!
Please enter your name here