[COLOR="#808080"]
// By Grumbo / slp13at420 of EmuDevs.com
#include "Chat.h"
#include "Language.h"
#include "Map.h"
#include "ObjectMgr.h"
#include "player.h"
#include "RBAC.h"
#include "ScriptMgr.h"
#include "Util.h"
float NPC_INFO_RADIUS = 25.0f;
class Player_Custom_Commands : public CommandScript
{
public:
Player_Custom_Commands() : CommandScript("Player_Custom_Commands") { }
std::vector<ChatCommand> GetCommands() const
{
static std::vector<ChatCommand> PlayerCustomCommandNpcTable =
{
{ "info", rbac::RBAC_IN_GRANTED_LIST, true, &HandlePlayerCustomCommandNpcInfo, "Player Custom command to show npc basic info." },
};
static std::vector<ChatCommand> PlayerCommandTable =
{
{ "npc", rbac::RBAC_IN_GRANTED_LIST, false, NULL, "Player Custom npc sub command tree.", PlayerCustomCommandNpcTable },
};
static std::vector<ChatCommand> commandTable =
{
{ "custom", rbac::RBAC_IN_GRANTED_LIST, false, NULL, "Player Custom command tree.", PlayerCommandTable },
};
return commandTable;
}
static bool HandlePlayerCustomCommandNpcInfo(ChatHandler* handler, const char* args)
{
Creature* target = NULL;
Player* player = handler->GetSession()->GetPlayer();
Map* map = player->GetMap();
if (handler->getSelectedCreature())
{
uint64 TtlRespawnDelay;
uint64 curRespawnDelay;
std::string defRespawnDelayStr;
std::string curRespawnDelayStr;
target = handler->getSelectedCreature();
TtlRespawnDelay = target->GetRespawnDelay();
curRespawnDelay = uint64(target->GetRespawnTimeEx() - time(NULL));
if (curRespawnDelay < 0)
curRespawnDelay = 0;
defRespawnDelayStr = secsToTimeString(TtlRespawnDelay, false);
curRespawnDelayStr = secsToTimeString(uint64(curRespawnDelay), false);
ChatHandler(player->GetSession()).PSendSysMessage("Creature info:");
ChatHandler(player->GetSession()).PSendSysMessage("____________");
ChatHandler(player->GetSession()).PSendSysMessage("Name:", target->GetName().c_str());
handler->PSendSysMessage(LANG_COMMAND_RAWPAWNTIMES, defRespawnDelayStr.c_str(), curRespawnDelayStr.c_str());
handler->PSendSysMessage(LANG_NPCINFO_HEALTH, target->GetCreateHealth(), target->GetMaxHealth(), target->GetHealth());
handler->PSendSysMessage(LANG_NPCINFO_ARMOR, target->GetArmor());
}
else
{
handler->PSendSysMessage("No creature selected. Searching for near creatures.");
float distance = (!*args) ? NPC_INFO_RADIUS : float((atof(args)));
uint32 count = 0;
PreparedStatement* stmt = WorldDatabase.GetPreparedStatement(WORLD_SEL_CREATURE_NEAREST);
stmt->setFloat(0, player->GetPositionX());
stmt->setFloat(1, player->GetPositionY());
stmt->setFloat(2, player->GetPositionZ());
stmt->setUInt32(3, player->GetMapId());
stmt->setFloat(4, player->GetPositionX());
stmt->setFloat(5, player->GetPositionY());
stmt->setFloat(6, player->GetPositionZ());
stmt->setFloat(7, distance * distance);
PreparedQueryResult result = WorldDatabase.Query(stmt);
if (result)
{
do
{
Field* fields = result->Fetch();
ObjectGuid::LowType guid = fields[0].GetUInt32();
uint32 entry = fields[1].GetUInt32();
float x = fields[2].GetFloat();
float y = fields[3].GetFloat();
float z = fields[4].GetFloat();
uint16 mapId = fields[5].GetUInt16();
CreatureTemplate const* creatureTemplate = sObjectMgr->GetCreatureTemplate(entry);
if (!creatureTemplate)
continue;
CreatureData const* cr_data = sObjectMgr->GetCreatureData(guid);
target = map->GetCreature(ObjectGuid(HighGuid::Unit, cr_data->id, guid)); // ->ToCreature()
uint32 TtlRespawnDelay2 = cr_data->spawntimesecs;
std::string defRespawnDelayStr2 = secsToTimeString(TtlRespawnDelay2, true);
std::string curRespawnDelayStr2 = secsToTimeString(0, true);
handler->PSendSysMessage("__________________");
handler->PSendSysMessage("name:%s", creatureTemplate->Name.c_str());
handler->PSendSysMessage("id:%u", creatureTemplate->Entry);
handler->PSendSysMessage("GUIDLow:%u", guid);
handler->PSendSysMessage(LANG_COMMAND_RAWPAWNTIMES, defRespawnDelayStr2.c_str(), curRespawnDelayStr2.c_str());
handler->PSendSysMessage("current health:%uhp", cr_data->curhealth);
++count;
} while (result->NextRow());
handler->PSendSysMessage(" ");
handler->PSendSysMessage(LANG_COMMAND_NEAR_NPC_MESSAGE, distance, count);
}
else
{
handler->PSendSysMessage("No creatures found near you.");
}
}
return true;
}
};
void AddSC_Player_Custom_Commands()
{
new Player_Custom_Commands;
}
[/COLOR]