Postado Setembro 10, 2018 6 anos @Gnius Tenta assim então local danos = {10, 20, 30} -- em % function onStepIn(cid, item, position, fromPosition) if not isPlayer(cid) then return true end local dmg = danos[math.random(1, #danos)] local damage = math.ceil((dmg * 0.01) * getCreatureMaxHealth(cid)) doSendMagicEffect(getThingPos(cid), 6) doSendAnimatedText(getThingPos(cid), '- ' .. damage, TEXTCOLOR_LIGHTBLUE) doCreatureAddHealth(cid, - damage) return true end
Postado Setembro 10, 2018 6 anos Autor 22 minutos atrás, Sttorm disse: @Gnius Tenta assim então local danos = {10, 20, 30} -- em % function onStepIn(cid, item, position, fromPosition) if not isPlayer(cid) then return true end local dmg = danos[math.random(1, #danos)] local damage = math.ceil((dmg * 0.01) * getCreatureMaxHealth(cid)) doSendMagicEffect(getThingPos(cid), 6) doSendAnimatedText(getThingPos(cid), '- ' .. damage, TEXTCOLOR_LIGHTBLUE) doCreatureAddHealth(cid, - damage) return true end Agora sim esta perfeito, obrigado Mais sem querer ser chato, teria como por pra aparecer x efeito a cada % usado? Por exemplo: Ele tirou 20% ira aparecer x effect Ele tirou 10% ira aparecer x effect Cada effect para cada porcento Editado Setembro 10, 2018 6 anos por Gnius (veja o histórico de edições)
Postado Setembro 11, 2018 6 anos Tenta assim bródi Instruções em vermelho: -- {Fator de Porcentagem, efeito} conforme o cód sugerido pelo Sttorm, bem otimizado por ele :D local danos = { {0.1, 3}, {0.2, 6}, {0.3, 5}} function onStepIn(cid, item, position, fromPosition) if not isPlayer(cid) then return true end local dmg = danos[math.random(1, #danos)] local damage = dmg[1] * getCreatureMaxHealth(cid) -- Calculo otimizado com apenas 1 multiplicação, otimizado por mim :D doSendMagicEffect(getThingPos(cid), dmg[2]) doSendAnimatedText(getThingPos(cid), '- ' .. damage, TEXTCOLOR_LIGHTBLUE) doCreatureAddHealth(cid, - damage) return true end Editado Setembro 11, 2018 6 anos por dirso otimização do cálculo de dano e fator % (veja o histórico de edições)
Postado Setembro 11, 2018 6 anos Solução @Gnius local danos = { {10, 3}, {20, 6}, {30, 5}} -- {Porcentagem, effect} function onStepIn(cid, item, position, fromPosition) if not isPlayer(cid) then return true end local dmg = danos[math.random(1, #danos)] local damage = math.ceil((tonumber(dmg[1])* 0.01) * getCreatureMaxHealth(cid)) doSendMagicEffect(getThingPos(cid), dmg[2]) doSendAnimatedText(getThingPos(cid), '- ' .. damage, TEXTCOLOR_LIGHTBLUE) doCreatureAddHealth(cid, - damage) return true end
Postado Setembro 11, 2018 6 anos Autor 1 hora atrás, Sttorm disse: @Gnius local danos = { {10, 3}, {20, 6}, {30, 5}} -- {Porcentagem, effect} function onStepIn(cid, item, position, fromPosition) if not isPlayer(cid) then return true end local dmg = danos[math.random(1, #danos)] local damage = math.ceil((tonumber(dmg[1])* 0.01) * getCreatureMaxHealth(cid)) doSendMagicEffect(getThingPos(cid), dmg[2]) doSendAnimatedText(getThingPos(cid), '- ' .. damage, TEXTCOLOR_LIGHTBLUE) doCreatureAddHealth(cid, - damage) return true end Funcionou perfeitamente, obrigado
Participe da conversa
Você pode postar agora e se cadastrar mais tarde. Se você tem uma conta, faça o login para postar com sua conta.