Ir para conteúdo

[Função Lua] Dosavehouse(Houseid)


Posts Recomendados

arhPioO.png

Nome: Dosavehouse(Houseid)
Versão: 1.0
Código: Powers
Forum Origem: OTLand.net
Versão: Testado no TFS 0.3.4 e já Implementado no TFS 0.4.
Descrição: O comando pode ser usado, por exemplo, se um jogador organizar os itens na casa, e se o server crecha é o que você salvou.


Bom vamos ao tutorial:

Apenas useHouseDataStorage = "no" / Falso

Funciona apenas em servidor MySQL.

luascript.h:
static int32_t luaDoSaveHouse(lua_State* L);
luascript.cpp:
//doSaveHouse({list})
lua_register(m_luaState, "doSaveHouse", LuaScriptInterface::luaDoSaveHouse);
int32_t LuaScriptInterface::luaDoSaveHouse(lua_State* L)
{
//doSaveHouse(houseID)

if(g_config.getBool(ConfigManager::HOUSE_STORAGE))
{
std::stringstream s;
s << "config: useHouseDataStorage must be = no/false";
reportErrorFunc(s.str());
lua_pushboolean(L, false);
}

House* house = Houses::getInstance().getHouse(popNumber(L));
if(!house)
{
reportErrorFunc(getErrorDesc(LUA_ERROR_HOUSE_NOT_FOUND));
lua_pushboolean(L, false);
return 1;
}

Database* db = Database::getInstance();
DBTransaction trans(db);

if(!trans.begin())
{
lua_pushboolean(L, false);
return 1;
}

if(!IOMapSerialize::getInstance()->saveHouse(db, house))
{
std::stringstream s;
s << "Unable to save house information, ID: " << house->getHouseId();
reportErrorFunc(s.str());
}

if(!IOMapSerialize::getInstance()->saveHouseItems(db, house))
{
std::stringstream s;
s << "Unable to save house items, ID: " << house->getHouseId();
reportErrorFunc(s.str());
}

lua_pushboolean(L, trans.commit());
return 1;
}
iomapserialize.cpp:
Substitua de:
bool IOMapSerialize::saveHouse(Database* db, House* house)
Por:
bool IOMapSerialize::saveHouseItems(Database* db, House* house)
{
if(g_config.getBool(ConfigManager::HOUSE_STORAGE))
return false;

DBTransaction trans(db);
if(!trans.begin())
return false;

DBQuery query;
query << "DELETE FROM `tile_items` WHERE `tile_id` IN (SELECT `id` FROM `tiles` WHERE `house_id` = "
<< house->getHouseId() << " AND `world_id` = " << g_config.getNumber(ConfigManager::WORLD_ID)
<< ") AND `world_id` = " << g_config.getNumber(ConfigManager::WORLD_ID);
if(!db->executeQuery(query.str()))
return false;

query.str("");
query << "DELETE FROM `tiles` WHERE `house_id` = " << house->getHouseId()
<< " AND `world_id` = " << g_config.getNumber(ConfigManager::WORLD_ID);
if(!db->executeQuery(query.str()))
return false;

query.str("");
query << "SELECT `id` FROM `tiles` WHERE `world_id` = " << g_config.getNumber(ConfigManager::WORLD_ID) << " ORDER BY `id` DESC LIMIT 1;";

DBResult* result;
if(!(result = db->storeQuery(query.str())))
uint32_t tileId = 0;

uint32_t tileId = result->getDataInt("id")+1;
result->free();

return saveHouseRelational(db, house, tileId);
}



bool IOMapSerialize::saveHouseRelational(Database* db, House* house, uint32_t& tileId)
{
for(HouseTileList::iterator tit = house->getHouseTileBegin(); tit != house->getHouseTileEnd(); ++tit)
saveItems(db, tileId, house->getHouseId(), (*tit));

return true;
}
iomapserialize.h :
Abaixo de:
bool saveMapRelational(Map* map);
Adicione:
bool saveHouseRelational(Database* db, House* house, uint32_t& tileId);
Exemplo de uso: (Em talkaction)

Código Lua:
function onSay(cid, words, param, channel)


if exhaustion.check(cid, 25958) then
doPlayerSendCancel(cid, 'You are Exhausted (save house)')
return true
end


local playerHouseId = getHouseByPlayerGUID(getPlayerGUID(cid))

if playerHouseId ~= nil then

if doSaveHouse(playerHouseId) then
doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, 'House '.. getHouseName(playerHouseId) ..' saved succesfull!')
exhaustion.set(cid, 25958, 300)
else
doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_RED, 'House '.. getHouseName(playerHouseId) ..' saved failed!')
end

else
doPlayerSendCancel(cid, 'You do not rent any flat.')

end


return true
end
Editado por MatheusEnjoy
Link para o comentário
Compartilhar em outros sites

  • 1 month later...
×
×
  • Criar Novo...