Jump to content

Dungeon Function - Jump


Recommended Posts

  • Bronze

M2 Download Center

This is the hidden content, please
( Internal )

Hello!

Today, i would like to introduce a new quest trigger - jump. Simple thing, but usefull for people who wants to design more complicated dungeons.

Why? F.e: you can add some actions, after warping on eliminated.

So, lets start.

Open dungeon.cpp and change the struct FWarpToPosition for this one:

struct FWarpToPosition
{
	long lMapIndex;
	long x;
	long y;
	FWarpToPosition(long lMapIndex, long x, long y)
		: lMapIndex(lMapIndex), x(x), y(y)
		{}

	void operator()(LPENTITY ent)
	{
		if (!ent->IsType(ENTITY_CHARACTER)) {
			return;
		}
		LPCHARACTER ch = (LPCHARACTER)ent;
		if (!ch->IsPC()) {
			return;
		}
		ch->SaveExitLocation();
		if (ch->GetMapIndex() == lMapIndex)
		{
			ch->Show(lMapIndex, x, y, 0);
			ch->Stop();
			quest::CQuestManager::instance().Jump(ch->GetPlayerID());
		}
		else
		{
			ch->WarpSet(x,y,lMapIndex);
		}
	}
};

Change also this if statement:

	if (pDungeon)
	{
	   	pDungeon->JumpAll(m_lMapIndex, m_lWarpX, m_lWarpY);
	   	
		if (!m_stRegenFile.empty())
		{
			pDungeon->SpawnRegen(m_stRegenFile.c_str());
			m_stRegenFile.clear();
		}
	}

For that:

	if (pDungeon)
	{
		if (!m_stRegenFile.empty())
		{
			pDungeon->SpawnRegen(m_stRegenFile.c_str());
			m_stRegenFile.clear();
		}
		
		pDungeon->JumpAll(m_lMapIndex, m_lWarpX, m_lWarpY);
	}

And its all in dungeon.cpp.

Now open quest.h and add:

QUEST_JUMP_EVENT,

After this:

QUEST_ITEM_INFORMER_EVENT,

Ok, now you can close file above, and open questmanager.cpp.

There add this:

m_mapEventName.insert(TEventNameMap::value_type("jump", QUEST_JUMP_EVENT));

Below:

m_mapEventName.insert(TEventNameMap::value_type("item_informer", QUEST_ITEM_INFORMER_EVENT));

And simply add also this function anywhere:

void CQuestManager::Jump(unsigned int pc)
	{
		PC * pPC;
		
        if ((pPC = GetPC(pc)))
        {
            if (!CheckQuestLoaded(pPC))
                return;

            m_mapNPC[QUEST_NO_NPC].OnJump(*pPC);
        }
        else
            sys_err("QUEST no such pc id : %d", pc);
    }

Thats it. Now we are finished on this file.

Open questmanager.h and add function declaration:

void		Jump(unsigned int pc);

After editing questmanager.h, open questnpc.cpp and add this function:

	bool NPC::OnJump(PC& pc)
	{
		return HandleReceiveAllEvent(pc, QUEST_JUMP_EVENT);
	}

And declaration to questnpc.h:

bool	OnJump(PC& pc);

 

## UPDATE ##

Add this to dungeon.cpp:

void CDungeon::JumpAll_NEW(long index, long x, long y)
{
	m_lWarpMapIndex = index;
	m_lWarpX = x;
	m_lWarpY = y;
	event_cancel(&jump_to_event_);
	dungeon_id_info* info = AllocEventInfo<dungeon_id_info>();
	info->dungeon_id = m_id;
	jump_to_event_ = event_create(dungeon_jump_to_event, info, PASSES_PER_SEC(3));
}

And declaration to header:

void	JumpAll_NEW(long index, long x, long y);

And change final call of dungeon_jump_all to this one:

pDungeon->JumpAll_NEW(pDungeon->GetMapIndex(), (int)lua_tonumber(L, 1), (int)lua_tonumber(L, 2));

So.. Thats the point. Now look at little example below:

when 101.kill with pc.in_dungeon() begin
    d.jump_all(101, 101)
end
when jump begin
    say("Yep, I killed dog and we jumped")
end

Hope it will help you.

  • Metin2 Dev 6
  • Good 1
  • Love 6
Link to comment
Share on other sites

  • 1 year later...

I had some problems with this trigger because it happens for every single player on map and it didn't work good for me. Some contitions were executed more than one time. If someone wants here is how to trigger it only for the first player on the dungeon's character list:

In struct FWarpToPosition remove

quest::CQuestManager::instance().Jump(ch->GetPlayerID());

Then after

	if (!pMap)
	{
		sys_err("cannot find map by index %d", lFromMapIndex);
		return;
	}

in void CDungeon::JumpAll(long lFromMapIndex, int x, int y) dungeon.cpp add

	if (!m_set_pkCharacter.empty())
	{
		itertype(m_set_pkCharacter) it = m_set_pkCharacter.begin();
		LPCHARACTER ch = *it;
		quest::CQuestManager::instance().Jump(ch->GetPlayerID());
	}

Then do the same for void CDungeon::JumpParty(LPPARTY pParty, long lFromMapIndex, int x, int y) if you want to.

I also made a function that takes current dungeon as argument instead of player but in this case you can't use pc functions in when jump trigger(e.g. pc.get_map_index()) and you have to use only dungeon functions (e.g. d.get_map_index()) so for it wouldn't be good for begginers.

Link to comment
Share on other sites

  • 3 weeks later...
  • Bronze
Dnia 14.07.2017 o 23:10, Den napisał:

I had some problems with this trigger because it happens for every single player on map and it didn't work good for me. Some contitions were executed more than one time. If someone wants here is how to trigger it only for the first player on the dungeon's character list:

In struct FWarpToPosition remove


quest::CQuestManager::instance().Jump(ch->GetPlayerID());

Then after


	if (!pMap)
	{
		sys_err("cannot find map by index %d", lFromMapIndex);
		return;
	}

in void CDungeon::JumpAll(long lFromMapIndex, int x, int y) dungeon.cpp add


	if (!m_set_pkCharacter.empty())
	{
		itertype(m_set_pkCharacter) it = m_set_pkCharacter.begin();
		LPCHARACTER ch = *it;
		quest::CQuestManager::instance().Jump(ch->GetPlayerID());
	}

Then do the same for void CDungeon::JumpParty(LPPARTY pParty, long lFromMapIndex, int x, int y) if you want to.

I also made a function that takes current dungeon as argument instead of player but in this case you can't use pc functions in when jump trigger(e.g. pc.get_map_index()) and you have to use only dungeon functions (e.g. d.get_map_index()) so for it wouldn't be good for begginers.

That`s a good point but I would rather go into my new solution.

If someone (as you say) is beginner this might cost him a lot of troubles..

This release is really out of date so once I find some time I will probably update this topic :)

Using jump triggers is the more practical and newbie-friendly couse` it requires just minimal lua knowledge.

Link to comment
Share on other sites

  • 3 months later...

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.