Jump to content

C++ unequip Function


Recommended Posts

  • Premium

Hallo

 

So I Want Some Helps Iam 0 in C++ But i See That This Fuction Work Fine And Compile Good , But It's Don't Work .

    int item_unequip_selected(lua_State* L)
    {
        LPCHARACTER ch = CQuestManager::instance().GetCurrentCharacterPtr();
         
        if (!lua_isnumber(L, 1))
        {
            sys_err("Argument error.");
            lua_pushboolean(L, false);
            return 1;
        }
 
        int bCell = (int)lua_tonumber(L, 1);
        if (bCell < 0 || bCell >= WEAR_MAX_NUM)
        {
            sys_err("Invalid wear position %d. Index out of range(0..%d)", bCell, WEAR_MAX_NUM);
            lua_pushboolean(L, false);
            return 1;
        }
 
         
        LPITEM item = CQuestManager::instance().GetCurrentItem();       //current item in used
        LPITEM equipped = ch->GetWear(bCell);                            //current equipped item on target slot
         
        //check the pointers
        if (!ch || !item) return 0;
 
        //remove the equipped item
        if (equipped->GetVnum() != NULL || item->IsEquipped())
            ch->UnequipItem(equipped);
 
        lua_pushboolean(L, true);
        return 1;
    }
 

quest :

item.unequip(1)

But Didn't Work InGame !

Any Help ?

If you're going to do something, then do it right.

Link to comment
Share on other sites

Test this:

int item_unequip_selected(lua_State* L)
	{
		LPCHARACTER ch = CQuestManager::instance().GetCurrentCharacterPtr();

		if (!lua_isnumber(L, 1))
		{
			sys_err("Argument error.");
			lua_pushboolean(L, false);
			return 1;
		}

		BYTE bCell = lua_tonumber(L, 1); //bcell == BYTE, iCell == INT, dCell == DWORD ....
		if (bCell < 0 || bCell >= WEAR_MAX_NUM)
		{
			sys_err("Invalid wear position %d. Index out of range(0..%d)", bCell, WEAR_MAX_NUM);
			lua_pushboolean(L, false);
			return 1;
		}


		LPITEM item = CQuestManager::instance().GetCurrentItem();       //current item in used
		LPITEM equipped = ch->GetWear(bCell);                            //current equipped item on target slot

		//check the pointers
		if (!ch || !item) 
		{
			sys_err("No Item or Character Visible.");
			lua_pushboolean(L,false);
			return 1; 
		}

		//remove the equipped item
		if (equipped->GetVnum() != NULL || item->IsEquipped())
		{
			sys_log(0, "item_unequip_selected Player: %s Vnum: %d Cell: %d ::: TRUE ",ch->GetName(), item->GetVnum(), bCell);
			ch->UnequipItem(equipped);
			lua_pushboolean(L, true);
			return 1;
		}
		else 
		{
			sys_log(0, "item_unequip_selected Player: %s Vnum: %d Cell: %d ::: False ",ch->GetName(), item->GetVnum(), bCell);
			lua_pushboolean(L, false);
			return 1;
		}
	}
Link to comment
Share on other sites

  • Premium

 

Test this:

int item_unequip_selected(lua_State* L)
	{
		LPCHARACTER ch = CQuestManager::instance().GetCurrentCharacterPtr();

		if (!lua_isnumber(L, 1))
		{
			sys_err("Argument error.");
			lua_pushboolean(L, false);
			return 1;
		}

		BYTE bCell = lua_tonumber(L, 1); //bcell == BYTE, iCell == INT, dCell == DWORD ....
		if (bCell < 0 || bCell >= WEAR_MAX_NUM)
		{
			sys_err("Invalid wear position %d. Index out of range(0..%d)", bCell, WEAR_MAX_NUM);
			lua_pushboolean(L, false);
			return 1;
		}


		LPITEM item = CQuestManager::instance().GetCurrentItem();       //current item in used
		LPITEM equipped = ch->GetWear(bCell);                            //current equipped item on target slot

		//check the pointers
		if (!ch || !item) 
		{
			sys_err("No Item or Character Visible.");
			lua_pushboolean(L,false);
			return 1; 
		}

		//remove the equipped item
		if (equipped->GetVnum() != NULL || item->IsEquipped())
		{
			sys_log(0, "item_unequip_selected Player: %s Vnum: %d Cell: %d ::: TRUE ",ch->GetName(), item->GetVnum(), bCell);
			ch->UnequipItem(equipped);
			lua_pushboolean(L, true);
			return 1;
		}
		else 
		{
			sys_log(0, "item_unequip_selected Player: %s Vnum: %d Cell: %d ::: False ",ch->GetName(), item->GetVnum(), bCell);
			lua_pushboolean(L, false);
			return 1;
		}
	}

 

 

Vnxwyjl.png

 

quest :

quest test begin
    state start begin
        when login or enter or levelup or kill begin
            item.unequip(2) // armor slot
        end
    end
end
Edited by Metin2 Dev
Core X - External 2 Internal

If you're going to do something, then do it right.

Link to comment
Share on other sites

  • 3 years later...
int item_unequip_selected(lua_State* L)
	{
		LPCHARACTER ch = CQuestManager::instance().GetCurrentCharacterPtr();

		if (!lua_isnumber(L, 1))
		{
			sys_err("Argument error.");
			lua_pushboolean(L, false);
			return 1;
		}

		BYTE bCell = lua_tonumber(L, 1); //bcell == BYTE, iCell == INT, dCell == DWORD ....
		if (bCell < 0 || bCell >= WEAR_MAX_NUM)
		{
			sys_err("Invalid wear position %d. Index out of range(0..%d)", bCell, WEAR_MAX_NUM);
			lua_pushboolean(L, false);
			return 1;
		}


		//LPITEM item = CQuestManager::instance().GetCurrentItem();       //current item in used
		LPITEM equipped = ch->GetWear(bCell);                            //current equipped item on target slot

		//check the pointers
		if (!ch || !equipped)//!item) 
		{
			sys_err("No Item or Character Visible.");
			lua_pushboolean(L,false);
			return 1; 
		}

		//remove the equipped item
		if (equipped->IsEquipped())
		{
			sys_log(0, "item_unequip_selected Player: %s Vnum: %d Cell: %d ::: TRUE ",ch->GetName(), item->GetVnum(), bCell);
			ch->UnequipItem(equipped);
			lua_pushboolean(L, true);
			return 1;
		}
		else 
		{
			sys_log(0, "item_unequip_selected Player: %s Vnum: %d Cell: %d ::: False ",ch->GetName(), item->GetVnum(), bCell);
			lua_pushboolean(L, false);
			return 1;
		}
	}

try this

  • Love 1
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.