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

How to add new currency?

woeterman94

Inventor
Joined
Oct 2, 2008
Messages
84
Reaction score
6
Location
Belgium
Hi,

I looked on the forum for some tutorials about how to add new currency to my server

(like if you right click 100 crystal coins you get a new coin)

I'm using TFS 1.0

Problems:
- The coin must be usable in store / npc's
- I cannot find global.lua in my server data directory
- When I try to add "worth" in items.xml I get an error. 'Unkown key value"

Can anyone please help me?
 
Worth isn't necessary as the prices for the items can be set in the npc scripts. The script on that link doesn't even read from the items.xml in any way. So that being said, the script should still work. Did you not try it atleast? If so, what happened? Did you get an error, if so what did it say, I'm pretty sure it should work with 1.0, wouldn't work for 1.1 without a minor adjustment, pretty sure it will work for 1.0.

If you want you can even make the description include a worth.

The action script is easy, try learning the lua if you don't know, since this is support and not requests board, I assume that is your desire is to learn how to do it yourself right?

Please check the tutorial section it has great starter tutorials for scripting. Tutorials point is another great site, just do a search on google or something with keywords tutorialspoint and lua, you will find it.
 
Thank you Codinablack for your advice about learning programming...
I know how to make the coins change, but I want people to be able to pay with the coin.
I'll say it again. Right clicking on the 100 crystal coins turns the coin into the new currency item but it is not yet possible to buy something with that coin.


TFS 1.0 is a bit different from the 0.3 version because of some missing files (constants.lua does not contain a [ITEM_CRYSTAL_COIN] for example)



So I need to recompile then?
 
No. Add the receiver to NPC.
If player has gold nugget then
100 crystal coins - item price
Remove gold nugget.
 
add the nugget system here: modules.lua
Before he removes money from player, turn the gold nugget into virtual 100 crystal coins.
Code:
    function ShopModule:callbackOnBuy(cid, itemid, subType, amount, ignoreCap, inBackpacks)
        local shopItem = self:getShopItem(itemid, subType)
        if shopItem == nil then
            error("[ShopModule.onBuy] shopItem == nil")
            return false
        end

        if shopItem.buy == -1 then
            error("[ShopModule.onSell] attempt to buy a non-buyable item")
            return false
        end

        local backpack = 1988
        local totalCost = amount * shopItem.buy
        if(inBackpacks) then
            totalCost = isItemStackable(itemid) == TRUE and totalCost + 20 or totalCost + (math.max(1, math.floor(amount / getContainerCapById(backpack))) * 20)
        end

        local parseInfo = {
            [TAG_PLAYERNAME] = getPlayerName(cid),
            [TAG_ITEMCOUNT] = amount,
            [TAG_TOTALCOST] = totalCost,
            [TAG_ITEMNAME] = shopItem.name
        }

        if(getPlayerMoney(cid) < totalCost) then
            local msg = self.npcHandler:getMessage(MESSAGE_NEEDMONEY)
            msg = self.npcHandler:parseMessage(msg, parseInfo)
            doPlayerSendCancel(cid, msg)
            return false
        end

        local subType = shopItem.subType or 1
        local a, b = doNpcSellItem(cid, itemid, amount, subType, ignoreCap, inBackpacks, backpack)
        if(a < amount) then
            local msgId = MESSAGE_NEEDMORESPACE
            if(a == 0) then
                msgId = MESSAGE_NEEDSPACE
            end

            local msg = self.npcHandler:getMessage(msgId)
            parseInfo[TAG_ITEMCOUNT] = a
            msg = self.npcHandler:parseMessage(msg, parseInfo)
            doPlayerSendCancel(cid, msg)
            self.npcHandler.talkStart[cid] = os.time()

            if(a > 0) then
                doPlayerRemoveMoney(cid, ((a * shopItem.buy) + (b * 20)))
                return true
            end

            return false
        else
            local msg = self.npcHandler:getMessage(MESSAGE_BOUGHT)
            msg = self.npcHandler:parseMessage(msg, parseInfo)
            doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, msg)
            doPlayerRemoveMoney(cid, totalCost)
            self.npcHandler.talkStart[cid] = os.time()
            return true
        end
    end

EDIT:
im only assuming that: Player(cid):getMoney()
gives a number value what makes sense. not some kind of annoying table or string.

if it does give makes no sense string then yeah, source edit must be done.
OR selfmade goldSystem
 
Last edited:
Back
Top