Register for your free account! | Forgot your password?

You last visited: Today at 05:27

  • Please register to post and access all features, it's quick, easy and FREE!

Advertisement



[Rls] [C++] PetPickup

Discussion on [Rls] [C++] PetPickup within the Metin2 PServer Guides & Strategies forum part of the Metin2 Private Server category.

Reply
 
Old   #1
 
elite*gold: 20
Join Date: Jun 2011
Posts: 2,897
Received Thanks: 3,328
[Rls] [C++] PetPickup

PetPickUpSystem ( Pet luft zu den von euch gedroppten Items und hebt sie auf)
Wer fehler findet darf sie behalten.

Code:
service.h:
		add:
				#define __PET_PICKUP
PetSystem.h:
		search:
				void			SetSummonItem (LPITEM pItem);
		add below:
				#ifdef __PET_PICKUP
						void			PickUpItems(int range);
						void			BringItem();
						void			SetPickup(bool is_pickup) { m_is_pickup = is_pickup; }
						bool			IsPickup(){ return m_is_pickup; }
						void			SetPickupItem(LPITEM item) { m_pickup_item = item; }
						LPITEM			GetPickupItem(){ return m_pickup_item; }
				#endif
		search:
			LPCHARACTER		m_pkOwner;
		add below:
			#ifdef __PET_PICKUP
			bool			m_is_pickup;
			LPITEM			m_pickup_item;
			#endif


char.h:
		search:
				bool			PickupItem(DWORD vid);
		add below:
				#ifdef __PET_PICKUP
						bool			PickupItemByPet(DWORD vid);
						
				#endif


char_item.cpp:
		search:
			bool CHARACTER::PickupItem(DWORD dwVID)

		add above:
			#ifdef __PET_PICKUP
			bool CHARACTER::PickupItemByPet(DWORD dwVID)
			{
				LPITEM item = ITEM_MANAGER::instance().FindByVID(dwVID);
				if (IsObserverMode())
					return false;
				if (!item || !item->GetSectree())
					return false;
				if (item->IsOwnership(this))
				{
					if (item->GetType() == ITEM_ELK)
					{
						GiveGold(item->GetCount());
						item->RemoveFromGround();

						M2_DESTROY_ITEM(item);
						Save();
					}
					else
					{
						if (item->IsStackable() && !IS_SET(item->GetAntiFlag(), ITEM_ANTIFLAG_STACK))
						{
							BYTE bCount = item->GetCount();

							for (int i = 0; i < INVENTORY_MAX_NUM; ++i)
							{
								LPITEM item2 = GetInventoryItem(i);

								if (!item2)
									continue;

								if (item2->GetVnum() == item->GetVnum())
								{
									int j;

									for (j = 0; j < ITEM_SOCKET_MAX_NUM; ++j)
									if (item2->GetSocket(j) != item->GetSocket(j))
										break;

									if (j != ITEM_SOCKET_MAX_NUM)
										continue;

									BYTE bCount2 = MIN(200 - item2->GetCount(), bCount);
									bCount -= bCount2;

									item2->SetCount(item2->GetCount() + bCount2);

									if (bCount == 0)
									{
										ChatPacket(CHAT_TYPE_INFO, LC_TEXT(" ȹ: %s"), item2->GetName());
										M2_DESTROY_ITEM(item);
										if (item2->GetType() == ITEM_QUEST)
											quest::CQuestManager::instance().PickupItem(GetPlayerID(), item2);
										return true;
									}
								}
							}

							item->SetCount(bCount);
						}

						int iEmptyCell;
						if (item->IsDragonSoul())
						{
							if ((iEmptyCell = GetEmptyDragonSoulInventory(item)) == -1)
							{
								sys_log(0, "No empty ds inventory pid %u size 
 itemid %u", GetPlayerID(), item->GetSize(), item->GetID());
								ChatPacket(CHAT_TYPE_INFO, LC_TEXT("ϰ ִ  ʹ ϴ."));
								return false;
							}
						}
						else
						{
							if ((iEmptyCell = GetEmptyInventory(item->GetSize())) == -1)
							{
								sys_log(0, "No empty inventory pid %u size 
 itemid %u", GetPlayerID(), item->GetSize(), item->GetID());
								ChatPacket(CHAT_TYPE_INFO, LC_TEXT("ϰ ִ  ʹ ϴ."));
								return false;
							}
						}

						item->RemoveFromGround();

						if (item->IsDragonSoul())
							item->AddToCharacter(this, TItemPos(DRAGON_SOUL_INVENTORY, iEmptyCell));
						else
							item->AddToCharacter(this, TItemPos(INVENTORY, iEmptyCell));

						char szHint[32 + 1];
						snprintf(szHint, sizeof(szHint), "%s %u %u", item->GetName(), item->GetCount(), item->GetOriginalVnum());
						LogManager::instance().ItemLog(this, item, "GET", szHint);
						ChatPacket(CHAT_TYPE_INFO, LC_TEXT(" ȹ: %s"), item->GetName());

						if (item->GetType() == ITEM_QUEST)
							quest::CQuestManager::instance().PickupItem(GetPlayerID(), item);
					}
					//Motion(MOTION_PICKUP);
					return true;
				}

				return false;
			}
			#endif
PetSystem.cpp:
		search:
				bool CPetActor::Follow(float fMinDistance)
		add above:
				#ifdef __PET_PICKUP
				struct PetPickUpItemStruct
				{
					CPetActor * pet;
					int range;
					PetPickUpItemStruct(CPetActor * p, int r){

						pet = p;
						range = r;
					}
					void operator()(LPENTITY pEnt)
					{
						if (!pet->GetOwner() || !pet->GetCharacter())
							return;
						if (pet->IsPickup())
							return;
						if (pEnt->IsType(ENTITY_ITEM) == true)
						{
							
							LPITEM item = (LPITEM)pEnt;
							LPCHARACTER player = pet->GetOwner();
							if (!item->GetSectree() || !item->IsOwnership(player))
								return;

							int iDist = DISTANCE_APPROX(item->GetX() - player->GetX(), player->GetY() - player->GetY());

							if (iDist > range)
								return;
							pet->SetPickup(true);
							pet->SetPickupItem(item);
						}

					}
				};
				void CPetActor::PickUpItems(int range){
					if (IsPickup())
						return;
					long map = m_pkChar->GetMapIndex();
					PIXEL_POSITION m = m_pkChar->GetXYZ();
					LPSECTREE tree = SECTREE_MANAGER::instance().Get(map, m.x, m.y);
					if (!tree)
					{
						sys_err("cannot find sectree by %dx%d", m.x, m.y);
						return;
					}
					PetPickUpItemStruct f(this, range);
					tree->ForEachAround(f);
				}

				void CPetActor::BringItem(){
					if (!IsPickup())
						return;
					LPITEM item = GetPickupItem();
					if (!m_pkOwner || !m_pkChar || !item || !item->GetSectree())
						return;
					
					float fMinDistance = 20.0;
					float fPetX = m_pkChar->GetX();
					float fPetY = m_pkChar->GetY();

					float itemX = item->GetX();
					float itemY = item->GetY();

					float fDist = DISTANCE_SQRT(itemX - fPetX, itemY - fPetY);
					if (fDist <= 250.0)
					{
						SetPickup(false);
						m_pkOwner->PickupItemByPet(item->GetVID());
						SetPickupItem(NULL);
						m_pkChar->SendMovePacket(FUNC_WAIT, 0, 0, 0, 0, 0);
						return;
					}
					m_pkChar->SetRotationToXY(itemX, itemY);
					float fx, fy;

					float fDistToGo = fDist - fMinDistance;
					GetDeltaByDegree(m_pkChar->GetRotation(), fDistToGo, &fx, &fy);

					if (!m_pkChar->Goto((int)(fPetX + fx + 0.5f), (int)(fPetY + fy + 0.5f)))
						return;

					m_pkChar->SendMovePacket(FUNC_WAIT, 0, 0, 0, 0, 0);
				}
				#endif

	search:
		if (this->IsSummoned() && HasOption(EPetOption_Followable))

	add above:
			#ifdef __PET_PICKUP
				if (this->IsSummoned()){
					this->BringItem();
					this->PickUpItems(900); // 900 = RANGE
				}	
			#endif
	search:
		this->SetSummonItem(NULL);
	add below:
		#ifdef __PET_PICKUP
				this->SetPickupItem(NULL);
				this->SetPickup(false);
		#endif

	search:
		m_dwSummonItemVID = 0;
		m_dwSummonItemVnum = 0;
	add below:
		#ifdef __PET_PICKUP
				this->SetPickupItem(NULL);
				this->SetPickup(false);
		#endif
und nein, das ndern der normalen Pickup Function wollte nicht so recht (mit optionalem Parameter), da beim VS2013 sowie bei gcc der core beim pickup crashen wollte
xCPx is offline  
Thanks
25 Users
Old 05/09/2016, 19:58   #2
 
elite*gold: 105
Join Date: Jun 2015
Posts: 454
Received Thanks: 293
Cooles release!
Danke <3
Im Raylee is offline  
Old 05/09/2016, 20:10   #3
 
elite*gold: 2
Join Date: Jun 2013
Posts: 1,164
Received Thanks: 1,719
Hammer.
ProfessorEnte is offline  
Old 05/09/2016, 21:50   #4
 
elite*gold: 0
Join Date: Apr 2013
Posts: 555
Received Thanks: 437
Du Released auch immer nur Bullshit oder? Witz komm herbei , Danke.
.Achi' is offline  
Old 05/10/2016, 20:13   #5



 
elite*gold: 84
Join Date: Dec 2010
Posts: 820
Received Thanks: 402
Ty.
.xCl4w' is offline  
Old 05/10/2016, 22:35   #6
 
elite*gold: 0
Join Date: Dec 2014
Posts: 998
Received Thanks: 487
ty endlich mal wieder was ntztliches.
da du in letzter zeit so offen fr vorschlge bist:

besser wre es wenn nur bestimmte pets ber dieses feature verfgen.
BizepsSupportAccount is offline  
Old 05/10/2016, 23:09   #7
 
elite*gold: 20
Join Date: Jun 2011
Posts: 2,897
Received Thanks: 3,328
einfach in:

void CPetActor::PickUpItems(int range){
if (IsPickup())
return;
long map = m_pkChar->GetMapIndex();
PIXEL_POSITION m = m_pkChar->GetXYZ();
LPSECTREE tree = SECTREE_MANAGER::instance().Get(map, m.x, m.y);
if (!tree)
{
sys_err("cannot find sectree by %dx%d", m.x, m.y);
return;
}
PetPickUpItemStruct f(this, range);
tree->ForEachAround(f);
}


einfgen

If(m_pkChar->GetVnum() != 101)
return;

damit geht es nur bei vnum 101.
xCPx is offline  
Thanks
1 User
Old 05/11/2016, 15:31   #8
 
elite*gold: 0
Join Date: Aug 2014
Posts: 11
Received Thanks: 0
the problem is , this not really good for metin2

becous there too many items drops by mobs - stone ...

so every time when u want pick up the item it will take time , so this is very borring
Like this
if you make thia systen without pet goto item it will be very nice

Anyway thanks for you !
anaahmed10 is offline  
Old 05/11/2016, 17:52   #9
 
elite*gold: 0
Join Date: Dec 2014
Posts: 998
Received Thanks: 487
weiterer vorschlag? pets heben nur bestimmte items mit nem subtype auf z.b 27102 USE_ABILITY_UP
BizepsSupportAccount is offline  
Old 05/11/2016, 18:07   #10
 
elite*gold: 88
Join Date: Jun 2013
Posts: 667
Received Thanks: 243
So:

Player Test1 Dropt item 180 bei mob ***
Player Test2 Hat ein Pet bei sich, dieses Luft hin und kann dieses aufsammeln und es landet im inventar von Test2 Trotz bei dem item 180 Der name Test1 Trber steht.

Habs nicht getestet , aber ist ja nirgendo definiert was es aufheben kann.

Trzdem THX
"Sh4Xx" is offline  
Old 05/11/2016, 22:35   #11
 
elite*gold: 0
Join Date: May 2016
Posts: 3
Received Thanks: 11
vorab: ich beziehe mich nur auf den coding stil, da ich mich mit der game kein bisschen auskenne (nie mit befasst da der source nach meiner zeit kam)
also heult nicht rum dass ich es besser machen soll

ich wei ich wei, es ist persnliche vorliebe etc aber wollte es trotzdem mal ansprechen

1. warum benutzt du diese notation mit den underscores? (habe gerade den namen nicht mehr im kopf)
wird normaler weise fr die c++ standard libs und in c fr embedded systems verwendet

klar, kann man nutzen aber unter dem ganzen camel case sieht es bld aus

2. ich wrde auf nested conditionals verzichten weil es einfach nervig zu lesen ist

beispiel:

anstatt:

Code:
if(item) {
	if(item2) {
		....
	}
}

lieber:

Code:
if(!item)
	return;

if(!item2)
	return;
hast es ja teilweise gemacht aber der grte teil ist nested und das ist nervig zu lesen vor allem weil man einfach oft nach rechts scrollen muss

3. ist mir das aufgefallen (machen mehrere):

Code:
char szHint[32 + 1];
wieso??
knnte nun sagen ist ne unntige rechenoperation aber da trifft man hier eh auf taube ohren


4. dieses inline member function definition zeug ist auch schon 20 jahre alt
ist schner wenn es auerhalb der eigentlichen klassen bzw struct deklaration wre
ist auch fr auenstehende besser zu lesen.. wenn die nur wissen wollen was alles drin ist mssen die sich erst mal durch scrollen
Remix v110 is offline  
Thanks
4 Users
Old 05/12/2016, 14:38   #12

 
elite*gold: 70
Join Date: Mar 2015
Posts: 86
Received Thanks: 81
Funktioniert nicht
.Aphrodite is offline  
Old 05/12/2016, 17:19   #13
 
elite*gold: 0
Join Date: Apr 2010
Posts: 66
Received Thanks: 101
Quote:
Originally Posted by .Callous View Post
Funktioniert nicht


Code:
sys_log(0, "No empty ds inventory pid %u size 
 itemid %u", GetPlayerID(), item->GetSize(), item->GetID());
to

Code:
sys_log(0, "No empty ds inventory pid %u size itemid %u", GetPlayerID(), item->GetSize(), item->GetID());

space space space...
kralcocuk is offline  
Old 05/13/2016, 00:15   #14
 
elite*gold: 0
The Black Market: 105/0/0
Join Date: May 2016
Posts: 8,681
Received Thanks: 1,633
Sehr ntzlich Danke dir
悪地城 is offline  
Old 05/13/2016, 00:19   #15

 
elite*gold: 70
Join Date: Mar 2015
Posts: 86
Received Thanks: 81
Bug gefunden!

Wenn man ein Item auf den Boden wirft, hebt das Pet es wieder auf.
.Aphrodite is offline  
Reply




All times are GMT +1. The time now is 05:27.


Powered by vBulletin®
Copyright ©2000 - 2021, Jelsoft Enterprises Ltd.
SEO by vBSEO ©2011, Crawlability, Inc.
This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

BTC: 33E6kMtxYa7dApCFzrS3Jb7U3NrVvo8nsK
ETH: 0xc6ec801B7563A4376751F33b0573308aDa611E05

Support | Contact Us | FAQ | Advertising | Privacy Policy | Terms of Service | Abuse
Copyright ©2020 elitepvpers All Rights Reserved.