reworked the script for my needs may be useful to someone test on 0.3.4 tfs
(only useHouseDataStorage = "no" / false ;work only save house to MySQL )
luascript.h:
luascript.cpp:
iomapserialize.cpp:
iomapserialize.h :
example use: (in talkaction)
//command can be used for example if a player arrange the items in the house, and if the crash is what you saved.
(only useHouseDataStorage = "no" / false ;work only save house to MySQL )
luascript.h:
Code:
static int32_t luaDoSaveHouse(lua_State* L);
luascript.cpp:
Code:
//doSaveHouse({list})
lua_register(m_luaState, "doSaveHouse", LuaScriptInterface::luaDoSaveHouse);
Code:
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:
Code:
[B]UNDER:
bool IOMapSerialize::saveHouse(Database* db, House* house)[/B]
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 :
Code:
[B]UNDER:
bool saveMapRelational(Map* map);[/B]
bool saveHouseRelational(Database* db, House* house, uint32_t& tileId);
example use: (in talkaction)
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
//command can be used for example if a player arrange the items in the house, and if the crash is what you saved.
Last edited: