Item on Gossip

Im looking to add an NPC that gives an item to you upon speaking with them, but only if you have a specific quest. Can someone point me in the right direction, thanks.

C++?

Upon talking to him… You mean when you click a gossip option or when you click the NPC to talk to him?

Why not take a look at the example script for gossip and try to use player->IsActiveQuest(entry) in combination with player->AddItem(entry, count); or what was it…

https://github.com/TrinityCore/TrinityCore/blob/master/src/server/scripts/Examples/example_gossip_codebox.cpp#L49

http://www.trinitycore.net/d2/d4b/classPlayer.html#aa60201d424a30c33bc293ddca4cb6c82

http://www.trinitycore.net/d2/d4b/classPlayer.html#a14a4c0bd0215f10b44ef739083e4f577

Either. Simply clicking on him and having him say hello would be fine.

Cant get any simpler.

class AddItemOnTalkIfQuest : public CreatureScript
{
public:
    AddItemOnTalkIfQuest() : CreatureScript("AddItemOnTalkIfQuest") {}

    bool OnGossipHello(Player* player, Creature* creature) OVERRIDE
    {
        if (player->IsActiveQuest(entry))
            player->AddItem(entry, count);
        return false;
    }
};

void AddSC_AddItemOnTalkIfQuest()
{
    new AddItemOnTalkIfQuest();
}

Does this have to be done with C++ or can it be done in db?

You should be able to use conditions on a gossip option to show if you have the quest and then on click sai gives item.

but why do it in db, this tiny c++ is much more user friendly