У меня есть некоторые проблемы, я пытаюсь заставить эту вещь работать, однако у меня есть некоторые проблемы со строкой для получения имени.
Я получаю следующую ошибку:ссылка на нестатический член должна относиться к определенному объекту. На
std::string GetName(uint32 entry) //this is the error causer.
{
return sObjectMgr->GetItemTemplate(entry)->Name1;
};
Однако функция Getname выдает ошибку для любого другого класса
#include "ScriptMgr.h"
#include "Creature.h"
#include "ScriptedCreature.h"
#include "ScriptedGossip.h"
#include "ObjectMgr.h"
#include "Player.h"
#include "WorldSession.h"
struct tokenData { uint32 TAKE_ENTRY, TAKE_AMOUNT, GIVE_ENTRY, GIVE_AMOUNT; };
struct tokenData Tokens[] =
{
{191201, 10, 191202, 1},
{191202, 1, 191201, 10},
{191202, 25, 191203, 1},
{191203, 1, 191202, 25},
{191203, 50, 191204, 1},
{191204, 1, 191203, 50},
{191204, 100, 191205, 1},
{191205, 1, 191204, 100}
};
const uint32 tokensSize = sizeof Tokens / sizeof(*Tokens);
class Exchanger_npc : public CreatureScript
{
public:
Exchanger_npc() : CreatureScript("Exchanger_npc") { }
std::string GetName(uint32 entry) //this is the error causer.
{
return sObjectMgr->GetItemTemplate(entry)->Name1;
};
static bool OnGossipHello(Player* player, Creature* creature)
{
for (uint32 i = 0; i < tokensSize; ++i)
{
std::ostringstream ss;
ss << "Swap " << Tokens[i].TAKE_AMOUNT << " x " << GetName(Tokens[i].TAKE_ENTRY) << " to " << Tokens[i].GIVE_AMOUNT << " x " << GetName(Tokens[i].GIVE_ENTRY);
AddGossipItemFor(player, 0, ss.str(), GOSSIP_SENDER_MAIN, i, "Are you sure?", 0, false);
}
SendGossipMenuFor(player, DEFAULT_GOSSIP_MESSAGE, creature->GetGUID());
return true;
}
static bool OnGossipSelect(Player* player, Creature* creature, uint32 sender, uint32 action)
{
player->PlayerTalkClass->ClearMenus();
if (sender == GOSSIP_SENDER_MAIN && action < tokensSize)
{
if (player->HasItemCount(Tokens[action].TAKE_ENTRY, Tokens[action].TAKE_AMOUNT))
{
if (player->AddItem(Tokens[action].GIVE_ENTRY, Tokens[action].GIVE_AMOUNT))
{
player->DestroyItemCount(Tokens[action].TAKE_ENTRY, Tokens[action].TAKE_AMOUNT, true);
player->GetSession()->SendAreaTriggerMessage("%u x %s swapped to %u x %s", Tokens[action].TAKE_AMOUNT, GetName(Tokens[action].TAKE_ENTRY).c_str(), Tokens[action].GIVE_AMOUNT, GetName(Tokens[action].GIVE_ENTRY).c_str());
}
}
else
player->GetSession()->SendNotification("You need at least %u x %ss", Tokens[action].TAKE_AMOUNT, GetName(Tokens[action].TAKE_ENTRY).c_str());
}
OnGossipHello(player, creature);
return true;
}
};
struct MyAI : public ScriptedAI
{
MyAI(Creature* creature) : ScriptedAI(creature) { }
bool GossipHello(Player* player) override
{
return OnGossipHello(player, me);
}
bool GossipSelect(Player* player, uint32 menuId, uint32 gossipListId) override
{
uint32 sender = player->PlayerTalkClass->GetGossipOptionSender(gossipListId);
uint32 action = player->PlayerTalkClass->GetGossipOptionAction(gossipListId);
return OnGossipSelect(player, me, sender, action);
}
};
CreatureAI* GetAI(Creature* creature) const override
{
return new MyAI(creature);
}
};
void AddSC_Exchanger_npc()
{
new Exchanger_npc();
}