Jump to content

Quest to check if item exist in inventory?


Recommended Posts

Hello I need help writing a quest that would detect if an item exists in inventory, but it has to be without login trigger

It only works when I do it like this:

quest item_detect begin
    state start begin
    when login or enter begin
        if pc.count_item(50709)==1 then
        chat("You have x item in your inventory.")
end
end
end
end

My intended result is to make the quest spontaneously spit this chat whenever player receives said item in inventory, whether through exchange, drop, or other means, without waiting for login to trigger it.

Link to comment
Share on other sites

  • Honorable Member

If the item you are checking is quest type, then you can only check whether you have picked the item from the ground using the “pick” trigger which is called like this:

quest detect_item begin
	state start begin
		when 50709.pick begin
			chat("You have x item in your inventory.")
		end
	end
end

Quests are limited, you can't check every action you so this isn't possible unless you add a new trigger to your quest manager source file.

The only solution if you want to do this via quest without modifying the source is to use a timer to keep checking for the item but I strongly don’t recommend this.
Regardless, this is how you would do it:

quest detect_item begin
	state start begin
		function get(vnum, count)
			if pc.count_item(vnum) >= count then
				return true
			end
			return false
		end

		when login begin
			timer("item_detector_1", 3)
		end

		when item_detector_1.timer begin
			if detect_item.check(50709, 1) then
				chat("You have x item in your inventory.")
			end
			timer("item_detector_2", 3)
		end

		when item_detector_2.timer begin
			if detect_item.check(50709, 1) then
				chat("You have x item in your inventory.")
			end
			timer("item_detector_1", 3)
		end
	end
end

 

Edited by Owsap
  • Metin2 Dev 2
Link to comment
Share on other sites

  • Premium
3 hours ago, covfefe said:

that's gonna eat all of my CPU usage..

?

Sir, I don't think you have any idea how timers work. Also...

Quote

make the quest spontaneously spit this chat whenever player receives said item in inventory, whether through exchange, drop, or other means, without waiting for login to trigger it.

The green part is doable in lua, via the method @Owsap explained, the .pick trigger.

The red part is not doable in lua, since there's no trigger for exchange.

 

Timers would be useless here, but they don't "EAT YOUR CPU".

 

Quote

WoM2 did it so there must be a way.

It's easy to make a new trigger for that, but you have to make changes to the sourcecode, you can't do that with what the default Metin2 triggers.

Edited by Syreldar

 

"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



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