mirror of
				https://github.com/TES3MP/openmw-tes3mp.git
				synced 2025-11-04 09:56:42 +00:00 
			
		
		
		
	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
```
		
	
			
		
			
				
	
	
		
			190 lines
		
	
	
	
		
			3.9 KiB
		
	
	
	
		
			C++
		
	
	
	
	
	
			
		
		
	
	
			190 lines
		
	
	
	
		
			3.9 KiB
		
	
	
	
		
			C++
		
	
	
	
	
	
//
 | 
						|
// Created by koncord on 07.01.16.
 | 
						|
//
 | 
						|
 | 
						|
#ifndef OPENMW_BASEPLAYER_HPP
 | 
						|
#define OPENMW_BASEPLAYER_HPP
 | 
						|
 | 
						|
#include <components/esm/npcstats.hpp>
 | 
						|
#include <components/esm/loadcell.hpp>
 | 
						|
#include <components/esm/loadnpc.hpp>
 | 
						|
#include <components/esm/creaturestats.hpp>
 | 
						|
#include <components/esm/loadclas.hpp>
 | 
						|
#include <RakNetTypes.h>
 | 
						|
 | 
						|
namespace mwmp
 | 
						|
{
 | 
						|
    class Attack
 | 
						|
    {
 | 
						|
    public:
 | 
						|
        RakNet::RakNetGUID target;
 | 
						|
        RakNet::RakNetGUID attacker;
 | 
						|
        char type; // 0 - melee, 1 - magic, 2 - throwable
 | 
						|
        std::string refid; // id of spell (e.g. "fireball")
 | 
						|
        char success;
 | 
						|
        char block;
 | 
						|
        float damage;
 | 
						|
        char pressed;
 | 
						|
        char knockdown;
 | 
						|
    };
 | 
						|
 | 
						|
    struct Item
 | 
						|
    {
 | 
						|
        std::string refid;
 | 
						|
        int count;
 | 
						|
        int health;
 | 
						|
        inline bool operator==(const Item& rhs)
 | 
						|
        {
 | 
						|
            return refid == rhs.refid && count == rhs.count && health == rhs.health;
 | 
						|
        }
 | 
						|
    };
 | 
						|
 | 
						|
    struct Inventory
 | 
						|
    {
 | 
						|
        std::vector<Item> items;
 | 
						|
        unsigned int count;
 | 
						|
        enum ACTION_TYPE
 | 
						|
        {
 | 
						|
            UPDATE = 0,
 | 
						|
            ADDITEM,
 | 
						|
            REMOVEITEM
 | 
						|
        };
 | 
						|
        int action; //0 - FullUpdate, 1 - AddItem, 2 - RemoveItem
 | 
						|
    };
 | 
						|
 | 
						|
    class BasePlayer
 | 
						|
    {
 | 
						|
    public:
 | 
						|
 | 
						|
        struct CGStage
 | 
						|
        {
 | 
						|
            int current, end;
 | 
						|
        };
 | 
						|
 | 
						|
        struct GUIMessageBox
 | 
						|
        {
 | 
						|
            int id;
 | 
						|
            int type;
 | 
						|
            enum GUI_TYPE
 | 
						|
            {
 | 
						|
                MessageBox = 0,
 | 
						|
                CustomMessageBox,
 | 
						|
                InputDialog,
 | 
						|
                PasswordDialog
 | 
						|
            };
 | 
						|
            std::string label;
 | 
						|
            std::string buttons;
 | 
						|
 | 
						|
            std::string data;
 | 
						|
        };
 | 
						|
 | 
						|
        BasePlayer(RakNet::RakNetGUID guid) : guid(guid)
 | 
						|
        {
 | 
						|
            inventory.action = 0;
 | 
						|
            inventory.count = 0;
 | 
						|
        }
 | 
						|
 | 
						|
        BasePlayer()
 | 
						|
        {
 | 
						|
 | 
						|
        }
 | 
						|
 | 
						|
        virtual ESM::Position *Position()
 | 
						|
        {
 | 
						|
            return &pos;
 | 
						|
        }
 | 
						|
        virtual ESM::NPC *Npc()
 | 
						|
        {
 | 
						|
            return &npc;
 | 
						|
        }
 | 
						|
        virtual ESM::NpcStats *NpcStats()
 | 
						|
        {
 | 
						|
            return &npcStats;
 | 
						|
        }
 | 
						|
        virtual ESM::CreatureStats *CreatureStats()
 | 
						|
        {
 | 
						|
            return &creatureStats;
 | 
						|
        }
 | 
						|
 | 
						|
        virtual unsigned int *MovementFlags()
 | 
						|
        {
 | 
						|
            return &movementFlags;
 | 
						|
        }
 | 
						|
        virtual ESM::Cell *GetCell()
 | 
						|
        {
 | 
						|
            return &cell;
 | 
						|
        }
 | 
						|
 | 
						|
        virtual Item *EquipedItem(int id)
 | 
						|
        {
 | 
						|
            if (id >= 18) return &equipedItems[18];
 | 
						|
            return &equipedItems[id];
 | 
						|
        }
 | 
						|
 | 
						|
        virtual char *MovementAnim()
 | 
						|
        {
 | 
						|
            return &movementAnim;
 | 
						|
        }
 | 
						|
 | 
						|
        virtual char *DrawState()
 | 
						|
        {
 | 
						|
            return &drawState;
 | 
						|
        }
 | 
						|
 | 
						|
        virtual ESM::Position *Dir()
 | 
						|
        {
 | 
						|
            return &dir;
 | 
						|
        }
 | 
						|
 | 
						|
        virtual Attack *GetAttack()
 | 
						|
        {
 | 
						|
            return &attack;
 | 
						|
        }
 | 
						|
 | 
						|
        virtual std::string *BirthSign()
 | 
						|
        {
 | 
						|
            return &birthSign;
 | 
						|
        }
 | 
						|
 | 
						|
        virtual std::string *ChatMessage()
 | 
						|
        {
 | 
						|
            return &chatMessage;
 | 
						|
        }
 | 
						|
 | 
						|
        virtual CGStage *CharGenStage()
 | 
						|
        {
 | 
						|
            return &stage;
 | 
						|
        }
 | 
						|
 | 
						|
        virtual std::string *GetPassw()
 | 
						|
        {
 | 
						|
            return &passw;
 | 
						|
        }
 | 
						|
        RakNet::RakNetGUID guid;
 | 
						|
        GUIMessageBox guiMessageBox;
 | 
						|
        ESM::Class charClass;
 | 
						|
        int month;
 | 
						|
        int day;
 | 
						|
        double hour;
 | 
						|
        Inventory inventory;
 | 
						|
 | 
						|
    protected:
 | 
						|
        ESM::Position pos;
 | 
						|
        ESM::Position dir;
 | 
						|
        ESM::Cell cell;
 | 
						|
        ESM::NPC npc;
 | 
						|
        ESM::NpcStats npcStats;
 | 
						|
        ESM::CreatureStats creatureStats;
 | 
						|
        Item equipedItems[19];
 | 
						|
        unsigned int movementFlags;
 | 
						|
        char movementAnim;
 | 
						|
        char drawState;
 | 
						|
        Attack attack;
 | 
						|
        std::string birthSign;
 | 
						|
        std::string chatMessage;
 | 
						|
        CGStage stage;
 | 
						|
        std::string passw;
 | 
						|
    };
 | 
						|
}
 | 
						|
 | 
						|
#endif //OPENMW_BASEPLAYER_HPP
 |