Jump to content
metin2dev
  • 0
Sign in to follow this  
Denny2399

open Help with bonuses

Question

Hello,
Can anyone experienced help me out a little with this piece of code?
It should consider number of bonuses when adding new, but it doesn't. Maybe the function attrcount is wrongly defined?
The define checks if you can add bonus into an item and highlights with red or green.
 

Spoiler

    def __CanAddItemAttr(self, dstSlotPos):
        dstItemVNum = player.GetItemIndex(dstSlotPos)
        if dstItemVNum == 0:
            return False

        item.SelectItem(dstItemVNum)
        
        if not item.GetItemType() in (item.ITEM_TYPE_WEAPON, item.ITEM_TYPE_ARMOR):    
            return False
            
        attrCount = 0
        for i in xrange(player.METIN_SOCKET_MAX_NUM):
            if player.GetItemAttribute(dstSlotPos, i) != 0:
                return True

        if attrCount<4:
            return False

                                
        return False

 

 

Share this post


Link to post
Share on other sites

22 answers to this question

Recommended Posts

  • 0
2 hours ago, ragem0re said:

player.METIN_SOCKET_MAX_NUM think thats not a default constant. does it return ITEM_SOCKET_SLOT_MAX_NUM (3)?

Well I've checked multiple roots with uiinventory script an there is the same code, can't find that constant anywhere too. Where can I find out what it returns?

Share this post


Link to post
Share on other sites
  • 0
21 minutes ago, ragem0re said:

check your binary source code UserInterface\PythonPlayerModule.cpp

image.png.2f72f0abafa8b842ec0c3a6fb9686406.png

Should I use ATTRIBUTE_SLOT_MAX_NUM instead?

Share this post


Link to post
Share on other sites
  • 0
11 minutes ago, ragem0re said:

where does the attrCount variable get changed in your code?

I don't understand python much, but it should be here:
 

Spoiler

        if attrCount<(number of attributes):
            return False

 


The variable is only present in the definition

Share this post


Link to post
Share on other sites
  • 0

The player.GetItemAttribute([slotWindow=INVENTORY,] slotPos, attrIndex) returns a tuple, don't forget.

		attrCount = 0
		for i in xrange(player.ATTRIBUTE_SLOT_NORM_NUM):
			if player.GetItemAttribute(dstSlotWindow, dstSlotPos, i)[0] != 0:
				attrCount += 1

		if attrCount < 4:
			return True

		return False

 

  • Like 1

Share this post


Link to post
Share on other sites
  • 0
58 minutes ago, xP3NG3Rx said:

The player.GetItemAttribute([slotWindow=INVENTORY,] slotPos, attrIndex) returns a tuple, don't forget.


		attrCount = 0
		for i in xrange(player.ATTRIBUTE_SLOT_NORM_NUM):
			if player.GetItemAttribute(dstSlotWindow, dstSlotPos, i)[0] != 0:
				attrCount += 1

		if attrCount < 4:
			return True

		return False

 

You made new const for it right? Can you point me to how to do that too please?
I would like to make one for normal bonus checking and 6/7 bonus checking.

Share this post


Link to post
Share on other sites
  • 0

Both ITEM_ATTRIBUTE_SLOT_MAX_NUM and ITEM_SOCKET_SLOT_MAX_NUM are in Userinterface/GameType.h,  and can be called as ATTRIBUTE_SLOT_MAX_NUM and METIN_SOCKET_MAX_NUM respectively within python scripts

Spoiler

enum
{
    ITEM_SOCKET_SLOT_MAX_NUM = 3,
    ITEM_ATTRIBUTE_SLOT_MAX_NUM = 7,
};

However sincerly i can't understand your code:
 

  attrCount = 0                                          //here you inizialize the constant
        for i in xrange(player.METIN_SOCKET_MAX_NUM):     // for i in xrange(3):
            if player.GetItemAttribute(dstSlotPos, i) != 0:             // GetItemAttribute: is this a custom function you made or are you using a incomplete type of the void                                                                                     //CPythonPlayer::GetItemAttribute(TItemPos Cell, DWORD dwAttrSlotIndex, BYTE * pbyType, short * psValue)?  if so                                                            //it will check against ITEM_ATTRIBUTE_SLOT_MAX_NUM == 7 (it will return true for 5, 6 and 7th bonuses)
                return True

        if attrCount<4:                                        //here if attrCount is 3, 2, 1 will return false is this intended? maybe attrCount>3
            return False

                                
        return False

Share this post


Link to post
Share on other sites
  • 0
5 hours ago, OtherChoice said:

Both ITEM_ATTRIBUTE_SLOT_MAX_NUM and ITEM_SOCKET_SLOT_MAX_NUM are in Userinterface/GameType.h,  and can be called as ATTRIBUTE_SLOT_MAX_NUM and METIN_SOCKET_MAX_NUM respectively within python scripts

  Reveal hidden contents

enum
{
    ITEM_SOCKET_SLOT_MAX_NUM = 3,
    ITEM_ATTRIBUTE_SLOT_MAX_NUM = 7,
};

However sincerly i can't understand your code:
 

  attrCount = 0                                          //here you inizialize the constant
        for i in xrange(player.METIN_SOCKET_MAX_NUM):     // for i in xrange(3):
            if player.GetItemAttribute(dstSlotPos, i) != 0:             // GetItemAttribute: is this a custom function you made or are you using a incomplete type of the void                                                                                     //CPythonPlayer::GetItemAttribute(TItemPos Cell, DWORD dwAttrSlotIndex, BYTE * pbyType, short * psValue)?  if so                                                            //it will check against ITEM_ATTRIBUTE_SLOT_MAX_NUM == 7 (it will return true for 5, 6 and 7th bonuses)
                return True

        if attrCount<4:                                        //here if attrCount is 3, 2, 1 will return false is this intended? maybe attrCount>3
            return False

                                
        return False

The function was like this when I downloaded the client and so is in every client I tried to look into. It's part of the uiinventory.py where it checks if you can put item to destination item. I didn't edit this script in any way and should be then functional? But it's not. Even though I have a value of true it doesn't seem to work and numbers of attrCount don't change anything. I tried putting there elif with different value and return, still didn't succeed. It behaves like attrCount does nothing.

I guess the function is incomplete as you say.
Also, there should be true in my opinion as well :)

if attrCount<4:
   return True
else:
   return False

Did not work.

Share this post


Link to post
Share on other sites
  • 0
12 minutes ago, ragem0re said:

Please repeat once again, what exactly do you want?

Maybe I can try to help with my limited python skills :ph34r:

My python skills are limited more than yours I bet :D
Anyway.. I want the python script to check correctly if I can add a bonus into an item. When you hover with bonus over an item it should show green or red color, depending on if you can add it or not. The script is not correct, however, because it doesn't do so.

Example: If I have 4 bonuses, it should be red when hovering with normal bonuses over it and green if not, but it's always green.
Also when I have 4 bonuses I would like 5th bonus to show green and when you have 5 bonuses to mark it as red
If 6/7.. you understand me don't you?

Share this post


Link to post
Share on other sites
  • 0
40 minutes ago, Denny2399 said:

The function was like this when I downloaded the client and so is in every client I tried to look into. It's part of the uiinventory.py where it checks if you can put item to destination item. I didn't edit this script in any way and should be then functional? But it's not. Even though I have a value of true it doesn't seem to work and numbers of attrCount don't change anything. I tried putting there elif with different value and return, still didn't succeed. It behaves like attrCount does nothing.

This is the function i have, as you can see the last part is different

Spoiler

def __CanAddItemAttr(self, dstSlotPos):
        dstItemVNum = player.GetItemIndex(dstSlotPos)
        if dstItemVNum == 0:
            return False

        item.SelectItem(dstItemVNum)
        
        if not item.GetItemType() in (item.ITEM_TYPE_WEAPON, item.ITEM_TYPE_ARMOR):     
            return False
            
        attrCount = 0
        for i in xrange(player.METIN_SOCKET_MAX_NUM):
            if player.GetItemAttribute(dstSlotPos, i) != 0:
                attrCount += 1

        if attrCount<4:
            return True                   //THIS RETURNS TRUE if attrcount is 1,2,3 while in yours it will return false
                                
        return False

 

Share this post


Link to post
Share on other sites
  • 0

There's a function which colors the background,

there you have to add this check(s).

 

But first I need to find this function,

maybe it's in the source.

  • Like 1

Share this post


Link to post
Share on other sites
  • 0

To be clear: your function __CanAddItemAttr(self, dstSlotPos) has a wrong false 

Spoiler

 if attrCount<4:
            return False

replace with 

 if attrCount<4:
            return True

However this function will return true for bonus 1,2,3,4 and false for 5,6,7 and it is used to check whether  you can add a bonus with reinforce item (vnum 71085).
What was your goal? having reinforce item higlighting the item?

Share this post


Link to post
Share on other sites
  • 0
3 hours ago, OtherChoice said:

To be clear: your function __CanAddItemAttr(self, dstSlotPos) has a wrong false 

  Hide contents

 if attrCount<4:
            return False

replace with 

 if attrCount<4:
            return True

However this function will return true for bonus 1,2,3,4 and false for 5,6,7 and it is used to check whether  you can add a bonus with reinforce item (vnum 71085).
What was your goal? having reinforce item higlighting the item?

I did edit it this way before, then I returned it back how it was:)
I knew there has to be true, but even then it doesn't work how it should.
I had it exactly the way you have it, but something is probably wrong. Anyway just to be sure I will try it again and report you back in a moment.

EDIT: I used your function and the marking is red in every situation, even when I can add the bonus.
Might something be wrong in my source?
I'm using mainline released.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.

×