douglasscherner
Member
- Joined
- Aug 15, 2014
- Messages
- 143
- Reaction score
- 24
Hello everyone, I've been trying to fix this function for a while, but I'm still not good enough to create it.
I need your help.
Sometimes my server crashes and generates rollback in the houses which is very bad.
I need you to help me adapt the function that saves the houses separately so I will use the onmoveitem function to save houses and the character instantly.
This function is very useful but it only catches on tfs 0.4 and I use 1.3.
luascript.h:
luascript.cpp:
iomapserialize.cpp:
iomapserialize.h :
example use: (in talkaction)
Can anyone help me modify to tfs 1.3?
I need your help.
Sometimes my server crashes and generates rollback in the houses which is very bad.
I need you to help me adapt the function that saves the houses separately so I will use the onmoveitem function to save houses and the character instantly.
This function is very useful but it only catches on tfs 0.4 and I use 1.3.
luascript.h:
Lua:
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)
Code:
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
Can anyone help me modify to tfs 1.3?