[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, "")
new-script-api
Koncord 7 years ago
parent 7a0b45d456
commit dffd3bfa7d

@ -79,7 +79,8 @@ void Player::Init(LuaState &lua)
"getCellState", &Player::getCellState, "getCellState", &Player::getCellState,
"cellStateSize", &Player::cellStateSize, "cellStateSize", &Player::cellStateSize,
"addCellExplored", &Player::addCellExplored, "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(); npcStats.blank();
creatureStats.blank(); creatureStats.blank();
charClass.blank(); charClass.blank();
customData = mwmp::Networking::get().getState().getState()->create_table();
} }
Player::~Player() Player::~Player()
@ -250,9 +252,9 @@ void Player::forEachLoaded(std::function<void(Player *pl, Player *other)> func)
{ {
std::list <Player*> plList; std::list <Player*> plList;
for (auto cell : cells) for (auto &&cell : cells)
{ {
for (auto pl : *cell) for (auto &&pl : *cell)
{ {
if (pl != nullptr && !pl->npc.mName.empty()) if (pl != nullptr && !pl->npc.mName.empty())
plList.push_back(pl); plList.push_back(pl);
@ -262,7 +264,7 @@ void Player::forEachLoaded(std::function<void(Player *pl, Player *other)> func)
plList.sort(); plList.sort();
plList.unique(); plList.unique();
for (auto pl : plList) for (auto &&pl : plList)
{ {
if (pl == this) continue; if (pl == this) continue;
func(this, pl); func(this, pl);

@ -189,6 +189,7 @@ private:
Factions factions; Factions factions;
Quests quests; Quests quests;
Spells spells; Spells spells;
sol::table customData;
}; };
#endif //OPENMW_PLAYER_HPP #endif //OPENMW_PLAYER_HPP

Loading…
Cancel
Save