C++ gold limit

Lurk

Member
Joined
Dec 4, 2017
Messages
150
Best answers
0
Reaction score
18
Location
Brazil
I'm using TFS 0.4 rev 3777 and I'm trying to change the gold limit from init32_t to int64_t, I've been messing with some of my source files and i've already changed the Worth and moneyCount to int64_t and everything was fine when compiling but the gold limit was still in int32... Then I changed on luascript.cpp

from
int32_t LuaInterface::luaDoPlayerAddMoney(lua_State* L)
to
int64_t LuaInterface::luaDoPlayerAddMoney(lua_State* L)
I've changed removeMoney and transferMoney as well in the same way, and then on luascript.h I've changed

from
static int32_t luaDoPlayerAddMoney(lua_State* L);
to
static int64_t luaDoPlayerAddMoney(lua_State* L);
but then I got this error:
luascript.cpp invalid conversion from `int64_t (*)(lua_State*)' to `int (*)(lua_State*)'


referent to this line:
lua_register(m_luaState, "doPlayerAddMoney", LuaInterface::luaDoPlayerAddMoney);

Does anyone knows how to solve this?
 
Last edited:

Delusion

Divine Intellect
Support Team
Joined
Feb 14, 2015
Messages
5,098
Best answers
484
Reaction score
2,739
lua requires that you use int as the type for C functions when using lua API. the value returned by those functions has absolutely nothing to do with what your function does, it returns the number of results you push onto the stack
tl;dr don't change the first 4 lines you showed in your post to int64_t, leave them as int32_t

can you post the luaDoPlayerAddMoney function so we can see it?
and post Game::addMoney from game.cpp
 
OP
Lurk

Lurk

Member
Joined
Dec 4, 2017
Messages
150
Best answers
0
Reaction score
18
Location
Brazil
that was a really good explanation, thank you, will really help me in the future

here's luaDoPlayerAddMoney:
C++:
int32_t LuaInterface::luaDoPlayerAddMoney(lua_State* L)
{
    //doPlayerAddMoney(cid, money)
    uint64_t money = popNumber(L);

    ScriptEnviroment* env = getEnv();
    if(Player* player = env->getPlayerByUID(popNumber(L)))
    {
        g_game.addMoney(player, money);
        lua_pushboolean(L, true);
    }
    else
    {
        errorEx(getError(LUA_ERROR_PLAYER_NOT_FOUND));
        lua_pushboolean(L, false);
    }

    return 1;
}
and here is Game::addMoney from game.cpp
C++:
void Game::addMoney(Cylinder* cylinder, int64_t money, uint32_t flags /*= 0*/)
{
    IntegerMap moneyMap = Item::items.getMoneyMap();
    for(IntegerMap::reverse_iterator it = moneyMap.rbegin(); it != moneyMap.rend(); ++it)
    {
        int64_t tmp = money / it->first;
        money -= tmp * it->first;
        if(!tmp)
            continue;

        do
        {
            Item* remainItem = Item::CreateItem(it->second, std::min((int64_t)100, tmp));
            if(internalAddItem(NULL, cylinder, remainItem, INDEX_WHEREEVER, flags) != RET_NOERROR)
                internalAddItem(NULL, cylinder->getTile(), remainItem, INDEX_WHEREEVER, FLAG_NOLIMIT);

            tmp -= std::min((int64_t)100, tmp);
        }
        while(tmp > 0);
    }
}
there's one moe thing I'd like to ask you though... Will I need to change something on npc.cpp as well since they will be dealing with more money?
 

Delusion

Divine Intellect
Support Team
Joined
Feb 14, 2015
Messages
5,098
Best answers
484
Reaction score
2,739
that was a really good explanation, thank you, will really help me in the future

here's luaDoPlayerAddMoney:
C++:
int32_t LuaInterface::luaDoPlayerAddMoney(lua_State* L)
{
    //doPlayerAddMoney(cid, money)
    uint64_t money = popNumber(L);

    ScriptEnviroment* env = getEnv();
    if(Player* player = env->getPlayerByUID(popNumber(L)))
    {
        g_game.addMoney(player, money);
        lua_pushboolean(L, true);
    }
    else
    {
        errorEx(getError(LUA_ERROR_PLAYER_NOT_FOUND));
        lua_pushboolean(L, false);
    }

    return 1;
}
and here is Game::addMoney from game.cpp
C++:
void Game::addMoney(Cylinder* cylinder, int64_t money, uint32_t flags /*= 0*/)
{
    IntegerMap moneyMap = Item::items.getMoneyMap();
    for(IntegerMap::reverse_iterator it = moneyMap.rbegin(); it != moneyMap.rend(); ++it)
    {
        int64_t tmp = money / it->first;
        money -= tmp * it->first;
        if(!tmp)
            continue;

        do
        {
            Item* remainItem = Item::CreateItem(it->second, std::min((int64_t)100, tmp));
            if(internalAddItem(NULL, cylinder, remainItem, INDEX_WHEREEVER, flags) != RET_NOERROR)
                internalAddItem(NULL, cylinder->getTile(), remainItem, INDEX_WHEREEVER, FLAG_NOLIMIT);

            tmp -= std::min((int64_t)100, tmp);
        }
        while(tmp > 0);
    }
}
there's one moe thing I'd like to ask you though... Will I need to change something on npc.cpp as well since they will be dealing with more money?
everything is already in int64_t, what exactly are you trying to lift? the number of money shown in the trade window for the npc?
 
OP
Lurk

Lurk

Member
Joined
Dec 4, 2017
Messages
150
Best answers
0
Reaction score
18
Location
Brazil
Yes exactly it, and there's another problem as well... I'm using a lever script that gives an item in exchange of gold, but if a player has passed the integer (3000000000 for example) and the end of the transaction he'll receive the maxium value an integer can support, which is 2000000000something

--edit--
and there's a bank npc which is limtied to 2000000000something as well (the balance on my database supports higher values)
 

Delusion

Divine Intellect
Support Team
Joined
Feb 14, 2015
Messages
5,098
Best answers
484
Reaction score
2,739
Yes exactly it, and there's another problem as well... I'm using a lever script that gives an item in exchange of gold, but if a player has passed the integer (3000000000 for example) and the end of the transaction he'll receive the maxium value an integer can support, which is 2000000000something

--edit--
and there's a bank npc which is limtied to 2000000000something as well (the balance on my database supports higher values)
it's the client that's limited when the npc shows how much money you have, not the engine or any scripts
i'd just suggest you don't use such gigantic values instead of being forced to meddle around in the sources to find a solution and having to lift integer maximums
 
OP
Lurk

Lurk

Member
Joined
Dec 4, 2017
Messages
150
Best answers
0
Reaction score
18
Location
Brazil
so there's no solution... that's kinda sad, but thank you for your time and attention !
could you help me with another problem though? whenever I'm trying to add somenting in a backpack that is inside a backpack that is inside a backpack that is inside a backpack
like: bp(bp(bp(bp())))
the item just drops on the ground, doesn't matter if I'm using /i, buying or tradng something, just like there's not space anymore, even if I have another free backpack
I've read in another forum and a player said that the problem might be on the queryadd add function from player.cpp and that this problem was already solved in rev 3884, but I've compared both and found no diference whatsoever....

-- Edit --

just found out that the bug occurs on rev 3884 as well
 
Last edited:

HjugO

Member
Joined
Feb 7, 2015
Messages
46
Best answers
2
Reaction score
9
so there's no solution... that's kinda sad, but thank you for your time and attention !
could you help me with another problem though? whenever I'm trying to add somenting in a backpack that is inside a backpack that is inside a backpack that is inside a backpack
like: bp(bp(bp(bp())))
the item just drops on the ground, doesn't matter if I'm using /i, buying or tradng something, just like there's not space anymore, even if I have another free backpack
I've read in another forum and a player said that the problem might be on the queryadd add function from player.cpp and that this problem was already solved in rev 3884, but I've compared both and found no diference whatsoever....
Compare container.cpp file
 
OP
Lurk

Lurk

Member
Joined
Dec 4, 2017
Messages
150
Best answers
0
Reaction score
18
Location
Brazil
Ops, forgot to say I tried this one as well Hjugo, there are no diferences between them at all

-- Edit --
I was testing the rev 3884 and the bug is still there
 
Last edited:
Top