Jump to content

Cannot find item by 0


Recommended Posts

I dont have resolution but... This is not for "lang" options in item_proto? Like first or second original line in column? Idk where or how is definition in source for this function if exist, but I know it is in item_proto (original) definition just "clear" column for lang.. Im interesting with this problem but if I have this column with id (1?) in item_proto I dont have this problem.. But if I delete this column (just logically why, hh) I get this error in game (I mean after use /i cmd but Im not sure...)

Link to comment
Share on other sites

  • Premium
#define DEBUG_SELECT_ITEM
#ifdef DEBUG_SELECT_ITEM
	#include "PythonChat.h"
#endif

PyObject * itemSelectItem(PyObject * poSelf, PyObject * poArgs)
{
    int iIndex;
    if (!PyTuple_GetInteger(poArgs, 0, &iIndex))
        return Py_BadArgument();

    if (!CItemManager::Instance().SelectItemData(iIndex))
    {
#ifdef DEBUG_SELECT_ITEM
        CPythonChat::Instance().AppendChat(CHAT_TYPE_TALKING, "Cannot find item!!!!!");
#else
        TraceError("Cannot find item by %d", iIndex);
#endif
        CItemManager::Instance().SelectItemData(60001);
    }

    return Py_BuildNone();
}

 

The error comes from here. But this function is used A LOT in python, in lot of fkn places.

So i'm suggesting to see the moment when error gets triggered to figure out better.

  • Love 1
Link to comment
Share on other sites

  • Honorable Member

I would recommend to extend the function with a hint as well then when the problem is fixed revert the codes back to the original.

 

By the way this SelectItem sometimes messes up some codes, as you can see in the official codes about the sashes, you need to select an another item(the drained) to query some informations about that, then to not mess up the rest of the codes what comes after the external function call, you need to select the original vnum back after you are done.

This is just an example about the weakness of the SelectItem function, highly possible none of you are using this except me ?.

Also might be the problem is not because of these kind of codes, I just wanted to let you know about this.

Spoiler

		## This is the AddItemData function. Here an external function will be called which needs to query some informations about the drained item, also here the acce is the selected item. This function will run down on an item when you move your cursor on it, this function needs to run down to the end with the originally selected item otherwise some unexcpected errors may show up.
  		## ÄÚ˝şĂő ľĆŔĚĹŰ ##
		elif 0 != isCostumeItem:
			self.__AppendLimitInformation()
			
			if item.GetItemSubType() == item.COSTUME_TYPE_ACCE:
				self.__AppendAffectInformationAcce(slotIndex, window_type, metinSlot)
				self.__AppendAcceItemAffectInformation(itemVnum, window_type, slotIndex, metinSlot) #!!! Here goes the itemVnum as the recently selected itemVnum which is the sash vnum.
				self.__AppendAttributeInformationAcce(itemVnum, attrSlot, slotIndex, window_type, metinSlot)
			else:
				self.__AppendAffectInformation()
				self.__AppendAttributeInformation(attrSlot)

	#Here is the function which will select the drained item, then at the end it selects the original back
	def __AppendAcceItemAffectInformation(self, oriitemVnum, window_type, slotIndex, metinSlot):
	
		(affectTypeAcce, affectValueAcce) = item.GetAffect(0)
		socketInDrainValue = 0
	
		if item.GetRefinedVnum() == 0:
			## ŔüĽłµî±Ţ ČíĽöŔ˛ ľËľĆżŔ±â.
			if app.ENABLE_EXTEND_INVEN_SYSTEM:
				socketInDrainValue = 0
				if window_type == playerm2g2.INVENTORY or window_type == playerm2g2.EQUIPMENT:
					socketInDrainValue = playerm2g2.GetItemMetinSocket(window_type, slotIndex, 1)
					if not metinSlot[1] == 0 and socketInDrainValue == 0:
							socketInDrainValue = metinSlot[1]
				elif window_type == playerm2g2.ACCEREFINE:
					socketInDrainValue = playerm2g2.GetAcceItemMetinSocket(slotIndex, 1)
				elif window_type == playerm2g2.SAFEBOX:
					socketInDrainValue = safebox.GetItemMetinSocket(slotIndex, 1)
			else:
				if window_type == playerm2g2.INVENTORY:
					socketInDrainValue = playerm2g2.GetItemMetinSocket(slotIndex, 1)
					if not metinSlot[1] == 0 and socketInDrainValue == 0:
							socketInDrainValue = metinSlot[1]
				elif window_type == playerm2g2.ACCEREFINE:
					socketInDrainValue = playerm2g2.GetAcceItemMetinSocket(slotIndex, 1)
				elif window_type == playerm2g2.SAFEBOX:
					socketInDrainValue = safebox.GetItemMetinSocket(slotIndex, 1)

			drainlate = socketInDrainValue / 100.0
		else:
			drainlate = affectValueAcce / 100.0
			socketInDrainValue = affectValueAcce
			
		if socketInDrainValue == 0:
			return
		
		
		## Á¤ş¸ »ĚľĆżĂ ľĆŔĚĹŰ ľËľĆżŔ±â.
		if app.ENABLE_EXTEND_INVEN_SYSTEM:
			socketInDrainItemVnum = 0
			if window_type == playerm2g2.INVENTORY or window_type == playerm2g2.EQUIPMENT:
				socketInDrainItemVnum = playerm2g2.GetItemMetinSocket(window_type, slotIndex, 0)
				if not metinSlot[0] == 0 and socketInDrainItemVnum == 0:
					socketInDrainItemVnum = metinSlot[0]
			elif window_type == playerm2g2.ACCEREFINE:
				socketInDrainItemVnum = playerm2g2.GetAcceItemMetinSocket(slotIndex, 0)
			elif window_type == playerm2g2.SAFEBOX:
				socketInDrainItemVnum = safebox.GetItemMetinSocket(slotIndex, 0)
		else:
			if window_type == playerm2g2.INVENTORY:
				socketInDrainItemVnum = playerm2g2.GetItemMetinSocket(slotIndex, 0)
				if not metinSlot[0] == 0 and socketInDrainItemVnum == 0:
					socketInDrainItemVnum = metinSlot[0]
			elif window_type == playerm2g2.ACCEREFINE:
				socketInDrainItemVnum = playerm2g2.GetAcceItemMetinSocket(slotIndex, 0)
			elif window_type == playerm2g2.SAFEBOX:
				socketInDrainItemVnum = safebox.GetItemMetinSocket(slotIndex, 0)

		## ČíĽöÇŃ ľÇĽĽĽ­¸® ľĆŔĚĹ۸¸ ş¸ż©ÁÖ±âŔ§ÇŘ °É·ŻÁŘ´Ů.
		if socketInDrainItemVnum == 0:
			return
		
		item.SelectItem(socketInDrainItemVnum)
		
		itemtype = item.GetItemType()
		
		if itemtype == item.ITEM_TYPE_WEAPON:
			## Ăß°ˇ µĄąĚÁö
			addPower = item.GetValue(5)

			## ą«±â. Attact
			if item.GetValue(3) >= 1 and item.GetValue(4) >= 1:
				minPower = max(((item.GetValue(3) + addPower) * drainlate) , 1)
				maxPower = max(((item.GetValue(4) + addPower) * drainlate) , 1)
		
				if maxPower > minPower:
					self.AppendTextLineAcce(localeInfo.TOOLTIP_ITEM_ATT_POWER % (minPower, maxPower), self.POSITIVE_COLOR)
				else:
					self.AppendTextLineAcce(localeInfo.TOOLTIP_ITEM_ATT_POWER_ONE_ARG % (minPower), self.POSITIVE_COLOR)

			## ą«±â. Magic
			if item.GetValue(1) >= 1 or item.GetValue(2) >= 1:
				minMagicAttackPower = max(((item.GetValue(1) + addPower) * drainlate) , 1)
				maxMagicAttackPower = max(((item.GetValue(2) + addPower) * drainlate) , 1)

				if maxMagicAttackPower > minMagicAttackPower:
					self.AppendTextLineAcce(localeInfo.TOOLTIP_ITEM_MAGIC_ATT_POWER % (minMagicAttackPower, maxMagicAttackPower), self.POSITIVE_COLOR)
				else:
					self.AppendTextLineAcce(localeInfo.TOOLTIP_ITEM_MAGIC_ATT_POWER_ONE_ARG % (minMagicAttackPower), self.POSITIVE_COLOR)

		elif itemtype == item.ITEM_TYPE_ARMOR:

			## ąćľî·Â
			defBonus = item.GetValue(5)*2 ## ąćľî·Â ÇĄ˝Ă Ŕ߸ř µÇ´Â ą®Á¦¸¦ ĽöÁ¤
			if item.GetValue(1) >= 1:
				defGrade = max(((item.GetValue(1) + defBonus) * drainlate) , 1)
				if defGrade > 0:
					self.AppendSpace(5)
					self.AppendTextLineAcce(localeInfo.TOOLTIP_ITEM_DEF_GRADE % (defGrade), self.GetChangeTextLineColor(defGrade))

		## Itemtable żˇ ŔÖ´Â ±âş» ĽÓĽş Ŕűżë.
		## ľÇĽĽĽ­¸®żˇ´Â - °© ex Ŕ̵żĽÓµµ Ŕűżë ľČÇÔ.
		for i in xrange(item.ITEM_APPLY_MAX_NUM):
			(affectType, affectValue) = item.GetAffect(i)
			if affectValue > 0:
				affectValue = max((affectValue * drainlate) , 1)
				affectString = self.__GetAffectString(affectType, affectValue)
				if affectString:
					self.AppendTextLineAcce(affectString, self.GetChangeTextLineColor(affectValue))

		item.SelectItem(oriitemVnum)

 

 

And the hint I started to talk about:

#define BULLSEYE
PyObject * itemSelectItem(PyObject * poSelf, PyObject * poArgs)
{
	DWORD dwItemIndex;
	if (!PyTuple_GetUnsignedLong(poArgs, 0, &dwItemIndex))
		return Py_BadArgument();

#ifdef BULLSEYE
	char* szHint;
	if (2 == PyTuple_Size(poArgs))
	{
		if (!PyTuple_GetString(poArgs, 1, &szHint))
			return Py_BadArgument();
	}
#endif

	if (!CItemManager::Instance().SelectItemData(dwItemIndex))
	{
#ifdef BULLSEYE
		TraceError("Cannot find item by %lu hint: %s", dwItemIndex, szHint);
#else
		TraceError("Cannot find item by %lu", dwItemIndex);
#endif
		CItemManager::Instance().SelectItemData(60001);
		return Py_BuildValue("i", FALSE);
	}

	return Py_BuildValue("i", TRUE);
}

You might have some syntax errors, my function looks a bit different then the public ones, after I reversed this from the official and built my own pythoncore with fixxed errors about the unsigned long stuffs. But you can see in the macro the hint stuff. PS: Totally unnecesary the PythonChat, it will write to the syserr anyways.

After this you just start replacing all of your calls in your python files like:

	def GetRefineSuccessPercentage(self, scrollSlotIndex, itemSlotIndex):

		if -1 != scrollSlotIndex:
			if player.IsRefineGradeScroll(scrollSlotIndex):
				curGrade = player.GetItemGrade(itemSlotIndex)
				itemIndex = player.GetItemIndex(itemSlotIndex)

				item.SelectItem(itemIndex)
	def GetRefineSuccessPercentage(self, scrollSlotIndex, itemSlotIndex):

		if -1 != scrollSlotIndex:
			if player.IsRefineGradeScroll(scrollSlotIndex):
				curGrade = player.GetItemGrade(itemSlotIndex)
				itemIndex = player.GetItemIndex(itemSlotIndex)

				item.SelectItem(itemIndex, "uiRefine.GetRefineSuccessPercentage")

Or also you can discover it via this:

J7Pu8jq.png

# utils.py
import inspect
def getLineInfo():
	stack = inspect.stack()
	return "%s.%s at line %d" % (stack[1][1], stack[1][3], stack[1][2])

This requires the inspect module which also requires the following modules:

dis

opcode

string

token

tokenize

 

So with this you just need to call the utils.getLineInfo() as the 2nd argument of the item.SelectItem function

item.SelectItem(itemVnum, utils.getLineInfo())

and also the utils has to be imported to the file where you use the item modul for selecting an item during the debugging.

DID NOT TESTED ON CYTHONIZED CODES, AND NEVER WILL, cython is not for debugging anyways :)

Edited by Metin2 Dev
Core X - External 2 Internal
  • Good 1
  • Love 3
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.