Jump to content

set_quest_state and pc.select


Recommended Posts

Hello m2dev.

Well, i have this situation right here:

questlib.lua:

Spoiler

registeredList = {}

co_mission.quest:

Spoiler

quest co_mission begin
    state start begin
        when NPC_ID.chat."Register For Co-Op" begin
            say_title("Co-Op:")
            say("Wanna register for Co-Op?")
        
            local yn = select("Yes", "No")
            if yn = 1 then
                table.insert(registeredList, pc.get_name())
                if table.getn(registeredList) >= 2 then
                    co_mission.StartCoOp()
                end
            end
        end
            
        function StartCoOp()
            local originalPC = pc.get_vid()
            for i = 1, table.getn(registeredList) do
                local findPC = find_pc_by_name(registeredList)
                if findPC ~= 0 then
                    pc.select(findPC)
                    set_quest_state("co_mission", "run")
                end
            end
            pc.select(originalPC)
        end
    end
    
    state run begin
        notice_in_map("The player "..pc.get_name().." entered Co-Op Mission!")
    end
end

Imagine the table "registeredList" has 2 vid, and players are ONLINE

When calling this StartAllRegistered() function, it should go to quest state "run" on "co_mission", but it only goes on the last registered player, why?

 

Thanks in advance.

Link to comment
Share on other sites

  • Replies 6
  • Created
  • Last Reply

Top Posters In This Topic

Popular Days

Top Posters In This Topic

 

quest co_mission begin
	state start begin
		function StartCoOp()
			for i = 1, table.getn(registeredList), 1 do
				pc.select(find_pc_by_name(registeredList[i])) -- It's an array.
				set_quest_state("co_mission", "run")
			end
		end
		when NPC_ID.chat."Register for CO-Op" begin
			say_title("Co-Op:")
			say("")
			--"1234567890"
			say("Do you wanna register for Co-op?")
			if (select(locale.yes, locale.no) == 2) then return end
			table.insert(registeredList, pc.get_name())
			if (table.getn(registeredList) == 2) then
				co_mission.StartCoOp()
			end
		end
	end
	
	state run begin
		notice_in_map(string.format("The player %s entered Co-Op mission", pc.name))
	end
end
You're creating a table in the questlib.lua and you're using for-loop to call the names and select them. If you don't add that just like that, your quest is only call the first member or the last number. (I never test that) Whatever, your quest should be just like that.

Kind Regards ~ Ken

 

Do not be sorry, be better.

Link to comment
Share on other sites

1 hour ago, Ken said:

 


quest co_mission begin
	state start begin
		function StartCoOp()
			for i = 1, table.getn(registeredList), 1 do
				pc.select(find_pc_by_name(registeredList[i])) -- It's an array.
				set_quest_state("co_mission", "run")
			end
		end
		when NPC_ID.chat."Register for CO-Op" begin
			say_title("Co-Op:")
			say("")
			--"1234567890"
			say("Do you wanna register for Co-op?")
			if (select(locale.yes, locale.no) == 2) then return end
			table.insert(registeredList, pc.get_name())
			if (table.getn(registeredList) == 2) then
				co_mission.StartCoOp()
			end
		end
	end
	
	state run begin
		notice_in_map(string.format("The player %s entered Co-Op mission", pc.name))
	end
end

You're creating a table in the questlib.lua and you're using for-loop to call the names and select them. If you don't add that just like that, your quest is only call the first member or the last number. (I never test that) Whatever, your quest should be just like that.

Kind Regards ~ Ken

 

That quest will only work with 2 people at the same time.

Try this:

 

quest co_mission begin
	state start begin
		function checkAvailable()
			local slotAvailable = 0
			for i = 1, table.getn(allRegisteredList), 1 do
				if table.getn(allRegisteredList[i]) < 2 then 
					for a=1, table.getn(allRegisteredList[i], 1 do
						local findPC = find_pc_by_name(allRegisteredList[i][a])
						if findPC ~= 0 then slotAvailable = i break end
					end
				end
			end
			
			return slotAvailable
		end
		
		
		function StartCoOp(slot)
			for i = 1, table.getn(allRegisteredList[slot]), 1 do
				pc.select(find_pc_by_name(allRegisteredList[slot])) -- It's an array.
				set_quest_state("co_mission", "run")
			end
		end
		
		when NPC_ID.chat."Register for CO-Op" begin
			say_title("Co-Op:")
			say("")
			--"1234567890"
			say("Do you wanna register for Co-op?")
			if (select(locale.yes, locale.no) == 2) then return end
			local slot = co_mission.checkAvailable()
			if slot == 0 then table.insert(allRegisteredList, {pc.name})
			else table.insert(allRegisteredList[slot], pc.name) co_mission.StartCoOp(slot) end
		end
	end
	
	state run begin
		notice_in_map(string.format("The player %s entered Co-Op mission", pc.name))
	end
end

 (I didn't test it yet)
Link to comment
Share on other sites

2 hours ago, Ken said:

 


quest co_mission begin
	state start begin
		function StartCoOp()
			for i = 1, table.getn(registeredList), 1 do
				pc.select(find_pc_by_name(registeredList[i])) -- It's an array.
				set_quest_state("co_mission", "run")
			end
		end
		when NPC_ID.chat."Register for CO-Op" begin
			say_title("Co-Op:")
			say("")
			--"1234567890"
			say("Do you wanna register for Co-op?")
			if (select(locale.yes, locale.no) == 2) then return end
			table.insert(registeredList, pc.get_name())
			if (table.getn(registeredList) == 2) then
				co_mission.StartCoOp()
			end
		end
	end
	
	state run begin
		notice_in_map(string.format("The player %s entered Co-Op mission", pc.name))
	end
end

You're creating a table in the questlib.lua and you're using for-loop to call the names and select them. If you don't add that just like that, your quest is only call the first member or the last number. (I never test that) Whatever, your quest should be just like that.

Kind Regards ~ Ken

 

You are right but, i putted this to debug on StartCoOp() after pc.select(): chat(""..registeredList.."is entering Co-Op: Index"..i)

But it gives me 2 times on the last registering like this:

MPPBydp.jpg

And just the last character, in this case Slot2, goes to "run" state.

It sould show on each character, and not on the last entering person right?

I presume is set_quest_state problem.

Edited by Metin2 Dev
Core X - External 2 Internal
Link to comment
Share on other sites

1 hour ago, NewWars said:

You are right but, i putted this to debug on StartCoOp() after pc.select(): chat(""..registeredList.."is entering Co-Op: Index"..i)

But it gives me 2 times on the last registering like this:

MPPBydp.jpg

And just the last character, in this case Slot2, goes to "run" state.

It sould show on each character, and not on the last entering person right?

I presume is set_quest_state problem.

I think what pc.select does is to only select the person infos, not interact with the person.

Edited by Metin2 Dev
Core X - External 2 Internal
Link to comment
Share on other sites

32 minutes ago, Frozen said:

I think what pc.select does is to only select the person infos, not interact with the person.

Actually i did it other way, and pc.select really selects a PC, but when you do set_quest_state on other PC, "when enter" doesnt rly work.

I have pc.selected the person and then i warped them to the same place, and it worked.

Thanks for the help anyway.

Link to comment
Share on other sites

41 minutes ago, NewWars said:

Actually i did it other way, and pc.select really selects a PC, but when you do set_quest_state on other PC, "when enter" doesnt rly work.

I have pc.selected the person and then i warped them to the same place, and it worked.

Thanks for the help anyway.

Yes thats because its a pc function. (pc.warp)

But you cant use chat functions or item functions...

PS: my bad i expressed wrong in the other post.

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.