Jump to content

Quest - Get items from table


Go to solution Solved by VegaS™,

Recommended Posts

  • Active Member

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

  • Forum Moderator
  • Solution
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™
  • Love 2
Link to comment
Share on other sites

  • Active Member

@ 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

  • Forum 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)

 

  • Love 1
Link to comment
Share on other sites

  • Active Member

@ 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

 

  • Cry 1
  • Smile Tear 1
  • Confused 1
Link to comment
Share on other sites

Guest
This topic is now closed to further replies.

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.