Example #1
0
void cPlayer::TossItem(
    bool a_bDraggingItem,
    char a_Amount /* = 1 */,
    short a_CreateType /* = 0 */,
    short a_CreateHealth /* = 0 */
)
{
    cItems Drops;
    if (a_CreateType != 0)
    {
        // Just create item without touching the inventory (used in creative mode)
        Drops.push_back(cItem(a_CreateType, a_Amount, a_CreateHealth));
    }
    else
    {
        // Drop an item from the inventory:
        if (a_bDraggingItem)
        {
            cItem & Item = GetDraggingItem();
            if (!Item.IsEmpty())
            {
                char OriginalItemAmount = Item.m_ItemCount;
                Item.m_ItemCount = std::min(OriginalItemAmount, a_Amount);
                Drops.push_back(Item);
                if (OriginalItemAmount > a_Amount)
                {
                    Item.m_ItemCount = OriginalItemAmount - (char)a_Amount;
                }
                else
                {
                    Item.Empty();
                }
            }
        }
        else
        {
            // Else drop equipped item
            cItem DroppedItem(GetInventory().GetEquippedItem());
            if (!DroppedItem.IsEmpty())
            {
                if (GetInventory().RemoveOneEquippedItem())
                {
                    DroppedItem.m_ItemCount = 1; // RemoveItem decreases the count, so set it to 1 again
                    Drops.push_back(DroppedItem);
                }
            }
        }
    }
    double vX = 0, vY = 0, vZ = 0;
    EulerToVector(-GetRotation(), GetPitch(), vZ, vX, vY);
    vY = -vY * 2 + 1.f;
    m_World->SpawnItemPickups(Drops, GetPosX(), GetPosY() + 1.6f, GetPosZ(), vX * 3, vY * 3, vZ * 3, true); // 'true' because created by player
}
Example #2
0
void cPlayer::TossHeldItem(char a_Amount)
{
	cItems Drops;
	cItem & Item = GetDraggingItem();
	if (!Item.IsEmpty())
	{
		char OriginalItemAmount = Item.m_ItemCount;
		Item.m_ItemCount = std::min(OriginalItemAmount, a_Amount);
		Drops.push_back(Item);

		if (OriginalItemAmount > a_Amount)
		{
			Item.m_ItemCount = OriginalItemAmount - a_Amount;
		}
		else
		{
			Item.Empty();
		}
	}

	TossItems(Drops);
}
Example #3
0
void cPlayer::TossHeldItem(char a_Amount)
{
	cItems Drops;
	cItem & Item = GetDraggingItem();
	if (!Item.IsEmpty())
	{
		char OriginalItemAmount = Item.m_ItemCount;
		Item.m_ItemCount = std::min(OriginalItemAmount, a_Amount);
		Drops.push_back(Item);
		if (OriginalItemAmount > a_Amount)
		{
			Item.m_ItemCount = OriginalItemAmount - a_Amount;
		}
		else
		{
			Item.Empty();
		}
	}

	double vX = 0, vY = 0, vZ = 0;
	EulerToVector(-GetYaw(), GetPitch(), vZ, vX, vY);
	vY = -vY * 2 + 1.f;
	m_World->SpawnItemPickups(Drops, GetPosX(), GetEyeHeight(), GetPosZ(), vX * 3, vY * 3, vZ * 3, true); // 'true' because created by player
}