本文整理汇总了C++中PlayerSAO::getMeta方法的典型用法代码示例。如果您正苦于以下问题:C++ PlayerSAO::getMeta方法的具体用法?C++ PlayerSAO::getMeta怎么用?C++ PlayerSAO::getMeta使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PlayerSAO
的用法示例。
在下文中一共展示了PlayerSAO::getMeta方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: l_get_meta
// get_meta(self, attribute)
int ObjectRef::l_get_meta(lua_State *L)
{
ObjectRef *ref = checkobject(L, 1);
PlayerSAO *co = getplayersao(ref);
if (co == NULL)
return 0;
PlayerMetaRef::create(L, &co->getMeta());
return 1;
}
示例2: l_set_attribute
// set_attribute(self, attribute, value)
int ObjectRef::l_set_attribute(lua_State *L)
{
log_deprecated(L,
"Deprecated call to set_attribute, use MetaDataRef methods instead.");
ObjectRef *ref = checkobject(L, 1);
PlayerSAO* co = getplayersao(ref);
if (co == NULL)
return 0;
std::string attr = luaL_checkstring(L, 2);
if (lua_isnil(L, 3)) {
co->getMeta().removeString(attr);
} else {
std::string value = luaL_checkstring(L, 3);
co->getMeta().setString(attr, value);
}
return 1;
}
示例3: l_get_attribute
// get_attribute(self, attribute)
int ObjectRef::l_get_attribute(lua_State *L)
{
log_deprecated(L,
"Deprecated call to get_attribute, use MetaDataRef methods instead.");
ObjectRef *ref = checkobject(L, 1);
PlayerSAO* co = getplayersao(ref);
if (co == NULL)
return 0;
std::string attr = luaL_checkstring(L, 2);
std::string value;
if (co->getMeta().getStringToRef(attr, value)) {
lua_pushstring(L, value.c_str());
return 1;
}
return 0;
}
示例4: savePlayer
void PlayerDatabasePostgreSQL::savePlayer(RemotePlayer *player)
{
PlayerSAO* sao = player->getPlayerSAO();
if (!sao)
return;
verifyDatabase();
v3f pos = sao->getBasePosition();
std::string pitch = ftos(sao->getPitch());
std::string yaw = ftos(sao->getYaw());
std::string posx = ftos(pos.X);
std::string posy = ftos(pos.Y);
std::string posz = ftos(pos.Z);
std::string hp = itos(sao->getHP());
std::string breath = itos(sao->getBreath());
const char *values[] = {
player->getName(),
pitch.c_str(),
yaw.c_str(),
posx.c_str(), posy.c_str(), posz.c_str(),
hp.c_str(),
breath.c_str()
};
const char* rmvalues[] = { player->getName() };
beginSave();
if (getPGVersion() < 90500) {
if (!playerDataExists(player->getName()))
execPrepared("create_player", 8, values, true, false);
else
execPrepared("update_player", 8, values, true, false);
}
else
execPrepared("save_player", 8, values, true, false);
// Write player inventories
execPrepared("remove_player_inventories", 1, rmvalues);
execPrepared("remove_player_inventory_items", 1, rmvalues);
std::vector<const InventoryList*> inventory_lists = sao->getInventory()->getLists();
for (u16 i = 0; i < inventory_lists.size(); i++) {
const InventoryList* list = inventory_lists[i];
const std::string &name = list->getName();
std::string width = itos(list->getWidth()),
inv_id = itos(i), lsize = itos(list->getSize());
const char* inv_values[] = {
player->getName(),
inv_id.c_str(),
width.c_str(),
name.c_str(),
lsize.c_str()
};
execPrepared("add_player_inventory", 5, inv_values);
for (u32 j = 0; j < list->getSize(); j++) {
std::ostringstream os;
list->getItem(j).serialize(os);
std::string itemStr = os.str(), slotId = itos(j);
const char* invitem_values[] = {
player->getName(),
inv_id.c_str(),
slotId.c_str(),
itemStr.c_str()
};
execPrepared("add_player_inventory_item", 4, invitem_values);
}
}
execPrepared("remove_player_metadata", 1, rmvalues);
const StringMap &attrs = sao->getMeta().getStrings();
for (const auto &attr : attrs) {
const char *meta_values[] = {
player->getName(),
attr.first.c_str(),
attr.second.c_str()
};
execPrepared("save_player_metadata", 3, meta_values);
}
sao->getMeta().setModified(false);
endSave();
}