Block Renegeration

Christopher172

New Member
Joined
Jun 16, 2016
Messages
10
Reaction score
0
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?
 

Stigma

Veteran OT User
Joined
Feb 14, 2015
Messages
4,395
Reaction score
1,974
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
 

Zippiex

Member
Joined
Nov 4, 2015
Messages
255
Reaction score
19
Location
Sweden
I think it's possible. I'm not good at this but I'm pretty sure you can make some edit in sources.
 

Snurq

Member
Joined
Jul 7, 2012
Messages
51
Reaction score
12
why dont just remove certain amount of hp/mana every x sec?
 

Himii

Premium User
Premium User
Joined
Jan 19, 2011
Messages
1,206
Reaction score
146
Location
Sweden
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
 

Stigma

Veteran OT User
Joined
Feb 14, 2015
Messages
4,395
Reaction score
1,974
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?
 
OP
C

Christopher172

New Member
Joined
Jun 16, 2016
Messages
10
Reaction score
0
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
 

Ninja

Global Moderator
Staff member
Global Moderator
Joined
Apr 6, 2010
Messages
5,942
Reaction score
1,403
Location
Sweden
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);
 

Zippiex

Member
Joined
Nov 4, 2015
Messages
255
Reaction score
19
Location
Sweden
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! :)
 
OP
C

Christopher172

New Member
Joined
Jun 16, 2016
Messages
10
Reaction score
0
Hello people. Please forgive me as soon as I opened the topic I missed a connection for days. I tested it here and I solved my problem. Thank you all.
 
Top