Implement inventory functions
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 ```pull/112/merge
parent
81dfd21d9a
commit
c27351c19e
@ -0,0 +1,44 @@
|
||||
//
|
||||
// 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);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,22 @@
|
||||
//
|
||||
// Created by koncord on 22.10.16.
|
||||
//
|
||||
|
||||
#ifndef OPENMW_PACKETINVENTORY_HPP
|
||||
#define OPENMW_PACKETINVENTORY_HPP
|
||||
|
||||
#include <components/openmw-mp/Packets/BasePacket.hpp>
|
||||
|
||||
namespace mwmp
|
||||
{
|
||||
class PacketInventory : public BasePacket
|
||||
{
|
||||
public:
|
||||
PacketInventory(RakNet::RakPeerInterface *peer);
|
||||
|
||||
virtual void Packet(RakNet::BitStream *bs, BasePlayer *player, bool send);
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
#endif //OPENMW_PACKETINVENTORY_HPP
|
Loading…
Reference in New Issue