Jump to content

[Source] how to do "Can't use mount/horse in dungeon"


Recommended Posts

Hi, I'd like to add in source that you can't use the mount and horse while you are in a dungeon

				if pc.in_dungeon() then
					syschat("You can't use this mount while you are in a Dungeon.")
					return
				end

I used this in my quest of ride.lua, but i would prefer add this in the server source and add that you can't summon/ride the horse in dungeon and if you are riding a mount/horse you unmount it.

Anyone can help me to do this? Thank you again!

Link to comment
Share on other sites

On 10/5/2019 at 4:22 PM, WeedHex said:

Like this you won't ride in any map with index >=10000 it's not safe.

Do the check with the dungeon index.

Only the dungeon should have >= 10000, so I don't think this could be a problem for me, it is fine if every dungeon has mount blocked.

I'm trying to make that when you enter a dungeon you unmount the horse or mount, but i can't make it work :(

This is working only for horse, if you are riding a mount it doesn't work

 

		when login with dungeon_test.beran_test_index(pc.get_map_index()) begin
			pc.set_warp_location (99, 1234, 5678)
			
			if pc.get_level() < 90 then
				warp_to_village()
			end
			
			timer ( "time_test_dungeon", 20 * 60 )
			pc.unmount()
			horse.unsummon()
			d.setf("mobs_left", d.count_monster())
		end

 

EDIT:
I resolved the mount problem adding

timer ( "time_unmount", 6 ) above the other timer

        when time_unmount.timer with dungeon_test.beran_test_index(pc.get_map_index()) begin
                    pc.unmount()
        end

But i don't really like this solution..., i was wondering if there is something better

Link to comment
Share on other sites

  • Forum Moderator

Not tested, but you can try to do something like:

  • Srcs/Server/game/src/questlua_horse.cpp
Spoiler

// Search in horse_summon function:
		bool bFromFar = lua_isboolean(L, 1) ? lua_toboolean(L, 1) : false;
// Add before:
#ifdef ENABLE_BLOCK_RIDING_IN_DUNGEON
		if (ch && ch->GetDungeon())
			return 0;
#endif
  • Srcs/Server/game/src/questlua_pc.cpp
Spoiler

// Search in pc_mount_bonus and pc_mount function:
		LPCHARACTER ch = CQuestManager::instance().GetCurrentCharacterPtr();
// Add after:
#ifdef ENABLE_BLOCK_RIDING_IN_DUNGEON
		if (ch && ch->GetDungeon())
			return 0;
#endif
  • Srcs/Server/game/src/input_login.cpp
Spoiler

// Search in CInputLogin::Entergame(LPDESC d, const char * data) for:
	if (ch->GetHorseLevel() > 0)
	{
		DWORD pid = ch->GetPlayerID();

		if (pid != 0 && CHorseNameManager::instance().GetHorseName(pid) == NULL)
			db_clientdesc->DBPacket(HEADER_GD_REQ_HORSE_NAME, 0, &pid, sizeof(DWORD));
	}
// Add after:
#ifdef ENABLE_BLOCK_RIDING_IN_DUNGEON
		if (ch && ch->GetDungeon())
		{
			if (ch->IsHorseRiding())
			{
				ch->StopRiding();
				ch->HorseSummon(false);
			}

			if (ch->FindAffect(AFFECT_MOUNT))
			{
				ch->RemoveAffect(AFFECT_MOUNT);
				ch->RemoveAffect(AFFECT_MOUNT_BONUS);
			}
		}
#endif
  • Srcs/Server/game/service.h
Spoiler

#define ENABLE_BLOCK_RIDING_IN_DUNGEON
Link to comment
Share on other sites

11 hours ago, VegaS™ said:

Not tested, but you can try to do something like:

  • Srcs/Server/game/src/questlua_horse.cpp
  Hide contents


// Search in horse_summon function:
		bool bFromFar = lua_isboolean(L, 1) ? lua_toboolean(L, 1) : false;
// Add before:
#ifdef ENABLE_BLOCK_RIDING_IN_DUNGEON
		if (ch && ch->GetDungeon() && ch->IsHorseRiding())
		{
			ch->StopRiding();
			ch->HorseSummon(false);
			return 0;
		}
#endif
  • Srcs/Server/game/src/questlua_pc.cpp
  Hide contents


// Search in pc_mount_bonus function:
		LPCHARACTER ch = CQuestManager::instance().GetCurrentCharacterPtr();
// Add after:
#ifdef ENABLE_BLOCK_RIDING_IN_DUNGEON
		if (ch && ch->GetDungeon() && ch->FindAffect(AFFECT_MOUNT))
		{
			ch->RemoveAffect(AFFECT_MOUNT);
			ch->RemoveAffect(AFFECT_MOUNT_BONUS);
			return 0;
		}
#endif
  • Srcs/Server/game/src/input_login.cpp
  Hide contents


// Search in CInputLogin::Entergame(LPDESC d, const char * data) for:
	if (ch->GetHorseLevel() > 0)
	{
		DWORD pid = ch->GetPlayerID();

		if (pid != 0 && CHorseNameManager::instance().GetHorseName(pid) == NULL)
			db_clientdesc->DBPacket(HEADER_GD_REQ_HORSE_NAME, 0, &pid, sizeof(DWORD));
	}
// Add after:
#ifdef ENABLE_BLOCK_RIDING_IN_DUNGEON
		if (ch && ch->GetDungeon())
		{
			if (ch->IsHorseRiding())
			{
				ch->StopRiding();
				ch->HorseSummon(false);
			}

			if (ch->FindAffect(AFFECT_MOUNT))
			{
				ch->RemoveAffect(AFFECT_MOUNT);
				ch->RemoveAffect(AFFECT_MOUNT_BONUS);
			}
		}
#endif
  • Srcs/Server/game/service.h
  Hide contents


#define ENABLE_BLOCK_RIDING_IN_DUNGEON

Thank you, it is working for horse, but not for the mount :(

Maybe is because first the game read if i'm riding and make me StopRiding, but if I login in a map while i was riding a mount, the game doesn't immediatly know I'm riding and update my character riding 1 second later? Sometimes when i login with a mount i see my character standing and 1 second later i am riding again my mount

I'm not sure if i did this part as you write in your message, maybe the problem is here?

Spoiler

	if (ch->GetHorseLevel() > 0)
	{
		DWORD pid = ch->GetPlayerID();

		if (pid != 0 && CHorseNameManager::instance().GetHorseName(pid) == NULL)
			db_clientdesc->DBPacket(HEADER_GD_REQ_HORSE_NAME, 0, &pid, sizeof(DWORD));
		//@fix horse_level update at login
		ch->SetHorseLevel(ch->GetHorseLevel());
		ch->SkillLevelPacket();
#ifdef ENABLE_BLOCK_RIDING_IN_DUNGEON
		if (ch && ch->GetDungeon())
		{
			if (ch->IsHorseRiding())
			{
				ch->StopRiding();
				ch->HorseSummon(false);
			}

			if (ch->FindAffect(AFFECT_MOUNT))
			{
				ch->RemoveAffect(AFFECT_MOUNT);
				ch->RemoveAffect(AFFECT_MOUNT_BONUS);
			}
		}
#endif
	}

 

 

Link to comment
Share on other sites

  • Forum Moderator
2 hours ago, Cripplez said:

I'm not sure if i did this part as you write in your message, maybe the problem is here?

  Hide contents


	if (ch->GetHorseLevel() > 0)
	{
		DWORD pid = ch->GetPlayerID();

		if (pid != 0 && CHorseNameManager::instance().GetHorseName(pid) == NULL)
			db_clientdesc->DBPacket(HEADER_GD_REQ_HORSE_NAME, 0, &pid, sizeof(DWORD));
		//@fix horse_level update at login
		ch->SetHorseLevel(ch->GetHorseLevel());
		ch->SkillLevelPacket();
#ifdef ENABLE_BLOCK_RIDING_IN_DUNGEON
		if (ch && ch->GetDungeon())
		{
			if (ch->IsHorseRiding())
			{
				ch->StopRiding();
				ch->HorseSummon(false);
			}

			if (ch->FindAffect(AFFECT_MOUNT))
			{
				ch->RemoveAffect(AFFECT_MOUNT);
				ch->RemoveAffect(AFFECT_MOUNT_BONUS);
			}
		}
#endif
	}

 

You added it wrong, not inside of GetHorseLevel > 0, outside of condition. 

Spoiler

	if (ch->GetHorseLevel() > 0)
	{
		DWORD pid = ch->GetPlayerID();

		if (pid != 0 && CHorseNameManager::instance().GetHorseName(pid) == NULL)
			db_clientdesc->DBPacket(HEADER_GD_REQ_HORSE_NAME, 0, &pid, sizeof(DWORD));
		//@fix horse_level update at login
		ch->SetHorseLevel(ch->GetHorseLevel());
		ch->SkillLevelPacket();
	}
#ifdef ENABLE_BLOCK_RIDING_IN_DUNGEON
	if (ch && ch->GetDungeon())
	{
		if (ch->IsHorseRiding())
		{
			ch->StopRiding();
			ch->HorseSummon(false);
		}

		if (ch->FindAffect(AFFECT_MOUNT))
		{
			ch->RemoveAffect(AFFECT_MOUNT);
			ch->RemoveAffect(AFFECT_MOUNT_BONUS);
		}
	}
#endif

 

 

Link to comment
Share on other sites

5 hours ago, VegaS™ said:

You added it wrong, not inside of GetHorseLevel > 0, outside of condition. 

  Reveal hidden contents


	if (ch->GetHorseLevel() > 0)
	{
		DWORD pid = ch->GetPlayerID();

		if (pid != 0 && CHorseNameManager::instance().GetHorseName(pid) == NULL)
			db_clientdesc->DBPacket(HEADER_GD_REQ_HORSE_NAME, 0, &pid, sizeof(DWORD));
		//@fix horse_level update at login
		ch->SetHorseLevel(ch->GetHorseLevel());
		ch->SkillLevelPacket();
	}
#ifdef ENABLE_BLOCK_RIDING_IN_DUNGEON
	if (ch && ch->GetDungeon())
	{
		if (ch->IsHorseRiding())
		{
			ch->StopRiding();
			ch->HorseSummon(false);
		}

		if (ch->FindAffect(AFFECT_MOUNT))
		{
			ch->RemoveAffect(AFFECT_MOUNT);
			ch->RemoveAffect(AFFECT_MOUNT_BONUS);
		}
	}
#endif

 

 

Okay

I tried like this but when i'm riding a mount it still doesn't make me unmount it :( with the horse it is perfect

Link to comment
Share on other sites

  • Forum Moderator
1 hour ago, Cripplez said:

I tried like this but when i'm riding a mount it still doesn't make me unmount it :( with the horse it is perfect

Then your problem is that you've costume mount slot, not the default mount, replace the code what i gave you with:

#ifdef ENABLE_BLOCK_RIDING_IN_DUNGEON
	if (ch && ch->GetDungeon())
	{
		const LPITEM pMount = ch->GetWear(WEAR_COSTUME_MOUNT);
		if (pMount && pMount->IsEquipped())
			ch->UnequipItem(pMount);
	
		if (ch->IsHorseRiding())
		{
			ch->StopRiding();
			ch->HorseSummon(false);
		}
	}
#endif

Be careful to have on all of your vnums type: ITEM_COSTUME < 28, sub type: COSTUME_MOUNT < 2

  • Love 1
Link to comment
Share on other sites

  • Forum Moderator
On 10/9/2019 at 11:44 PM, WeedHex said:

Was better with timer solution, mount begin load after other things so checking the login is useless cuz there isn't still mount at login :)

No, we don't need a timer for this, you're right that you can't do this inside of login because the POINT_MOUNT is seted after, so, this method is for all types of mounts/horses: 

This is the hidden content, please

Not tested.

  • Metin2 Dev 5
  • Think 1
  • Good 1
  • Love 1
  • Love 7
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.