From dffd3bfa7d525b31736a71d9fdb5acb092b072db Mon Sep 17 00:00:00 2001 From: Koncord Date: Wed, 18 Oct 2017 22:31:44 +0800 Subject: [PATCH] [Server] Add customData to Player example: counter = 0 Event.register(Events.ON_PLAYER_CONNECT, function(player) player.customData.counter = counter counter = counter + 1 return true end) CommandController.registerCommand("test", function(player, args) player:message(player.customData.counter, false) return true end, "") --- apps/openmw-mp/Player.cpp | 10 ++++++---- apps/openmw-mp/Player.hpp | 1 + 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/apps/openmw-mp/Player.cpp b/apps/openmw-mp/Player.cpp index ac422f0a7..b24ee43c3 100644 --- a/apps/openmw-mp/Player.cpp +++ b/apps/openmw-mp/Player.cpp @@ -79,7 +79,8 @@ void Player::Init(LuaState &lua) "getCellState", &Player::getCellState, "cellStateSize", &Player::cellStateSize, "addCellExplored", &Player::addCellExplored, - "setAuthority", &Player::setAuthority + "setAuthority", &Player::setAuthority, + "customData", &Player::customData ); } @@ -98,6 +99,7 @@ Player::Player(RakNet::RakNetGUID guid) : BasePlayer(guid), NetActor(), changedM npcStats.blank(); creatureStats.blank(); charClass.blank(); + customData = mwmp::Networking::get().getState().getState()->create_table(); } Player::~Player() @@ -250,9 +252,9 @@ void Player::forEachLoaded(std::function func) { std::list plList; - for (auto cell : cells) + for (auto &&cell : cells) { - for (auto pl : *cell) + for (auto &&pl : *cell) { if (pl != nullptr && !pl->npc.mName.empty()) plList.push_back(pl); @@ -262,7 +264,7 @@ void Player::forEachLoaded(std::function func) plList.sort(); plList.unique(); - for (auto pl : plList) + for (auto &&pl : plList) { if (pl == this) continue; func(this, pl); diff --git a/apps/openmw-mp/Player.hpp b/apps/openmw-mp/Player.hpp index ceb064567..6c4c04048 100644 --- a/apps/openmw-mp/Player.hpp +++ b/apps/openmw-mp/Player.hpp @@ -189,6 +189,7 @@ private: Factions factions; Quests quests; Spells spells; + sol::table customData; }; #endif //OPENMW_PLAYER_HPP