TFS 0.X Buy items with money backpack or bank balance 0.4

Discussion in 'Support' started by gmstrikker, Sep 7, 2018.

  1. gmstrikker

    gmstrikker Active Member

    Joined:
    Jul 30, 2014
    Messages:
    371
    Likes Received:
    31
    Best Answers:
    1
    Hello guys,

    I was looking to a way to make 8.6 servers like 11+
    Actual tibia have some changes really nice that should have on 8.6 servers and one of this is this:
    When you buy some in stores (hi,trade), if you don't have money on backpack, it check and remove money to your bank balance...
    Is anyone here know how to do it?

    I mean on default trade system
    Code (Text):
    1.  
    2. <parameter key="shop_buyable" value="jagged sword,8602,300;steel axe,8601,300;daramanian mace,2439,300;crimson sword,7385,3000;barbarian axe,2429,3000;clerical mace,2423,3000" />
    3.  
    Using bank system like the NPC script system (balance,deposit,withdraw):
    bank_npc.lua
    Code (Text):
    1.  
    2. local keywordHandler = KeywordHandler:new()
    3. local npcHandler = NpcHandler:new(keywordHandler)
    4. NpcSystem.parseParameters(npcHandler)
    5.  
    6. local Topic, count, transfer = {}, {}, {}
    7.  
    8. function onCreatureAppear(cid)            npcHandler:onCreatureAppear(cid)        end
    9. function onCreatureDisappear(cid)        npcHandler:onCreatureDisappear(cid)        end
    10. function onCreatureSay(cid, type, msg)        npcHandler:onCreatureSay(cid, type, msg)    end
    11. function onThink()                npcHandler:onThink()                end
    12.  
    13.  
    14. local function getCount(s)
    15.     local b, e = s:find('%d+')
    16.     return b and e and math.min(4294967295, tonumber(s:sub(b, e))) or -1
    17. end
    18.  
    19. local function findPlayer(name)
    20.     local resultId = db.storeQuery('SELECT name FROM players WHERE name=' .. db.escapeString(name) .. ' LIMIT 1'), nil
    21.     if resultId == false then
    22.         return
    23.     end
    24.     local r = result.getDataString(resultId, "name")
    25.     result.free(resultId)
    26.     return r
    27. end
    28.  
    29. local function getTown(name)
    30.     local resultId = db.storeQuery('SELECT town_id FROM players WHERE name=' .. db.escapeString(name) .. ' LIMIT 1'), nil
    31.     if resultId == false then
    32.         return
    33.     end
    34.     local r = result.getDataInt(resultId, "town_id")
    35.     result.free(resultId)
    36.     return r
    37. end
    38.  
    39. local function vocation(name)
    40.     local resultId = db.storeQuery('SELECT vocation FROM players WHERE name=' .. db.escapeString(name) .. ' LIMIT 1'), nil
    41.     if resultId == false then
    42.         return
    43.     end
    44.     local r = result.getDataInt(resultId, "vocation")
    45.     result.free(resultId)
    46.     return r
    47. end
    48.  
    49. local function updatePlayerBalance(name, value)
    50.     db.query('UPDATE players SET balance=' .. value .. ' WHERE name=' .. db.escapeString(name) .. ' LIMIT 1')
    51. end
    52.  
    53. function greet(cid)
    54.     Topic[cid], count[cid], transfer[cid] = nil, nil, nil
    55.     return true
    56. end
    57.  
    58. function creatureSayCallback(cid, type, msg)
    59.     if not npcHandler:isFocused(cid) then
    60.         return false
    61.     elseif msgcontains(msg, 'balance') then
    62.         npcHandler:say('Your account balance is ' .. getPlayerBalance(cid) .. ' gold.', cid)
    63.         Topic[cid] = nil
    64.     elseif msgcontains(msg, 'deposit') and msgcontains(msg, 'all') then
    65.         if getPlayerMoney(cid) == 0 then
    66.             npcHandler:say('You don\'t have any gold with you.', cid)
    67.             Topic[cid] = nil
    68.         else
    69.             count[cid] = getPlayerMoney(cid)
    70.             npcHandler:say('Would you really like to deposit ' .. count[cid] .. ' gold?', cid)
    71.             Topic[cid] = 2
    72.         end
    73.     elseif msgcontains(msg, 'deposit') then
    74.         if getCount(msg) == 0 then
    75.             npcHandler:say('You are joking, aren\'t you??', cid)
    76.             Topic[cid] = nil
    77.         elseif getCount(msg) ~= -1 then
    78.             if getPlayerMoney(cid) >= getCount(msg) then
    79.                 count[cid] = getCount(msg)
    80.                 npcHandler:say('Would you really like to deposit ' .. count[cid] .. ' gold?', cid)
    81.                 Topic[cid] = 2
    82.             else
    83.                 npcHandler:say('You do not have enough gold.', cid)
    84.                 Topic[cid] = nil
    85.             end
    86.         elseif getPlayerMoney(cid) == 0 then
    87.             npcHandler:say('You don\'t have any gold with you.', cid)
    88.             Topic[cid] = nil
    89.         else
    90.             npcHandler:say('Please tell me how much gold it is you would like to deposit.', cid)
    91.             Topic[cid] = 1
    92.         end
    93.     elseif Topic[cid] == 1 then
    94.         if getCount(msg) == -1 then
    95.             npcHandler:say('Please tell me how much gold it is you would like to deposit.', cid)
    96.             Topic[cid] = 1
    97.         elseif getPlayerMoney(cid) >= getCount(msg) then
    98.             count[cid] = getCount(msg)
    99.             npcHandler:say('Would you really like to deposit ' .. count[cid] .. ' gold?', cid)
    100.             Topic[cid] = 2
    101.         else
    102.             npcHandler:say('You do not have enough gold.', cid)
    103.             Topic[cid] = nil
    104.         end
    105.     elseif msgcontains(msg, 'yes') and Topic[cid] == 2 then
    106.         if doPlayerRemoveMoney(cid, count[cid]) then
    107.             doPlayerSetBalance(cid, getPlayerBalance(cid) + count[cid])
    108.             updatePlayerBalance(getCreatureByName(cid), getPlayerBalance(cid))
    109.             npcHandler:say('Alright, we have added the amount of ' .. count[cid] .. ' gold to your balance. You can withdraw your money anytime you want to.', cid)
    110.         else
    111.             npcHandler:say('I am inconsolable, but it seems you have lost your gold. I hope you get it back.', cid)
    112.         end
    113.         Topic[cid] = nil
    114.     elseif msgcontains(msg, 'no') and Topic[cid] == 2 then
    115.         npcHandler:say('As you wish. Is there something else I can do for you?', cid)
    116.         Topic[cid] = nil
    117.     elseif msgcontains(msg, 'withdraw') then
    118.         if getCount(msg) == 0 then
    119.             npcHandler:say('Sure, you want nothing you get nothing!', cid)
    120.             Topic[cid] = nil
    121.         elseif getCount(msg) ~= -1 then
    122.             if getPlayerBalance(cid) >= getCount(msg) then
    123.                 count[cid] = getCount(msg)
    124.                 npcHandler:say('Are you sure you wish to withdraw ' .. count[cid] .. ' gold from your bank account?', cid)
    125.                 Topic[cid] = 4
    126.             else
    127.                 npcHandler:say('There is not enough gold on your account.', cid)
    128.                 Topic[cid] = nil
    129.             end
    130.         elseif getPlayerBalance(cid) == 0 then
    131.             npcHandler:say('You don\'t have any money on your bank account.', cid)
    132.             Topic[cid] = nil
    133.         else
    134.             npcHandler:say('Please tell me how much gold you would like to withdraw.', cid)
    135.             Topic[cid] = 3
    136.         end
    137.     elseif Topic[cid] == 3 then
    138.         if getCount(msg) == -1 then
    139.             npcHandler:say('Please tell me how much gold you would like to withdraw.', cid)
    140.             Topic[cid] = 3
    141.         elseif getPlayerBalance(cid) >= getCount(msg) then
    142.             count[cid] = getCount(msg)
    143.             npcHandler:say('Are you sure you wish to withdraw ' .. count[cid] .. ' gold from your bank account?', cid)
    144.             Topic[cid] = 4
    145.         else
    146.             npcHandler:say('There is not enough gold on your account.', cid)
    147.             Topic[cid] = nil
    148.         end
    149.     elseif msgcontains(msg, 'yes') and Topic[cid] == 4 then
    150.         if getPlayerBalance(cid) >= count[cid] then
    151.             doPlayerAddMoney(cid, count[cid])
    152.             doPlayerSetBalance(cid, getPlayerBalance(cid) - count[cid])
    153.             updatePlayerBalance(getCreatureByName(cid), getPlayerBalance(cid))
    154.             npcHandler:say('Here you are, ' .. count[cid] .. ' gold. Please let me know if there is something else I can do for you.', cid)
    155.         else
    156.             npcHandler:say('There is not enough gold on your account.', cid)
    157.         end
    158.         Topic[cid] = nil
    159.     elseif msgcontains(msg, 'no') and Topic[cid] == 4 then
    160.         npcHandler:say('The customer is king! Come back anytime you want to if you wish to withdraw your money.', cid)
    161.         Topic[cid] = nil
    162.     elseif msgcontains(msg, 'transfer') then
    163.         if getCount(msg) == 0 then
    164.             npcHandler:say('Please think about it. Okay?', cid)
    165.             Topic[cid] = nil
    166.         elseif getCount(msg) ~= -1 then
    167.    
    168.             count[cid] = getCount(msg)
    169.             if getPlayerBalance(cid) >= count[cid] then
    170.                 npcHandler:say('Who would you like to transfer ' .. count[cid] .. ' gold to?', cid)
    171.                 Topic[cid] = 6
    172.             else
    173.                 npcHandler:say('There is not enough gold on your account.', cid)
    174.                 Topic[cid] = nil
    175.             end
    176.  
    177.         else
    178.             npcHandler:say('Please tell me the amount of gold you would like to transfer.', cid)
    179.             Topic[cid] = 5
    180.         end
    181.     elseif Topic[cid] == 5 then
    182.         if getCount(msg) == -1 then
    183.             npcHandler:say('Please tell me the amount of gold you would like to transfer.', cid)
    184.             Topic[cid] = 5
    185.         else
    186.             count[cid] = getCount(msg)
    187.             if getPlayerBalance(cid) >= count[cid] then
    188.                 npcHandler:say('Who would you like to transfer ' .. count[cid] .. ' gold to?', cid)
    189.                 Topic[cid] = 6
    190.             else
    191.                 npcHandler:say('There is not enough gold on your account.', cid)
    192.                 Topic[cid] = nil
    193.             end
    194.         end
    195.     elseif Topic[cid] == 6 then
    196.         local v = getCreatureByName(msg)
    197.         if getPlayerBalance(cid) >= count[cid] then
    198.             local temp = (v and getCreatureName(v) or false)
    199.             if temp then
    200.                 if getPlayerTown(v) == 7 then
    201.                     if getPlayerTown(cid) ~= getPlayerTown(v) then
    202.                         npcHandler:say('You can not transfer money to players from Rookgaardia if you are not from Rookgaardia.', cid)
    203.                         Topic[cid] = nil
    204.                         return true
    205.                     end
    206.                 elseif getPlayerTown(v) == 9 then
    207.                     if getPlayerTown(cid) ~= getPlayerTown(v) then
    208.                         npcHandler:say('You can not transfer money to players from Dawn Hills if you are not from Dawn Hills.', cid)
    209.                         Topic[cid] = nil
    210.                         return true
    211.                     end
    212.                 end
    213.  
    214.  
    215.                 transfer[cid] = msg
    216.                 npcHandler:say('Would you really like to transfer ' .. count[cid] .. ' gold to ' .. temp .. '?', cid)
    217.                 Topic[cid] = 7
    218.             elseif getPlayerGUIDByName(msg:lower()) ~= 0 then
    219.                 if getTown(msg:lower()) == 7 then
    220.                     if getPlayerTown(cid) ~= 7 then
    221.                         npcHandler:say('You can not transfer money to players from Rookgaardia if you are not from Rookgaardia.', cid)
    222.                         Topic[cid] = nil
    223.                         return true
    224.                     end
    225.                 elseif getTown(msg:lower()) == 9 then
    226.                     if getPlayerTown(cid) ~= 9 then
    227.                         npcHandler:say('You can not transfer money to players from Dawn Hills if you are not from Dawn Hills.', cid)
    228.                         Topic[cid] = nil
    229.                         return true
    230.                     end
    231.                 end
    232.  
    233.  
    234.                 transfer[cid] = msg
    235.                 npcHandler:say('Would you really like to transfer ' .. count[cid] .. ' gold to ' .. findPlayer(msg) .. '?', cid)
    236.                 Topic[cid] = 7            
    237.             else
    238.                 npcHandler:say('This player does not exist on this world!', cid)
    239.                 Topic[cid] = nil
    240.             end
    241.         else
    242.             npcHandler:say('There is not enough gold on your account.', cid)
    243.             Topic[cid] = nil
    244.         end
    245.     elseif Topic[cid] == 7 and msgcontains(msg, 'yes') then
    246.         if getPlayerBalance(cid) >= count[cid] then
    247.             local v = getCreatureByName(transfer[cid])
    248.             if v then
    249.                 doPlayerSetBalance(cid, getPlayerBalance(cid) - count[cid])
    250.                 updatePlayerBalance(getCreatureName(cid), getPlayerBalance(cid))
    251.                 doPlayerSetBalance(v, getPlayerBalance(v) + count[cid])
    252.                 updatePlayerBalance(getCreatureName(v), getPlayerBalance(v))
    253.                 npcHandler:say('Very well. You have transferred ' .. count[cid] .. ' gold to ' .. getCreatureName(v) .. '.', cid)
    254.             elseif findPlayer(transfer[cid]):lower() == transfer[cid]:lower() then
    255.                 doPlayerSetBalance(cid, getPlayerBalance(cid) - count[cid])
    256.                 updatePlayerBalance(getCreatureName(cid), getPlayerBalance(cid))
    257.                 db.query('UPDATE players SET balance=balance+' .. count[cid] .. ' WHERE name=' .. db.escapeString(transfer[cid]) .. ' LIMIT 1')
    258.                 npcHandler:say('Very well. You have transferred ' .. count[cid] .. ' gold to ' .. findPlayer(transfer[cid]) .. '.', cid)
    259.             else
    260.                 npcHandler:say('This player does not exist.', cid)
    261.             end
    262.         else
    263.             npcHandler:say('There is not enough gold on your account.', cid)
    264.         end
    265.         Topic[cid] = nil
    266.     elseif Topic[cid] == 7 and msgcontains(msg, 'no') then
    267.         npcHandler:say('Alright, is there something else I can do for you?', cid)
    268.         Topic[cid] = nil
    269.     elseif msgcontains(msg, 'change gold') then
    270.         npcHandler:say('How many platinum coins would you like to get?', cid)
    271.         Topic[cid] = 8
    272.     elseif Topic[cid] == 8 then
    273.         if getCount(msg) < 1 then
    274.             npcHandler:say('Hmm, can I help you with something else?', cid)
    275.             Topic[cid] = nil
    276.         else
    277.             count[cid] = math.min(500, getCount(msg))
    278.             npcHandler:say('So you would like me to change ' .. count[cid] * 100 .. ' of your gold coins into ' .. count[cid] .. ' platinum coins?', cid)
    279.             Topic[cid] = 9
    280.         end
    281.     elseif Topic[cid] == 9 then
    282.         if msgcontains(msg, 'yes') then
    283.             if doPlayerRemoveItem(cid, 2148, count[cid] * 100) then
    284.                 npcHandler:say('Here you are.', cid)
    285.                 doPlayerAddItem(cid, 2152, count[cid])
    286.             else
    287.                 npcHandler:say('Sorry, you do not have enough gold coins.', cid)
    288.             end
    289.         else
    290.             npcHandler:say('Well, can I help you with something else?', cid)
    291.         end
    292.         Topic[cid] = nil
    293.     elseif msgcontains(msg, 'change platinum') then
    294.         npcHandler:say('Would you like to change your platinum coins into gold or crystal?', cid)
    295.         Topic[cid] = 10
    296.     elseif Topic[cid] == 10 then
    297.         if msgcontains(msg, 'gold') then
    298.             npcHandler:say('How many platinum coins would you like to change into gold?', cid)
    299.             Topic[cid] = 11
    300.         elseif msgcontains(msg, 'crystal') then
    301.             npcHandler:say('How many crystal coins would you like to get?', cid)
    302.             Topic[cid] = 13
    303.         else
    304.             npcHandler:say('Well, can I help you with something else?', cid)
    305.             Topic[cid] = nil
    306.         end
    307.     elseif Topic[cid] == 11 then
    308.         if getCount(msg) < 1 then
    309.             npcHandler:say('Hmm, can I help you with something else?', cid)
    310.             Topic[cid] = nil
    311.         else
    312.             count[cid] = math.min(500, getCount(msg))
    313.             npcHandler:say('So you would like me to change ' .. count[cid] .. ' of your platinum coins into ' .. count[cid] * 100 .. ' gold coins for you?', cid)
    314.             Topic[cid] = 12
    315.         end
    316.     elseif Topic[cid] == 12 then
    317.         if msgcontains(msg, 'yes') then
    318.             if doPlayerRemoveItem(cid, 2152, count[cid]) then
    319.                 npcHandler:say('Here you are.', cid)
    320.                 doPlayerAddItem(cid, 2148, count[cid] * 100)
    321.             else
    322.                 npcHandler:say('Sorry, you do not have enough platinum coins.', cid)
    323.             end
    324.         else
    325.             npcHandler:say('Well, can I help you with something else?', cid)
    326.         end
    327.         Topic[cid] = nil
    328.     elseif Topic[cid] == 13 then
    329.         if getCount(msg) < 1 then
    330.             npcHandler:say('Hmm, can I help you with something else?', cid)
    331.             Topic[cid] = nil
    332.         else
    333.             count[cid] = math.min(500, getCount(msg))
    334.             npcHandler:say('So you would like me to change ' .. count[cid] * 100 .. ' of your platinum coins into ' .. count[cid] .. ' crystal coins for you?', cid)
    335.             Topic[cid] = 14
    336.         end
    337.     elseif Topic[cid] == 14 then
    338.         if msgcontains(msg, 'yes') then
    339.             if doPlayerRemoveItem(cid, 2152, count[cid] * 100) then
    340.                 npcHandler:say('Here you are.', cid)
    341.                 doPlayerAddItem(cid, 2160, count[cid])
    342.             else
    343.                 npcHandler:say('Sorry, you do not have enough platinum coins.', cid)
    344.             end
    345.         else
    346.             npcHandler:say('Well, can I help you with something else?', cid)
    347.         end
    348.         Topic[cid] = nil
    349.     elseif msgcontains(msg, 'change crystal') then
    350.         npcHandler:say('How many crystal coins would you like to change into platinum?', cid)
    351.         Topic[cid] = 15
    352.     elseif Topic[cid] == 15 then
    353.         if getCount(msg) == -1 or getCount(msg) == 0 then
    354.             npcHandler:say('Hmm, can I help you with something else?', cid)
    355.             Topic[cid] = nil
    356.         else
    357.             count[cid] = math.min(500, getCount(msg))
    358.             npcHandler:say('So you would like me to change ' .. count[cid] .. ' of your crystal coins into ' .. count[cid] * 100 .. ' platinum coins for you?', cid)
    359.             Topic[cid] = 16
    360.         end
    361.     elseif Topic[cid] == 16 then
    362.         if msgcontains(msg, 'yes') then
    363.             if doPlayerRemoveItem(cid, 2160, count[cid]) then
    364.                 npcHandler:say('Here you are.', cid)
    365.                 doPlayerAddItem(cid, 2152, count[cid] * 100)
    366.             else
    367.                 npcHandler:say('Sorry, you do not have enough crystal coins.', cid)
    368.             end
    369.         else
    370.             npcHandler:say('Well, can I help you with something else?', cid)
    371.         end
    372.         Topic[cid] = nil
    373.     elseif msgcontains(msg, 'change') then
    374.         npcHandler:say('There are three different coin types in Tibia: 100 gold coins equal 1 platinum coin, 100 platinum coins equal 1 crystal coin. So if you\'d like to change 100 gold into 1 platinum, simply say \'{change gold}\' and then \'1 platinum\'.', cid)
    375.         Topic[cid] = nil
    376.     elseif msgcontains(msg, 'bank') then
    377.         npcHandler:say('We can change money for you. You can also access your bank account.', cid)
    378.         Topic[cid] = nil
    379.     end
    380.     return true
    381. end
    382.  
    383. npcHandler:setCallback(CALLBACK_GREET, greet)
    384. npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
    385. npcHandler:addModule(FocusModule:new())
    386.  
    It do need sources change?
    Fir3element/3777

    Or can be done only on LUA?
    data\npc\lib\npcsystem\modules.lua
    Fir3element/3777
    On removemoney lines...

    Idk how to do by myself and i don't found nothing here on forum, only ppl asking for this...
    Anybody can help?
     
    supergt likes this.
  2. Best Answer:
    Post #5 by Erexo, Sep 13, 2018
  3. supergt

    supergt Member

    Joined:
    May 11, 2017
    Messages:
    65
    Likes Received:
    22
    Best Answers:
    0
    If you find the way to do it, please share...
     
  4. gmstrikker

    gmstrikker Active Member

    Joined:
    Jul 30, 2014
    Messages:
    371
    Likes Received:
    31
    Best Answers:
    1
  5. gmstrikker

    gmstrikker Active Member

    Joined:
    Jul 30, 2014
    Messages:
    371
    Likes Received:
    31
    Best Answers:
    1
  6. Erexo

    Erexo Kage

    Joined:
    Mar 27, 2010
    Messages:
    667
    Likes Received:
    105
    Best Answers:
    5
    Best Answer
    Modifying getMoney/removeMoney from game.cpp should be enough.

    Code (C++):
    1. uint32_t Game::getMoney(const Cylinder* cylinder)
    2. {
    3. [...]
    4.  
    5.     if(const Player* p = dynamic_cast<const Player*>(cylinder))
    6.     {
    7.         moneyCount += p->balance;
    8.     }
    9.  
    10.     return moneyCount;
    11. }
    Code (C++):
    1. bool Game::removeMoney(Cylinder* cylinder, int32_t money, uint32_t flags /*= 0*/)
    2. {
    3. [...]
    4.  
    5.     Player* p = dynamic_cast<Player*>(cylinder);
    6.     if(p)
    7.     {
    8.         moneyCount += p->balance;
    9.     }
    10.  
    11.     // Not enough money
    12.     if(moneyCount < money)
    13.     {
    14.         return false;
    15.     }
    16.  
    17. [...]
    18.  
    19.     moneyMap.clear();
    20.     if(money > 0 && p && (int32_t)p->balance >= money)
    21.     {
    22.         p->balance -= money;
    23.         std::stringstream ss;
    24.         ss << "Paid " << money << " gold from bank account. Your account balance is now " << p->balance << " gold.";
    25.         p->sendTextMessage(MSG_INFO_DESCR, ss.str());
    26.         return true;
    27.     }
    28.  
    29.     return money == 0;
    30. }
    But beware, since balance is u64, players with more than 4294kk in the bank will be actually poor as duck :D
     
    Last edited: Sep 15, 2018
    gmstrikker and supergt like this.
  7. supergt

    supergt Member

    Joined:
    May 11, 2017
    Messages:
    65
    Likes Received:
    22
    Best Answers:
    0
    My server have a high loot, so i'm thinking about make a limit on deposit, on LUA NPC...
    Or should be more better change money to 64 too? I have no knowledge in C++
     
  8. gmstrikker

    gmstrikker Active Member

    Joined:
    Jul 30, 2014
    Messages:
    371
    Likes Received:
    31
    Best Answers:
    1
    Get money is already 64 guys (i think so)...

    what do i doing wrong?
    my game.cpp
    hastebin

    errors
    Code (Text):
    1.  
    2. game.cpp: In member function ‘uint64_t Game::getMoney(const Cylinder*)’:
    3. game.cpp:1949:50: error: cannot dynamic_cast ‘cylinder’ (of type ‘const class Cylinder*’) to type ‘class Player*’ (conversion casts away constness)
    4.      if(Player* p = dynamic_cast<Player*>(cylinder))
    5.                                                   ^
    6. game.cpp:1949:5: warning: this ‘if’ clause does not guard... [-Wmisleading-indentation]
    7.      if(Player* p = dynamic_cast<Player*>(cylinder))
    8.      ^~
    9. game.cpp:1952:2: note: ...this statement, but the latter is misleadingly indented as if it is guarded by the ‘if’
    10.   return moneyCount;
    11.   ^~~~~~
    12. game.cpp: In member function ‘bool Game::removeMoney(Cylinder*, int64_t, uint32_t)’:
    13. game.cpp:2006:5: warning: this ‘if’ clause does not guard... [-Wmisleading-indentation]
    14.      if(p)
    15.      ^~
    16. game.cpp:2010:2: note: ...this statement, but the latter is misleadingly indented as if it is guarded by the ‘if’
    17.   if(moneyCount < money)
    18.   ^~
    19. game.cpp:2034:37: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
    20.      if(money > 0 && p && p->balance >= money)
    21.                           ~~~~~~~~~~~^~~~~~~~
    22. Makefile:33: recipe for target 'game.o' failed
    23. make: *** [game.o] Error 1
    24. make: *** Waiting for unfinished jobs....
    25.  
    26.  
     
    supergt likes this.
  9. Erexo

    Erexo Kage

    Joined:
    Mar 27, 2010
    Messages:
    667
    Likes Received:
    105
    Best Answers:
    5
    I've updated my answer, now it should work.
    If you really think that a player can have more than 429497cc (that is 4294967295gp, or 215bps filled with stacked cc), you should change getMoney to uint64_t, and I think that there will be more problems with that.
     
    supergt and gmstrikker like this.
  10. gmstrikker

    gmstrikker Active Member

    Joined:
    Jul 30, 2014
    Messages:
    371
    Likes Received:
    31
    Best Answers:
    1
    That was not my point, i dont care about this 4294967295gp limit, players will never have it on my server...
    I just was answer him that 3777, 0.4 (atlast mine), is already 64

    Now it's working, thank you so much to being help us...

    But i need to ask 2 more things to you:
    1- When i compile this game.cpp: hastebin
    i got a lot warnings:
    Code (Text):
    1.  
    2. CC       = g++
    3. game.cpp: In member function ‘uint64_t Game::getMoney(const Cylinder*)’:
    4. game.cpp:1949:5: warning: this ‘if’ clause does not guard... [-Wmisleading-indentation]
    5.      if(const Player* p = dynamic_cast<const Player*>(cylinder))
    6.      ^~
    7. game.cpp:1952:2: note: ...this statement, but the latter is misleadingly indented as if it is guarded by the ‘if’
    8.   return moneyCount;
    9.   ^~~~~~
    10. game.cpp: In member function ‘bool Game::removeMoney(Cylinder*, int64_t, uint32_t)’:
    11. game.cpp:2006:5: warning: this ‘if’ clause does not guard... [-Wmisleading-indentation]
    12.      if(p)
    13.      ^~
    14. game.cpp:2010:2: note: ...this statement, but the latter is misleadingly indented as if it is guarded by the ‘if’
    15.   if(moneyCount < money)
    16.   ^~
    17. game.cpp:2034:37: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
    18.      if(money > 0 && p && p->balance >= money)
    19.                           ~~~~~~~~~~~^~~~~~~~
    20. game.cpp: In constructor ‘Game::Game()’:
    21. game.cpp:80:24: warning: iteration 2 invokes undefined behavior [-Waggressive-loop-optimizations]
    22.    globalSaveMessage[i] = false;
    23.    ~~~~~~~~~~~~~~~~~~~~~^~~~~~~
    24. game.cpp:79:23: note: within this loop
    25.   for(int32_t i = 0; i < 3; i++)
    26.                      ~~^~~
    27. In file included from game.cpp:18:0:
    28. game.h: In member function ‘void Game::globalSave()’:
    29. game.h:616:78: warning: iteration 2 invokes undefined behavior [-Waggressive-loop-optimizations]
    30.    void setGlobalSaveMessage(int16_t key, bool value) {globalSaveMessage[key] = value;}
    31.                                                        ~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~
    32. game.cpp:6356:23: note: within this loop
    33.   for(int16_t i = 0; i < 3; i++)
    34.                      ~~^~~
    35.  
    There is a problem there?

    2- How to add a line to show bank balance, after buy something with bank balance?
    I've tried this line, but got this errors
    Code (Text):
    1.  
    2.     moneyMap.clear();
    3.     // check bankBalance onBuy 3
    4.     if(money > 0 && p && p->balance >= money)
    5.     {
    6.         p->balance -= money;
    7.         p->sendTextMessage(MSG_INFO_DESCR, "Your bank balance now is: " + p->balance + ".");
    8.         return true;
    9.     }
    10.  
    Code (Text):
    1.  
    2. game.cpp:2037:86: error: invalid operands of types ‘const char*’ and ‘const char [2]’ to binary ‘operator+’
    3.          p->sendTextMessage(MSG_INFO_DESCR, "Your bank balance now is: " + p->balance + ".");
    4.                                             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~
    5. Makefile:33: recipe for target 'game.o' failed
    6. make: *** [game.o] Error 1
    7.  
    8.  
     
    supergt likes this.
  11. Erexo

    Erexo Kage

    Joined:
    Mar 27, 2010
    Messages:
    667
    Likes Received:
    105
    Best Answers:
    5
    Those warnings are nothing to worry about, I've edited the code to get rid of them.
    I've also added the message you've requested, I've copied the text from real tibia.
     
    supergt and gmstrikker like this.
  12. gmstrikker

    gmstrikker Active Member

    Joined:
    Jul 30, 2014
    Messages:
    371
    Likes Received:
    31
    Best Answers:
    1
    PERFECT thank you so much!
    Now everybody who have 8.6 can uses bank money like tibia 11...

    Or almost i got one last problem...

    I had 2000 gps on bank, withdraw 1000 for my backpack, let 1000 on bank
    Said deposit all, to deposit 1000, and got 2k on bank again

    But got this message
    Code (Text):
    1.  
    2. 12:43 Paid 1000 gold from bank account. Your account balance is now 0 gold.
    3.  
    Says:
    Code (Text):
    1.  
    2. 12:43 Kratos [22]: balance
    3. 12:43 Bank: Your account balance is 2000 gold.
    4. 12:43 Kratos [22]: withdraw 1000
    5. 12:43 Bank: Are you sure you wish to withdraw 1000 gold from your bank account?
    6. 12:43 Kratos [22]: yes
    7. 12:43 Bank: Here you are, 1000 gold. Please let me know if there is something else I can do for you.
    8. 12:43 Kratos [22]: deposit all
    9. 12:43 Bank: Would you really like to deposit 2000 gold?
    10. 12:43 Kratos [22]: yes
    11. 12:43 Bank: Alright, we have added the amount of 2000 gold to your balance. You can withdraw your money anytime you want to.
    12.  
    bank_npc.lua
    firstpost

    I have a idea, but idk how to do, and i even dont know if this the best way to fix it

    The problem should be on getPlayerMoney(cid)...

    I was thinking in someway do on sources to by defaul getPlayerMoney(cid) have a bank parament bank = false
    Everywhere i put getPlayerMoney(cid), send the message:
    12:43 Paid 1000 gold from bank account. Your account balance is now 0 gold.

    But on bank i put getPlayerMoney(cid, true) to check only backpack money

    What do u think? Thats the way? Is it possible? Sorry if its tottally wrong, i just studying...
     
    Last edited: Sep 16, 2018
    supergt likes this.
  13. Erexo

    Erexo Kage

    Joined:
    Mar 27, 2010
    Messages:
    667
    Likes Received:
    105
    Best Answers:
    5
    You can edit those functions in luascript.cpp

    Code (C++):
    1. int32_t LuaScriptInterface::luaDoPlayerRemoveMoney(lua_State* L)
    2. {
    3.     //doPlayerRemoveMoney(cid,money[, includeBank = true])
    4.  
    5.     bool includeBank = true;
    6.     if(lua_gettop(L) > 2)
    7.         includeBank = popBoolean(L);
    8.  
    9.     uint64_t money = popNumber(L);
    10.  
    11.     ScriptEnviroment* env = getEnv();
    12.     if(Player* player = env->getPlayerByUID(popNumber(L)))
    13.         lua_pushboolean(L, g_game.removeMoney(player, money, 0, includeBank));
    14.     else
    15.     {
    16.         errorEx(getError(LUA_ERROR_PLAYER_NOT_FOUND));
    17.         lua_pushboolean(L, false);
    18.     }
    19.     return 1;
    20. }
    Code (C++):
    1. int32_t LuaScriptInterface::luaGetPlayerMoney(lua_State* L)
    2. {
    3.     //getPlayerMoney(cid[, includeBank = true])
    4.  
    5.     bool includeBank = true;
    6.     if(lua_gettop(L) > 1)
    7.         includeBank = popBoolean(L);
    8.  
    9.     ScriptEnviroment* env = getEnv();
    10.     if(Player* player = env->getPlayerByUID(popNumber(L)))
    11.         lua_pushnumber(L, g_game.getMoney(player, includeBank));
    12.     else
    13.     {
    14.         errorEx(getError(LUA_ERROR_PLAYER_NOT_FOUND));
    15.         lua_pushboolean(L, false);
    16.     }
    17.     return 1;
    18. }
    then in game.h edit headers
    Code (C++):
    1. uint32_t getMoney(const Cylinder* cylinder, bool includeBank = true);
    2. bool removeMoney(Cylinder* cylinder, int32_t money, uint32_t flags = 0, bool includeBank = true);
    3.  
    and in game.cpp
    Code (C++):
    1. uint32_t Game::getMoney(const Cylinder* cylinder, bool includeBank /*= true*/)
    2. {
    3. [...]
    4.  
    5.     if(includeBank)
    6.     {
    7.         if(const Player* p = dynamic_cast<const Player*>(cylinder))
    8.         {
    9.             moneyCount += p->balance;
    10.         }
    11.     }
    12.  
    13.     return moneyCount;
    14. }
    Code (C++):
    1. bool Game::removeMoney(Cylinder* cylinder, int32_t money, uint32_t flags /*= 0*/, bool includeBank /*= true*/)
    2. {
    3. [...]
    4.  
    5.     Player* p = includeBank ? dynamic_cast<Player*>(cylinder) : NULL;
    6.     if(p)
    7.     {
    8.         moneyCount += p->balance;
    9.     }
    10.  
    11.     // Not enough money
    12.     if(moneyCount < money)
    13.     {
    14.         return false;
    15.     }
    16.  
    17. [...]
    18.  
    19.     moneyMap.clear();
    20.     if(money > 0 && p && (int32_t)p->balance >= money)
    21.     {
    22.         p->balance -= money;
    23.         std::stringstream ss;
    24.         ss << "Paid " << money << " gold from bank account. Your account balance is now " << p->balance << " gold.";
    25.         p->sendTextMessage(MSG_INFO_DESCR, ss.str());
    26.         return true;
    27.     }
    28.  
    29.     return money == 0;
    30. }
    then in your bank script (and anywhere else that you don't want to use the bank), use those two functions like that:
    doPlayerRemoveMoney(cid, money, false)
    getPlayerMoney(cid, false)
     
    Last edited: Sep 17, 2018
    supergt and gmstrikker like this.
  14. gmstrikker

    gmstrikker Active Member

    Joined:
    Jul 30, 2014
    Messages:
    371
    Likes Received:
    31
    Best Answers:
    1
    I did added what u post (i just don't changed what was 64 to 32 scaring to do some shit), but got an error on game.cpp
    Code (Text):
    1.  
    2. game.cpp: In member function ‘uint64_t Game::getMoney(const Cylinder*, bool)’:
    3. game.cpp:1949:23: error: expected primary-expression before ‘const’
    4.      if(includeBank && const Player* p = dynamic_cast<const Player*>(cylinder))
    5.                        ^~~~~
    6. game.cpp:1949:23: error: expected ‘)’ before ‘const’
    7. game.cpp:1951:23: error: ‘p’ was not declared in this scope
    8.          moneyCount += p->balance;
    9.                        ^
    10. Makefile:33: recipe for target 'game.o' failed
    11. make: *** [game.o] Error 1
    12.  
    13.  

    So i tried to change on game.cpp what i think should fix
    Code (Text):
    1.  
    2.     // check bankBalance onBuy 1
    3.     const Player* p = dynamic_cast<const Player*>(cylinder);
    4.     if(includeBank && p)
    5.     {
    6.         moneyCount += p->balance;
    7.     }
    8.  
    I think that not work...
    Code (Text):
    1.  
    2. CC -o tfs
    3. house.o: In function `Houses::payRent(Player*, House*, unsigned int, long)':
    4. house.cpp:(.text+0x1305): undefined reference to `Game::removeMoney(Cylinder*, long, unsigned int)'
    5. protocolgame.o: In function `ProtocolGame::sendGoods(std::__cxx11::list<ShopInfo, std::allocator<ShopInfo> > const&)':
    6. protocolgame.cpp:(.text+0xedb3): undefined reference to `Game::getMoney(Cylinder const*)'
    7. npc.o: In function `Npc::getResponse(std::__cxx11::list<NpcResponse*, std::allocator<NpcResponse*> > const&, Player const*, NpcState*, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, bool)':
    8. npc.cpp:(.text+0x2e48): undefined reference to `Game::getMoney(Cylinder const*)'
    9. npc.o: In function `Npc::executeResponse(Player*, NpcState*, NpcResponse const*)':
    10. npc.cpp:(.text+0x7a53): undefined reference to `Game::getMoney(Cylinder const*)'
    11. npc.cpp:(.text+0x7d30): undefined reference to `Game::removeMoney(Cylinder*, long, unsigned int)'
    12. talkaction.o: In function `TalkAction::houseBuy(Creature*, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)':
    13. talkaction.cpp:(.text+0x10d2): undefined reference to `Game::getMoney(Cylinder const*)'
    14. talkaction.cpp:(.text+0x10ef): undefined reference to `Game::removeMoney(Cylinder*, long, unsigned int)'
    15. collect2: error: ld returned 1 exit status
    16. Makefile:37: recipe for target 'tfs' failed
    17. make: *** [tfs] Error 1
    18.  
     
    supergt likes this.
  15. Erexo

    Erexo Kage

    Joined:
    Mar 27, 2010
    Messages:
    667
    Likes Received:
    105
    Best Answers:
    5
    did you update game.h method headers? Not add but update them
     
    gmstrikker and supergt like this.
  16. gmstrikker

    gmstrikker Active Member

    Joined:
    Jul 30, 2014
    Messages:
    371
    Likes Received:
    31
    Best Answers:
    1
    I think so:
    game.h - e8c04908
     
    supergt likes this.
  17. Erexo

    Erexo Kage

    Joined:
    Mar 27, 2010
    Messages:
    667
    Likes Received:
    105
    Best Answers:
    5
    can you post your game.cpp?
     
    supergt and gmstrikker like this.
  18. gmstrikker

    gmstrikker Active Member

    Joined:
    Jul 30, 2014
    Messages:
    371
    Likes Received:
    31
    Best Answers:
    1
    supergt likes this.
  19. Erexo

    Erexo Kage

    Joined:
    Mar 27, 2010
    Messages:
    667
    Likes Received:
    105
    Best Answers:
    5
    The code looks fine, try to clean and rebuild.
     
    supergt and gmstrikker like this.
  20. gmstrikker

    gmstrikker Active Member

    Joined:
    Jul 30, 2014
    Messages:
    371
    Likes Received:
    31
    Best Answers:
    1
    Code (Text):
    1.  
    2. game.cpp: In member function ‘uint64_t Game::getMoney(const Cylinder*, bool)’:
    3. game.cpp:1949:23: error: expected primary-expression before ‘const’
    4.      if(includeBank && const Player* p = dynamic_cast<const Player*>(cylinder))
    5.                        ^~~~~
    6. game.cpp:1949:23: error: expected ‘)’ before ‘const’
    7. game.cpp:1951:23: error: ‘p’ was not declared in this scope
    8.          moneyCount += p->balance;
    9.                        ^
    10.  
    11.  
    1949: if(includeBank && const Player* p = dynamic_cast<const Player*>(cylinder))
    Code (Text):
    1.  
    2.     // check bankBalance onBuy 1
    3.     if(includeBank && const Player* p = dynamic_cast<const Player*>(cylinder))
    4.     {
    5.         moneyCount += p->balance;
    6.     }
    7.  
    8.    return moneyCount;
    9.  
     
    supergt likes this.
  21. Erexo

    Erexo Kage

    Joined:
    Mar 27, 2010
    Messages:
    667
    Likes Received:
    105
    Best Answers:
    5
    yop, I've already fixed that. Your solution was also good
     
    gmstrikker and supergt like this.

Share This Page

Loading...