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

Lua [TFS 1.2] Crystal Coin -> Gold Nugget

PRLOts

Member
Joined
Jun 24, 2017
Messages
116
Solutions
4
Reaction score
15
Hey Otland!

I have huge problem with gold nuggets. The convertion works perfectly to me, from cc to gold nuggets, but npc can't see the value of that nuggets, and key="worth" in items.xml is not anymore in TFS 1.2 . Anyone know how to make gold nuggets visible to npc?

Thanks for reply, and best regards!


My changegold.lua

Lua:
local config = {
    [ITEM_GOLD_COIN] = {changeTo = ITEM_PLATINUM_COIN},
    [ITEM_PLATINUM_COIN] = {changeBack = ITEM_GOLD_COIN, changeTo = ITEM_CRYSTAL_COIN},
    [ITEM_CRYSTAL_COIN] = {changeBack = ITEM_PLATINUM_COIN, changeTo = ITEM_GOLD_NUGGET},
    [ITEM_GOLD_NUGGET] = {changeBack = ITEM_CRYSTAL_COIN}
}

function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    local coin = config[item:getId()]
    if coin.changeTo and item.type == 100 then
        item:remove()
        player:addItem(coin.changeTo, 1)
    elseif coin.changeBack then
        item:remove(1)
        player:addItem(coin.changeBack, 100)
    else
        return false
    end
    return true
end
 
Solution
inside of item.cpp
C++:
uint32_t Item::getWorth() const
{
    switch (id) {
        case ITEM_GOLD_COIN:
            return count;

        case ITEM_PLATINUM_COIN:
            return count * 100;

        case ITEM_CRYSTAL_COIN:
            return count * 10000;

        case ITEM_GOLD_NUGGET:
            return count * 1000000;

        default:
            return 0;
    }
}

in const.h under ITEM_CRYSTAL_COIN = 2160,
C++:
ITEM_GOLD_NUGGET = idhere,

luascript.cpp under registerEnum(ITEM_CRYSTAL_COIN)
C++:
registerEnum(ITEM_GOLD_NUGGET)

game.cpp replace this:
C++:
void Game::addMoney(Cylinder* cylinder, uint64_t money, uint32_t flags /*= 0*/)
{
    if (money == 0) {
        return;
    }

    uint32_t crystalCoins = money / 10000...
inside of item.cpp
C++:
uint32_t Item::getWorth() const
{
    switch (id) {
        case ITEM_GOLD_COIN:
            return count;

        case ITEM_PLATINUM_COIN:
            return count * 100;

        case ITEM_CRYSTAL_COIN:
            return count * 10000;

        case ITEM_GOLD_NUGGET:
            return count * 1000000;

        default:
            return 0;
    }
}

in const.h under ITEM_CRYSTAL_COIN = 2160,
C++:
ITEM_GOLD_NUGGET = idhere,

luascript.cpp under registerEnum(ITEM_CRYSTAL_COIN)
C++:
registerEnum(ITEM_GOLD_NUGGET)

game.cpp replace this:
C++:
void Game::addMoney(Cylinder* cylinder, uint64_t money, uint32_t flags /*= 0*/)
{
    if (money == 0) {
        return;
    }

    uint32_t crystalCoins = money / 10000;
    money -= crystalCoins * 10000;
    while (crystalCoins > 0) {
        const uint16_t count = std::min<uint32_t>(100, crystalCoins);

        Item* remaindItem = Item::CreateItem(ITEM_CRYSTAL_COIN, count);

        ReturnValue ret = internalAddItem(cylinder, remaindItem, INDEX_WHEREEVER, flags);
        if (ret != RETURNVALUE_NOERROR) {
            internalAddItem(cylinder->getTile(), remaindItem, INDEX_WHEREEVER, FLAG_NOLIMIT);
        }

        crystalCoins -= count;
    }

    uint16_t platinumCoins = money / 100;
    if (platinumCoins != 0) {
        Item* remaindItem = Item::CreateItem(ITEM_PLATINUM_COIN, platinumCoins);

        ReturnValue ret = internalAddItem(cylinder, remaindItem, INDEX_WHEREEVER, flags);
        if (ret != RETURNVALUE_NOERROR) {
            internalAddItem(cylinder->getTile(), remaindItem, INDEX_WHEREEVER, FLAG_NOLIMIT);
        }

        money -= platinumCoins * 100;
    }

    if (money != 0) {
        Item* remaindItem = Item::CreateItem(ITEM_GOLD_COIN, money);

        ReturnValue ret = internalAddItem(cylinder, remaindItem, INDEX_WHEREEVER, flags);
        if (ret != RETURNVALUE_NOERROR) {
            internalAddItem(cylinder->getTile(), remaindItem, INDEX_WHEREEVER, FLAG_NOLIMIT);
        }
    }
}
with this:
C++:
void Game::addMoney(Cylinder* cylinder, uint64_t money, uint32_t flags /*= 0*/)
{
    if (money == 0) {
        return;
    }

    uint32_t goldNuggets = money / 1000000;
    money -= goldNuggets * 1000000;
    while (goldNuggets > 0) {
        const uint16_t count = std::min<uint32_t>(100, goldNuggets);

        Item* remaindItem = Item::CreateItem(ITEM_GOLD_NUGGET, count);

        ReturnValue ret = internalAddItem(cylinder, remaindItem, INDEX_WHEREEVER, flags);
        if (ret != RETURNVALUE_NOERROR) {
            internalAddItem(cylinder->getTile(), remaindItem, INDEX_WHEREEVER, FLAG_NOLIMIT);
        }

        goldNuggets -= count;
    }

    uint32_t crystalCoins = money / 10000;
    if (crystalCoins != 0) {
        Item* remaindItem = Item::CreateItem(ITEM_CRYSTAL_COIN, crystalCoins);

        ReturnValue ret = internalAddItem(cylinder, remaindItem, INDEX_WHEREEVER, flags);
        if (ret != RETURNVALUE_NOERROR) {
            internalAddItem(cylinder->getTile(), remaindItem, INDEX_WHEREEVER, FLAG_NOLIMIT);
        }

        money -= crystalCoins * 10000;
    }

    uint16_t platinumCoins = money / 100;
    if (platinumCoins != 0) {
        Item* remaindItem = Item::CreateItem(ITEM_PLATINUM_COIN, platinumCoins);

        ReturnValue ret = internalAddItem(cylinder, remaindItem, INDEX_WHEREEVER, flags);
        if (ret != RETURNVALUE_NOERROR) {
            internalAddItem(cylinder->getTile(), remaindItem, INDEX_WHEREEVER, FLAG_NOLIMIT);
        }

        money -= platinumCoins * 100;
    }

    if (money != 0) {
        Item* remaindItem = Item::CreateItem(ITEM_GOLD_COIN, money);

        ReturnValue ret = internalAddItem(cylinder, remaindItem, INDEX_WHEREEVER, flags);
        if (ret != RETURNVALUE_NOERROR) {
            internalAddItem(cylinder->getTile(), remaindItem, INDEX_WHEREEVER, FLAG_NOLIMIT);
        }
    }
}

in player.cpp replace this:
C++:
if (itemId != ITEM_GOLD_COIN && itemId != ITEM_PLATINUM_COIN && itemId != ITEM_CRYSTAL_COIN) {
with this:
C++:
if (itemId != ITEM_GOLD_COIN && itemId != ITEM_PLATINUM_COIN && itemId != ITEM_CRYSTAL_COIN && itemId != ITEM_GOLD_NUGGET) {
and that should be it
 
Last edited:
Solution
inside of item.cpp
C++:
uint32_t Item::getWorth() const
{
    switch (id) {
        case ITEM_GOLD_COIN:
            return count;

        case ITEM_PLATINUM_COIN:
            return count * 100;

        case ITEM_CRYSTAL_COIN:
            return count * 10000;

        case ITEM_GOLD_NUGGET:
            return count * 1000000;

        default:
            return 0;
    }
}

in const.h under ITEM_CRYSTAL_COIN = 2160,
C++:
ITEM_GOLD_NUGGET = idhere,

luascript.cpp under registerEnum(ITEM_CRYSTAL_COIN)
C++:
registerEnum(ITEM_GOLD_NUGGET)

game.cpp replace this:
C++:
void Game::addMoney(Cylinder* cylinder, uint64_t money, uint32_t flags /*= 0*/)
{
    if (money == 0) {
        return;
    }

    uint32_t crystalCoins = money / 10000;
    money -= crystalCoins * 10000;
    while (crystalCoins > 0) {
        const uint16_t count = std::min<uint32_t>(100, crystalCoins);

        Item* remaindItem = Item::CreateItem(ITEM_CRYSTAL_COIN, count);

        ReturnValue ret = internalAddItem(cylinder, remaindItem, INDEX_WHEREEVER, flags);
        if (ret != RETURNVALUE_NOERROR) {
            internalAddItem(cylinder->getTile(), remaindItem, INDEX_WHEREEVER, FLAG_NOLIMIT);
        }

        crystalCoins -= count;
    }

    uint16_t platinumCoins = money / 100;
    if (platinumCoins != 0) {
        Item* remaindItem = Item::CreateItem(ITEM_PLATINUM_COIN, platinumCoins);

        ReturnValue ret = internalAddItem(cylinder, remaindItem, INDEX_WHEREEVER, flags);
        if (ret != RETURNVALUE_NOERROR) {
            internalAddItem(cylinder->getTile(), remaindItem, INDEX_WHEREEVER, FLAG_NOLIMIT);
        }

        money -= platinumCoins * 100;
    }

    if (money != 0) {
        Item* remaindItem = Item::CreateItem(ITEM_GOLD_COIN, money);

        ReturnValue ret = internalAddItem(cylinder, remaindItem, INDEX_WHEREEVER, flags);
        if (ret != RETURNVALUE_NOERROR) {
            internalAddItem(cylinder->getTile(), remaindItem, INDEX_WHEREEVER, FLAG_NOLIMIT);
        }
    }
}
with this:
C++:
void Game::addMoney(Cylinder* cylinder, uint64_t money, uint32_t flags /*= 0*/)
{
    if (money == 0) {
        return;
    }

    uint32_t goldNuggets = money / 1000000;
    money -= goldNuggets * 1000000;
    while (goldNuggets > 0) {
        const uint16_t count = std::min<uint32_t>(100, goldNuggets);

        Item* remaindItem = Item::CreateItem(ITEM_GOLD_NUGGET, count);

        ReturnValue ret = internalAddItem(cylinder, remaindItem, INDEX_WHEREEVER, flags);
        if (ret != RETURNVALUE_NOERROR) {
            internalAddItem(cylinder->getTile(), remaindItem, INDEX_WHEREEVER, FLAG_NOLIMIT);
        }

        goldNuggets -= count;
    }

    uint32_t crystalCoins = money / 10000;
    if (crystalCoins != 0) {
        Item* remaindItem = Item::CreateItem(ITEM_CRYSTAL_COIN, count);

        ReturnValue ret = internalAddItem(cylinder, remaindItem, INDEX_WHEREEVER, flags);
        if (ret != RETURNVALUE_NOERROR) {
            internalAddItem(cylinder->getTile(), remaindItem, INDEX_WHEREEVER, FLAG_NOLIMIT);
        }

        money -= crystalCoins * 10000;
    }

    uint16_t platinumCoins = money / 100;
    if (platinumCoins != 0) {
        Item* remaindItem = Item::CreateItem(ITEM_PLATINUM_COIN, platinumCoins);

        ReturnValue ret = internalAddItem(cylinder, remaindItem, INDEX_WHEREEVER, flags);
        if (ret != RETURNVALUE_NOERROR) {
            internalAddItem(cylinder->getTile(), remaindItem, INDEX_WHEREEVER, FLAG_NOLIMIT);
        }

        money -= platinumCoins * 100;
    }

    if (money != 0) {
        Item* remaindItem = Item::CreateItem(ITEM_GOLD_COIN, money);

        ReturnValue ret = internalAddItem(cylinder, remaindItem, INDEX_WHEREEVER, flags);
        if (ret != RETURNVALUE_NOERROR) {
            internalAddItem(cylinder->getTile(), remaindItem, INDEX_WHEREEVER, FLAG_NOLIMIT);
        }
    }
}

in player.cpp replace this:
C++:
if (itemId != ITEM_GOLD_COIN && itemId != ITEM_PLATINUM_COIN && itemId != ITEM_CRYSTAL_COIN) {
with this:
C++:
if (itemId != ITEM_GOLD_COIN && itemId != ITEM_PLATINUM_COIN && itemId != ITEM_CRYSTAL_COIN && itemId != ITEM_GOLD_NUGGET) {
and that should be it

Thanks mate, I need to recompile this ya?
 
Not working.

Code:
/home/ots/src/game.cpp: In member function ‘void Game::addMoney(Cylinder*, uint64_t, uint32_t)’:
/home/ots/src/game.cpp:1502:65: error: ‘count’ was not declared in this scope
         Item* remaindItem = Item::CreateItem(ITEM_CRYSTAL_COIN, count);
                                                                 ^
/home/ots/src/game.cpp:1502:65: note: suggested alternative:
In file included from /usr/include/c++/4.9/algorithm:62:0,
                 from /home/ots/src/otpch.h:25,
                 from /home/ots/build/cotire/tfs_CXX_prefix.cxx:4,
                 from /home/ots/build/cotire/tfs_CXX_prefix.hxx:4:
/usr/include/c++/4.9/bits/stl_algo.h:3947:5: note:   ‘std::count’
     count(_InputIterator __first, _InputIterator __last, const _Tp& __value)
     ^
CMakeFiles/tfs.dir/build.make:599: recipe for target 'CMakeFiles/tfs.dir/src/game.cpp.o' failed
make[2]: *** [CMakeFiles/tfs.dir/src/game.cpp.o] Error 1
CMakeFiles/Makefile2:122: recipe for target 'CMakeFiles/tfs.dir/all' failed
make[1]: *** [CMakeFiles/tfs.dir/all] Error 2
Makefile:76: recipe for target 'all' failed
make: *** [all] Error 2
 
Not working.

Code:
/home/ots/src/game.cpp: In member function ‘void Game::addMoney(Cylinder*, uint64_t, uint32_t)’:
/home/ots/src/game.cpp:1502:65: error: ‘count’ was not declared in this scope
         Item* remaindItem = Item::CreateItem(ITEM_CRYSTAL_COIN, count);
                                                                 ^
/home/ots/src/game.cpp:1502:65: note: suggested alternative:
In file included from /usr/include/c++/4.9/algorithm:62:0,
                 from /home/ots/src/otpch.h:25,
                 from /home/ots/build/cotire/tfs_CXX_prefix.cxx:4,
                 from /home/ots/build/cotire/tfs_CXX_prefix.hxx:4:
/usr/include/c++/4.9/bits/stl_algo.h:3947:5: note:   ‘std::count’
     count(_InputIterator __first, _InputIterator __last, const _Tp& __value)
     ^
CMakeFiles/tfs.dir/build.make:599: recipe for target 'CMakeFiles/tfs.dir/src/game.cpp.o' failed
make[2]: *** [CMakeFiles/tfs.dir/src/game.cpp.o] Error 1
CMakeFiles/Makefile2:122: recipe for target 'CMakeFiles/tfs.dir/all' failed
make[1]: *** [CMakeFiles/tfs.dir/all] Error 2
Makefile:76: recipe for target 'all' failed
make: *** [all] Error 2

You are using the wrong TFS most likely or you didn't copy it right.
 
Not working.

Code:
/home/ots/src/game.cpp: In member function ‘void Game::addMoney(Cylinder*, uint64_t, uint32_t)’:
/home/ots/src/game.cpp:1502:65: error: ‘count’ was not declared in this scope
         Item* remaindItem = Item::CreateItem(ITEM_CRYSTAL_COIN, count);
                                                                 ^
/home/ots/src/game.cpp:1502:65: note: suggested alternative:
In file included from /usr/include/c++/4.9/algorithm:62:0,
                 from /home/ots/src/otpch.h:25,
                 from /home/ots/build/cotire/tfs_CXX_prefix.cxx:4,
                 from /home/ots/build/cotire/tfs_CXX_prefix.hxx:4:
/usr/include/c++/4.9/bits/stl_algo.h:3947:5: note:   ‘std::count’
     count(_InputIterator __first, _InputIterator __last, const _Tp& __value)
     ^
CMakeFiles/tfs.dir/build.make:599: recipe for target 'CMakeFiles/tfs.dir/src/game.cpp.o' failed
make[2]: *** [CMakeFiles/tfs.dir/src/game.cpp.o] Error 1
CMakeFiles/Makefile2:122: recipe for target 'CMakeFiles/tfs.dir/all' failed
make[1]: *** [CMakeFiles/tfs.dir/all] Error 2
Makefile:76: recipe for target 'all' failed
make: *** [all] Error 2

Try this bro

[8.60] The Forgotten Server 1.2

You are using the wrong TFS most likely or you didn't copy it right.

Nice to see you WibbenZ !
 
not working in tfs 1.3 otx 3.10
this error:
Code:
[ 28%] Building CXX object CMakeFiles/tfs.dir/src/game.cpp.o
/home/otx/src/game.cpp: In member function ‘void Game::addMoney(Cylinder*, uint64_t, uint32_t)’:
/home/otx/src/game.cpp:1509:65: error: ‘count’ was not declared in this scope
         Item* remaindItem = Item::CreateItem(ITEM_CRYSTAL_COIN, count);
                                                                 ^
/home/otx/src/game.cpp:1509:65: note: suggested alternative:
In file included from /usr/include/c++/4.8/algorithm:62:0,
                 from /home/otx/src/otpch.h:25,
                 from /home/otx/src/game.cpp:20:
/usr/include/c++/4.8/bits/stl_algo.h:4622:5: note:   ‘std::count’
     count(_InputIterator __first, _InputIterator __last, const _Tp& __value)
     ^
make[2]: *** [CMakeFiles/tfs.dir/src/game.cpp.o] Error 1
make[1]: *** [CMakeFiles/tfs.dir/all] Error 2
make: *** [all] Error 2
 
not working in tfs 1.3 otx 3.10
this error:
Code:
[ 28%] Building CXX object CMakeFiles/tfs.dir/src/game.cpp.o
/home/otx/src/game.cpp: In member function ‘void Game::addMoney(Cylinder*, uint64_t, uint32_t)’:
/home/otx/src/game.cpp:1509:65: error: ‘count’ was not declared in this scope
         Item* remaindItem = Item::CreateItem(ITEM_CRYSTAL_COIN, count);
                                                                 ^
/home/otx/src/game.cpp:1509:65: note: suggested alternative:
In file included from /usr/include/c++/4.8/algorithm:62:0,
                 from /home/otx/src/otpch.h:25,
                 from /home/otx/src/game.cpp:20:
/usr/include/c++/4.8/bits/stl_algo.h:4622:5: note:   ‘std::count’
     count(_InputIterator __first, _InputIterator __last, const _Tp& __value)
     ^
make[2]: *** [CMakeFiles/tfs.dir/src/game.cpp.o] Error 1
make[1]: *** [CMakeFiles/tfs.dir/all] Error 2
make: *** [all] Error 2
edited the post, re copy the entire addMoney function from my post
 
There is a bug when selling items to an NPC. if you sell more than 1kk items at once, it bugs.

For example. Selling 50 steel boots at 30k. total cash 1.5kk.

Currency you get: 1 nugget, and 149 CC. Crystal coins stacking more than 100. You get 1kk extra.
Currency you should get: 1 nugget 49 CC.

Checked many times the code. Fixes would really be appreciate it. Thanks @Static_
 
Any updates on this? Really appreciate it! Thanks.
Try changing
Lua:
uint32_t crystalCoins = money / 10000;
if (crystalCoins != 0) {
    Item* remaindItem = Item::CreateItem(ITEM_CRYSTAL_COIN, crystalCoins);

    ReturnValue ret = internalAddItem(cylinder, remaindItem, INDEX_WHEREEVER, flags);
    if (ret != RETURNVALUE_NOERROR) {
        internalAddItem(cylinder->getTile(), remaindItem, INDEX_WHEREEVER, FLAG_NOLIMIT);
    }

    money -= crystalCoins * 10000;
}
to
Lua:
uint32_t crystalCoins = money / 10000;
money -= crystalCoins * 10000;
while (crystalCoins > 0) {
    const uint16_t count = std::min<uint32_t>(100, crystalCoins);

    Item* remaindItem = Item::CreateItem(ITEM_CRYSTAL_COIN, count);

    ReturnValue ret = internalAddItem(cylinder, remaindItem, INDEX_WHEREEVER, flags);
    if (ret != RETURNVALUE_NOERROR) {
        internalAddItem(cylinder->getTile(), remaindItem, INDEX_WHEREEVER, FLAG_NOLIMIT);
    }

    crystalCoins -= count;
}
 
That fixed the stacking problem.
But you now get:
100 cc 49cc and 1 nugget, so you still get 1kk extra instead of 50cc 1 nugget.
 
That fixed the stacking problem.
But you now get:
100 cc 49cc and 1 nugget, so you still get 1kk extra instead of 50cc 1 nugget.
You must have added some faulty code to your NPC system in that case. Can you verify whether it adds an extra 100CC if you call Player.addMoney directly?
 
I didnt change anything other than that, much less on NPC.
Checked the code like 10 times, recopied, and recompiled. Everything is as the upper code.
Just tested this:
Lua:
function onUse(player, item, fromPosition, target, toPosition, isHotkey)
     player:addMoney(1500000)
end
It added the same. 100cc 49cc 1 nugget.

EDIT: Tested with bank NPC, happens the same when you withdraw more than 1kk.
 
I have now tested the snippet above, and unfortunately I do not end up with the same result as you do (I received a gold nugget and 50CC).
 
inside of item.cpp
C++:
uint32_t Item::getWorth() const
{
    switch (id) {
        case ITEM_GOLD_COIN:
            return count;

        case ITEM_PLATINUM_COIN:
            return count * 100;

        case ITEM_CRYSTAL_COIN:
            return count * 10000;

        case ITEM_GOLD_NUGGET:
            return count * 1000000;

        default:
            return 0;
    }
}

in const.h under ITEM_CRYSTAL_COIN = 2160,
C++:
ITEM_GOLD_NUGGET = idhere,

luascript.cpp under registerEnum(ITEM_CRYSTAL_COIN)
C++:
registerEnum(ITEM_GOLD_NUGGET)

game.cpp replace this:
C++:
void Game::addMoney(Cylinder* cylinder, uint64_t money, uint32_t flags /*= 0*/)
{
    if (money == 0) {
        return;
    }

    uint32_t crystalCoins = money / 10000;
    money -= crystalCoins * 10000;
    while (crystalCoins > 0) {
        const uint16_t count = std::min<uint32_t>(100, crystalCoins);

        Item* remaindItem = Item::CreateItem(ITEM_CRYSTAL_COIN, count);

        ReturnValue ret = internalAddItem(cylinder, remaindItem, INDEX_WHEREEVER, flags);
        if (ret != RETURNVALUE_NOERROR) {
            internalAddItem(cylinder->getTile(), remaindItem, INDEX_WHEREEVER, FLAG_NOLIMIT);
        }

        crystalCoins -= count;
    }

    uint16_t platinumCoins = money / 100;
    if (platinumCoins != 0) {
        Item* remaindItem = Item::CreateItem(ITEM_PLATINUM_COIN, platinumCoins);

        ReturnValue ret = internalAddItem(cylinder, remaindItem, INDEX_WHEREEVER, flags);
        if (ret != RETURNVALUE_NOERROR) {
            internalAddItem(cylinder->getTile(), remaindItem, INDEX_WHEREEVER, FLAG_NOLIMIT);
        }

        money -= platinumCoins * 100;
    }

    if (money != 0) {
        Item* remaindItem = Item::CreateItem(ITEM_GOLD_COIN, money);

        ReturnValue ret = internalAddItem(cylinder, remaindItem, INDEX_WHEREEVER, flags);
        if (ret != RETURNVALUE_NOERROR) {
            internalAddItem(cylinder->getTile(), remaindItem, INDEX_WHEREEVER, FLAG_NOLIMIT);
        }
    }
}
with this:
C++:
void Game::addMoney(Cylinder* cylinder, uint64_t money, uint32_t flags /*= 0*/)
{
    if (money == 0) {
        return;
    }

    uint32_t goldNuggets = money / 1000000;
    money -= goldNuggets * 1000000;
    while (goldNuggets > 0) {
        const uint16_t count = std::min<uint32_t>(100, goldNuggets);

        Item* remaindItem = Item::CreateItem(ITEM_GOLD_NUGGET, count);

        ReturnValue ret = internalAddItem(cylinder, remaindItem, INDEX_WHEREEVER, flags);
        if (ret != RETURNVALUE_NOERROR) {
            internalAddItem(cylinder->getTile(), remaindItem, INDEX_WHEREEVER, FLAG_NOLIMIT);
        }

        goldNuggets -= count;
    }

    uint32_t crystalCoins = money / 10000;
    if (crystalCoins != 0) {
        Item* remaindItem = Item::CreateItem(ITEM_CRYSTAL_COIN, crystalCoins);

        ReturnValue ret = internalAddItem(cylinder, remaindItem, INDEX_WHEREEVER, flags);
        if (ret != RETURNVALUE_NOERROR) {
            internalAddItem(cylinder->getTile(), remaindItem, INDEX_WHEREEVER, FLAG_NOLIMIT);
        }

        money -= crystalCoins * 10000;
    }

    uint16_t platinumCoins = money / 100;
    if (platinumCoins != 0) {
        Item* remaindItem = Item::CreateItem(ITEM_PLATINUM_COIN, platinumCoins);

        ReturnValue ret = internalAddItem(cylinder, remaindItem, INDEX_WHEREEVER, flags);
        if (ret != RETURNVALUE_NOERROR) {
            internalAddItem(cylinder->getTile(), remaindItem, INDEX_WHEREEVER, FLAG_NOLIMIT);
        }

        money -= platinumCoins * 100;
    }

    if (money != 0) {
        Item* remaindItem = Item::CreateItem(ITEM_GOLD_COIN, money);

        ReturnValue ret = internalAddItem(cylinder, remaindItem, INDEX_WHEREEVER, flags);
        if (ret != RETURNVALUE_NOERROR) {
            internalAddItem(cylinder->getTile(), remaindItem, INDEX_WHEREEVER, FLAG_NOLIMIT);
        }
    }
}

in player.cpp replace this:
C++:
if (itemId != ITEM_GOLD_COIN && itemId != ITEM_PLATINUM_COIN && itemId != ITEM_CRYSTAL_COIN) {
with this:
C++:
if (itemId != ITEM_GOLD_COIN && itemId != ITEM_PLATINUM_COIN && itemId != ITEM_CRYSTAL_COIN && itemId != ITEM_GOLD_NUGGET) {
and that should be it
ignore any posts guys its working 100% thank you
 
I've added all the source changes and that gives no error but when I change my change gold file

from:


Code:
local config = {
    [ITEM_GOLD_COIN] = {changeTo = ITEM_PLATINUM_COIN},
    [ITEM_PLATINUM_COIN] = {changeBack = ITEM_GOLD_COIN, changeTo = ITEM_CRYSTAL_COIN},
    [ITEM_CRYSTAL_COIN] = {changeBack = ITEM_PLATINUM_COIN}
}

function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    local coin = config[item:getId()]
    if coin.changeTo and item.type == 100 then
        item:remove()
        player:addItem(coin.changeTo, 1)
    elseif coin.changeBack then
        item:remove(1)
        player:addItem(coin.changeBack, 100)
    else
        return false
    end
    return true
end


to this:

Code:
local config = {
    [ITEM_GOLD_COIN] = {changeTo = ITEM_PLATINUM_COIN},
    [ITEM_PLATINUM_COIN] = {changeBack = ITEM_GOLD_COIN, changeTo = ITEM_CRYSTAL_COIN},
    [ITEM_CRYSTAL_COIN] = {changeBack = ITEM_PLATINUM_COIN, changeTo = ITEM_GOLD_NUGGET},
    [ITEM_GOLD_NUGGET] = {changeBack = ITEM_CRYSTAL_COIN}
}

function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    local coin = config[item:getId()]
    if coin.changeTo and item.type == 100 then
        item:remove()
        player:addItem(coin.changeTo, 1)
    elseif coin.changeBack then
        item:remove(1)
        player:addItem(coin.changeBack, 100)
    else
        return false
    end
    return true
end

It doesnt work, error message:
[Warning - Event::checkScript] Can not load script: scripts/other/changegold.lua

did add this line in actions.xml
<action itemid="2157" script="other/changegold.lua" />


I'm using TFS 1.3, hopefully somebody understands whats wrong... Cuz it doesnt make any sense in my head!

@Delusion Read my post above please, for some reason I cant private message you...

@Delusion I managed to make the crystal coin change to gold nugget now using this script:

Code:
local items = {
   [ITEM_GOLD_COIN] = {to = ITEM_PLATINUM_COIN},
   [ITEM_PLATINUM_COIN] = {from = ITEM_GOLD_COIN, to = ITEM_CRYSTAL_COIN},
   [ITEM_CRYSTAL_COIN] = {from = ITEM_PLATINUM_COIN, to = 2157},
   [2157] = {from = ITEM_CRYSTAL_COIN},
   }
function onUse(cid, item, fromPosition, itemEx, toPosition, isHotkey)
   local coin = items[item.itemid]
   if coin then
     if(item.type == 100 and coin.to ~= nil)then
       Item(item.uid):remove()
       Player(cid):addItem(coin.to, 1)
     elseif(coin.from ~= nil)then
       Item(item.uid):remove(1)
       Player(cid):addItem(coin.from, 100)
     end
   end
   return true
end


Tho, i cannot deposit this item to the bank or buy products in shop using gold nuggets... and I dont see an error in console either!

My problems is solved. I had to rebuild the TFS as i changed source files (I as a noob wasnt aware of that) A friend of mine helped me thanks so much @Evolunia
 

Similar threads

Back
Top