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

open Unequipe item automtically with time is 0

Question

Hello I would like to make sure that this item automatically unequips when the time reaches 0.

i have try this code in char_item.cpp but not succes

	case ITEM_RING:
            {    
                LPITEM item;
                const time_t current = get_global_time();
                
                if (item->IsEquipped())
                {
                    if (item->GetSocket(0) < current)
                    {
                        UnequipItem(item);
                    }
                }
                
                if (!item->IsEquipped())
                    EquipItem(item);
                else
                    UnequipItem(item);        
            }
            break;
	

help me please

Share this post


Link to post
Share on other sites

21 answers to this question

Recommended Posts

  • 0

i use this fonction in item.cpp now

	EVENTFUNC(real_time_expire_event)
{
    const item_vid_event_info* info = reinterpret_cast<const item_vid_event_info*>(event->info);
    
    //LPCHARACTER pOwner = GetOwner();
    //m_pOwner = ch;
    
    int Cell;
    
    if (NULL == info)
        return 0;
	    const LPITEM item = ITEM_MANAGER::instance().FindByVID( info->item_vid );
	    if (NULL == item)
        return 0;
	    const time_t current = get_global_time();
    
    if (current > item->GetSocket(0))
    {
        switch (item->GetVnum())
        {
            if(item->IsNewMountItem())
            {
                if (item->GetSocket(2) != 0)
                    item->ClearMountAttributeAndAffect();
            }
            break;
        }
	        if (item->GetType() == ITEM_RING)
        {
            item->Unequip();
        }
        else if (item->GetType() != ITEM_RING)
        {
            ITEM_MANAGER::instance().RemoveItem(item, "REAL_TIME_EXPIRE");
        }
        
        return 0;
    }
	    return PASSES_PER_SEC(1);
}
	

item has desequipe but is invisible in inventory, I am forced to reboot the server to make it appear

Share this post


Link to post
Share on other sites
  • 0

i have try this fonction in item_manageur,

	bool ITEM_MANAGER::AddItem(LPITEM item)
{
    LPCHARACTER owner = funcFindOwnership.owner;
    int pos;
	    if (item->GetWindow() == EQUIPMENT)
    {
        item->RemoveFromCharacter();
        item->AddToCharacter(owner, TItemPos(INVENTORY, pos));
    }
	    return true;
}
	

but game.core  with this error :

	#0  CItem::AddToCharacter (this=0x2c4bd000, ch=0x2c4bd000, Cell={window_type = 1 '\001', cell = 0}) at item.h:47
47                      const char *    GetName()               { return m_pProto ? m_pProto->szLocaleName : NULL; }
[New LWP 100580]
(gdb) bt full
#0  CItem::AddToCharacter (this=0x2940d090, ch=0x28d62198, Cell={window_type = 0 '\0', cell = 0}) at item.h:47
        pos = 35803
        window_type = 0 '\0'
        __FUNCTION__ = "AddToCharacter"
#1  0x28c5dbe6 in basename_r () from /usr/lib32/libc.so.7
No symbol table info available.
#2  0x083a9d3e in CSemaphore::Wait ()
No symbol table info available.
#3  0x083a8fad in CAsyncSQL::ChildLoop ()
No symbol table info available.
#4  0x083a980e in AsyncSQLThread ()
No symbol table info available.
#5  0x287abbbc in pthread_condattr_init () from /usr/lib32/libthr.so.3
No symbol table info available.
#6  0x00000000 in ?? ()

Share this post


Link to post
Share on other sites
  • 0

So if you have an equipped item that has a time limit, do you want that item to automatically unequip when time reaches 0?

Share this post


Link to post
Share on other sites
  • 0
// item.cpp
// void CItem::StartUniqueExpireEvent()
// Under
bool CItem::IsItemUsedTime()
{
	return m_pkRealTimeExpireEvent != nullptr;
}

// item.h
// void StartRealTimeExpireEvent(); 
// Under
	bool IsItemUsedTime();

 

	case ITEM_RING:
	{
		if (item->IsItemUsedTime() and item->IsEquipped())
		{
			UnequipItem(item);
		}
	}
	break;

Not tested

Share this post


Link to post
Share on other sites
  • 0
1 oră în urmă, Tallywa a spus:

!now i cant equip because i unequip automatic

Is not that normal?
When an item with type  ITEM_RING reaches 0, it automatically unequip.

 

If you want a good answer, ask a good question.

Share this post


Link to post
Share on other sites
  • 0

is normal but wuth type item ring reaches time 7 day is not normal automatically unequip

my code in char_item

	case ITEM_RING:
            if (!item->IsEquipped())
            {
                EquipItem(item);
            }
            if (item->IsItemUsedTime() and item->IsEquipped())
            {
                UnequipItem(item);
            }
            break;

 

my code in item.cpp

	bool CItem::IsItemUsedTime()
{
    return m_pkRealTimeExpireEvent != NULL;
}

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.

×