Jump to content
For maintenance and updates, the community will be offline on 31 December 2022 ×
  • 1

Quest - Get items from table


ReFresh

Question

  • Premium

Hey guys,

can someone help me with selecting items from a list? I need to select item vnum and item count from list and then give items from a local variable to player in one line. I want to do that, because I don't want to write pc.give_item2(item_vnum, item count) 10000 times.

I tried to do something like this, but it doesn't work, because something is missing. I'm not sure how to do that. Can someone correct me?

Spoiler
local same_items = 
			{
				{13005, 1},
				{14005, 1},
				{17005, 1},
				{16005, 1},
				{15005, 1},
				{72701, 1},
				{72702, 1},
				{39039, 1},
				{39042, 1},
				{70057, 200}
			}

			for i = 1, table.getn(same_items) do
			pc.give_item2(same_items[pc.countitem()])

 

Thanks for answers!

Sincerely,

ReFresh

Edited by ReFresh

I'll be always helpful! 👊 

Link to comment
Share on other sites

4 answers to this question

Recommended Posts

  • 2
  • Moderator
23 minutes ago, ReFresh said:
			for i = 1, table.getn(same_items) do
			pc.give_item2(same_items[pc.countitem()])

 

It should be like this:

for key, value in ipairs(same_items) do
	pc.give_item2(unpack(value))
end
Edited by VegaS™
Link to comment
Share on other sites

  • 2
  • Moderator
20 minutes ago, ReFresh said:

And if I want to add race index? I tried something like this and it doesn't work. I still cannot get how these tables works.

 

local job_items = 
{
	[0] = {	{15, 1},	{11205, 1},	{12205, 1} },
	[1] = {	{1005, 1},	{11405, 1},	{12345, 1} },
	[2] = {	{15, 1},	{11605, 1},	{12485, 1} },
	[3] = {	{7005, 1},	{11805, 1},	{12625, 1} },
}

local item_table = job_items[pc.get_job()]
if item_table ~= nil then
	for key, value in ipairs(item_table) do
		pc.give_item2(unpack(value))
	end
end

Just to know:

pc.give_item2(unpack(value))
-- equivalent to:
pc.give_item2(value[0], value[1])
-- equivalent to:
local vnum, count = unpack(value)
pc.give_item2(vnum, count)

 

Link to comment
Share on other sites

  • 1
  • Premium

@ VegaS™ And if I want to add race index? I tried something like this and it doesn't work. I still cannot get how these tables works.

Spoiler
local job_items = 
			{
				[0] = {15, 1}, {11205, 1}, {12205, 1},
				[1] = {1005, 1}, {11405, 1}, {12345, 1},
				[2] = {15, 1}, {11605, 1}, {12485, 1},
				[3] = {7005, 1}, {11805, 1}, {12625, 1}
			}
			
			for index, key, value in pairs(job_items[index[pc.get_job()+1]]) do
				pc.give_item2(unpack(value))
			end

 

 

Edited by ReFresh

I'll be always helpful! 👊 

Link to comment
Share on other sites

  • 0
  • Bronze

@ ReFresh

 

quest give_itemssss begin
	state start begin
			local giveitemss = {
				[0] = {15, 1}, {11205, 1}, {12205, 1},
				[1] = {1005, 1}, {11405, 1}, {12345, 1},
				[2] = {15, 1}, {11605, 1}, {12485, 1},
				[3] = {7005, 1}, {11805, 1}, {12625, 1}
			};
			table.insert(giveitemss[pc.get_job()], "Not now. ");
			local item_give = select_table(giveitemss[pc.get_job()]);
			if (item_give ~= table.getn(giveitemss)) then
				pc.pc.give_item2(item_give);
			end
		end
	end
end

 

Link to comment
Share on other sites

Guest
This topic is now closed to further replies.


  • Activity

    1. 1

      Costume shining/costume effect system

    2. 992

      [40250] Reference Serverfile + Client + Src [15 Available Languages]

    3. 3

      Biologist Manager (C++ & LUA)

    4. 3

      Visual studio 2022 compiling issue

    5. 63

      Metin2 | Mount System Renewal

    6. 58

      Metin2 2004 Beta Client

    7. 0

      🔥Paradise2 PVP SERVER GLOBAL!! EN-ES-PT 🕐📢Apertura 11 de diciembre 21 horas de España!

  • 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.