Jump to content

Recommended Posts

Hello, i want to write quest/change source to lose level after death to make something similar to roguelike games.
After death character level should be reset to 1 and whole inventory cleaned, it cna be done by source, quest, or force client to speak by player /ip /l 1, what ever, anyone know how to do it?

Link to comment
https://metin2.dev/topic/28530-death-event-lose-level-after-death/
Share on other sites

  • Premium

Go to char_battle.cpp and search for (in ::Dead function):

CGuildManager::instance().Kill(pkKiller, this);

 

Add this after:

#ifdef DEATH_EVENT
#define DEATH_INITIAL_LEVEL	1 // What's the level the player should start?

			ResetPoint(MINMAX(1, DEATH_INITIAL_LEVEL, PLAYER_MAX_LEVEL_CONST));
			ClearSkill();
			ClearSubSkill();


			LPITEM	item;
			for (int i = 0; i < INVENTORY_AND_EQUIP_SLOT_MAX; ++i)
			{
				if ((item = GetInventoryItem(i)))
				{
					ITEM_MANAGER::instance().RemoveItem(item, "DEATH_EVENT");
					SyncQuickslot(QUICKSLOT_TYPE_ITEM, i, 255);
				}
			}

			ChatPacket(CHAT_TYPE_INFO, "<Death Event> You died and as such, your level is now %d and you lost all your equipment", GetLevel());
#endif

 

In service.h, add:

#define DEATH_EVENT

 

Edited by msnas

@ msnas Could you help me again?
I want to make quest when talk to NPC for example 20094.chat."balbla" she will reset level to 1 and give me gold equal to level i had.
I dont know how to call dead function in quest, she can even kill me to cause definition you helped me last time.
Thanks in advance

1 hour ago, Mefarious said:

@ msnas Could you help me again?
I want to make quest when talk to NPC for example 20094.chat."balbla" she will reset level to 1 and give me gold equal to level i had.
I dont know how to call dead function in quest, she can even kill me to cause definition you helped me last time.
Thanks in advance

 

Add this to your questlua_pc + add quest_functions according. pc.reset_level (code not tested)



{ "reset_level",	pc_reset_level},

#ifdef DEATH_EVENT
#define DEATH_INITIAL_LEVEL	1 // What's the level the player should start?
ALUA(pc_reset_level)
{
	LPCHARACTER ch = CQuestManager::instance().GetCurrentCharacterPtr();
	int lvlBeforeReset = ch->GetLevel();
	
	ch->ResetPoint(MINMAX(1, DEATH_INITIAL_LEVEL, PLAYER_MAX_LEVEL_CONST));
	ch->ClearSkill();
	ch->ClearSubSkill();

	LPITEM item;
	for (int i = 0; i < INVENTORY_AND_EQUIP_SLOT_MAX; ++i)
	{
		if ((item = ch->GetInventoryItem(i)))
		{
			ITEM_MANAGER::instance().RemoveItem(item, "DEATH_EVENT_BY_QUEST");
			ch->SyncQuickslot(QUICKSLOT_TYPE_ITEM, i, 255);
		}
	}
	
	ch->PointChange(POINT_GOLD, lvlBeforeReset);
	ch->ChatPacket(CHAT_TYPE_INFO, "<Death Request> Resetted. Your level was %d, because of that same amount of gold is credited.", lvlBeforeReset);
}
#endif

 

Then in quest like:

 

quest resetchar begin
	state start begin
		when 20094.chat."balbla" begin
			if pc.get_level() > 1 then
				pc.reset_level()
			end
		end
	end
end

 

Edited by Minton

🖥️ SysAdmin — Government (HU)
🛠️ Freelance Metin2 Dev • DevOps
🐧 FreeBSD / Linux | 🛡️ Security & WAF | 🚀 Performance | 🔥 Firewalls | ⚙ Automation
Open to work - Contact me on Discord @matteo_r

3 minutes ago, Mefarious said:

OKey im trying to compile it, and now shiuld i type all possibilities each of 120lvls give different amount of gold after reset? 
i dont understand this 
ch->PointChange(POINT_GOLD, lvlBeforeReset);

It gives gold.

If you reset a lv 120 character you get 120 gold

If you reset a lv10 character you get 10 gold

Is that you wanted?

 

 

 

🖥️ SysAdmin — Government (HU)
🛠️ Freelance Metin2 Dev • DevOps
🐧 FreeBSD / Linux | 🛡️ Security & WAF | 🚀 Performance | 🔥 Firewalls | ⚙ Automation
Open to work - Contact me on Discord @matteo_r

yea i wanted to get gold, but i have to think about how muchm its like im creating RogueLike server and need for example
2 lvl -50yang
3lvl 75yang
4lvl 150yang etc etc as i want 120 lvl -10kk etc

edit, quest doesnt work, it doesnt reset level

Edited by Mefarious
31 minutes ago, Mefarious said:

yea i wanted to get gold, but i have to think about how muchm its like im creating RogueLike server and need for example
2 lvl -50yang
3lvl 75yang
4lvl 150yang etc etc as i want 120 lvl -10kk etc

edit, quest doesnt work, it doesnt reset level

You should fill in all level gold rewards. What it says? nothing? 

 

ALUA(pc_reset_level)
{
	LPCHARACTER ch = CQuestManager::instance().GetCurrentCharacterPtr();
	int lvlBeforeReset = ch->GetLevel();
	
	ch->ResetPoint(MINMAX(1, DEATH_INITIAL_LEVEL, PLAYER_MAX_LEVEL_CONST));
	ch->ClearSkill();
	ch->ClearSubSkill();

	LPITEM item;
	for (int i = 0; i < INVENTORY_AND_EQUIP_SLOT_MAX; ++i)
	{
		if ((item = ch->GetInventoryItem(i)))
		{
			ITEM_MANAGER::instance().RemoveItem(item, "DEATH_EVENT_BY_QUEST");
			ch->SyncQuickslot(QUICKSLOT_TYPE_ITEM, i, 255);
		}
	}
	int goldByLevel[PLAYER_EXP_TABLE_MAX + 1] =
	{
		0,  // PLACEHOLDER
		10, // LV 1
		20, // LV 2
		30, // LV 3
		40, // LV 4
		50, // LV 5
		60, // LV 6
	};
	ch->PointChange(POINT_GOLD, goldByLevel[lvlBeforeReset]);
	ch->ChatPacket(CHAT_TYPE_INFO, "<Death Request> Your level was %d, because of that same amount of gold is credited.", lvlBeforeReset);
	
	return 0;
}

 

🖥️ SysAdmin — Government (HU)
🛠️ Freelance Metin2 Dev • DevOps
🐧 FreeBSD / Linux | 🛡️ Security & WAF | 🚀 Performance | 🔥 Firewalls | ⚙ Automation
Open to work - Contact me on Discord @matteo_r

2 minutes ago, Mefarious said:

Its not working for me or i just put it wrong , no error show up, quest reads function without error, but when i click on npc to reset nothing happens

Add me on Discord.

🖥️ SysAdmin — Government (HU)
🛠️ Freelance Metin2 Dev • DevOps
🐧 FreeBSD / Linux | 🛡️ Security & WAF | 🚀 Performance | 🔥 Firewalls | ⚙ Automation
Open to work - Contact me on Discord @matteo_r

  • 1 year later...
On 1/3/2022 at 5:05 PM, msnas said:

I tried to modify the code for my needs but it doesn't work i think i'm doing something wrong, i need that only the equipment that the character is wearing is gonna fall on the ground, don't need level drop and not even all the inventory could you help me with that? also do you think that there is a way to make spawn an interactive item like a tombstone, and by clicking on it a window containing all the items will open up? instead of make them drop on the ground

 

  • Premium
11 hours ago, Alessio said:

I tried to modify the code for my needs but it doesn't work i think i'm doing something wrong, i need that only the equipment that the character is wearing is gonna fall on the ground, don't need level drop and not even all the inventory could you help me with that?

	PIXEL_POSITION pxPos = GetXYZ();
	LPITEM item;
	for (int i = 0; i < WEAR_MAX_NUM; ++i)
	{
		if ((item = ch->GetWear(i)))
		{
			item->RemoveFromCharacter();
			item->AddToGround(GetMapIndex(), pxPos);
			item->StartDestroyEvent();
			
			LogManager::instance().ItemLog(this, item, "DROP_EVENT", item->GetID());
		}
	}

 

11 hours ago, Alessio said:

also do you think that there is a way to make spawn an interactive item like a tombstone, and by clicking on it a window containing all the items will open up? instead of make them drop on the ground

It's possible but it would require time.

Edited by msnas

is it working the code that @msnas writed for you? i tried it and it doesn't work, i think that i'm doing something wrong but i don't understand what, i'm writing everythin exactly where he said

On 2/23/2023 at 11:51 AM, msnas said:
	PIXEL_POSITION pxPos = GetXYZ();
	LPITEM item;
	for (int i = 0; i < WEAR_MAX_NUM; ++i)
	{
		if ((item = ch->GetWear(i)))
		{
			item->RemoveFromCharacter();
			item->AddToGround(GetMapIndex(), pxPos);
			item->StartDestroyEvent();
			
			LogManager::instance().ItemLog(this, item, "DROP_EVENT", item->GetID());
		}
	}

i tried to use the code but nothing happen in game when i die, i also tried to use the cose that you shared the first time but still nothing, do you have any ideas on what am i doing wrong?

 

Edited by Alessio
On 2/23/2023 at 11:51 AM, msnas said:
	PIXEL_POSITION pxPos = GetXYZ();
	LPITEM item;
	for (int i = 0; i < WEAR_MAX_NUM; ++i)
	{
		if ((item = ch->GetWear(i)))
		{
			item->RemoveFromCharacter();
			item->AddToGround(GetMapIndex(), pxPos);
			item->StartDestroyEvent();
			
			LogManager::instance().ItemLog(this, item, "DROP_EVENT", item->GetID());
		}
	}

 

hey i understood my mistake, i wasn't doing gamecompile after modifing the files, i tried the code that you have writed for Mefarious and it work super good, then i tried to modify it like you showed me and i get this error while i do gamecompile

char_battle.cpp:1258:15: error: use of undeclared identifier 'ch'
                if ((item = ch->GetWear(i)))
                                   ^
char_battle.cpp:1264:27: error: no matching member function for call to 'ItemLog'
                        LogManager::instance().ItemLog(this, item, "DROP_EVENT", item->GetID());
                        ~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~
./log.h:29:9: note: candidate function not viable: no known conversion from 'DWORD' (aka 'unsigned int') to 'const                                                                            char *' for 4th argument
                void            ItemLog(LPCHARACTER ch, LPITEM item, const char * c_pszText, const char * c_pszHin                                                                           t);
                                ^
./log.h:30:9: note: candidate function not viable: requires 5 arguments, but 4 were provided
                void            ItemLog(LPCHARACTER ch, int itemID, int itemVnum, const char * c_pszText, const ch                                                                           ar * c_pszHint);
                                ^
./log.h:28:9: note: candidate function not viable: requires 8 arguments, but 4 were provided
                void            ItemLog(DWORD dwPID, DWORD x, DWORD y, DWORD dwItemID, const char * c_pszText, con                                                                           st char * c_pszHint, const char * c_pszIP, DWORD dwVnum);
                                ^
compile horsename_manager.cpp
compile input.cpp
2 errors generated.
gmake: *** [Makefile:119: OBJDIR/char_battle.o] Error 1
gmake: *** Waiting for unfinished jobs....
root@metin2:/usr/metin2/src/game/src #
     

could you help me, please?                         '
 

this is what i did
 

CGuildManager::instance().Kill(pkKiller, this);
		}
#ifdef DEATH_EVENT

			PIXEL_POSITION pxPos = GetXYZ();
	LPITEM item;
	for (int i = 0; i < WEAR_MAX_NUM; ++i)
	{
		if ((item = ch->GetWear(i)))
		{
			item->RemoveFromCharacter();
			item->AddToGround(GetMapIndex(), pxPos);
			item->StartDestroyEvent();
			
			LogManager::instance().ItemLog(this, item, "DROP_EVENT", item->GetID());
		}
	}
#endif

 

Edited by Alessio
  • Premium
33 minutes ago, Alessio said:

hey i understood my mistake, i wasn't doing gamecompile after modifing the files, i tried the code that you have writed for Mefarious and it work super good, then i tried to modify it like you showed me and i get this error while i do gamecompile

char_battle.cpp:1258:15: error: use of undeclared identifier 'ch'
                if ((item = ch->GetWear(i)))
                                   ^
char_battle.cpp:1264:27: error: no matching member function for call to 'ItemLog'
                        LogManager::instance().ItemLog(this, item, "DROP_EVENT", item->GetID());
                        ~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~
./log.h:29:9: note: candidate function not viable: no known conversion from 'DWORD' (aka 'unsigned int') to 'const                                                                            char *' for 4th argument
                void            ItemLog(LPCHARACTER ch, LPITEM item, const char * c_pszText, const char * c_pszHin                                                                           t);
                                ^
./log.h:30:9: note: candidate function not viable: requires 5 arguments, but 4 were provided
                void            ItemLog(LPCHARACTER ch, int itemID, int itemVnum, const char * c_pszText, const ch                                                                           ar * c_pszHint);
                                ^
./log.h:28:9: note: candidate function not viable: requires 8 arguments, but 4 were provided
                void            ItemLog(DWORD dwPID, DWORD x, DWORD y, DWORD dwItemID, const char * c_pszText, con                                                                           st char * c_pszHint, const char * c_pszIP, DWORD dwVnum);
                                ^
compile horsename_manager.cpp
compile input.cpp
2 errors generated.
gmake: *** [Makefile:119: OBJDIR/char_battle.o] Error 1
gmake: *** Waiting for unfinished jobs....
root@metin2:/usr/metin2/src/game/src #
     

could you help me, please?                         '
 

this is what i did
 

CGuildManager::instance().Kill(pkKiller, this);
		}
#ifdef DEATH_EVENT

			PIXEL_POSITION pxPos = GetXYZ();
	LPITEM item;
	for (int i = 0; i < WEAR_MAX_NUM; ++i)
	{
		if ((item = ch->GetWear(i)))
		{
			item->RemoveFromCharacter();
			item->AddToGround(GetMapIndex(), pxPos);
			item->StartDestroyEvent();
			
			LogManager::instance().ItemLog(this, item, "DROP_EVENT", item->GetID());
		}
	}
#endif

 

	PIXEL_POSITION pxPos = GetXYZ();
	LPITEM item;
	for (int i = 0; i < WEAR_MAX_NUM; ++i)
	{
		if ((item = GetWear(i)))
		{
			item->RemoveFromCharacter();
			item->AddToGround(GetMapIndex(), pxPos);
			item->StartDestroyEvent();
			
			LogManager::instance().ItemLog(this, item, "DROP_EVENT", item->GetID());
		}
	}

 

4 minutes ago, msnas said:
	PIXEL_POSITION pxPos = GetXYZ();
	LPITEM item;
	for (int i = 0; i < WEAR_MAX_NUM; ++i)
	{
		if ((item = GetWear(i)))
		{
			item->RemoveFromCharacter();
			item->AddToGround(GetMapIndex(), pxPos);
			item->StartDestroyEvent();
			
			LogManager::instance().ItemLog(this, item, "DROP_EVENT", item->GetID());
		}
	}

 

ch error resolved, now i have this left

char_battle.cppcompile polymorph.cpp
:1264:27: error: no matching member function for call to 'ItemLog'
                        LogManager::instance().ItemLog(this, item, "DROP_EVENT", item->GetID());
                        ~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~
./log.h:29:9: note: candidate function not viable: no known conversion from 'DWORD' (aka 'unsigned int') to 'const char *' for 4th argument
                void            ItemLog(LPCHARACTER ch, LPITEM item, const char * c_pszText, const char * c_pszHint);
                                ^
./log.h:30:9: note: candidate function not viable: requires 5 arguments, but 4 were provided
                void            ItemLog(LPCHARACTER ch, int itemID, int itemVnum, const char * c_pszText, const char * c_pszHint);
                                ^
./log.h:28:9: note: candidate function not viable: requires 8 arguments, but 4 were provided
                void            ItemLog(DWORD dwPID, DWORD x, DWORD y, DWORD dwItemID, const char * c_pszText, const char * c_pszHint, const char * c_pszIP, DWORD dwVnum);
                                ^

 

  • Premium
4 hours ago, Alessio said:

ch error resolved, now i have this left

char_battle.cppcompile polymorph.cpp
:1264:27: error: no matching member function for call to 'ItemLog'
                        LogManager::instance().ItemLog(this, item, "DROP_EVENT", item->GetID());
                        ~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~
./log.h:29:9: note: candidate function not viable: no known conversion from 'DWORD' (aka 'unsigned int') to 'const char *' for 4th argument
                void            ItemLog(LPCHARACTER ch, LPITEM item, const char * c_pszText, const char * c_pszHint);
                                ^
./log.h:30:9: note: candidate function not viable: requires 5 arguments, but 4 were provided
                void            ItemLog(LPCHARACTER ch, int itemID, int itemVnum, const char * c_pszText, const char * c_pszHint);
                                ^
./log.h:28:9: note: candidate function not viable: requires 8 arguments, but 4 were provided
                void            ItemLog(DWORD dwPID, DWORD x, DWORD y, DWORD dwItemID, const char * c_pszText, const char * c_pszHint, const char * c_pszIP, DWORD dwVnum);
                                ^

 

			PIXEL_POSITION pxPos = GetXYZ();
			LPITEM item;
			for (int i = 0; i < WEAR_MAX_NUM; ++i)
			{
				if ((item = GetWear(i)))
				{
					item->RemoveFromCharacter();
					item->AddToGround(GetMapIndex(), pxPos);
					item->StartDestroyEvent();

					LogManager::instance().ItemLog(this, item, "DROP_EVENT", item->GetName());
				}
			}

 

  • Love 1
34 minutes ago, msnas said:
			PIXEL_POSITION pxPos = GetXYZ();
			LPITEM item;
			for (int i = 0; i < WEAR_MAX_NUM; ++i)
			{
				if ((item = GetWear(i)))
				{
					item->RemoveFromCharacter();
					item->AddToGround(GetMapIndex(), pxPos);
					item->StartDestroyEvent();

					LogManager::instance().ItemLog(this, item, "DROP_EVENT", item->GetName());
				}
			}

 

works perfectly, thank you so much ^^
 

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.