mirror of
https://github.com/TES3MP/openmw-tes3mp.git
synced 2025-01-16 11:49:56 +00:00
c27351c19e
AddItem, RemoveItem, GetItemName, GetItemCount, GetItemHealth, GetInventorySize SendInventory Example: ```lua tes3mp.AddItem(pid, "glass dagger", 1, 50) tes3mp.AddItem(pid, "glass dagger", 1, -1) tes3mp.SendInventory(pid) tes3mp.RemoveItem(pid, "glass dagger", 1) tes3mp.SendInventory(pid) local invSize = tes3mp.GetInventorySize(pid) - 1 for i = 0, invSize do print(("%s %d %d"):format(tes3mp.GetItemName(pid, i), tes3mp.GetItemCount(pid, i), tes3mp.GetItemHealth(pid, i))) end ```
44 lines
1.1 KiB
C++
44 lines
1.1 KiB
C++
//
|
|
// Created by koncord on 22.10.16.
|
|
//
|
|
|
|
#include <components/openmw-mp/NetworkMessages.hpp>
|
|
#include "PacketInventory.hpp"
|
|
|
|
using namespace std;
|
|
using namespace mwmp;
|
|
|
|
PacketInventory::PacketInventory(RakNet::RakPeerInterface *peer) : BasePacket(peer)
|
|
{
|
|
packetID = ID_GAME_INVENTORY;
|
|
}
|
|
|
|
void PacketInventory::Packet(RakNet::BitStream *bs, BasePlayer *player, bool send)
|
|
{
|
|
BasePacket::Packet(bs, player, send);
|
|
|
|
RW(player->inventory.action, send);
|
|
if (!send)
|
|
player->inventory.items.clear();
|
|
else
|
|
player->inventory.count = (unsigned int) (player->inventory.items.size());
|
|
RW(player->inventory.count, send);
|
|
for (int i = 0; i < player->inventory.count; i++)
|
|
{
|
|
Item item;
|
|
if (send)
|
|
{
|
|
item = player->inventory.items[i];
|
|
RW(item.refid, send);
|
|
RW(item.count, send);
|
|
RW(item.health, send);
|
|
}
|
|
else
|
|
{
|
|
RW(item.refid, send);
|
|
RW(item.count, send);
|
|
RW(item.health, send);
|
|
player->inventory.items.push_back(item);
|
|
}
|
|
}
|
|
}
|