Problem with "Realm First" achievement

Hi all ^^

I was trying to implement this Realm First achievement: Realm First! Grand Crusader and I wrote this piece of code:

[CODE]class criteria_tribute_to_insanity : public AchievementCriteriaScript

{

public:

    criteria_tribute_to_insanity() : AchievementCriteriaScript("criteria_tribute_to_insanity") { }


    bool OnCheck(Player* source, Unit* /*target*/)

    {

        if (!source)

            return false;


        InstanceScript* instance = source->GetInstanceScript();


        if (!instance || source->GetMapId() != TOC_RAID_MAP)

            return false;


        if (instance->GetData(TYPE_COUNTER) >= 50)

            return true;


        return false;

    }

};[/CODE]

and added the following sql in db (after deleting related rows in table disables and alredy existing rows in achievement_criteria_data):

INSERT INTO `achievement_criteria_data` (`criteria_id`, `type`, `value1`, `value2`, `ScriptName`) VALUES (12350,11,0,0,'criteria_tribute_to_insanity'), (12350,12,3,0,'');[/sql]

The achievement is correctly given if players complete ToGC 25 with 50 attempts remaining, but is given every time this happens and not only the first time. So is there something else I must add to make this achievement work properly?

Thanks in advance for your help.

A realm first has to be recorded somewhere in the database, and checked if it has already been granted.

Take a look at the code for the other realm-first achievements (first grandmaster miner, first level 80 shaman, etc) and see what they are doing.

BH

/agree a simple SQL check for the achievement will fix the issue.

The core already performs this control in function AchievementMgr::IsCompletedCriteria


if (achievement->flags & (ACHIEVEMENT_FLAG_REALM_FIRST_REACH | ACHIEVEMENT_FLAG_REALM_FIRST_KILL))

{

    // someone on this realm has already completed that achievement

    if (sAchievementMgr->IsRealmCompleted(achievement))

        return false;

}

I checked the DBC and the achievement is correctly flagged as a Realm First achievement.

EDIT: maybe I found the source of the problem: in function AchievementMgr::CompletedAchievement there is this piece of code:


// don't insert for ACHIEVEMENT_FLAG_REALM_FIRST_KILL since otherwise only the first group member would reach that achievement

// TODO: where do set this instead?

if (!(achievement->flags & ACHIEVEMENT_FLAG_REALM_FIRST_KILL))

    sAchievementMgr->SetRealmCompleted(achievement);