• 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!

Solved Global Bank System You don't have enough money.

Majster12

Member
Joined
Feb 20, 2009
Messages
134
Solutions
1
Reaction score
16
TFS 1.2
Any ideas?

luascript.cpp
Code:
int LuaScriptInterface::luaPlayerGetMoney(lua_State* L)
{
    // player:getMoney()
    Player* player = getUserdata<Player>(L, 1);
    if (player) {
        lua_pushnumber(L, player->getMoney());
    }
    else {
        lua_pushnil(L);
    }
    return 1;
}
Code:
int LuaScriptInterface::luaPlayerRemoveMoney(lua_State* L)
{
    // player:removeMoney(money)mon
    Player* player = getUserdata<Player>(L, 1);
    bool success = false;
    if (player) {
        uint64_t money = getNumber<uint64_t>(L, 2);
        if (!g_game.removeMoney(player, money))
        {
            uint64_t playerTotal = player->getMoney() + player->getBankBalance();

            if (playerTotal >= money)
            {
                money -= player->getMoney(); //discount player money
                if (money < 0) money = 0;
                g_game.removeMoney(player, player->getMoney()); //1
                if (player->getMoney() < 0) money = 0;
                // player money is 0, and its value is discounted. Now remove from balance the rest
                playerTotal = player->getBankBalance() - money;
                if (playerTotal < 0) playerTotal = 0;
                player->setBankBalance(playerTotal);
                std::ostringstream ss;
                ss << "Paid " << money << " gold from bank account. Your account balance is now " << player->getBankBalance() << " gold.";
                player->sendTextMessage(MESSAGE_INFO_DESCR, ss.str());
                success = true;
            }
        }
        else
        {
            success = true;
        }
        pushBoolean(L, success);
    }
    else {
        lua_pushnil(L);
    }
    return 1;
}
npcsystem\modules.lua
http://pastebin.com/raw/UzY2vvZt

npcsystem\npchandler.lua
http://pastebin.com/raw/cNg0sXhH


2oBr5Xr.gif
 
Check using print if this function causing this message:

npcsystem\modules.lua:
Code:
       if player:getMoney() + player:getBankBalance() < totalCost then
            local msg = self.npcHandler:getMessage(MESSAGE_NEEDMONEY)
            msg = self.npcHandler:parseMessage(msg, parseInfo)
            player:sendCancelMessage(msg)
            return false
        end
 
Check using print if this function causing this message:

npcsystem\modules.lua:
Code:
       if player:getMoney() + player:getBankBalance() < totalCost then
            local msg = self.npcHandler:getMessage(MESSAGE_NEEDMONEY)
            msg = self.npcHandler:parseMessage(msg, parseInfo)
            player:sendCancelMessage(msg)
            return false
        end
Working fine now after i added "()"
Solved.

Code:
        if ((player:getMoney() + player:getBankBalance()) < totalCost) then
            local msg = self.npcHandler:getMessage(MESSAGE_NEEDMONEY)
            msg = self.npcHandler:parseMessage(msg, parseInfo)
            player:sendCancelMessage(msg)
            return false
        end
 
How did u make this work, to npc retrieve balance from bank account?
 
editing sources, btw I was sure that you know more that you actually know
I was thinking of source edits, but thought that maybe somewhere in lua.
Well, I asked just to be sure. Because i just cant do c++ xD
 
This is a bad solution tbh, cause sometimes you just wanna remove the money without removing from balance too.
 
Back
Top Bottom