Jump to content

Npc spawn and purge


Recommended Posts

Good day to you all!

I have got a little problem. I would like my quest to spawn an npc, then purge it - but! - if two players are doing the quest simultaneously, they can only purge "their" npc, they spawned.

I cannot figure out, why this quest is not working for me:

quest npcspawn begin
	state start begin
		when letter begin
			send_letter("NpcSpawn")
		end
		when button or info begin
			local x = (pc.get_local_x())
			local y = (pc.get_local_y())
			mob.spawn(4001, x+2, y+2, 2, 2, 1)
			game.set_event_flag("player", pc.get_player_id())
		end
		when 4001.click begin
			if game.get_event_flag("player") == (pc.get_player_id()) then
				say("jonapot")
				wait()
				say("aviszontlátásra")
				wait()
				game.set_event_flag("player", 0)
				npc.purge()
			else
			return
			end
		end
	end
end

I just do not understand, why this isnt working. I used the player id as a local number, yet when I tried it with two players, spawned them both and they purged the other else's spawned npc.

 

Anyone could help me please?

Thanks!

Link to comment
Share on other sites

  • Premium

That makes no sense. You're using the same global flag to save the player's id, meaning it will get overwritten every time a player opens the letter.

Also using a global flag, something which is used for events or global settings, to save a var for a player is something you totally should not do.

 

 

 

"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

Simply use vid to bind spawned npc to a player (mob.spawn returns monster's vid in case if one was spawned and zero if spawned was somehow unsuccessful).

quest npcspawn begin
	state start begin
		when letter begin
			send_letter("NpcSpawn")
		end
		when button or info begin
			local x = (pc.get_local_x())
			local y = (pc.get_local_y())
			local iVID = mob.spawn(4001, x+2, y+2, 2, 2, 1)
			if iVID == 0 then
				say("Cannot spawn.")
			else
				pc.setqf("spawnedVID", iVID)
			end
		end
		when 4001.click begin
			if npc.get_vid() == pc.getqf("spawnedVID") then
				say("jonapot")
				wait()
				say("aviszontlátásra")
				wait()
				game.set_event_flag("player", 0)
				npc.purge()
			end
		end
	end
end
Edited by Sherer
  • Metin2 Dev 1
  • Good 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.