Jump to content

Recommended Posts

Hi, I wrote a Lua function that checks the requirements, including item, level, and quest flag validation for every player.
If someone does not meet the requirements, their name will appear under the topic of what they are missing and return
false or true.
I hope it will be useful to some people.

If you have TMP4's sf, you have to change this:

  • function check_party(need_item, need_lvl, key, flag)
  • pc.getf(key, flag)

to this:

  • function check_party(need_item, need_lvl, flag)
  • pc.getqf(flag)


https://metin2.download/picture/T7g8DYc6Xk8xm1ZXbI8a7faMdzQ030Mb/.png

Spoiler
--Usage:
check_party(30319, 120, "test_dungeon", "cdtest") --item, lvl, quest-key, quest-flag

--TMP4's sf
check_party(30319, 120, "cdtest") --item, lvl, quest-flag

when 20019.chat."Test" begin
    say("Test?")
    local menu = select("Yes","No")
    if menu == 1 then
        if check_party(30319,120, "test_dungeon", "cdtest") then
            say("Everyone pass")
        end
    end
end

 

Spoiler
--questlib.lua:
function check_party(need_item, need_lvl, key, flag)
	if party.is_party() then
		local all_ok = true
		local pid = {party.get_member_pids()}
		local check = {}
		for _, pid in ipairs(pid) do
		    q.begin_other_pc_block(pid)
		    local name, count, lvl, getcd = pc.get_name(), pc.count_item(need_item), pc.get_level(), pc.getf(key, flag)
		    q.end_other_pc_block()
		    table.insert(check, {name, lvl, count, getcd})
		end
		
		local reqitem, reqlvl, reqcd = {}, {}, {}
		for i = 1, table.getn(check) do
		    local name, lvl, count, getcd = check[i][1], check[i][2], check[i][3], check[i][4]
		    if count < 1 then
		        table.insert(reqitem, name)
		    end
		    if lvl < need_lvl then
		        table.insert(reqlvl, name)
		    end
		    if getcd >= get_time() then
		        table.insert(reqcd, name)
		    end
		end
		
		if table.getn(reqitem) > 0 or table.getn(reqlvl) > 0 or table.getn(reqcd) > 0 then
		    all_ok = false
		end
		
		local noitem, nolvl, cannot = "", "", ""
		if table.getn(reqitem) > 0 then
		    noitem = noitem .. "The following players lack an entry item: [ENTER]"..table.concat(reqitem, ", ")
		    say(noitem)
		    say()
		end
		if table.getn(reqlvl) > 0 then
		    nolvl = nolvl .. "The following players don't meet the level requirement: [ENTER]"..table.concat(reqlvl, ", ")
		    say(nolvl)
		    say()
		end
		if table.getn(reqcd) > 0 then
		    cannot = cannot .. "The following players are still on cooldown:: [ENTER]"..table.concat(reqcd, ", ")
		    say(cannot)
		    say()
		end
		
		if all_ok then
		    return true
		else
		    return false
		end
	else
		say("You are not part of any party.")
	end
end

 

 

  • Metin2 Dev 1
Link to comment
https://metin2.dev/topic/33809-party-requirements-lua/
Share on other sites

Don't use any images from : imgur, turkmmop, freakgamers, inforge, hizliresim... Or your content will be deleted without notice...
Use : https://metin2.download/media/add/

Please use https://metin2.download/ when uploading files smaller than 100MB, otherwise the approval will take longer due to manual upload.

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
×
×
  • 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.