• 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!
  • 2026 staff recruitment is open! Check it out and consider applying!

C++ Compiling new added code to my source [tfs 0.3.7]

CipsoftStinks

www.relicaria.com
Joined
Oct 1, 2016
Messages
946
Solutions
3
Reaction score
138
Location
Argentina
Hello Otland
I need help with some source editing or change
well i changed dorelocate code into my sources files.(i took the code from othire)

why i did this?. because i want that dorelocate function works as it does in othire
use un-walkable items to make teleport to another player and for if an unwalkable item its in front of an open door and the player its standing in the door frames he'll be pushed(when the door it is closing) above the unwalkable item


i edited some part of the code to avoid compilation errors
some declarations like
reportErrorFunc to errorEx
getErrorDesc to getError
FLAG_IGNORENOTMOVEABLE to FLAG_IGNORENOTMOVABLE
posdata: The code its exactly as the othire one i just made the changed above mentioned

This code :

Code:
int32_t LuaInterface::luaDoRelocate(lua_State* L)
{
    //doRelocate(pos, posTo[, creatures = true[, unmovable = true]])
    //Moves all[ movable] objects from pos to posTo
    //Uses protected methods for optimal speed
    //el de otx por default
    bool unmovable = true, creatures = true;
    int32_t params = lua_gettop(L);
    if (params > 3)
        unmovable = popBoolean(L);

    if (params > 2)
        creatures = popBoolean(L);

    PositionEx toPos;
    popPosition(L, toPos);

    PositionEx fromPos;
    popPosition(L, fromPos);

    Tile* fromTile = g_game.getTile(fromPos);
    if (!fromTile)
    {
        errorEx(getError(LUA_ERROR_TILE_NOT_FOUND));
        lua_pushboolean(L, false);
        return 1;
    }

    Tile* toTile = g_game.getTile(toPos);
    if (!toTile)
    {
        errorEx(getError(LUA_ERROR_TILE_NOT_FOUND));
        lua_pushboolean(L, false);
        return 1;
    }

    if (fromTile == toTile)
    {
        lua_pushboolean(L, false);
        return 1;
    }

    TileItemVector *toItems = toTile->getItemList(),
        *fromItems = fromTile->getItemList();
    if (fromItems && toItems)
    {
        int32_t itemLimit = g_config.getNumber(toTile->hasFlag(TILESTATE_PROTECTIONZONE)
            ? ConfigManager::PROTECTION_TILE_LIMIT : ConfigManager::TILE_LIMIT), count = 0;
        for (ItemVector::iterator it = fromItems->getBeginDownItem(); it != fromItems->getEndDownItem(); )
        {
            if (itemLimit && (int32_t)toItems->size() > itemLimit)
                break;

            const ItemType& iType = Item::items[(*it)->getID()];
            if (!iType.isGroundTile() && !iType.alwaysOnTop && !iType.isMagicField() && (unmovable || iType.movable))
            {
                if (Item* item = (*it))
                {
                    it = fromItems->erase(it);
                    fromItems->removeDownItem();
                    fromTile->updateTileFlags(item, true);

                    g_moveEvents->onItemMove(NULL, item, fromTile, false);
                    g_moveEvents->onRemoveTileItem(fromTile, item);

                    item->setParent(toTile);
                    ++count;

                    toItems->insert(toItems->getBeginDownItem(), item);
                    toItems->addDownItem();
                    toTile->updateTileFlags(item, false);

                    g_moveEvents->onAddTileItem(toTile, item);
                    g_moveEvents->onItemMove(NULL, item, toTile, true);
                }
                else
                    ++it;
            }
            else
                ++it;
        }

        fromTile->updateThingCount(-count);
        toTile->updateThingCount(count);

        fromTile->onUpdateTile();
        toTile->onUpdateTile();
        if (g_config.getBool(ConfigManager::STORE_TRASH)
            && fromTile->hasFlag(TILESTATE_TRASHED))
        {
            g_game.addTrash(toPos);
            toTile->setFlag(TILESTATE_TRASHED);
        }
    }

    if (creatures)
    {
        CreatureVector* creatureVector = fromTile->getCreatures();
        Creature* creature = NULL;
        while (creatureVector && !creatureVector->empty())
        {
            if ((creature = (*creatureVector->begin())))
                g_game.internalMoveCreature(NULL, creature, fromTile, toTile, FLAG_NOLIMIT);
        }
    }

    lua_pushboolean(L, true);
    return 1;
}
Code:
static int32_t luaDoRelocate(lua_State* L);

Was changed to this:
Code:
int LuaInterface::luaDoRelocate(lua_State *L)
{
    //doRelocate(pos, posTo, <optional: default: false> moveUnmoveable, <optional: default: 0> maxAmount)
    /*Moves all objects from pos to posTo (limited by the value of maxAmount - so only the first maxAmount items are
    relocated even if there are too many items at the tile - it is important to prevent lag if there are too many items)
    It also move ALL creatures from pos to posTo (it doesn't matter how many creatures there are in the tile). */
    int32_t parameters = lua_gettop(L);

    int32_t maxAmount = 0;
    bool moveUnmoveable = false;
    if (parameters > 3) {
        maxAmount = popNumber(L);
    }
    if (parameters > 2) {
        moveUnmoveable = popBoolean(L);
    }

    PositionEx toPos;
    popPosition(L, toPos);

    PositionEx fromPos;
    popPosition(L, fromPos);

    Tile* fromTile = g_game.getTile(fromPos.x, fromPos.y, fromPos.z);
    if (!fromTile) {
        errorEx(getError(LUA_ERROR_TILE_NOT_FOUND));
        lua_pushboolean(L, false);
        return 1;
    }

    Tile* toTile = g_game.getTile(toPos.x, toPos.y, toPos.z);
    if (!toTile) {
        std::stringstream ss;
        ss << toPos << " " << getError(LUA_ERROR_TILE_NOT_FOUND);
        errorEx(ss.str().c_str());
        lua_pushboolean(L, false);
        return 1;
    }

    if (fromTile != toTile) {
        int32_t thingCount = fromTile->getThingCount();
        if (maxAmount > 0) {
            thingCount = std::min(thingCount, maxAmount);
        }
        for (int32_t i = thingCount - 1; i >= 0; --i) {
            Thing* thing = fromTile->__getThing(i);
            if (thing) {
                if (Item* item = thing->getItem()) {
                    const ItemType& it = Item::items[item->getID()];
                    if (!it.isGroundTile() && !it.alwaysOnTop && !it.isMagicField()) {
                        uint32_t flags = moveUnmoveable ? FLAG_IGNORENOTMOVABLE : 0;
                        g_game.internalTeleport(item, toPos, flags);
                    }
                }
                else if (Creature* creature = thing->getCreature()) {
                    if (Position::areInRange<1, 1>(fromPos, toPos)) {
                        g_game.internalMoveCreature(creature, fromTile, toTile, FLAG_NOLIMIT);
                    }
                    else {
                        g_game.internalTeleport(creature, toPos);
                    }
                }
            }
        }
        //makes sure that every creature at the tile has been moved even if maxAmount was reached
        if (thingCount > maxAmount) {
            if (CreatureVector* creatures = (fromTile->getCreatures())) {
                for (CreatureVector::iterator cit = creatures->begin(); cit != creatures->end(); ++cit) {
                    if (Position::areInRange<1, 1>(fromPos, toPos)) {
                        g_game.internalMoveCreature(*cit, fromTile, toTile, FLAG_NOLIMIT);
                    }
                    else {
                        g_game.internalTeleport(*cit, toPos);
                    }
                }
            }
        }
    }

    lua_pushboolean(L, true);
    return 1;
}

Code:
static int luaDoRelocate(lua_State* L);

output error list
Code:
1>..\luascript.cpp(4230): warning C4800: 'uint32_t': forcing value to bool 'true' or 'false' (performance warning)
1>..\luascript.cpp(4235): error C2664: 'ReturnValue Game::internalMoveCreature(Creature *,Creature *,Cylinder *,Cylinder *,uint32_t,bool)': cannot convert argument 2 from 'Tile *' to 'Creature *'
1>  ..\luascript.cpp(4235): note: Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
1>..\luascript.cpp(4238): error C2660: 'Game::internalTeleport': function does not take 2 arguments
1>..\luascript.cpp(4248): error C2664: 'ReturnValue Game::internalMoveCreature(Creature *,Creature *,Cylinder *,Cylinder *,uint32_t,bool)': cannot convert argument 2 from 'Tile *' to 'Creature *'
1>  ..\luascript.cpp(4248): note: Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
1>..\luascript.cpp(4251): error C2660: 'Game::internalTeleport': function does not take 2 arguments
1>  monster.cpp
1>..\luascript.cpp(11526): warning C4319: '~': zero extending 'uint32_t' to 'lua_Number' of greater size

ERROR LIST
Code:
Severity    Code    Description    Project    File    Line    Suppression State    Detail Description
Error (active)        no instance of overloaded function "Game::internalMoveCreature" matches the argument list    TFS-SERVER    c:\Users\Cheng Zhi\Desktop\TFS-LAST-7.72\sources-LAST\luascript.cpp    4235                    argument types are: (Creature *, Tile *, Tile *, CylinderFlags_t)
            object type is: Game
Severity    Code    Description    Project    File    Line    Suppression State
Error (active)        too few arguments in function call    TFS-SERVER    c:\Users\Cheng Zhi\Desktop\TFS-LAST-7.72\sources-LAST\luascript.cpp    4238 
Severity    Code    Description    Project    File    Line    Suppression State    Detail Description
Error (active)        no instance of overloaded function "Game::internalMoveCreature" matches the argument list    TFS-SERVER    c:\Users\Cheng Zhi\Desktop\TFS-LAST-7.72\sources-LAST\luascript.cpp    4248                    argument types are: (Creature *, Tile *, Tile *, CylinderFlags_t)
            object type is: Game
Severity    Code    Description    Project    File    Line    Suppression State
Error (active)        too few arguments in function call    TFS-SERVER    c:\Users\Cheng Zhi\Desktop\TFS-LAST-7.72\sources-LAST\luascript.cpp    4251 
Severity    Code    Description    Project    File    Line    Suppression State
Warning    C4800    'uint32_t': forcing value to bool 'true' or 'false' (performance warning)    TFS-SERVER    C:\Users\Cheng Zhi\Desktop\TFS-LAST-7.72\sources-LAST\luascript.cpp    4230
Severity    Code    Description    Project    File    Line    Suppression State
Error    C2664    'ReturnValue Game::internalMoveCreature(Creature *,Creature *,Cylinder *,Cylinder *,uint32_t,bool)': cannot convert argument 2 from 'Tile *' to 'Creature *'    TFS-SERVER    C:\Users\Cheng Zhi\Desktop\TFS-LAST-7.72\sources-LAST\luascript.cpp    4235 
Severity    Code    Description    Project    File    Line    Suppression State
Error    C2660    'Game::internalTeleport': function does not take 2 arguments    TFS-SERVER    C:\Users\Cheng Zhi\Desktop\TFS-LAST-7.72\sources-LAST\luascript.cpp    4238 
Severity    Code    Description    Project    File    Line    Suppression State
Error    C2664    'ReturnValue Game::internalMoveCreature(Creature *,Creature *,Cylinder *,Cylinder *,uint32_t,bool)': cannot convert argument 2 from 'Tile *' to 'Creature *'    TFS-SERVER    C:\Users\Cheng Zhi\Desktop\TFS-LAST-7.72\sources-LAST\luascript.cpp    4248 
Severity    Code    Description    Project    File    Line    Suppression State
Error    C2660    'Game::internalTeleport': function does not take 2 arguments    TFS-SERVER    C:\Users\Cheng Zhi\Desktop\TFS-LAST-7.72\sources-LAST\luascript.cpp    4251 
Severity    Code    Description    Project    File    Line    Suppression State
Warning    C4319    '~': zero extending 'uint32_t' to 'lua_Number' of greater size    TFS-SERVER    C:\Users\Cheng Zhi\Desktop\TFS-LAST-7.72\sources-LAST\luascript.cpp    11526
 
  1. 1>..\luascript.cpp(4230): warning C4800: 'uint32_t': forcing value to bool 'true' or 'false' (performance warning)
This is just a warning, you are converting something uint32_t to bool or something.
I think its the if line "if (thingCount > maxAmount)" one is uint32 other is bool maybe.
Try casting maxAmount to uint32_t
C++:
maxAmount = (uint32_t) popNumber(L);

  1. 1>..\luascript.cpp(4235): error C2664: 'ReturnValue Game::internalMoveCreature(Creature *,Creature *,Cylinder *,Cylinder *,uint32_t,bool)': cannot convert argument 2 from 'Tile *' to 'Creature *'
This error msg is pretty obvious, you are passing a pointer to a Tile and not a Creature (maybe add an if to check what it is but I don't think that should be the way to solve it, if the code is trying to move a tile that means something is wrong)
  1. 1> ..\luascript.cpp(4235): note: Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
idk
  1. 1>..\luascript.cpp(4238): error C2660: 'Game::internalTeleport': function does not take 2 arguments
This is strange, I checked tfs source code and this function has 4 arguments, 2 of them have default values meaning you should be ok only passing the two you passed, maybe check in game.h if that function has default values for the arguments you are not passing.
  1. 1>..\luascript.cpp(4248): error C2664: 'ReturnValue Game::internalMoveCreature(Creature *,Creature *,Cylinder *,Cylinder *,uint32_t,bool)': cannot convert argument 2 from 'Tile *' to 'Creature *'
Same error as before
  1. 1> ..\luascript.cpp(4248): note: Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
Same error as before
  1. 1>..\luascript.cpp(4251): error C2660: 'Game::internalTeleport': function does not take 2 arguments
Same error as before
  1. 1> monster.cpp
  2. 1>..\luascript.cpp(11526): warning C4319: '~': zero extending 'uint32_t' to 'lua_Number' of greater size
What type is lua_Number? maybe a 32bit int and you are trying to pass something greater? possibly
 
Back
Top