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.
changegold.lua
I'm using these codes below in the source:
item.cpp
const.h
luascript.cpp
game.cpp
This error is happening in the distro when I try to change the golden bar to crystal coin.
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);
}
}
}