• 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!
  • 2026 staff recruitment is open! Check it out and consider applying!

Solved Changegold issues. 1.2

Caduceus

Unknown Member
Joined
May 10, 2010
Messages
321
Solutions
2
Reaction score
24
Did I miss something here? I have all of the source edits in for currency changes. I can use all of the forms of currency to purchase goods from an npc. However, I cannot get scarab coin to convert back to gold bar. all other conversions work.

changegold.lua
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_BAR},
    [ITEM_GOLD_BAR] = {changeBack = ITEM_CRYSTAL_COIN, changeTo = ITEM_SCARAB_COIN},
    [ITEM_SCARAB_COIN] = {changeBack = ITEM_GOLD_BAR}
}

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

item.cpp
Code:
int32_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_BAR:
            return count * 1000000;

        case ITEM_SCARAB_COIN:
            return count * 100000000;

        default:
            return 0;
    }
}

luascript.cpp
Code:
registerEnum(ITEM_GOLD_BAR)
registerEnum(ITEM_SCARAB_COIN)

player.cpp
Code:
bool Player::updateSaleShopList(const Item* item)
{
    uint16_t itemId = item->getID();
    if (itemId != ITEM_GOLD_COIN && itemId != ITEM_PLATINUM_COIN && itemId != ITEM_CRYSTAL_COIN && itemId != ITEM_GOLD_BAR && itemId != ITEM_SCARAB_COIN) {
        auto it = std::find_if(shopItemList.begin(), shopItemList.end(), [itemId](const ShopInfo& shopInfo) { return shopInfo.itemId == itemId && shopInfo.sellPrice != 0; });
        if (it == shopItemList.end()) {
            const Container* container = item->getContainer();
            if (!container) {
                return false;
            }

            const auto& items = container->getItemList();
            return std::any_of(items.begin(), items.end(), [this](const Item* containerItem) {
                return updateSaleShopList(containerItem);
            });
        }

const.h
Code:
ITEM_GOLD_BAR = 15515,
ITEM_SCARAB_COIN = 2159,

game.cpp
Code:
void Game::addMoney(Cylinder* cylinder, uint64_t money, uint32_t flags /*= 0*/)
{
 
uint32_t scarab = money / 100000000;
    money -= scarab * 100000000;
    if (scarab > 0) {
        Item* remaindItem = Item::CreateItem(ITEM_SCARAB_COIN, std::min<int32_t>(100, scarab));

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

        scarab -= std::min<int32_t>(100, scarab);
    }

    uint32_t bar = money / 1000000;
    money -= bar * 1000000;
    if (bar > 0) {
        Item* remaindItem = Item::CreateItem(ITEM_GOLD_BAR, std::min<int32_t>(100, bar));

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

        bar -= std::min<int32_t>(100, bar);
    }
 
Last edited:
Are they even defined?

yes, I can use all of the currency in npc's. I receive the correct change back, soo I assume it is defined correctly. Updated main post with source edits. Maybe I missed something.
 
Last edited:
First, the condition on the first file does not make much sense, how are you evaluation "chantoto" as Boolean, if they have value assigned to it? First, you should make a homogenous table, if some items has changeto property, make them all have it.

Second, converting from shop, from click, from what? There are many files out there, what are we exactling talking about?
 
First, the condition on the first file does not make much sense, how are you evaluation "chantoto" as Boolean, if they have value assigned to it? First, you should make a homogenous table, if some items has changeto property, make them all have it.

Second, converting from shop, from click, from what? There are many files out there, what are we exactling talking about?

I don't understand what you are trying to say here. All I am simply trying to do it convert Scarab Coin back to a Gold Bars.

Code:
[ITEM_GOLD_BAR] = {changeBack = ITEM_CRYSTAL_COIN, changeTo = ITEM_SCARAB_COIN},
[ITEM_SCARAB_COIN] = {changeBack = ITEM_GOLD_BAR}
 
Back
Top