• This is a read only backup of the old Emudevs forum. If you want to have anything removed, please message me on Discord: KittyKaev

Hello all! Maybe someone have script time to ress world boss?

jimteck

Emulation Addict
Maybe someone have script time to ress world boss?
The Gossip menu the player can see how much time is left before the resurrection of the boss.
 

slp13at420

Mad Scientist
hmmm I swear I just did a simple CPP script for a command that would post npc info like respawn duration and respawn time left. let me look thru my clutter n get back with you.
doesn't mean I will find it right away if someone else has something already handy then by all means link it :)
 

slp13at420

Mad Scientist
if you still are having problems after examining the conversation thread from the link posted above I will wrap it up in a small script that is command based.
it is a .CPP script so you will need to know how to compile and add scripts to a source project.
 

MrPixelMC

Member
if you still are having problems after examining the conversation thread from the link posted above I will wrap it up in a small script that is command based.
it is a .CPP script so you will need to know how to compile and add scripts to a source project.

I believe you're using target though, if I am a player and I want to know the respawn time left for a dead boss, the corpse has probably disappeared, should use something else imo.
 

jimteck

Emulation Addict
I try compile,but have errors in "action".

#include "ScriptPCH.h"
#include "ScriptMgr.h"
#include "ObjectMgr.h"
#include "Chat.h"
#include "Transport.h"
#include "CreatureGroups.h"
#include "Language.h"
#include "TargetedMovementGenerator.h"
#include "CreatureAI.h"
#include "Player.h"
#include "Pet.h"




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


bool OnGossipHello(Player * player, Creature * creature)

{


{

player->ADD_GOSSIP_ITEM(0, "|cff000080Test boss 1", GOSSIP_SENDER_MAIN, 100);
return true;
}
}

static bool HandleNpcInfoCommand(ChatHandler* handler, char const* /*args*/, Player *player, Creature *_Creature)
{

Creature* target = handler->getSelectedCreature();

int64 curRespawnDelay = target->GetRespawnTimeEx() - time(NULL);

if (curRespawnDelay < 0)
curRespawnDelay = 0;

switch(action)

{


//////////////// MAIN MENUS -> Normal Menus //////////////////

case 100: // test boss 1
player->CLOSE_GOSSIP_MENU();
std::string curRespawnDelayStr = secsToTimeString(uint64(curRespawnDelay), true);
std::string defRespawnDelayStr = secsToTimeString(100050->GetRespawnDelay(), true);
handler->PSendSysMessage(LANG_COMMAND_RAWPAWNTIMES, defRespawnDelayStr.c_str(), curRespawnDelayStr.c_str());
break;


}

}


};

void AddSC_npc_time()
{
new npc_time();
}
 

MrPixelMC

Member
I try compile,but have errors in "action".

There's so many errors in that code, you should read a guide about the basics before starting to code..
  • Why so many includes?
  • You're using HandleNpcInfoCommand, that's not the one you want to use, you want to use OnGossipSelect, that's why it's giving you an error, because "action" doesn't actually exist.
  • Also some of the brackets are useless, you should remove them.
 
Last edited:

slp13at420

Mad Scientist
I got this working rough draft :
Code:
[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]

I type ".custom npc info" while targeting an npc alive/dead and it will post info about hp... and respawn times.

I type ".custom npc info" with out targeting any npc and it will search around the player for npc's within 10' radius and post guid, name, x, y, z. but not the respawn times ... yet ..
just cant seem to figure out how to get the respawn times for an npc via its guid.
 
Last edited:

MrPixelMC

Member
just cant seem to figure out how to get the respawn times for an npc via its guid.

Take a look at this. Use it inside a for loop like:

Code:
for (int i = 0; i < creaturesInRadius; i++)
{
  Map* map = player->GetMap();
  Creature* creature = map->GetCreature(creatureGUID);
  if (creature)
  {
    creature->GetRespawnTimeEx();
    // blabla
  }
}

(I don't know if I used the correct functions, I'm not home so I can't check reference.)
Edit: I think there's a easier way to do it than what you've done, but I'm not entirely sure though.
 
Last edited:
Top