Here is a simple Anti-Push System, it was tested on 0.4 and worked properly.
with this code items [all items, certain items or only stackable items it's all configurable in config.lua, "antiThrowCertainItems" must be disabled so "antiThrowStackables" can work] can't be dropped nor thrown at others [including npcs, monsters and players, you can also make it only work for players by enabling "antiThrowAtPlayers"], works out of protection zone.
Let's star with config.lua, paste this anywhere
in game.cpp, replace
with
in configmanager.cpp, after
paste
and after
paste
in configmanager.h, after
paste
and after
paste
We are done .
with this code items [all items, certain items or only stackable items it's all configurable in config.lua, "antiThrowCertainItems" must be disabled so "antiThrowStackables" can work] can't be dropped nor thrown at others [including npcs, monsters and players, you can also make it only work for players by enabling "antiThrowAtPlayers"], works out of protection zone.
Let's star with config.lua, paste this anywhere
Code:
antiDropItems = true
antiThrowAtPlayers = true -- items can't be thrown at players only, disabling this will make items allowed to be thrown at all creatures
antiThrowCertainItems = false
antiThrowItemIds = "2152, 2148"
antiThrowStackables = true -- stackables only are blocked [works if "antiThrowCertainItems" is disabled]
in game.cpp, replace
Code:
if(!canThrowObjectTo(mapFromPos, mapToPos) && !player->hasCustomFlag(PlayerCustomFlag_CanThrowAnywhere))
{
player->sendCancelMessage(RET_CANNOTTHROW);
return false;
}
with
Code:
bool checkCertain = false;
int32_t throwCertain = g_config.getBool(ConfigManager::ANTI_THROW_CERTAIN_ITEMS);
if(throwCertain){
std::string throwIds = g_config.getString(ConfigManager::ANTI_THROW_ITEM_IDS);
if(throwIds.size())
{
IntegerVec tmpVec = vectorAtoi(explodeString(throwIds, ","));
if(tmpVec[0] != 0)
{
for(IntegerVec::iterator it = tmpVec.begin(); it != tmpVec.end(); ++it)
{
if(item->getID() == uint32_t(*it))
checkCertain = true;
}
}
}
}
Tile* toTile = map->getTile(toPos);
int32_t canThrowAnywhere = player->hasCustomFlag(PlayerCustomFlag_CanThrowAnywhere);
if((!canThrowObjectTo(mapFromPos, mapToPos) && !canThrowAnywhere) || (g_config.getBool(ConfigManager::ANTI_DROP_ITEMS) && !canThrowAnywhere &&
toTile && toTile->getCreatureCount() && (!g_config.getBool(ConfigManager::ANTI_THROW_AT_PLAYERS) || toTile->getTopCreature()->getPlayer()) &&
!toTile->getTile()->hasFlag(TILESTATE_PROTECTIONZONE) && (checkCertain || (!throwCertain && (!g_config.getBool(ConfigManager::ANTI_THROW_STACKABLES) || item->isStackable())))))
{
player->sendCancelMessage(RET_CANNOTTHROW);
return false;
}
in configmanager.cpp, after
Code:
m_confBool[CHECK_CORPSE_OWNER] = getGlobalBool("checkCorpseOwner", true);
paste
Code:
m_confBool[ANTI_DROP_ITEMS] = getGlobalBool("antiDropItems", false);
m_confBool[ANTI_THROW_AT_PLAYERS] = getGlobalBool("antiThrowAtPlayers", false);
m_confBool[ANTI_THROW_CERTAIN_ITEMS] = getGlobalBool("antiThrowCertainItems", false);
m_confBool[ANTI_THROW_STACKABLES] = getGlobalBool("antiThrowStackables", false);
and after
Code:
m_confString[MAP_AUTHOR] = getGlobalString("mapAuthor", "Unknown");
paste
Code:
m_confString[ANTI_THROW_ITEM_IDS] = getGlobalString("antiThrowItemIds", "");
in configmanager.h, after
Code:
CHECK_CORPSE_OWNER,
paste
Code:
ANTI_DROP_ITEMS,
ANTI_THROW_AT_PLAYERS,
ANTI_THROW_CERTAIN_ITEMS,
ANTI_THROW_STACKABLES,
and after
Code:
MAP_AUTHOR,
paste
Code:
ANTI_THROW_ITEM_IDS,
We are done .
Last edited: