TFS 1.X+ Character Stats functionality (stamina, wisdom)

Itutorial

Premium User
Premium User
Joined
Dec 23, 2014
Messages
1,497
Best answers
33
Reaction score
337
So I am creating a stat system on items like WoW and many other RPGs nowadays.

I need help figuring out how to make it so when a player equips items with: +stamina or +wisdom
it will change their health/mana and also when they remove it.

I tried modifying movement.cpp
Code:
uint32_t MoveEvent::EquipItem(MoveEvent* moveEvent, Player* player, Item* item, slots_t slot, bool isCheck)

uint32_t MoveEvent::DeEquipItem(MoveEvent*, Player* player, Item* item, slots_t slot, bool)
I tried to have it change the players health/mana there.

Unfortunately
player->manaMax
and
creature->healthMax

are protected.

I tried creating a way to change them even though they are protected like this:

Code:
creature.h
void setMaxHealth(int32_t newMaxHealth) {
     healthMax = newMaxHealth;
}

player.h
void setMaxMana(uint32_t newMaxMana) {
    manaMax = newMaxMana;
}
Obviously not the right way to do it because I could no longer move armor off of my character though, my god character was able to move items off of him.

Will someone help me with this?
 

Evil Puncker

I'd rather kiss a rattlesnake
Joined
May 30, 2009
Messages
5,561
Best answers
14
Reaction score
1,645
Location
160,54,7
have you took a look at the code from this already? it maybe can help you to have an idea
 
OP
Itutorial

Itutorial

Premium User
Premium User
Joined
Dec 23, 2014
Messages
1,497
Best answers
33
Reaction score
337
What do you mean?
 

Delusion

Divine Intellect
Support Team
Joined
Feb 14, 2015
Messages
4,935
Best answers
451
Reaction score
2,547
Or you could force scripted items to execute normal equip/deEquip conditions and just script the items in Lua rather than hardcoding them.
C++:
uint32_t MoveEvent::fireEquip(Player* player, Item* item, slots_t slot, bool isCheck)
{
    if (scripted) {
        bool scriptSuccess = executeEquip(player, item, slot, isCheck);
        if (!scriptSuccess) {
            return 0;
        }
        return getEventType() == MOVE_EVENT_EQUIP ? EquipItem(this, player, item, slot, isCheck) : DeEquipItem(this, player, item, slot, isCheck);
    }
    return equipFunction(this, player, item, slot, isCheck);
}
Then all you have to do is script the item and register it in movements, equip you give more hp, deequip you remove the bonus.
 
OP
Itutorial

Itutorial

Premium User
Premium User
Joined
Dec 23, 2014
Messages
1,497
Best answers
33
Reaction score
337
Pretty much every or a lot of items will have stamina or wisdom on it. Adding in each item is a waste of time. Thanks for the reply though. Hopefully I can find something soon. I know there is a distro that was released with this kind of stuff already in it but I can't find it.
 

Delusion

Divine Intellect
Support Team
Joined
Feb 14, 2015
Messages
4,935
Best answers
451
Reaction score
2,547
You can simply use 1 script and find+replace all function="equipItem"/deequip in your movements.xml and replace it with the script and have the script read +wis/stamina/w/e you want on it, and add it according to what values are parsed from the item.
 
OP
Itutorial

Itutorial

Premium User
Premium User
Joined
Dec 23, 2014
Messages
1,497
Best answers
33
Reaction score
337
I was trying something like this in CPP

Code:
for (int32_t i = SKILL_FIRST; i <= SKILL_LAST; ++i) {
        if (it.abilities->skills[i]) {
            needUpdateSkills = true;
            player->setVarSkill(static_cast<skills_t>(i), it.abilities->skills[i]);

            if (i == SKILL_STAMINA) {
                needUpdateStats = true;
                player->setVarStats(static_cast<stats_t>(STAT_MAXHITPOINTS), player->getMaxHealth() + (it.abilities->skills[i] * 2));
            }
            
            if (i == SKILL_WISDOM) {
                needUpdateStats = true;
                player->setVarStats(static_cast<stats_t>(STAT_MAXMANAPOINTS), player->getMaxMana() + (it.abilities->skills[i] * 2));
            }
        }
    }
That is in the moveevnts equipitem and dequipitem
 
OP
Itutorial

Itutorial

Premium User
Premium User
Joined
Dec 23, 2014
Messages
1,497
Best answers
33
Reaction score
337
Alright, I got it working.

This is what the code looks like

Code:
//skill modifiers
    bool needUpdateSkills = false;
    bool needUpdateStats = false;
    
    for (int32_t i = SKILL_FIRST; i <= SKILL_LAST; ++i) {
        if (it.abilities->skills[i] != 0) {
            needUpdateSkills = true;
            player->setVarSkill(static_cast<skills_t>(i), -it.abilities->skills[i]);

            if (i == SKILL_STAMINA) {
                needUpdateStats = true;
                player->setVarStats(static_cast<stats_t>(STAT_MAXHITPOINTS), -(it.abilities->skills[i] * 2));
            }
            
            if (i == SKILL_WISDOM) {
                needUpdateStats = true;
                player->setVarStats(static_cast<stats_t>(STAT_MAXMANAPOINTS), -(it.abilities->skills[i] * 2));
            }
        }
    }

    if (needUpdateSkills) {
        player->sendSkills();
    }

    if (needUpdateStats) {
        player->sendStats();
    }
Delusions comment lead me to the answer which was that the item wasn't being registered in moveevents in the xml file. Big wups and a lot of hassle for nothing there.

Now, if anyone can tell me why the stats are not being updated in otclient. My character gets the new health correctly in the in-game screen and everything is registered right, but otclient doesn't show the new health.

Thank you to everyone who has commented.

So it seems like I need to send something to the client to tell it to update the players health/mana. The players stats are changing correctly server side but not client side. How can I do it?
 
Top