Jump to content

Check - party.marriage_in_party()


Recommended Posts

int marriage_in_party(lua_State* L)
	{
		LPCHARACTER ch = CQuestManager::instance().GetCurrentCharacterPtr();
		if (ch==NULL){lua_pushboolean(L, 0);return 0;}
		marriage::TMarriage* pMarriage = marriage::CManager::instance().Get(ch->GetPlayerID());
		unsigned int pidMarriage;
		if (pMarriage)
		{
			LPCHARACTER you = CHARACTER_MANAGER::instance().FindByPID(pMarriage->GetOther(ch->GetPlayerID()));
			if (you == NULL) return 0;
			pidMarriage = you->GetPlayerID();
		}else{lua_pushboolean(L, 0);return 0;}
		
		LPPARTY pParty = ch->GetParty();
		if (NULL == pParty){lua_pushboolean(L, 0);return 0;}
			
		FPartyPIDCollector f;
		pParty->ForEachOnMapMember(f, ch->GetMapIndex());
		
		std::vector <DWORD>::iterator it = f.vecPIDs.begin();
		bool is_in = false;
		for (f.vecPIDs.begin(); it != f.vecPIDs.end(); it++)
			if (pidMarriage == *it)
			{
				is_in = true;
				break;
			}
		
		lua_pushboolean(L, is_in ? 1:0);
		return 1;
	}

Function check if your wife/husband is in party with you. Players must be in the same group and on the same map.

  • Love 4
Link to comment
Share on other sites

  • Premium

Great idea, but this won't be a cleaner way?

int party_spouse_in_party(lua_State* L)
{
	// Get the current character
	const LPCHARACTER ch = CQuestManager::instance().GetCurrentCharacterPtr();

	// Something went wrong, character does not exist
	if (!ch)
	{
		lua_pushboolean(L, false);
		return 1;
	}

	// I'm not in party
	if (!ch->GetParty())
	{
		lua_pushboolean(L, false);
		return 1;
	}
	
	// Get my marriage partner
	const LPCHARACTER tch = ch->GetMarryPartner();

	// I don't have marriage partner
	if (!tch)
	{
		lua_pushboolean(L, false);
		return 1;
	}

	// My spouse is not in party
	if (!tch->GetParty())
	{
		lua_pushboolean(L, false);
		return 1;
	}

	// We are not on the same map
	if (tch->GetMapIndex() != ch->GetMapIndex())
	{
		lua_pushboolean(L, false);
		return 1;
	}

	// We are not in the same party
	if (!ch->GetParty()->IsMember(tch->GetPlayerID()))
	{
		lua_pushboolean(L, false);
		return 1;
	}

	lua_pushboolean(L, true);
	return 1;
}
  • Love 4
Link to comment
Share on other sites

Announcements



×
×
  • Create New...

Important Information

Terms of Use / Privacy Policy / Guidelines / We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.