Jump to content
  • 0

C++ unequip Function


MrLibya

Question

  • VIP

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

5 answers to this question

Recommended Posts

  • 0

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
  • 0
  • VIP

 

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

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

Link to comment
  • 0
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

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


×
×
  • 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.