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

TFS 1.X+ TFS 1.2 - Change crystal coin > golden bar

Forkz

Well-Known Member
Joined
Jun 29, 2020
Messages
380
Solutions
1
Reaction score
89
hello,
This error is happening in the distro when I try to change the golden bar to crystal coin.

otland.png
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 = 7503},
    [ITEM_GOLDEN_BAR] = {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


I'm using these codes below in the source:

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_GOLDEN_BAR:
            return count * 1000000;

        default:
            return 0;
    }
}

const.h
C++:
    ITEM_GOLDEN_BAR = 7503,

luascript.cpp
C++:
    registerEnum(ITEM_GOLDEN_BAR)

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

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

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

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

        goldenBars -= 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);
        }
    }
}
 
you could just edit the change gold in actions
Post automatically merged:

if getPlayerItemCount(cid, <IDITEM>) == 100 then
if player:removeItem(<IDITEM>, 1) then
player:addItem(<IDITEM>, 1)
 
Last edited:
you could just edit the change gold in actions
Post automatically merged:

if getPlayerItemCount(cid, <IDITEM>) == 100 then
if player:removeItem(<IDITEM>, 1) then
player:addItem(<IDITEM>, 1)
I didn't understand, could I fix the script?
 
at the first line add this
local ITEM_GOLDEN_BAR = 7053

Continues with the same error!
on source there is one more code that I didn't find on my source see below.

player.cpp
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_GOLDEN_BAR) {

is that the reason that is cauing this error?
 
Continues with the same error!
on source there is one more code that I didn't find on my source see below.

player.cpp
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_GOLDEN_BAR) {

is that the reason that is cauing this error?
i don't think so, idk how you couldn't find it, check your player.h maybe it was transferred in your version, tbh i suggest changing this distro.

EDIT --
try to remove 7503 and add ITEM_GOLDEN_BAR, don't forget to reload the actions before testing and the line i sent you put it in the top even if it didn't work
 
at the first line add this
local ITEM_GOLDEN_BAR = 7053

if you are using bank system or any money included system it might bugs, like giving you less money or more than you should take while withdrawing, you can fix it using this C++ - Money currency little bug (https://otland.net/threads/money-currency-little-bug.259681/)
Regarding the deposit and purchase of items with "ITEM_GOLDEN_BAR" is working correctly, the only problem is that it does not "transform" into "ITEM_CRYSTAL_COIN".
 
solved, I used a 'coin' check, and it worked, below is the correct script for anyone who wants to use it.

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_GOLDEN_BAR},
    [ITEM_GOLDEN_BAR] = {changeBack = ITEM_CRYSTAL_COIN}
}

function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    local coin = config[item:getId()]
        if(not coin) then
        return false
    end
    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
 
What is this Coin check that you speak about? Care to share maybe? I cant seem to be able to fix the issue, i just changed all ids to Gold ingot insted of Golden bar since i dont have that item in my TFS 1.3. My error below.

Any tip would be nice !
 

Attachments

Back
Top