Jump to content

pc.give_item2 for all player possible?


Recommended Posts

        when 24930.kill with pc.in_dungeon() and pc.get_map_index() >= 40000 and pc.get_map_index() < 40000+10 begin
            d.kill_all()
            d.clear_regen()
            pc.give_item2(71084, 50)
            pc.give_item2(71085, 50)
            pc.give_item2(70024, 5)
            pc.give_item2(50300, 2)
            pc.give_exp2(200000)
        end

 

how can i doit? I want , how the quest give items to all player on the map.

Thank You 
 

Link to comment
Share on other sites

  • Premium
when 24930.kill with pc.in_dungeon() and pc.get_map_index() >= 40000 and pc.get_map_index() < 40000+10 begin -- ?????

This check means that if there are more than 10 active instances of that specific dungeon, it'll stop working. I'd start by fixing that.

Regarding your question, you can write this:

d.kill_all()
d.clear_regen()

if (party.is_party()) then
	for _, pid in ipairs({party.get_member_pids()}) do
		q.begin_other_pc_block(pid);
		--
		pc.give_item2(71084, 50)
		pc.give_item2(71085, 50)
		pc.give_item2(70024, 5)
		pc.give_item2(50300, 2)
		pc.give_exp2(200000)
		--
		q.end_other_pc_block();
	end -- for
else
	pc.give_item2(71084, 50)
	pc.give_item2(71085, 50)
	pc.give_item2(70024, 5)
	pc.give_item2(50300, 2)
	pc.give_exp2(200000)
end -- if/else

Although I'd write a function.

Edited by Syreldar
  • Love 1

 

"Nothing's free in this life.

Ignorant people have an obligation to make up for their ignorance by paying those who help them.

Either you got the brains or cash, if you lack both you're useless."

Syreldar

Link to comment
Share on other sites

On 11/12/2022 at 6:50 PM, Syreldar said:
when 24930.kill with pc.in_dungeon() and pc.get_map_index() >= 40000 and pc.get_map_index() < 40000+10 begin -- ?????

This check means that if there are more than 10 active instances of that specific dungeon, it'll stop working. I'd start by fixing that.

Regarding your question, you can write this:

d.kill_all()
d.clear_regen()

if (party.is_party()) then
	for _, pid in ipairs({party.get_member_pids()}) do
		q.begin_other_pc_block(pid);
		--
		pc.give_item2(71084, 50)
		pc.give_item2(71085, 50)
		pc.give_item2(70024, 5)
		pc.give_item2(50300, 2)
		pc.give_exp2(200000)
		--
		q.end_other_pc_block();
	end -- for
else
	pc.give_item2(71084, 50)
	pc.give_item2(71085, 50)
	pc.give_item2(70024, 5)
	pc.give_item2(50300, 2)
	pc.give_exp2(200000)
end -- if/else

Although I'd write a function.

Thank you so much 

Link to comment
Share on other sites

questlua_dungeon.cpp
 

	ALUA(dungeon_give_item)
	{
		if (!lua_tonumber(L, 1))
			return 0;
		
		int count = 1;
		
		if (lua_tonumber(L, 2) > 1)
			count = lua_tonumber(L, 2);
		
		CQuestManager& q = CQuestManager::instance();
		
		LPDUNGEON pDungeon = q.GetCurrentDungeon();

		if (pDungeon)
			pDungeon->GiveItem(lua_tonumber(L, 1), count);

		return 0;
	}
	

--------------------------------------------------
			{"give_item2", dungeon_give_item},

 

dungeon.cpp
 

namespace
{
	struct FGiveItem
	{
		FGiveItem(int vnum, int count) : m_vnum(vnum), m_count(count)
		{
		}

		void operator() (LPENTITY ent)
		{
			if (ent->IsType(ENTITY_CHARACTER))
			{
				LPCHARACTER ch = (LPCHARACTER) ent;
				if (ch && ch->IsPC())
				{
					int iCount = m_count;
					//ch->ChatPacket(CHAT_TYPE_COMMAND, "%s", m_psz);
					const auto& item = ITEM_MANAGER::instance().CreateItem(m_vnum, m_count, 0, true);
					if (item->IsStackable())
					{
						ch->AutoGiveItem(m_vnum, m_count);
					}
					else
					{
						while (iCount > 0) {
							ch->AutoGiveItem(m_vnum, 1);
							iCount -= 1;
						}
					}
					ITEM_MANAGER::instance().DestroyItem(item);
				}
			}
		}

		int m_vnum;
		int m_count;
	};
}

void CDungeon::GiveItem(int vnum, int count)
{
	sys_log(0, "XXX Dungeon GiveItem %p %d %d", this, vnum, count);
	LPSECTREE_MAP pMap = SECTREE_MANAGER::instance().GetMap(m_lMapIndex);

	if (!pMap)
	{
		sys_err("cannot find map by index %d", m_lMapIndex);
		return;
	}
	
	FGiveItem f(vnum, count);
	pMap->for_each(f);
}

dungeon.h

	public:
		void	GiveItem(int vnum, int count);


quest_function

d.give_item2

And finally in your quest

d.give_item2(vnum, count)

 

  • Love 1
Link to comment
Share on other sites

On 11/15/2022 at 3:42 PM, PetePeter said:

questlua_dungeon.cpp
 

	ALUA(dungeon_give_item)
	{
		if (!lua_tonumber(L, 1))
			return 0;
		
		int count = 1;
		
		if (lua_tonumber(L, 2) > 1)
			count = lua_tonumber(L, 2);
		
		CQuestManager& q = CQuestManager::instance();
		
		LPDUNGEON pDungeon = q.GetCurrentDungeon();

		if (pDungeon)
			pDungeon->GiveItem(lua_tonumber(L, 1), count);

		return 0;
	}
	

--------------------------------------------------
			{"give_item2", dungeon_give_item},

 

dungeon.cpp
 

namespace
{
	struct FGiveItem
	{
		FGiveItem(int vnum, int count) : m_vnum(vnum), m_count(count)
		{
		}

		void operator() (LPENTITY ent)
		{
			if (ent->IsType(ENTITY_CHARACTER))
			{
				LPCHARACTER ch = (LPCHARACTER) ent;
				if (ch && ch->IsPC())
				{
					int iCount = m_count;
					//ch->ChatPacket(CHAT_TYPE_COMMAND, "%s", m_psz);
					const auto& item = ITEM_MANAGER::instance().CreateItem(m_vnum, m_count, 0, true);
					if (item->IsStackable())
					{
						ch->AutoGiveItem(m_vnum, m_count);
					}
					else
					{
						while (iCount > 0) {
							ch->AutoGiveItem(m_vnum, 1);
							iCount -= 1;
						}
					}
					ITEM_MANAGER::instance().DestroyItem(item);
				}
			}
		}

		int m_vnum;
		int m_count;
	};
}

void CDungeon::GiveItem(int vnum, int count)
{
	sys_log(0, "XXX Dungeon GiveItem %p %d %d", this, vnum, count);
	LPSECTREE_MAP pMap = SECTREE_MANAGER::instance().GetMap(m_lMapIndex);

	if (!pMap)
	{
		sys_err("cannot find map by index %d", m_lMapIndex);
		return;
	}
	
	FGiveItem f(vnum, count);
	pMap->for_each(f);
}

dungeon.h

	public:
		void	GiveItem(int vnum, int count);


quest_function

d.give_item2

And finally in your quest

d.give_item2(vnum, count)

 

I need this. Thank you

Link to comment
Share on other sites

  • Active Member

Alternative (no C++, only lua)

 

party.give_item2 = function(item_vnum, item_count)
	if party.is_party() then
		local pids = {party.get_member_pids()}
		for _, pid in next, pids, nil do
			q.begin_other_pc_block(pid)
			pc.give_item2(item_vnum, item_count)
			q.end_other_pc_block()
		end
		party.get_member_pids()
	else
		pc.give_item2(item_vnum, item_count)
	end
end

 

Advantage:

You can to use in dungeon or not.

 

Usage (example):

party.give_item2(27001, 200)

 

quest_functions: party.give_item2

 

¡Saludos!

Link to comment
Share on other sites

1 hour ago, caanmasu said:

Alternative (no C++, only lua)

 

party.give_item2 = function(item_vnum, item_count)
	if party.is_party() then
		local pids = {party.get_member_pids()}
		for _, pid in next, pids, nil do
			q.begin_other_pc_block(pid)
			pc.give_item2(item_vnum, item_count)
			q.end_other_pc_block()
		end
		party.get_member_pids()
	else
		pc.give_item2(item_vnum, item_count)
	end
end

 

Advantage:

You can to use in dungeon or not.

 

Usage (example):

party.give_item2(27001, 200)

 

quest_functions: party.give_item2

 

¡Saludos!

Not true, work only with party member. If you have any special dungeon it's will not work (Like guild or public). And it's really not a good way to use "q.begin_other_pc_block" everytime

  • Cry 1
Link to comment
Share on other sites

  • Premium
4 hours ago, PetePeter said:

And it's really not a good way to use "q.begin_other_pc_block" everytime

?

 

"Nothing's free in this life.

Ignorant people have an obligation to make up for their ignorance by paying those who help them.

Either you got the brains or cash, if you lack both you're useless."

Syreldar

Link to comment
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now

Announcements



  • Similar Content

  • Activity

    1. 13

      Metin2 Closed Beta Content (2003-2004)

    2. 25

      [SRC] Metin2 on LINUX - The Old Metin2 Project

    3. 2

      United/Club/Midgard serverfiles?

    4. 13

      Metin2 Closed Beta Content (2003-2004)

    5. 13

      Metin2 Closed Beta Content (2003-2004)

  • Recently Browsing

    • No registered users viewing this page.
×
×
  • 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.