Modifying player stats through a PlayerScript and saving them.

Im trying to code a custom achievement script for when a player survives a fight with a creature with little health left, which gives them a stat boost if they survive… I get the values to change but it doesnt really boost the player it just changes the value for view and not actually raises their stats… This is a snipper of the code…

void OnCreatureKill(Player* player, Creature* creature)
{
if(!player->GetSession() || !player->IsAlive())
return;

uint32 cMax = creature->GetMaxHealth();
uint32 pCur = player->GetHealth();
uint32 pMax = player->GetMaxHealth();

if(player->GetHealth() <= (pMax / 3))
{
float _strength = (player->GetStat(STAT_INTELLECT) * 3) + (creature->GetStat(STAT_INTELLECT) + (creature->getLevel() / 2));
player->SetStat(STAT_INTELLECT, _strength);
player->GetSession()->SendNotification(“>SURVIVOR<”);
player->PlayDirectSound(8213,player);
player->PlayDirectSound(8192,player);
player->ApplyRatingMod(CR_CRIT_SPELL,_strength,true);
player->ApplyRatingMod(CR_HIT_SPELL,_strength,true);
player->ApplyRatingMod(CR_DODGE,_strength,true);
player->ApplyCastTimePercentMod(512,true);
player->SaveToDB(true);
}
}

Is this the proper way to handle player stats? Please help

— Canned message start —

This thread is not related to the official Trinity codebase and was moved to the Custom Code section.

Please read the stickies next time.

— Canned message end —

I apologize. I’ll be sure to do so, can u please delete my latest post? i posted again on the topic i thought it didnt submit

No. The mods are only temporary.

When a player logs in, only the base stats are taken, then gear and spells are applied.

So when you apply custom rating mods etc, they will only last until relog.

Cant check right now, but not sure why the values would be only visual.

Yeah thats another thing, but wht if you could script the mods to save to db and on login have the stats read from db instead ? and i was wrong, they arent just visual i checked deeper into it

Is that a request?

If yes, then no.

You can do it yourself.

You should have a variable(s) in player class that keep track in some way how many times the player was rewared or how much he has earned stats or something.

Then…

Just make a playerscript and on login to load the stats from DB and apply the stats from the variables.

On save, save the stats to DB from the variables.

When rewarding, make sure to change the variables.

no i can do it myself ofcourse, I was just wondering if that would work. and ifI make a variable, would it increment effiently? idk if the update function would keep the survive times up to date. id have to save that variable in the db also.