• TibiaFace

    Tibiaface | Una comunidad Open Tibia donde encontras : mapas, scripts, Otserver, npc y amigos etc ...

    .
    demo menumenu

    Afiliados



    Votar:

    [Codigo] Nuevos atributos TFS 0.4 Y OTX 2 SERIES(Crítico/Esquivar/Vida y absorción de maná/Vida y absorción de maná)

    Compartir:

    Ver el tema anterior Ver el tema siguiente Ir abajo  Mensaje (Página 1 de 1.)

    [Admin] God Maya

    [Admin] God Maya
    Administrador
    Administrador
    Puede funcionar en TFS 0.4, OTX 2.X y tal vez TFS 0.4, pero la probabilidad de errores es mayor debido a que tiene diferentes nombres de funciones y variables.

    [Codigo] Nuevos atributos TFS 0.4 Y OTX 2 SERIES(Crítico/Esquivar/Vida y absorción de maná/Vida y absorción de maná) Image_14

    Hice un video siguiendo el paso a paso a continuación para facilitar el proceso de instalación del sistema.



    Hoy les estaré enseñando cómo instalar los siguientes nuevos atributos/sistemas en su fuente

    CriticalHitChance y DodgeChance -- (Funciona de la misma manera que el script básico crítico, pero sin errores de callstack)
    Life and Mana Absorb -- (Regenera, según el % asignado, del daño recibido)
    Life and Mana Leech - - (Regenera, según el % asignado, del daño infligido)

    En primer lugar, deberá desactivar el crítico predeterminado de Tibia (puede omitir esta parte si lo desea)

    Vaya a configmanager.cpp y busque:

    Código:
    m_confNumber[CRITICAL_HIT_CHANCE] = getGlobalNumber("criticalHitChance", 5);

    Código:
    m_confBool[DISPLAY_CRITICAL_HIT] = getGlobalBool("displayCriticalHitNotify", false);

    Código:
    m_confDouble[CRITICAL_HIT_MUL] = getGlobalDouble("criticalHitMultiplier", 1);

    borrar

    configmanager.h busque y borre

    Código:


             CRITICAL_HIT_CHANCE, // APAGUE
             
             CRITICAL_HIT_MUL, // APAGUE

             DISPLAY_CRITICAL_HIT, // APAGUE

    en player.cpp busque

    Código:

    void Player::sendCritical() const
    {
       if(g_config.getBool(ConfigManager::DISPLAY_CRITICAL_HIT))
          g_game.addAnimatedText(getPosition(), COLOR_DARKRED, "CRITICAL!");
    }

    y reemplaze

    Código:

    /*void Player::sendCritical() const
    {
       if(g_config.getBool(ConfigManager::DISPLAY_CRITICAL_HIT))
          g_game.addAnimatedText(getPosition(), COLOR_DARKRED, "CRITICAL!");
    }*/

    player.h busque

    Código:
    void sendCritical() const;

    reemplaze

    Código:

    /*void sendCritical() const;*/


    Por último vaya a weapons.cpp y busque

    Código:

    if(g_config.getNumber(ConfigManager::CRITICAL_HIT_CHANCE) >= random_range(1, 100))
       {
          maxDamage = std::pow(maxDamage, g_config.getDouble(ConfigManager::CRITICAL_HIT_MUL));
          player->sendCritical();
       }

    Substitua por:

    Código:

    /*   if(g_config.getNumber(ConfigManager::CRITICAL_HIT_CHANCE) >= random_range(1, 100))
       {
          maxDamage = std::pow(maxDamage, g_config.getDouble(ConfigManager::CRITICAL_HIT_MUL));
          player->sendCritical();
       }*/

    busque nuevamente

    Código:

    if(g_config.getNumber(ConfigManager::CRITICAL_HIT_CHANCE) >= random_range(1, 100))
       {
          maxValue = std::pow(maxValue, g_config.getDouble(ConfigManager::CRITICAL_HIT_MUL));
          player->sendCritical();
       }

    Substitua por:

    Código:

    /*   if(g_config.getNumber(ConfigManager::CRITICAL_HIT_CHANCE) >= random_range(1, 100))
       {
          maxValue = std::pow(maxValue, g_config.getDouble(ConfigManager::CRITICAL_HIT_MUL));
          player->sendCritical();
       }*/

    busque

    Código:

    if(g_config.getNumber(ConfigManager::CRITICAL_HIT_CHANCE) >= random_range(1, 100))
       {
          maxValue *= g_config.getDouble(ConfigManager::CRITICAL_HIT_MUL);
          player->sendCritical();
       }

    sustituya por

    Código:

    /*    if(g_config.getNumber(ConfigManager::CRITICAL_HIT_CHANCE) >= random_range(1, 100))
       {
          maxValue *= g_config.getDouble(ConfigManager::CRITICAL_HIT_MUL);
          player->sendCritical();
       }*/

    por último, busque

    Código:

    if(maxDamage)
       {
          player->sendCritical();
          return -maxValue;
       }


    Substitua por:

    Código:

    if(maxDamage)
       {
          //player->sendCritical();
          return -maxValue;
       }

    vamos por la segunda parte ahora vamos a items.cpp

    buscamos

    Código:
    attackSpeed = 0;

    abajo coloque

    Código:
       criticalHitChance = dodgeChance = lifeAbsorb = manaAbsorb = lifeLeech = manaLeech = 0;

    en items.cpp busque

    Código:

    else if(tmpStrValue == "extradefense" || tmpStrValue == "extradef")
          {
             if(readXMLInteger(itemAttributesNode, "chance", intValue))
                it.extraDefenseChance = intValue;
             if(readXMLInteger(itemAttributesNode, "value", intValue))
                it.extraDefense = intValue;
             if(readXMLInteger(itemAttributesNode, "random_min", intValue))
                it.extraDefenseRndMin = intValue;
             if(readXMLInteger(itemAttributesNode, "random_max", intValue))
                it.extraDefenseRndMax = intValue;
          }

    abajo cooque

    Código:

    else if(tmpStrValue == "criticalhitchance")
          {
             if(readXMLInteger(itemAttributesNode, "value", intValue))
                it.criticalHitChance = intValue;
          }
          
          else if(tmpStrValue == "dodgechance")
          {
             if(readXMLInteger(itemAttributesNode, "value", intValue))
                it.dodgeChance = intValue;
          }

          else if(tmpStrValue == "lifeabsorb")
          {
             if(readXMLInteger(itemAttributesNode, "value", intValue))
                it.lifeAbsorb = intValue;
          }

          else if(tmpStrValue == "manaabsorb")
          {
             if(readXMLInteger(itemAttributesNode, "value", intValue))
                it.manaAbsorb = intValue;
          }

          else if(tmpStrValue == "lifeleech")
          {
             if(readXMLInteger(itemAttributesNode, "value", intValue))
                it.lifeLeech = intValue;
          }

          else if(tmpStrValue == "manaleech")
          {
             if(readXMLInteger(itemAttributesNode, "value", intValue))
                it.manaLeech = intValue;
          }

    ahora en items.h busque

    Código:

    int32_t attack, extraAttack, defense, extraDefense, armor, breakChance, hitChance, maxHitChance,
             runeLevel, runeMagLevel, lightLevel, lightColor, decayTo, rotateTo, alwaysOnTopOrder;

    abajo coloque

    Código:

    int32_t criticalHitChance, dodgeChance, lifeAbsorb, manaAbsorb, lifeLeech, manaLeech;

    en item.cpp busque

    Código:

    case ATTR_ATTACK:
          {
             int32_t attack;
             if(!propStream.getLong((uint32_t&)attack))
                return ATTR_READ_ERROR;

             setAttribute("attack", attack);
             break;
          }

    ensima coloque esto

    Código:

    case ATTR_CRITICALHITCHANCE:
          {
             int32_t criticalHitChance;
             if(!propStream.getLong((uint32_t&)criticalHitChance))
                return ATTR_READ_ERROR;

             setAttribute("criticalhitchance", criticalHitChance);
             break;
          }

          case ATTR_DODGECHANCE:
          {
             int32_t dodgeChance;
             if(!propStream.getLong((uint32_t&)dodgeChance))
                return ATTR_READ_ERROR;

             setAttribute("dodgechance", dodgeChance);
             break;
          }

          case ATTR_LIFEABSORB:
          {
             int32_t lifeAbsorb;
             if(!propStream.getLong((uint32_t&)lifeAbsorb))
                return ATTR_READ_ERROR;

             setAttribute("lifeabsorb", lifeAbsorb);
             break;
          }

          case ATTR_MANAABSORB:
          {
             int32_t manaAbsorb;
             if(!propStream.getLong((uint32_t&)manaAbsorb))
                return ATTR_READ_ERROR;

             setAttribute("manaabsorb", manaAbsorb);
             break;
          }

          case ATTR_LIFELEECH:
          {
             int32_t lifeLeech;
             if(!propStream.getLong((uint32_t&)lifeLeech))
                return ATTR_READ_ERROR;

             setAttribute("lifeleech", lifeLeech);
             break;
          }

          case ATTR_MANALEECH:
          {
             int32_t manaLeech;
             if(!propStream.getLong((uint32_t&)manaLeech))
                return ATTR_READ_ERROR;

             setAttribute("manaleech", manaLeech);
             break;
          }

    ahora busque

    Código:

    if(it.weaponType == WEAPON_DIST && it.ammoType != AMMO_NONE)
          {
             begin = false;
             s << " (Range:" << int32_t(item ? item->getShootRange() : it.shootRange);
             if(it.attack || it.extraAttack || (item && (item->getAttack() || item->getExtraAttack())))
             {
                s << ", Atk " << std::showpos << int32_t(item ? item->getAttack() : it.attack);
                if(it.extraAttack || (item && item->getExtraAttack()))
                   s << " " << std::showpos << int32_t(item ? item->getExtraAttack() : it.extraAttack) << std::noshowpos;
             }

             if(it.hitChance != -1 || (item && item->getHitChance() != -1))
                s << ", Hit% " << std::showpos << (item ? item->getHitChance() : it.hitChance) << std::noshowpos;
          }
          else if(it.weaponType != WEAPON_AMMO && it.weaponType != WEAPON_WAND)
          {
             if(it.attack || it.extraAttack || (item && (item->getAttack() || item->getExtraAttack())))
             {
                begin = false;
                s << " (Atk:";
                if(it.abilities.elementType != COMBAT_NONE && it.decayTo < 1)
                {
                   s << std::max((int32_t)0, int32_t((item ? item->getAttack() : it.attack) - it.abilities.elementDamage));
                   if(it.extraAttack || (item && item->getExtraAttack()))
                      s << " " << std::showpos << int32_t(item ? item->getExtraAttack() : it.extraAttack) << std::noshowpos;

                   s << " physical + " << it.abilities.elementDamage << " " << getCombatName(it.abilities.elementType);
                }
                else
                {
                   s << int32_t(item ? item->getAttack() : it.attack);
                   if(it.extraAttack || (item && item->getExtraAttack()))
                      s << " " << std::showpos << int32_t(item ? item->getExtraAttack() : it.extraAttack) << std::noshowpos;
                }
             }

             if(it.defense || it.extraDefense || (item && (item->getDefense() || item->getExtraDefense())))
             {
                if(begin)
                {
                   begin = false;
                   s << " (";
                }
                else
                   s << ", ";

                s << "Def:" << int32_t(item ? item->getDefense() : it.defense);
                if(it.extraDefense || (item && item->getExtraDefense()))
                   s << " " << std::showpos << int32_t(item ? item->getExtraDefense() : it.extraDefense) << std::noshowpos;
             }
          }

    abajo coloque


    Código:

    if(it.criticalHitChance || (item && item->getCriticalHitChance()))
          {
             if(begin)
             {
                begin = false;
                s << " (";
             }
             else
                s << ", ";
                s << "Crit Chance:" << std::showpos << int32_t(item ? item->getCriticalHitChance() : it.criticalHitChance) << "%"<< std::noshowpos;
          }
          
          if(it.dodgeChance || (item && item->getDodgeChance()))
          {
             if(begin)
             {
                begin = false;
                s << " (";
             }
             else
                s << ", ";
                s << "Dodge Chance:" << std::showpos << int32_t(item ? item->getDodgeChance() : it.dodgeChance) << "%"<< std::noshowpos;
          }

          if(it.lifeAbsorb || (item && item->getLifeAbsorb()))
          {
             if(begin)
             {
                begin = false;
                s << " (";
             }
             else
                s << ", ";
                s << "Life Absorb:" << std::showpos << int32_t(item ? item->getLifeAbsorb() : it.lifeAbsorb) << "%"<< std::noshowpos;
          }
          
          if(it.manaAbsorb || (item && item->getManaAbsorb()))
          {
             if(begin)
             {
                begin = false;
                s << " (";
             }
             else
                s << ", ";
                s << "Mana Absorb:" << std::showpos << int32_t(item ? item->getManaAbsorb() : it.manaAbsorb) << "%"<< std::noshowpos;
          }

          if(it.lifeLeech || (item && item->getLifeLeech()))
          {
             if(begin)
             {
                begin = false;
                s << " (";
             }
             else
                s << ", ";
                s << "Life Leech:" << std::showpos << int32_t(item ? item->getLifeLeech() : it.lifeLeech) << "%"<< std::noshowpos;
          }
          
          if(it.manaLeech || (item && item->getManaLeech()))
          {
             if(begin)
             {
                begin = false;
                s << " (";
             }
             else
                s << ", ";
                s << "Mana Leech:" << std::showpos << int32_t(item ? item->getManaLeech() : it.manaLeech) << "%"<< std::noshowpos;
          }

    busque:

    Código:

    int32_t tmp = it.armor;
          if(item)
             tmp = item->getArmor();

          bool begin = true;
          if(tmp)
          {
             s << " (Arm:" << tmp;
             begin = false;
          }

    abajo coloque

    Código:

    if(it.criticalHitChance || (item && item->getCriticalHitChance()))
          {
             if(begin)
             {
                begin = false;
                s << " (";
             }
             else
                s << ", ";
                s << "Crit Chance:" << std::showpos << int32_t(item ? item->getCriticalHitChance() : it.criticalHitChance) << "%"<< std::noshowpos;
          }
          
          if(it.dodgeChance || (item && item->getDodgeChance()))
          {
             if(begin)
             {
                begin = false;
                s << " (";
             }
             else
                s << ", ";
                s << "Dodge Chance:" << std::showpos << int32_t(item ? item->getDodgeChance() : it.dodgeChance) << "%"<< std::noshowpos;
          }

          if(it.lifeAbsorb || (item && item->getLifeAbsorb()))
          {
             if(begin)
             {
                begin = false;
                s << " (";
             }
             else
                s << ", ";
                s << "Life Absorb:" << std::showpos << int32_t(item ? item->getLifeAbsorb() : it.lifeAbsorb) << "%"<< std::noshowpos;
          }
          
          if(it.manaAbsorb || (item && item->getManaAbsorb()))
          {
             if(begin)
             {
                begin = false;
                s << " (";
             }
             else
                s << ", ";
                s << "Mana Absorb:" << std::showpos << int32_t(item ? item->getManaAbsorb() : it.manaAbsorb) << "%"<< std::noshowpos;
          }

          if(it.lifeLeech || (item && item->getLifeLeech()))
          {
             if(begin)
             {
                begin = false;
                s << " (";
             }
             else
                s << ", ";
                s << "Life Leech:" << std::showpos << int32_t(item ? item->getLifeLeech() : it.lifeLeech) << "%"<< std::noshowpos;
          }
          
          if(it.manaLeech || (item && item->getManaLeech()))
          {
             if(begin)
             {
                begin = false;
                s << " (";
             }
             else
                s << ", ";
                s << "Mana Leech:" << std::showpos << int32_t(item ? item->getManaLeech() : it.manaLeech) << "%"<< std::noshowpos;
          }


    en item.h busque

    Código:
    ATTR_DUALWIELD = 43,

    abajo coloque

    Código:

    ATTR_CRITICALHITCHANCE = 44,
       ATTR_DODGECHANCE = 45,
       ATTR_LIFEABSORB = 46,
       ATTR_MANAABSORB = 47,
       ATTR_LIFELEECH = 48,
       ATTR_MANALEECH = 49,

    busque

    Código:
    int32_t getExtraDefense() const;

    abajo coloque

    Código:

    int32_t getCriticalHitChance() const;
          int32_t getDodgeChance() const;
          int32_t getLifeAbsorb() const;
          int32_t getManaAbsorb() const;
          int32_t getLifeLeech() const;
          int32_t getManaLeech() const;

    busque

    Código:

    inline int32_t Item::getExtraDefense() const
    {
       bool ok;
       int32_t v = getIntegerAttribute("extradefense", ok);
       if(ok)
          return v;

       return items[id].extraDefense;
    }

    abajo coloque

    Código:

    inline int32_t Item::getCriticalHitChance() const
    {
       bool ok;
       int32_t v = getIntegerAttribute("criticalhitchance", ok);
       if(ok)
          return v;

       return items[id].criticalHitChance;
    }

    inline int32_t Item::getDodgeChance() const
    {
       bool ok;
       int32_t v = getIntegerAttribute("dodgechance", ok);
       if(ok)
          return v;

       return items[id].dodgeChance;
    }

    inline int32_t Item::getLifeAbsorb() const
    {
       bool ok;
       int32_t v = getIntegerAttribute("lifeabsorb", ok);
       if(ok)
          return v;

       return items[id].lifeAbsorb;
    }

    inline int32_t Item::getManaAbsorb() const
    {
       bool ok;
       int32_t v = getIntegerAttribute("manaabsorb", ok);
       if(ok)
          return v;

       return items[id].manaAbsorb;
    }

    inline int32_t Item::getLifeLeech() const
    {
       bool ok;
       int32_t v = getIntegerAttribute("lifeleech", ok);
       if(ok)
          return v;

       return items[id].lifeLeech;
    }

    inline int32_t Item::getManaLeech() const
    {
       bool ok;
       int32_t v = getIntegerAttribute("manaleech", ok);
       if(ok)
          return v;

       return items[id].manaLeech;
    }

    en player.cpp busque

    Código:

    int32_t Player::getArmor() const
    {
       int32_t i = SLOT_FIRST, armor = 0;
       for(; i < SLOT_LAST; ++i)
       {
          if(Item* item = getInventoryItem((slots_t)i))
             armor += item->getArmor();
       }

       if(vocation->getMultiplier(MULTIPLIER_ARMOR) != 1.0)
          return int32_t(armor * vocation->getMultiplier(MULTIPLIER_ARMOR));

       return armor;
    }

    abajo coloque

    Código:

    int32_t Player::getCriticalHitChance() const
    {
       int32_t i = SLOT_FIRST, crit = 0;
       for(; i < SLOT_LAST; ++i)
       {
          if(Item* item = getInventoryItem((slots_t)i))
          crit += item->getCriticalHitChance();
       }
       return crit;
    }

    int32_t Player::getDodgeChance() const
    {
       int32_t i = SLOT_FIRST, dodge = 0;
       for(; i < SLOT_LAST; ++i)
       {
          if(Item* item = getInventoryItem((slots_t)i))
          dodge += item->getDodgeChance();
       }
       return dodge;
    }

    int32_t Player::getLifeAbsorb() const
    {
       int32_t i = SLOT_FIRST, life = 0;
       for(; i < SLOT_LAST; ++i)
       {
          if(Item* item = getInventoryItem((slots_t)i))
          life += item->getLifeAbsorb();
       }

       return life;
    }

    int32_t Player::getManaAbsorb() const
    {
       int32_t i = SLOT_FIRST, mana = 0;
       for(; i < SLOT_LAST; ++i)
       {
          if(Item* item = getInventoryItem((slots_t)i))
          mana += item->getManaAbsorb();
       }

       return mana;
    }

    int32_t Player::getLifeLeech() const
    {
       int32_t i = SLOT_FIRST, life = 0;
       for(; i < SLOT_LAST; ++i)
       {
          if(Item* item = getInventoryItem((slots_t)i))
          life += item->getLifeLeech();
       }

       return life;
    }

    int32_t Player::getManaLeech() const
    {
       int32_t i = SLOT_FIRST, mana = 0;
       for(; i < SLOT_LAST; ++i)
       {
          if(Item* item = getInventoryItem((slots_t)i))
          mana += item->getManaLeech();
       }

       return mana;
    }

    en player.h busque

    Código:
    virtual int32_t getDefense() const;

    abajo coloque

    Código:

    virtual int32_t getCriticalHitChance() const;
          virtual int32_t getDodgeChance() const;
          virtual int32_t getLifeAbsorb() const;
          virtual int32_t getManaAbsorb() const;
          virtual int32_t getLifeLeech() const;
          virtual int32_t getManaLeech() const;


    en luascript.cpp busque

    Código:

    //getCreatureHealth(cid)
       lua_register(m_luaState, "getCreatureHealth", LuaInterface::luaGetCreatureHealth);

    abajo coloque

    Código:

    //getPlayerCriticalHitChance(cid)
       lua_register(m_luaState, "getPlayerCriticalHitChance", LuaInterface::luaGetPlayerCriticalHitChance);

       //getPlayerDodgeChance(cid)
       lua_register(m_luaState, "getPlayerDodgeChance", LuaInterface::luaGetPlayerDodgeChance);
       
       //getPlayerLifeAbsorb(cid)
       lua_register(m_luaState, "getPlayerLifeAbsorb", LuaInterface::luaGetPlayerLifeAbsorb);
       
       //getPlayerManaAbsorb(cid)
       lua_register(m_luaState, "getPlayerManaAbsorb", LuaInterface::luaGetPlayerManaAbsorb);

       //getPlayerLifeLeech(cid)
       lua_register(m_luaState, "getPlayerLifeLeech", LuaInterface::luaGetPlayerLifeLeech);
       
       //getPlayerManaLeech(cid)
       lua_register(m_luaState, "getPlayerManaLeech", LuaInterface::luaGetPlayerManaLeech);

    busque

    Código:

    int32_t LuaInterface::luaGetCreatureMaxHealth(lua_State* L)
    {
       //getCreatureMaxHealth(cid[, ignoreModifiers = false])
       bool ignoreModifiers = false;
       if(lua_gettop(L) > 1)
          ignoreModifiers = popBoolean(L);

       ScriptEnviroment* env = getEnv();
       if(Creature* creature = env->getCreatureByUID(popNumber(L)))
          lua_pushnumber(L, creature->getPlayer() && ignoreModifiers ? creature->healthMax : creature->getMaxHealth());
       else
       {
          errorEx(getError(LUA_ERROR_CREATURE_NOT_FOUND));
          lua_pushboolean(L, false);
       }

       return 1;
    }

    abajo agregue

    Código:

    int32_t LuaInterface::luaGetPlayerCriticalHitChance(lua_State* L)
    {
       //getPlayerCriticalHitChance(cid)
       ScriptEnviroment* env = getEnv();
       if(Player* player = env->getPlayerByUID(popNumber(L)))
          lua_pushnumber(L, player->getCriticalHitChance());
       else
       {
          errorEx(getError(LUA_ERROR_PLAYER_NOT_FOUND));
          lua_pushboolean(L, false);
       }
       return 1;
    }

    int32_t LuaInterface::luaGetPlayerDodgeChance(lua_State* L)
    {
       //getPlayerDodgeChance(cid)
       ScriptEnviroment* env = getEnv();
       if(Player* player = env->getPlayerByUID(popNumber(L)))
          lua_pushnumber(L, player->getDodgeChance());
       else
       {
          errorEx(getError(LUA_ERROR_CREATURE_NOT_FOUND));
          lua_pushboolean(L, false);
       }

       return 1;
    }

    int32_t LuaInterface::luaGetPlayerLifeAbsorb(lua_State* L)
    {
       //getPlayerLifeAbsorb(cid)
       ScriptEnviroment* env = getEnv();
       if(Player* player = env->getPlayerByUID(popNumber(L)))
          lua_pushnumber(L, player->getLifeAbsorb());
       else
       {
          errorEx(getError(LUA_ERROR_CREATURE_NOT_FOUND));
          lua_pushboolean(L, false);
       }

       return 1;
    }

    int32_t LuaInterface::luaGetPlayerManaAbsorb(lua_State* L)
    {
       //getPlayerManaAbsorb(cid)
       ScriptEnviroment* env = getEnv();
       if(Player* player = env->getPlayerByUID(popNumber(L)))
          lua_pushnumber(L, player->getManaAbsorb());
       else
       {
          errorEx(getError(LUA_ERROR_CREATURE_NOT_FOUND));
          lua_pushboolean(L, false);
       }

       return 1;
    }

    int32_t LuaInterface::luaGetPlayerLifeLeech(lua_State* L)
    {
       //getPlayerLifeLeech(cid)
       ScriptEnviroment* env = getEnv();
       if(Player* player = env->getPlayerByUID(popNumber(L)))
          lua_pushnumber(L, player->getLifeLeech());
       else
       {
          errorEx(getError(LUA_ERROR_CREATURE_NOT_FOUND));
          lua_pushboolean(L, false);
       }

       return 1;
    }

    int32_t LuaInterface::luaGetPlayerManaLeech(lua_State* L)
    {
       //getPlayerManaLeech(cid)
       ScriptEnviroment* env = getEnv();
       if(Player* player = env->getPlayerByUID(popNumber(L)))
          lua_pushnumber(L, player->getManaLeech());
       else
       {
          errorEx(getError(LUA_ERROR_CREATURE_NOT_FOUND));
          lua_pushboolean(L, false);
       }

       return 1;
    }

    en luascript.h busque

    Código:

    static int32_t luaGetPlayerSpentMana(lua_State* L);

    abajo agregue

    Código:

    static int32_t luaGetPlayerCriticalHitChance(lua_State* L);
          static int32_t luaGetPlayerDodgeChance(lua_State* L);
          static int32_t luaGetPlayerLifeAbsorb(lua_State* L);
          static int32_t luaGetPlayerManaAbsorb(lua_State* L);
          static int32_t luaGetPlayerLifeLeech(lua_State* L);
          static int32_t luaGetPlayerManaLeech(lua_State* L);

    funciones adicionadas

    Código:

    getPlayerCriticalHitChance(cid)
    getPlayerDodgeChance(cid)
    getPlayerLifeAbsorb(cid)
    getPlayerManaAbsorb(cid)
    getPlayerLifeLeech(cid)
    getPlayerManaLeech(cid)

    esta parte es de game.cpp es ocional usted puede elegir si agregarla o no

    en game.cpp buscamos

    Código:

    bool Game::combatChangeHealth(const CombatParams& params, Creature* attacker, Creature* target, int32_t healthChange, bool force)

    dentro de esa funcion busque

    Código:
    const Position& targetPos = target->getPosition();

    abajo de aquello agregue

    Código:

    int32_t lifeLeech, manaLeech, lifeAbsorb, manaAbsorb = 0;

    dentro de la misma funcion busque

    Código:

    damage = std::min(target->getHealth(), damage);
             if(damage > 0)
             {

    abajo de aquello agregue

    Código:

    Player* player = NULL;
                if(attacker && (player = attacker->getPlayer()))
                {
                   if(random_range(1,100) < attacker->getPlayer()->getCriticalHitChance())
                   {
                      damage = damage * 2;
                      addAnimatedText(attacker->getPosition(), COLOR_DARKRED, "Critical!");
                   }   
                }
                
                if((player = target->getPlayer()) && (attacker != target) && target == player)
                {
                   if(random_range(1,100) < target->getPlayer()->getDodgeChance())
                   {
                      damage = damage * 0.5;
                      addAnimatedText(target->getPosition(), COLOR_BLUE, "Dodge!");
                   }
                }

    dentro de la funcion busque

    Código:

    if((player = target->getPlayer()) && attacker != target)
                   {
                      if(attacker)
                         ss << "You lose " << totalDamage << " hitpoint" << plural << " due to an attack by " << attacker->getNameDescription() << ".";
                      else
                         ss << "You lose " << totalDamage << " hitpoint" << plural << ".";

                      player->sendStatsMessage(MSG_DAMAGE_RECEIVED, ss.str(), targetPos, details);
                   }

    abajo de aeullo agregue

    Código:

    if(attacker && (player = attacker->getPlayer()))
                   {
                      if(attacker->getPlayer()->getLifeLeech() > 0)
                      {
                         lifeLeech = damage * (attacker->getPlayer()->getLifeLeech() * 0.01);
                         if(damage > 0)
                         {
                            combatChangeHealth(params, target, attacker, lifeLeech, true);
                         }
                      }
                      
                      if(attacker->getPlayer()->getManaLeech() > 0)
                      {
                         manaLeech = damage * (attacker->getPlayer()->getManaLeech() * 0.01);
                         if(damage > 0)
                         {
                            combatChangeMana(target, attacker, manaLeech, params.combatType, true);
                         
                      
                   
                   
                   

                     
                   
                        
                       () * 0.01);
                         if(damage > 0)
                         {
                            combatChangeHealth(params, attacker, target, lifeAbsorb, true);
                         }
                      }
                      
                        
                        
                         
                         
                            combatChangeMana(attacker, target, manaAbsorb, params.combatType, true);
                         }
                      }
                   }

    en game.cpp busque la siguiente funcion

    Código:

    bool Game::combatChangeMana(Creature* attacker, Creature* target, int32_t manaChange,
       CombatType_t combatType/* = COMBAT_MANADRAIN*/, bool inherited/* = false*/)

    dentro  esa funcion busque

    Código:

    const Position& targetPos = target->getPosition();

    agregue esto abajo

    Código:

    int32_t lifeLeech, manaLeech, lifeAbsorb, manaAbsorb = 0;

    dentro de la misma funcion busque

    Código:

    if((player = target->getPlayer()) && attacker != target)
             {
                if(attacker)
                   ss << "You lose " << manaLoss << " mana due to an attack by " << attacker->getNameDescription();
                else
                   ss << "You lose " << manaLoss << " mana.";

                player->sendStatsMessage(MSG_DAMAGE_RECEIVED, ss.str(), targetPos, details);
             }

    abajo coloque

    Código:

    // Life e Mana Leech
             if(attacker && (player = attacker->getPlayer()))
             {
                if(attacker->getPlayer()->getLifeLeech() > 0)
                {
                   lifeLeech = manaLoss * (attacker->getPlayer()->getLifeLeech() * 0.01);
                   if(manaLoss > 0)
                   {
                      combatChangeHealth(manaLoss < 1 ? COMBAT_UNDEFINEDDAMAGE : COMBAT_HEALING, target, attacker, lifeLeech, MAGIC_EFFECT_UNKNOWN, COLOR_UNKNOWN, false);
                   }
                }
                
                if(attacker->getPlayer()->getManaLeech() > 0)
                {
                   manaLeech = manaLoss * (attacker->getPlayer()->getManaLeech() * 0.01);
                   if(manaLoss > 0)
                   {
                      combatChangeMana(target, attacker, manaLeech, combatType, true);
                   }
                }
             }

    // Life e Mana Absorb
             if((player = target->getPlayer()) && (attacker != target))
             {
                if(target->getPlayer()->getLifeAbsorb() > 0)
                {
                   lifeAbsorb = manaLoss * (target->getPlayer()->getLifeAbsorb() * 0.01);
                   if(manaLoss > 0)
                   {
                      combatChangeHealth(manaLoss < 1 ? COMBAT_UNDEFINEDDAMAGE : COMBAT_HEALING, attacker, target, lifeAbsorb, MAGIC_EFFECT_UNKNOWN, COLOR_UNKNOWN, false);
                   }
                }
                
                if(target->getPlayer()->getManaAbsorb() > 0)
                {
                   manaAbsorb = manaLoss * (target->getPlayer()->getManaAbsorb() * 0.01);
                   if(manaLoss > 0)
                   {
                      combatChangeMana(attacker, target, manaAbsorb, combatType, true);
                   }
                }
             }


    Créditos: ~Mathias Kenfi

    el sistema fue implementado en estas sources: [Tienes que estar registrado y conectado para ver este vínculo]

    y el servidor completo: [Tienes que estar registrado y conectado para ver este vínculo]



    Última edición por [Admin] God Maya el Lun Feb 27, 2023 10:33 pm, editado 1 vez



    [Codigo] Nuevos atributos TFS 0.4 Y OTX 2 SERIES(Crítico/Esquivar/Vida y absorción de maná/Vida y absorción de maná) YNU5B25
    5 participantes
    http://www.tibiaface.com

    akane

    akane
    Miembro
    Miembro
    uff voy a probarlo enseguida, justo quería agregarle esas funciones pero no sabía por donde partir buscando.

    Gracias maya Very Happy

    5 participantes

    Gm Lurran

    Gm Lurran
    Miembro
    Miembro
    [Admin] God Maya escribió:Puede funcionar en TFS 0.4, OTX 2.X y tal vez TFS 0.4, pero la probabilidad de errores es mayor debido a que tiene diferentes nombres de funciones y variables.

    [Codigo] Nuevos atributos TFS 0.4 Y OTX 2 SERIES(Crítico/Esquivar/Vida y absorción de maná/Vida y absorción de maná) Image_14

    Hice un video siguiendo el paso a paso a continuación para facilitar el proceso de instalación del sistema.







    Hoy les estaré enseñando cómo instalar los siguientes nuevos atributos/sistemas en su fuente

    CriticalHitChance y DodgeChance -- (Funciona de la misma manera que el script básico crítico, pero sin errores de callstack)
    Life and Mana Absorb -- (Regenera, según el % asignado, del daño recibido)
    Life and Mana Leech - - (Regenera, según el % asignado, del daño infligido)

    En primer lugar, deberá desactivar el crítico predeterminado de Tibia (puede omitir esta parte si lo desea)

    Vaya a configmanager.cpp y busque:

    Código:
    m_confNumber[CRITICAL_HIT_CHANCE] = getGlobalNumber("criticalHitChance", 5);

    Código:
    m_confBool[DISPLAY_CRITICAL_HIT] = getGlobalBool("displayCriticalHitNotify", false);

    Código:
    m_confDouble[CRITICAL_HIT_MUL] = getGlobalDouble("criticalHitMultiplier", 1);

    borrar

    configmanager.h busque y borre

    Código:


             CRITICAL_HIT_CHANCE, // APAGUE
             
             CRITICAL_HIT_MUL, // APAGUE

             DISPLAY_CRITICAL_HIT, // APAGUE

    en player.cpp busque

    Código:

    void Player::sendCritical() const
    {
       if(g_config.getBool(ConfigManager::DISPLAY_CRITICAL_HIT))
          g_game.addAnimatedText(getPosition(), COLOR_DARKRED, "CRITICAL!");
    }

    y reemplaze

    Código:

    /*void Player::sendCritical() const
    {
       if(g_config.getBool(ConfigManager::DISPLAY_CRITICAL_HIT))
          g_game.addAnimatedText(getPosition(), COLOR_DARKRED, "CRITICAL!");
    }*/

    player.h busque

    Código:
    void sendCritical() const;

    reemplaze

    Código:

    /*void sendCritical() const;*/


    Por último vaya a weapons.cpp y busque

    Código:

    if(g_config.getNumber(ConfigManager::CRITICAL_HIT_CHANCE) >= random_range(1, 100))
       {
          maxDamage = std::pow(maxDamage, g_config.getDouble(ConfigManager::CRITICAL_HIT_MUL));
          player->sendCritical();
       }

    Substitua por:

    Código:

    /*   if(g_config.getNumber(ConfigManager::CRITICAL_HIT_CHANCE) >= random_range(1, 100))
       {
          maxDamage = std::pow(maxDamage, g_config.getDouble(ConfigManager::CRITICAL_HIT_MUL));
          player->sendCritical();
       }*/

    busque nuevamente

    Código:

    if(g_config.getNumber(ConfigManager::CRITICAL_HIT_CHANCE) >= random_range(1, 100))
       {
          maxValue = std::pow(maxValue, g_config.getDouble(ConfigManager::CRITICAL_HIT_MUL));
          player->sendCritical();
       }

    Substitua por:

    Código:

    /*   if(g_config.getNumber(ConfigManager::CRITICAL_HIT_CHANCE) >= random_range(1, 100))
       {
          maxValue = std::pow(maxValue, g_config.getDouble(ConfigManager::CRITICAL_HIT_MUL));
          player->sendCritical();
       }*/

    busque

    Código:

    if(g_config.getNumber(ConfigManager::CRITICAL_HIT_CHANCE) >= random_range(1, 100))
       {
          maxValue *= g_config.getDouble(ConfigManager::CRITICAL_HIT_MUL);
          player->sendCritical();
       }

    sustituya por

    Código:

    /*    if(g_config.getNumber(ConfigManager::CRITICAL_HIT_CHANCE) >= random_range(1, 100))
       {
          maxValue *= g_config.getDouble(ConfigManager::CRITICAL_HIT_MUL);
          player->sendCritical();
       }*/

    por último, busque

    Código:

    if(maxDamage)
       {
          player->sendCritical();
          return -maxValue;
       }


    Substitua por:

    Código:

    if(maxDamage)
       {
          //player->sendCritical();
          return -maxValue;
       }

    vamos por la segunda parte ahora vamos a items.cpp

    buscamos

    Código:
    attackSpeed = 0;

    abajo coloque

    Código:
       criticalHitChance = dodgeChance = lifeAbsorb = manaAbsorb = lifeLeech = manaLeech = 0;

    en items.cpp busque

    Código:

    else if(tmpStrValue == "extradefense" || tmpStrValue == "extradef")
          {
             if(readXMLInteger(itemAttributesNode, "chance", intValue))
                it.extraDefenseChance = intValue;
             if(readXMLInteger(itemAttributesNode, "value", intValue))
                it.extraDefense = intValue;
             if(readXMLInteger(itemAttributesNode, "random_min", intValue))
                it.extraDefenseRndMin = intValue;
             if(readXMLInteger(itemAttributesNode, "random_max", intValue))
                it.extraDefenseRndMax = intValue;
          }

    abajo cooque

    Código:

    else if(tmpStrValue == "criticalhitchance")
          {
             if(readXMLInteger(itemAttributesNode, "value", intValue))
                it.criticalHitChance = intValue;
          }
          
          else if(tmpStrValue == "dodgechance")
          {
             if(readXMLInteger(itemAttributesNode, "value", intValue))
                it.dodgeChance = intValue;
          }

          else if(tmpStrValue == "lifeabsorb")
          {
             if(readXMLInteger(itemAttributesNode, "value", intValue))
                it.lifeAbsorb = intValue;
          }

          else if(tmpStrValue == "manaabsorb")
          {
             if(readXMLInteger(itemAttributesNode, "value", intValue))
                it.manaAbsorb = intValue;
          }

          else if(tmpStrValue == "lifeleech")
          {
             if(readXMLInteger(itemAttributesNode, "value", intValue))
                it.lifeLeech = intValue;
          }

          else if(tmpStrValue == "manaleech")
          {
             if(readXMLInteger(itemAttributesNode, "value", intValue))
                it.manaLeech = intValue;
          }

    ahora en items.h busque

    Código:

    int32_t attack, extraAttack, defense, extraDefense, armor, breakChance, hitChance, maxHitChance,
             runeLevel, runeMagLevel, lightLevel, lightColor, decayTo, rotateTo, alwaysOnTopOrder;

    abajo coloque

    Código:

    int32_t criticalHitChance, dodgeChance, lifeAbsorb, manaAbsorb, lifeLeech, manaLeech;

    en item.cpp busque

    Código:

    case ATTR_ATTACK:
          {
             int32_t attack;
             if(!propStream.getLong((uint32_t&)attack))
                return ATTR_READ_ERROR;

             setAttribute("attack", attack);
             break;
          }

    ensima coloque esto

    Código:

    case ATTR_CRITICALHITCHANCE:
          {
             int32_t criticalHitChance;
             if(!propStream.getLong((uint32_t&)criticalHitChance))
                return ATTR_READ_ERROR;

             setAttribute("criticalhitchance", criticalHitChance);
             break;
          }

          case ATTR_DODGECHANCE:
          {
             int32_t dodgeChance;
             if(!propStream.getLong((uint32_t&)dodgeChance))
                return ATTR_READ_ERROR;

             setAttribute("dodgechance", dodgeChance);
             break;
          }

          case ATTR_LIFEABSORB:
          {
             int32_t lifeAbsorb;
             if(!propStream.getLong((uint32_t&)lifeAbsorb))
                return ATTR_READ_ERROR;

             setAttribute("lifeabsorb", lifeAbsorb);
             break;
          }

          case ATTR_MANAABSORB:
          {
             int32_t manaAbsorb;
             if(!propStream.getLong((uint32_t&)manaAbsorb))
                return ATTR_READ_ERROR;

             setAttribute("manaabsorb", manaAbsorb);
             break;
          }

          case ATTR_LIFELEECH:
          {
             int32_t lifeLeech;
             if(!propStream.getLong((uint32_t&)lifeLeech))
                return ATTR_READ_ERROR;

             setAttribute("lifeleech", lifeLeech);
             break;
          }

          case ATTR_MANALEECH:
          {
             int32_t manaLeech;
             if(!propStream.getLong((uint32_t&)manaLeech))
                return ATTR_READ_ERROR;

             setAttribute("manaleech", manaLeech);
             break;
          }

    ahora busque

    Código:

    if(it.weaponType == WEAPON_DIST && it.ammoType != AMMO_NONE)
          {
             begin = false;
             s << " (Range:" << int32_t(item ? item->getShootRange() : it.shootRange);
             if(it.attack || it.extraAttack || (item && (item->getAttack() || item->getExtraAttack())))
             {
                s << ", Atk " << std::showpos << int32_t(item ? item->getAttack() : it.attack);
                if(it.extraAttack || (item && item->getExtraAttack()))
                   s << " " << std::showpos << int32_t(item ? item->getExtraAttack() : it.extraAttack) << std::noshowpos;
             }

             if(it.hitChance != -1 || (item && item->getHitChance() != -1))
                s << ", Hit% " << std::showpos << (item ? item->getHitChance() : it.hitChance) << std::noshowpos;
          }
          else if(it.weaponType != WEAPON_AMMO && it.weaponType != WEAPON_WAND)
          {
             if(it.attack || it.extraAttack || (item && (item->getAttack() || item->getExtraAttack())))
             {
                begin = false;
                s << " (Atk:";
                if(it.abilities.elementType != COMBAT_NONE && it.decayTo < 1)
                {
                   s << std::max((int32_t)0, int32_t((item ? item->getAttack() : it.attack) - it.abilities.elementDamage));
                   if(it.extraAttack || (item && item->getExtraAttack()))
                      s << " " << std::showpos << int32_t(item ? item->getExtraAttack() : it.extraAttack) << std::noshowpos;

                   s << " physical + " << it.abilities.elementDamage << " " << getCombatName(it.abilities.elementType);
                }
                else
                {
                   s << int32_t(item ? item->getAttack() : it.attack);
                   if(it.extraAttack || (item && item->getExtraAttack()))
                      s << " " << std::showpos << int32_t(item ? item->getExtraAttack() : it.extraAttack) << std::noshowpos;
                }
             }

             if(it.defense || it.extraDefense || (item && (item->getDefense() || item->getExtraDefense())))
             {
                if(begin)
                {
                   begin = false;
                   s << " (";
                }
                else
                   s << ", ";

                s << "Def:" << int32_t(item ? item->getDefense() : it.defense);
                if(it.extraDefense || (item && item->getExtraDefense()))
                   s << " " << std::showpos << int32_t(item ? item->getExtraDefense() : it.extraDefense) << std::noshowpos;
             }
          }

    abajo coloque


    Código:

    if(it.criticalHitChance || (item && item->getCriticalHitChance()))
          {
             if(begin)
             {
                begin = false;
                s << " (";
             }
             else
                s << ", ";
                s << "Crit Chance:" << std::showpos << int32_t(item ? item->getCriticalHitChance() : it.criticalHitChance) << "%"<< std::noshowpos;
          }
          
          if(it.dodgeChance || (item && item->getDodgeChance()))
          {
             if(begin)
             {
                begin = false;
                s << " (";
             }
             else
                s << ", ";
                s << "Dodge Chance:" << std::showpos << int32_t(item ? item->getDodgeChance() : it.dodgeChance) << "%"<< std::noshowpos;
          }

          if(it.lifeAbsorb || (item && item->getLifeAbsorb()))
          {
             if(begin)
             {
                begin = false;
                s << " (";
             }
             else
                s << ", ";
                s << "Life Absorb:" << std::showpos << int32_t(item ? item->getLifeAbsorb() : it.lifeAbsorb) << "%"<< std::noshowpos;
          }
          
          if(it.manaAbsorb || (item && item->getManaAbsorb()))
          {
             if(begin)
             {
                begin = false;
                s << " (";
             }
             else
                s << ", ";
                s << "Mana Absorb:" << std::showpos << int32_t(item ? item->getManaAbsorb() : it.manaAbsorb) << "%"<< std::noshowpos;
          }

          if(it.lifeLeech || (item && item->getLifeLeech()))
          {
             if(begin)
             {
                begin = false;
                s << " (";
             }
             else
                s << ", ";
                s << "Life Leech:" << std::showpos << int32_t(item ? item->getLifeLeech() : it.lifeLeech) << "%"<< std::noshowpos;
          }
          
          if(it.manaLeech || (item && item->getManaLeech()))
          {
             if(begin)
             {
                begin = false;
                s << " (";
             }
             else
                s << ", ";
                s << "Mana Leech:" << std::showpos << int32_t(item ? item->getManaLeech() : it.manaLeech) << "%"<< std::noshowpos;
          }

    busque:

    Código:

    int32_t tmp = it.armor;
          if(item)
             tmp = item->getArmor();

          bool begin = true;
          if(tmp)
          {
             s << " (Arm:" << tmp;
             begin = false;
          }

    abajo coloque

    Código:

    if(it.criticalHitChance || (item && item->getCriticalHitChance()))
          {
             if(begin)
             {
                begin = false;
                s << " (";
             }
             else
                s << ", ";
                s << "Crit Chance:" << std::showpos << int32_t(item ? item->getCriticalHitChance() : it.criticalHitChance) << "%"<< std::noshowpos;
          }
          
          if(it.dodgeChance || (item && item->getDodgeChance()))
          {
             if(begin)
             {
                begin = false;
                s << " (";
             }
             else
                s << ", ";
                s << "Dodge Chance:" << std::showpos << int32_t(item ? item->getDodgeChance() : it.dodgeChance) << "%"<< std::noshowpos;
          }

          if(it.lifeAbsorb || (item && item->getLifeAbsorb()))
          {
             if(begin)
             {
                begin = false;
                s << " (";
             }
             else
                s << ", ";
                s << "Life Absorb:" << std::showpos << int32_t(item ? item->getLifeAbsorb() : it.lifeAbsorb) << "%"<< std::noshowpos;
          }
          
          if(it.manaAbsorb || (item && item->getManaAbsorb()))
          {
             if(begin)
             {
                begin = false;
                s << " (";
             }
             else
                s << ", ";
                s << "Mana Absorb:" << std::showpos << int32_t(item ? item->getManaAbsorb() : it.manaAbsorb) << "%"<< std::noshowpos;
          }

          if(it.lifeLeech || (item && item->getLifeLeech()))
          {
             if(begin)
             {
                begin = false;
                s << " (";
             }
             else
                s << ", ";
                s << "Life Leech:" << std::showpos << int32_t(item ? item->getLifeLeech() : it.lifeLeech) << "%"<< std::noshowpos;
          }
          
          if(it.manaLeech || (item && item->getManaLeech()))
          {
             if(begin)
             {
                begin = false;
                s << " (";
             }
             else
                s << ", ";
                s << "Mana Leech:" << std::showpos << int32_t(item ? item->getManaLeech() : it.manaLeech) << "%"<< std::noshowpos;
          }


    en item.h busque

    Código:
    ATTR_DUALWIELD = 43,

    abajo coloque

    Código:

    ATTR_CRITICALHITCHANCE = 44,
       ATTR_DODGECHANCE = 45,
       ATTR_LIFEABSORB = 46,
       ATTR_MANAABSORB = 47,
       ATTR_LIFELEECH = 48,
       ATTR_MANALEECH = 49,

    busque

    Código:
    int32_t getExtraDefense() const;

    abajo coloque

    Código:

    int32_t getCriticalHitChance() const;
          int32_t getDodgeChance() const;
          int32_t getLifeAbsorb() const;
          int32_t getManaAbsorb() const;
          int32_t getLifeLeech() const;
          int32_t getManaLeech() const;

    busque

    Código:

    inline int32_t Item::getExtraDefense() const
    {
       bool ok;
       int32_t v = getIntegerAttribute("extradefense", ok);
       if(ok)
          return v;

       return items[id].extraDefense;
    }

    abajo coloque

    Código:

    inline int32_t Item::getCriticalHitChance() const
    {
       bool ok;
       int32_t v = getIntegerAttribute("criticalhitchance", ok);
       if(ok)
          return v;

       return items[id].criticalHitChance;
    }

    inline int32_t Item::getDodgeChance() const
    {
       bool ok;
       int32_t v = getIntegerAttribute("dodgechance", ok);
       if(ok)
          return v;

       return items[id].dodgeChance;
    }

    inline int32_t Item::getLifeAbsorb() const
    {
       bool ok;
       int32_t v = getIntegerAttribute("lifeabsorb", ok);
       if(ok)
          return v;

       return items[id].lifeAbsorb;
    }

    inline int32_t Item::getManaAbsorb() const
    {
       bool ok;
       int32_t v = getIntegerAttribute("manaabsorb", ok);
       if(ok)
          return v;

       return items[id].manaAbsorb;
    }

    inline int32_t Item::getLifeLeech() const
    {
       bool ok;
       int32_t v = getIntegerAttribute("lifeleech", ok);
       if(ok)
          return v;

       return items[id].lifeLeech;
    }

    inline int32_t Item::getManaLeech() const
    {
       bool ok;
       int32_t v = getIntegerAttribute("manaleech", ok);
       if(ok)
          return v;

       return items[id].manaLeech;
    }

    en player.cpp busque

    Código:

    int32_t Player::getArmor() const
    {
       int32_t i = SLOT_FIRST, armor = 0;
       for(; i < SLOT_LAST; ++i)
       {
          if(Item* item = getInventoryItem((slots_t)i))
             armor += item->getArmor();
       }

       if(vocation->getMultiplier(MULTIPLIER_ARMOR) != 1.0)
          return int32_t(armor * vocation->getMultiplier(MULTIPLIER_ARMOR));

       return armor;
    }

    abajo coloque

    Código:

    int32_t Player::getCriticalHitChance() const
    {
       int32_t i = SLOT_FIRST, crit = 0;
       for(; i < SLOT_LAST; ++i)
       {
          if(Item* item = getInventoryItem((slots_t)i))
          crit += item->getCriticalHitChance();
       }
       return crit;
    }

    int32_t Player::getDodgeChance() const
    {
       int32_t i = SLOT_FIRST, dodge = 0;
       for(; i < SLOT_LAST; ++i)
       {
          if(Item* item = getInventoryItem((slots_t)i))
          dodge += item->getDodgeChance();
       }
       return dodge;
    }

    int32_t Player::getLifeAbsorb() const
    {
       int32_t i = SLOT_FIRST, life = 0;
       for(; i < SLOT_LAST; ++i)
       {
          if(Item* item = getInventoryItem((slots_t)i))
          life += item->getLifeAbsorb();
       }

       return life;
    }

    int32_t Player::getManaAbsorb() const
    {
       int32_t i = SLOT_FIRST, mana = 0;
       for(; i < SLOT_LAST; ++i)
       {
          if(Item* item = getInventoryItem((slots_t)i))
          mana += item->getManaAbsorb();
       }

       return mana;
    }

    int32_t Player::getLifeLeech() const
    {
       int32_t i = SLOT_FIRST, life = 0;
       for(; i < SLOT_LAST; ++i)
       {
          if(Item* item = getInventoryItem((slots_t)i))
          life += item->getLifeLeech();
       }

       return life;
    }

    int32_t Player::getManaLeech() const
    {
       int32_t i = SLOT_FIRST, mana = 0;
       for(; i < SLOT_LAST; ++i)
       {
          if(Item* item = getInventoryItem((slots_t)i))
          mana += item->getManaLeech();
       }

       return mana;
    }

    en player.h busque

    Código:
    virtual int32_t getDefense() const;

    abajo coloque

    Código:

    virtual int32_t getCriticalHitChance() const;
          virtual int32_t getDodgeChance() const;
          virtual int32_t getLifeAbsorb() const;
          virtual int32_t getManaAbsorb() const;
          virtual int32_t getLifeLeech() const;
          virtual int32_t getManaLeech() const;


    en luascript.cpp busque

    Código:

    //getCreatureHealth(cid)
       lua_register(m_luaState, "getCreatureHealth", LuaInterface::luaGetCreatureHealth);

    abajo coloque

    Código:

    //getPlayerCriticalHitChance(cid)
       lua_register(m_luaState, "getPlayerCriticalHitChance", LuaInterface::luaGetPlayerCriticalHitChance);

       //getPlayerDodgeChance(cid)
       lua_register(m_luaState, "getPlayerDodgeChance", LuaInterface::luaGetPlayerDodgeChance);
       
       //getPlayerLifeAbsorb(cid)
       lua_register(m_luaState, "getPlayerLifeAbsorb", LuaInterface::luaGetPlayerLifeAbsorb);
       
       //getPlayerManaAbsorb(cid)
       lua_register(m_luaState, "getPlayerManaAbsorb", LuaInterface::luaGetPlayerManaAbsorb);

       //getPlayerLifeLeech(cid)
       lua_register(m_luaState, "getPlayerLifeLeech", LuaInterface::luaGetPlayerLifeLeech);
       
       //getPlayerManaLeech(cid)
       lua_register(m_luaState, "getPlayerManaLeech", LuaInterface::luaGetPlayerManaLeech);

    busque

    Código:

    int32_t LuaInterface::luaGetCreatureMaxHealth(lua_State* L)
    {
       //getCreatureMaxHealth(cid[, ignoreModifiers = false])
       bool ignoreModifiers = false;
       if(lua_gettop(L) > 1)
          ignoreModifiers = popBoolean(L);

       ScriptEnviroment* env = getEnv();
       if(Creature* creature = env->getCreatureByUID(popNumber(L)))
          lua_pushnumber(L, creature->getPlayer() && ignoreModifiers ? creature->healthMax : creature->getMaxHealth());
       else
       {
          errorEx(getError(LUA_ERROR_CREATURE_NOT_FOUND));
          lua_pushboolean(L, false);
       }

       return 1;
    }

    abajo agregue

    Código:

    int32_t LuaInterface::luaGetPlayerCriticalHitChance(lua_State* L)
    {
       //getPlayerCriticalHitChance(cid)
       ScriptEnviroment* env = getEnv();
       if(Player* player = env->getPlayerByUID(popNumber(L)))
          lua_pushnumber(L, player->getCriticalHitChance());
       else
       {
          errorEx(getError(LUA_ERROR_PLAYER_NOT_FOUND));
          lua_pushboolean(L, false);
       }
       return 1;
    }

    int32_t LuaInterface::luaGetPlayerDodgeChance(lua_State* L)
    {
       //getPlayerDodgeChance(cid)
       ScriptEnviroment* env = getEnv();
       if(Player* player = env->getPlayerByUID(popNumber(L)))
          lua_pushnumber(L, player->getDodgeChance());
       else
       {
          errorEx(getError(LUA_ERROR_CREATURE_NOT_FOUND));
          lua_pushboolean(L, false);
       }

       return 1;
    }

    int32_t LuaInterface::luaGetPlayerLifeAbsorb(lua_State* L)
    {
       //getPlayerLifeAbsorb(cid)
       ScriptEnviroment* env = getEnv();
       if(Player* player = env->getPlayerByUID(popNumber(L)))
          lua_pushnumber(L, player->getLifeAbsorb());
       else
       {
          errorEx(getError(LUA_ERROR_CREATURE_NOT_FOUND));
          lua_pushboolean(L, false);
       }

       return 1;
    }

    int32_t LuaInterface::luaGetPlayerManaAbsorb(lua_State* L)
    {
       //getPlayerManaAbsorb(cid)
       ScriptEnviroment* env = getEnv();
       if(Player* player = env->getPlayerByUID(popNumber(L)))
          lua_pushnumber(L, player->getManaAbsorb());
       else
       {
          errorEx(getError(LUA_ERROR_CREATURE_NOT_FOUND));
          lua_pushboolean(L, false);
       }

       return 1;
    }

    int32_t LuaInterface::luaGetPlayerLifeLeech(lua_State* L)
    {
       //getPlayerLifeLeech(cid)
       ScriptEnviroment* env = getEnv();
       if(Player* player = env->getPlayerByUID(popNumber(L)))
          lua_pushnumber(L, player->getLifeLeech());
       else
       {
          errorEx(getError(LUA_ERROR_CREATURE_NOT_FOUND));
          lua_pushboolean(L, false);
       }

       return 1;
    }

    int32_t LuaInterface::luaGetPlayerManaLeech(lua_State* L)
    {
       //getPlayerManaLeech(cid)
       ScriptEnviroment* env = getEnv();
       if(Player* player = env->getPlayerByUID(popNumber(L)))
          lua_pushnumber(L, player->getManaLeech());
       else
       {
          errorEx(getError(LUA_ERROR_CREATURE_NOT_FOUND));
          lua_pushboolean(L, false);
       }

       return 1;
    }

    en luascript.h busque

    Código:

    static int32_t luaGetPlayerSpentMana(lua_State* L);

    abajo agregue

    Código:

    static int32_t luaGetPlayerCriticalHitChance(lua_State* L);
          static int32_t luaGetPlayerDodgeChance(lua_State* L);
          static int32_t luaGetPlayerLifeAbsorb(lua_State* L);
          static int32_t luaGetPlayerManaAbsorb(lua_State* L);
          static int32_t luaGetPlayerLifeLeech(lua_State* L);
          static int32_t luaGetPlayerManaLeech(lua_State* L);

    funciones adicionadas

    Código:

    getPlayerCriticalHitChance(cid)
    getPlayerDodgeChance(cid)
    getPlayerLifeAbsorb(cid)
    getPlayerManaAbsorb(cid)
    getPlayerLifeLeech(cid)
    getPlayerManaLeech(cid)

    esta parte es de game.cpp es ocional usted puede elegir si agregarla o no

    en game.cpp buscamos

    Código:

    bool Game::combatChangeHealth(const CombatParams& params, Creature* attacker, Creature* target, int32_t healthChange, bool force)

    dentro de esa funcion busque

    Código:
    const Position& targetPos = target->getPosition();

    abajo de aquello agregue

    Código:

    int32_t lifeLeech, manaLeech, lifeAbsorb, manaAbsorb = 0;

    dentro de la misma funcion busque

    Código:

    damage = std::min(target->getHealth(), damage);
             if(damage > 0)
             {

    abajo de aquello agregue

    Código:

    Player* player = NULL;
                if(attacker && (player = attacker->getPlayer()))
                {
                   if(random_range(1,100) < attacker->getPlayer()->getCriticalHitChance())
                   {
                      damage = damage * 2;
                      addAnimatedText(attacker->getPosition(), COLOR_DARKRED, "Critical!");
                   }   
                }
                
                if((player = target->getPlayer()) && (attacker != target) && target == player)
                {
                   if(random_range(1,100) < target->getPlayer()->getDodgeChance())
                   {
                      damage = damage * 0.5;
                      addAnimatedText(target->getPosition(), COLOR_BLUE, "Dodge!");
                   }
                }

    dentro de la funcion busque

    Código:

    if((player = target->getPlayer()) && attacker != target)
                   {
                      if(attacker)
                         ss << "You lose " << totalDamage << " hitpoint" << plural << " due to an attack by " << attacker->getNameDescription() << ".";
                      else
                         ss << "You lose " << totalDamage << " hitpoint" << plural << ".";

                      player->sendStatsMessage(MSG_DAMAGE_RECEIVED, ss.str(), targetPos, details);
                   }

    abajo de aeullo agregue

    Código:

    if(attacker && (player = attacker->getPlayer()))
                   {
                      if(attacker->getPlayer()->getLifeLeech() > 0)
                      {
                         lifeLeech = damage * (attacker->getPlayer()->getLifeLeech() * 0.01);
                         if(damage > 0)
                         {
                            combatChangeHealth(params, target, attacker, lifeLeech, true);
                         }
                      }
                      
                      if(attacker->getPlayer()->getManaLeech() > 0)
                      {
                         manaLeech = damage * (attacker->getPlayer()->getManaLeech() * 0.01);
                         if(damage > 0)
                         {
                            combatChangeMana(target, attacker, manaLeech, params.combatType, true);
                         
                      
                   
                   
                   

                     
                   
                        
                       () * 0.01);
                         if(damage > 0)
                         {
                            combatChangeHealth(params, attacker, target, lifeAbsorb, true);
                         }
                      }
                      
                        
                        
                         
                         
                            combatChangeMana(attacker, target, manaAbsorb, params.combatType, true);
                         }
                      }
                   }

    en game.cpp busque la siguiente funcion

    Código:

    bool Game::combatChangeMana(Creature* attacker, Creature* target, int32_t manaChange,
       CombatType_t combatType/* = COMBAT_MANADRAIN*/, bool inherited/* = false*/)

    dentro  esa funcion busque

    Código:

    const Position& targetPos = target->getPosition();

    agregue esto abajo

    Código:

    int32_t lifeLeech, manaLeech, lifeAbsorb, manaAbsorb = 0;

    dentro de la misma funcion busque

    Código:

    if((player = target->getPlayer()) && attacker != target)
             {
                if(attacker)
                   ss << "You lose " << manaLoss << " mana due to an attack by " << attacker->getNameDescription();
                else
                   ss << "You lose " << manaLoss << " mana.";

                player->sendStatsMessage(MSG_DAMAGE_RECEIVED, ss.str(), targetPos, details);
             }

    abajo coloque

    Código:

    // Life e Mana Leech
             if(attacker && (player = attacker->getPlayer()))
             {
                if(attacker->getPlayer()->getLifeLeech() > 0)
                {
                   lifeLeech = manaLoss * (attacker->getPlayer()->getLifeLeech() * 0.01);
                   if(manaLoss > 0)
                   {
                      combatChangeHealth(manaLoss < 1 ? COMBAT_UNDEFINEDDAMAGE : COMBAT_HEALING, target, attacker, lifeLeech, MAGIC_EFFECT_UNKNOWN, COLOR_UNKNOWN, false);
                   }
                }
                
                if(attacker->getPlayer()->getManaLeech() > 0)
                {
                   manaLeech = manaLoss * (attacker->getPlayer()->getManaLeech() * 0.01);
                   if(manaLoss > 0)
                   {
                      combatChangeMana(target, attacker, manaLeech, combatType, true);
                   }
                }
             }

    // Life e Mana Absorb
             if((player = target->getPlayer()) && (attacker != target))
             {
                if(target->getPlayer()->getLifeAbsorb() > 0)
                {
                   lifeAbsorb = manaLoss * (target->getPlayer()->getLifeAbsorb() * 0.01);
                   if(manaLoss > 0)
                   {
                      combatChangeHealth(manaLoss < 1 ? COMBAT_UNDEFINEDDAMAGE : COMBAT_HEALING, attacker, target, lifeAbsorb, MAGIC_EFFECT_UNKNOWN, COLOR_UNKNOWN, false);
                   }
                }
                
                if(target->getPlayer()->getManaAbsorb() > 0)
                {
                   manaAbsorb = manaLoss * (target->getPlayer()->getManaAbsorb() * 0.01);
                   if(manaLoss > 0)
                   {
                      combatChangeMana(attacker, target, manaAbsorb, combatType, true);
                   }
                }
             }


    Créditos: ~Mathias Kenfi

    el sistema fue implementado en estas sources: [Tienes que estar registrado y conectado para ver este vínculo]

    y el servidor completo: [Tienes que estar registrado y conectado para ver este vínculo]



    maya tengo algunas preguntas la primera es

    funciona en the otx server 2.15 ?


    la segunda solo funciona en items de tipo melee?

    porque no me a funcionado en armors , shields , helmets y wands!




    la tercera si ya ise todo porque cuando agrego el atributo dodgechance no me aparece y me arroja error en consola?


    pense que lo habia echo mal pero si estuviera mal no hubiera funcionado nisiquiera el critical y ese si funciono no arroja error ! saludos espero veas este post!

    5 participantes

    darksenki

    darksenki
    Miembro
    Miembro
    revisando

    5 participantes

    melquian

    melquian
    Nuevo Miembro
    Nuevo Miembro
    Existe um bug neste codigo. Ex. Você tem um anel que concede +10% de criticalchance, + 5 de magic level, se você equipa-lo no slot de anel vai receber ambos os atributos, mas se equipa-lo em uma das mãos ou no slot de ammo vai receber o atributo criticalchance.
    Acredito que existe uma checagem de slot nas sources que define os atributos se equipados no slot correto, no entanto não acontece com esses novos atributos.

    5 participantes

    Contenido patrocinado


    5 participantes

    Ver el tema anterior Ver el tema siguiente Volver arriba  Mensaje (Página 1 de 1.)

    Permisos de este foro:
    No puedes responder a temas en este foro.

     

    BienvenidosTibiaFace es una comunidad de Open Tibia. Para participar debes estar registrado (click para Regístrate).