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

[SOLVED] add a time if player in combat to do something

Status
Not open for further replies.

ricardodj

Member
hello guys i want to add time to do something if player is in combat i mean if player pull a boss for example dont allow the leader to change Loot Method, for 2 or 3 mins to avoid ninjas i dont know what i can put to do it :/
i have this now


i add this in group handler and work but without Time i mean if player leave combat then can change loot method instantly.

if(GetPlayer()->IsInCombat())
{
std::string str = "";
str = "you can't Modifying loot mode in combat.";
WorldPacket data(SMSG_NOTIFICATION, (str.size()+1));
data << str;
sWorld->SendGlobalGMMessage(&data);
return;
}
 
Last edited:

Hamar

BETA Tester
You could modify the GroupHandler.cpp method HandleLootMethodOpcode use a if statement to check if it is in instance combat.
trinity has already made a method for it in Group Class = group->InCombatToInstance(uint32 instanceId);

i.e : if(group->InCombatToInstance(GetPlayer()->GetInstanceId()) return; //

Compile, test and post the results please.
Since i can't do it myself. :banghead:

Sieppaa.jpg
 
Last edited:

ricardodj

Member
hello thanks for write
but i'm just want to add some minutes to the core edit
i mean if you enter in combat then Do not allow change loot method in maybe some mins to avoid ninjas
more easy to explain if you are in combat then you cant change to master loot for 2 minutes
and in these 2 minutes players need to stay without combat to allow it,

this work well. but but no has the timer event or idk how is called
to not allow change loot for 2 minutes, and also i want to say the resolution of the image is very low :V

if(GetPlayer()->IsInCombat())
{
std::string str = "";
str = "you can't Modifying loot mode in combat.";
WorldPacket data(SMSG_NOTIFICATION, (str.size()+1));
data << str;
sWorld->SendGlobalGMMessage(&data);
return;
}
 
Last edited:

Hamar

BETA Tester
Add a public variable in Group class (Group.h) named m_LastTimeInCombat. it should be a uint32 with a default value of 0.
i.e
Code:
uint32 m_LastTimeInCombat = 0;

Then let's go back to the GroupHandler.cpp to the HandleLootMethodOpcode method.
One solution i've come up with is to use a timestamp, it's not event based or timer tick based.
We'll be using few if statements and getMSTime() method.


Code:
	if (lootMethod == MASTER_LOOT)
	{
		if (group->m_LastTimeInCombat == 0)
			group->m_LastTimeInCombat = getMSTime(); // Set the timestamp.

		if (group->InCombatToInstance(GetPlayer()->GetInstanceId())) // Check if we are in combat.
		{
			GetPlayer()->GetSession()->SendNotification("You can't change loot mode in combat");
			group->m_LastTimeInCombat = getMSTime(); // If we are in combat just give a new stamp.
			return;
		}

		if (getMSTimeDiff(group->m_LastTimeInCombat, getMSTime()) < 1000 * 60 * 2) // check if the stamp and the current time differences by 2 minutes.
		{
			GetPlayer()->GetSession()->SendNotification("You need to wait 2 minutes before you can change the loot method");
			return;
		}

		group->m_LastTimeInCombat = 0; // Reset the stamp back to 0.
	}


The HandleLootMethodOpcode should now look more like this
Code:
void WorldSession::HandleLootMethodOpcode(WorldPacket& recvData)
{
    TC_LOG_DEBUG("network", "WORLD: Received CMSG_LOOT_METHOD");

    uint32 lootMethod;
    ObjectGuid lootMaster;
    uint32 lootThreshold;
    recvData >> lootMethod >> lootMaster >> lootThreshold;

    Group* group = GetPlayer()->GetGroup();
    if (!group)
        return;

    /** error handling **/
    if (!group->IsLeader(GetPlayer()->GetGUID()))
        return;

    if (lootMethod > NEED_BEFORE_GREED)
        return;

    if (lootThreshold < ITEM_QUALITY_UNCOMMON || lootThreshold > ITEM_QUALITY_ARTIFACT)
        return;

    if (lootMethod == MASTER_LOOT && !group->IsMember(lootMaster))
        return;

	if (lootMethod == MASTER_LOOT)
	{
		if (group->m_LastTimeInCombat == 0)
			group->m_LastTimeInCombat = getMSTime(); // Set the timestamp.

		if (group->InCombatToInstance(GetPlayer()->GetInstanceId)) // Check if we are in combat.
		{
			GetPlayer()->GetSession()->SendNotification("You can't change loot mode in combat");
			group->m_LastTimeInCombat = getMSTime(); // If we are in combat just give a new stamp.
			return;
		}

		if (getMSTimeDiff(group->m_LastTimeInCombat, getMSTime()) < 1000 * 60 * 2) // check if the stamp and the current time differences by 2 minutes.
		{
			GetPlayer()->GetSession()->SendNotification("You need to wait 2 minutes before you can change the loot method");
			return;
		}

		group->m_LastTimeInCombat = 0; // Reset the stamp back to 0.
	}

    /********************/

    // everything's fine, do it
    group->SetLootMethod((LootMethod)lootMethod);
    group->SetMasterLooterGuid(lootMaster);
    group->SetLootThreshold((ItemQualities)lootThreshold);
    group->SendUpdate();
}


And again i ask you to compile, test and post the results.
Not sure if this is what you're looking for.
 
Last edited:

ricardodj

Member
hello, thanks for reply but i have a little error >p
in if (group->InCombatToInstance(GetPlayer()->GetInstanceId))
screenshot here Screenshot (19h 19m 21s).jpg
 
Last edited:
Status
Not open for further replies.
Top