• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

Feature Anit-Push Sytem | TFS 0.4

Gomgom

Member
Joined
Oct 1, 2009
Messages
135
Reaction score
18
Location
Egypt
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
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 :D.
 
Last edited:
The installation looks very simple. I will try it, thanks for sharing! :D

Could you configure it so that we can set it by Item IDs as well?
 
Last edited:
do you even know what this is for? as I can see, you didn't try it out, you can't even understand the code, so simply use it if you want, I like the idea so I shared it and I'm sure someone else other than you will like it as well, it already happened imkingran liked the idea and requested something so I don't think you are in no position to say what said, when someone shares something you should say thank you, but apparently, you're incapable of saying "thanks", it doesn't matter whether or not you like it, your opinion doesn't even matter to me, I wouldn't share it if there wasn't a purpose.
 
Back
Top