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

Block Renegeration

Christopher172

New Member
Joined
Jun 16, 2016
Messages
13
Reaction score
1
Hello.
I'm developing a spell that the user stays invisible for a certain time. So far so good, but I wanted to make sure that while the character is invisible, he does not have regeneration. Is there any constant or something I can set in the player so that it is unable to regenerate HP / MANA?
 
Solution
Here you go (Moving this thread to Requests by the way) :p

condition.cpp
C++:
bool ConditionRegeneration::executeCondition(Creature* creature, int32_t interval)
{
    internalHealthTicks += interval;
    internalManaTicks += interval;

    if (creature->hasRegenerationBlocked() || creature->getZone() == ZONE_PROTECTION) {
        return ConditionGeneric::executeCondition(creature, interval);
    }

    if (internalHealthTicks >= healthTicks) {
        internalHealthTicks = 0;

        int32_t realHealthGain = creature->getHealth();
        creature->changeHealth(healthGain);
        realHealthGain = creature->getHealth() - realHealthGain;

        if (isBuff && realHealthGain > 0) {
            Player* player = creature->getPlayer()...
i don't think this is possible, by default in the sources it regens your health and mana from what's defined in vocations.xml
maybe it would work if you set a special vocation with no regeneration and changed the vocation of the player, but that's the only thing i can think of without touching the sources
 
why dont just remove certain amount of hp/mana every x sec?
Players regenerate different amounts depending on if they have been eating food


No, but I think @elf knows.
Elf is ralely online but there is some others here that would be able to do it but it is a bit of work and will probably be hard to get done for free
 
by all means it is possible, just not with what you're given by default. i just wasn't sure if you wanted to edit sources
what server version are you using?
 
why dont just remove certain amount of hp/mana every x sec?
We do not know exactly how much x.

No, but I think @elf knows.
Thank you.

Players regenerate different amounts depending on if they have been eating food



Elf is ralely online but there is some others here that would be able to do it but it is a bit of work and will probably be hard to get done for free
Not problem.

by all means it is possible, just not with what you're given by default. i just wasn't sure if you wanted to edit sources
what server version are you using?
The version my sourcers is 1.2
 
Here you go (Moving this thread to Requests by the way) :p

condition.cpp
C++:
bool ConditionRegeneration::executeCondition(Creature* creature, int32_t interval)
{
    internalHealthTicks += interval;
    internalManaTicks += interval;

    if (creature->hasRegenerationBlocked() || creature->getZone() == ZONE_PROTECTION) {
        return ConditionGeneric::executeCondition(creature, interval);
    }

    if (internalHealthTicks >= healthTicks) {
        internalHealthTicks = 0;

        int32_t realHealthGain = creature->getHealth();
        creature->changeHealth(healthGain);
        realHealthGain = creature->getHealth() - realHealthGain;

        if (isBuff && realHealthGain > 0) {
            Player* player = creature->getPlayer();
            if (player) {
                std::string healString = std::to_string(realHealthGain) + (realHealthGain != 1 ? " hitpoints." : " hitpoint.");

                TextMessage message(MESSAGE_HEALED, "You were healed for " + healString);
                message.position = player->getPosition();
                message.primary.value = realHealthGain;
                message.primary.color = TEXTCOLOR_MAYABLUE;
                player->sendTextMessage(message);

                SpectatorHashSet spectators;
                g_game.map.getSpectators(spectators, player->getPosition(), false, true);
                spectators.erase(player);
                if (!spectators.empty()) {
                    message.type = MESSAGE_HEALED_OTHERS;
                    message.text = player->getName() + " was healed for " + healString;
                    for (Creature* spectator : spectators) {
                        spectator->getPlayer()->sendTextMessage(message);
                    }
                }
            }
        }
    }

    if (internalManaTicks >= manaTicks) {
        internalManaTicks = 0;

        if (Player* player = creature->getPlayer()) {
            int32_t realManaGain = player->getMana();
            player->changeMana(manaGain);
            realManaGain = player->getMana() - realManaGain;

            if (isBuff && realManaGain > 0) {
                std::string manaGainString = std::to_string(realManaGain);

                TextMessage message(MESSAGE_HEALED, "You gained " + manaGainString + " mana.");
                message.position = player->getPosition();
                message.primary.value = realManaGain;
                message.primary.color = TEXTCOLOR_MAYABLUE;
                player->sendTextMessage(message);

                SpectatorHashSet spectators;
                g_game.map.getSpectators(spectators, player->getPosition(), false, true);
                spectators.erase(player);
                if (!spectators.empty()) {
                    message.type = MESSAGE_HEALED_OTHERS;
                    message.text = player->getName() + " gained " + manaGainString + " mana.";
                    for (Creature* spectator : spectators) {
                        spectator->getPlayer()->sendTextMessage(message);
                    }
                }
            }
        }
    }

    return ConditionGeneric::executeCondition(creature, interval);
}
creature.h
C++:
bool hasRegenerationBlocked() const {
    return blockRegeneration;
}

bool blockRegeneration = false;
luascript.cpp
C++:
registerMethod("Creature", "hasRegenerationBlocked", LuaScriptInterface::luaCreatureHasRegenerationBlocked);
registerMethod("Creature", "blockRegeneration", LuaScriptInterface::luaCreatureBlockRegeneration);

int LuaScriptInterface::luaCreatureHasRegenerationBlocked(lua_State* L)
{
    // creature:hasRegenerationBlocked()
    Creature* creature = getUserdata<Creature>(L, 1);
    if (!creature) {
        lua_pushnil(L);
        return 1;
    }

    pushBoolean(L, creature->hasRegenerationBlocked());
    return 1;
}

int LuaScriptInterface::luaCreatureBlockRegeneration(lua_State* L)
{
    // creature:blockRegeneration(boolean)
    Creature* creature = getUserdata<Creature>(L, 1);
    if (!creature) {
        lua_pushnil(L);
        return 1;
    }

    creature->blockRegeneration = getBoolean(L, 2);
    pushBoolean(L, true);
    return 1;
}
luascript.h
C++:
static int luaCreatureHasRegenerationBlocked(lua_State* L);
static int luaCreatureBlockRegeneration(lua_State* L);
 
Solution
Here you go (Moving this thread to Requests by the way) :p

condition.cpp
C++:
bool ConditionRegeneration::executeCondition(Creature* creature, int32_t interval)
{
    internalHealthTicks += interval;
    internalManaTicks += interval;

    if (creature->hasRegenerationBlocked() || creature->getZone() == ZONE_PROTECTION) {
        return ConditionGeneric::executeCondition(creature, interval);
    }

    if (internalHealthTicks >= healthTicks) {
        internalHealthTicks = 0;

        int32_t realHealthGain = creature->getHealth();
        creature->changeHealth(healthGain);
        realHealthGain = creature->getHealth() - realHealthGain;

        if (isBuff && realHealthGain > 0) {
            Player* player = creature->getPlayer();
            if (player) {
                std::string healString = std::to_string(realHealthGain) + (realHealthGain != 1 ? " hitpoints." : " hitpoint.");

                TextMessage message(MESSAGE_HEALED, "You were healed for " + healString);
                message.position = player->getPosition();
                message.primary.value = realHealthGain;
                message.primary.color = TEXTCOLOR_MAYABLUE;
                player->sendTextMessage(message);

                SpectatorHashSet spectators;
                g_game.map.getSpectators(spectators, player->getPosition(), false, true);
                spectators.erase(player);
                if (!spectators.empty()) {
                    message.type = MESSAGE_HEALED_OTHERS;
                    message.text = player->getName() + " was healed for " + healString;
                    for (Creature* spectator : spectators) {
                        spectator->getPlayer()->sendTextMessage(message);
                    }
                }
            }
        }
    }

    if (internalManaTicks >= manaTicks) {
        internalManaTicks = 0;

        if (Player* player = creature->getPlayer()) {
            int32_t realManaGain = player->getMana();
            player->changeMana(manaGain);
            realManaGain = player->getMana() - realManaGain;

            if (isBuff && realManaGain > 0) {
                std::string manaGainString = std::to_string(realManaGain);

                TextMessage message(MESSAGE_HEALED, "You gained " + manaGainString + " mana.");
                message.position = player->getPosition();
                message.primary.value = realManaGain;
                message.primary.color = TEXTCOLOR_MAYABLUE;
                player->sendTextMessage(message);

                SpectatorHashSet spectators;
                g_game.map.getSpectators(spectators, player->getPosition(), false, true);
                spectators.erase(player);
                if (!spectators.empty()) {
                    message.type = MESSAGE_HEALED_OTHERS;
                    message.text = player->getName() + " gained " + manaGainString + " mana.";
                    for (Creature* spectator : spectators) {
                        spectator->getPlayer()->sendTextMessage(message);
                    }
                }
            }
        }
    }

    return ConditionGeneric::executeCondition(creature, interval);
}
creature.h
C++:
bool hasRegenerationBlocked() const {
    return blockRegeneration;
}

bool blockRegeneration = false;
luascript.cpp
C++:
registerMethod("Creature", "hasRegenerationBlocked", LuaScriptInterface::luaCreatureHasRegenerationBlocked);
registerMethod("Creature", "blockRegeneration", LuaScriptInterface::luaCreatureBlockRegeneration);

int LuaScriptInterface::luaCreatureHasRegenerationBlocked(lua_State* L)
{
    // creature:hasRegenerationBlocked()
    Creature* creature = getUserdata<Creature>(L, 1);
    if (!creature) {
        lua_pushnil(L);
        return 1;
    }

    pushBoolean(L, creature->hasRegenerationBlocked());
    return 1;
}

int LuaScriptInterface::luaCreatureBlockRegeneration(lua_State* L)
{
    // creature:blockRegeneration(boolean)
    Creature* creature = getUserdata<Creature>(L, 1);
    if (!creature) {
        lua_pushnil(L);
        return 1;
    }

    creature->blockRegeneration = getBoolean(L, 2);
    pushBoolean(L, true);
    return 1;
}
luascript.h
C++:
static int luaCreatureHasRegenerationBlocked(lua_State* L);
static int luaCreatureBlockRegeneration(lua_State* L);
Ninja power! :)
 
Back
Top