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

RevScripts Get currency name?

Tibia Demon

New Member
Joined
Oct 15, 2020
Messages
33
Reaction score
3
Location
Tibia
Is it possible instead of returning the amount of gold coins to return the money name? like
You have bought an amulet of loss for 5 crystal coins, 3 platinum coins and 70 gold coins
I tried to add it to script like this.

Lua:
  if not player:removeTotalMoney(config.shopItem.cost) then
            player:sendTextMessage(MESSAGE_INFO_DESCR, 'You need '.. config.shopItem.cost ..' gold coins to buy '.. config.itemType:getName() .. '.')
            player:getPosition():sendMagicEffect(CONST_ME_POFF)
            return false
        end
Here is the full script
Lua:
local shop = {
    [13337] = {id = 12325, cost = 20, count = 1},
    [2081] = {id = 8300, cost = 30, count = 1},
    [2082] = {id = 12662, cost = 50, count = 5},
}

local AolSHOP = Action()
function AolSHOP.onUse(player, item, fromPosition, target, toPosition, isHotkey)
    local config = {}
    local AolSHOP = shop[item:getActionId()]
    
    config.shopItem = shop[item:getActionId()]
    config.itemType = ItemType(config.shopItem.id)

        if not player:removeTotalMoney(config.shopItem.cost) then
            player:sendTextMessage(MESSAGE_INFO_DESCR, 'You need '.. config.shopItem.cost ..' gold coins to buy '.. config.itemType:getName() .. '.')
            player:getPosition():sendMagicEffect(CONST_ME_POFF)
            return false
        end
        player:addItem(config.shopItem.id, config.shopItem.count)
        player:sendTextMessage(MESSAGE_INFO_DESCR, 'You bought a '.. config.itemType:getName() .. '.')
        player:getPosition():sendMagicEffect(CONST_ME_MAGIC_BLUE)
return true
end

for k, v in pairs(shop) do
    AolSHOP:aid(k)
end
AolSHOP:register()
 
Solution
Works very good.
I have another question related, is it possible to add this to like global.lua or lib files so instead of adding all the lines to every script with [removeMoney] I can just write ".. str .."?
It is possible, but you will have to handle the other parts of the message by yourself.
Code:
function getCoinString(price)
    local str = ""
    local cc = price - (price % 10000)
    local pc = price - cc - (price % 100)
    local gc = price - cc - pc

    if cc ~= 0 then
        str = str .. cc / 10000 .. " crystal coins"
    end
    if pc ~= 0 then
        if cc ~= 0 and gc == 0 then
            str = str .. " and "
        elseif cc ~= 0 and gc ~= 0 then...

dami1310

◄ Unidentified ►
Joined
Jan 27, 2013
Messages
590
Solutions
8
Reaction score
500
Location
Poland
Try it:
Code:
local str = "You have bought " .. config.itemType:getName() .. " for "
local cc = config.shopItem.cost - (config.shopItem.cost % 10000)
local pc = config.shopItem.cost - cc - (config.shopItem.cost % 100)
local gc = config.shopItem.cost - cc - pc

if cc ~= 0 then
    str = str .. cc / 10000 .. " crystal coins"
end
if pc ~= 0 then
    if cc ~= 0 and gc == 0 then
        str = str .. " and "
    elseif cc ~= 0 and gc ~= 0 then
        str = str .. ", "
    end
    str = str .. pc / 100 .. " platinum coins"
end
if gc ~= 0 then
    if cc ~= 0 or pc ~= 0 then
        str = str .. " and "
    end
    str = str .. gc .. " gold coins"
end

str = str .. "."
player:sendTextMessage(MESSAGE_INFO_DESCR, str)
 
OP
Tibia Demon

Tibia Demon

New Member
Joined
Oct 15, 2020
Messages
33
Reaction score
3
Location
Tibia
I tried by adding it like this.
Lua:
local shop = {
    [13337] = {id = 12325, cost = 20, count = 1},
    [2081] = {id = 8300, cost = 30, count = 1},
    [2082] = {id = 12662, cost = 50, count = 5},
}

local AolSHOP = Action()
function AolSHOP.onUse(player, item, fromPosition, target, toPosition, isHotkey)
    local config = {}
    local AolSHOP = shop[item:getActionId()]
    
    config.shopItem = shop[item:getActionId()]
    config.itemType = ItemType(config.shopItem.id)
    local str = "You have bought " .. config.itemType:getName() .. " for "
    local cc = config.shopItem.cost - (config.shopItem.cost % 10000)
    local pc = config.shopItem.cost - cc - (config.shopItem.cost % 100)
    local gc = config.shopItem.cost - cc - pc

        if cc ~= 0 then
            str = str .. cc / 10000 .. " crystal coins"
        end
        if pc ~= 0 then
        if cc ~= 0 and gc == 0 then
            str = str .. " and "
        elseif cc ~= 0 and gc ~= 0 then
            str = str .. ", "
        end
            str = str .. pc / 100 .. " platinum coins"
        end
        if gc ~= 0 then
        if cc ~= 0 or pc ~= 0 then
            str = str .. " and "
        end
            str = str .. gc .. " gold coins"
        end

            str = str .. "."
            player:sendTextMessage(MESSAGE_INFO_DESCR, str)

        if not player:removeTotalMoney(config.shopItem.cost) then
            player:sendTextMessage(MESSAGE_INFO_DESCR, 'You need '.. config.shopItem.cost ..' '.. str ..' to buy '.. config.itemType:getName() .. '.')
            player:getPosition():sendMagicEffect(CONST_ME_POFF)
            return false
        end
        player:addItem(config.shopItem.id, config.shopItem.count)
        player:sendTextMessage(MESSAGE_INFO_DESCR, 'You bought a '.. config.itemType:getName() .. '.')
        player:getPosition():sendMagicEffect(CONST_ME_MAGIC_BLUE)
return true
end

for k, v in pairs(shop) do
    AolSHOP:aid(k)
end
AolSHOP:register()
but it sends wrong text message, both messages at same time [I don't have any money on character].
at same time.PNG
 

Xikini

I whore myself out for likes
Support Team
Joined
Nov 17, 2010
Messages
5,352
Solutions
350
Reaction score
3,463
I tried by adding it like this.
Lua:
local shop = {
    [13337] = {id = 12325, cost = 20, count = 1},
    [2081] = {id = 8300, cost = 30, count = 1},
    [2082] = {id = 12662, cost = 50, count = 5},
}

local AolSHOP = Action()
function AolSHOP.onUse(player, item, fromPosition, target, toPosition, isHotkey)
    local config = {}
    local AolSHOP = shop[item:getActionId()]
   
    config.shopItem = shop[item:getActionId()]
    config.itemType = ItemType(config.shopItem.id)
    local str = "You have bought " .. config.itemType:getName() .. " for "
    local cc = config.shopItem.cost - (config.shopItem.cost % 10000)
    local pc = config.shopItem.cost - cc - (config.shopItem.cost % 100)
    local gc = config.shopItem.cost - cc - pc

        if cc ~= 0 then
            str = str .. cc / 10000 .. " crystal coins"
        end
        if pc ~= 0 then
        if cc ~= 0 and gc == 0 then
            str = str .. " and "
        elseif cc ~= 0 and gc ~= 0 then
            str = str .. ", "
        end
            str = str .. pc / 100 .. " platinum coins"
        end
        if gc ~= 0 then
        if cc ~= 0 or pc ~= 0 then
            str = str .. " and "
        end
            str = str .. gc .. " gold coins"
        end

            str = str .. "."
            player:sendTextMessage(MESSAGE_INFO_DESCR, str)

        if not player:removeTotalMoney(config.shopItem.cost) then
            player:sendTextMessage(MESSAGE_INFO_DESCR, 'You need '.. config.shopItem.cost ..' '.. str ..' to buy '.. config.itemType:getName() .. '.')
            player:getPosition():sendMagicEffect(CONST_ME_POFF)
            return false
        end
        player:addItem(config.shopItem.id, config.shopItem.count)
        player:sendTextMessage(MESSAGE_INFO_DESCR, 'You bought a '.. config.itemType:getName() .. '.')
        player:getPosition():sendMagicEffect(CONST_ME_MAGIC_BLUE)
return true
end

for k, v in pairs(shop) do
    AolSHOP:aid(k)
end
AolSHOP:register()
but it sends wrong text message, both messages at same time [I don't have any money on character].
View attachment 59477
You're close. xP

Try this
Lua:
local shop = {
    [13337] = {id = 12325, cost = 20, count = 1},
    [2081] = {id = 8300, cost = 30, count = 1},
    [2082] = {id = 12662, cost = 50, count = 5},
}

local AolSHOP = Action()
function AolSHOP.onUse(player, item, fromPosition, target, toPosition, isHotkey)
    local config = {}
    local AolSHOP = shop[item:getActionId()]
    
    config.shopItem = shop[item:getActionId()]
    config.itemType = ItemType(config.shopItem.id)
    local str = ""
    local cc = config.shopItem.cost - (config.shopItem.cost % 10000)
    local pc = config.shopItem.cost - cc - (config.shopItem.cost % 100)
    local gc = config.shopItem.cost - cc - pc
    
    if cc ~= 0 then
        str = str .. cc / 10000 .. " crystal coins"
    end
    if pc ~= 0 then
    if cc ~= 0 and gc == 0 then
        str = str .. " and "
    elseif cc ~= 0 and gc ~= 0 then
        str = str .. ", "
    end
        str = str .. pc / 100 .. " platinum coins"
    end
    if gc ~= 0 then
    if cc ~= 0 or pc ~= 0 then
        str = str .. " and "
    end
        str = str .. gc .. " gold coins"
    end
    
    if not player:removeTotalMoney(config.shopItem.cost) then
        player:sendTextMessage(MESSAGE_INFO_DESCR, "You need ".. str .." to buy ".. config.itemType:getName() .. ".")
        player:getPosition():sendMagicEffect(CONST_ME_POFF)
        return false
    end
    player:addItem(config.shopItem.id, config.shopItem.count)
    player:sendTextMessage(MESSAGE_INFO_DESCR, "You have bought " .. config.itemType:getName() .. " for " .. str .. ".")
    player:getPosition():sendMagicEffect(CONST_ME_MAGIC_BLUE)
    return true
end

for k, v in pairs(shop) do
    AolSHOP:aid(k)
end
AolSHOP:register()
 
OP
Tibia Demon

Tibia Demon

New Member
Joined
Oct 15, 2020
Messages
33
Reaction score
3
Location
Tibia
Works very good.
I have another question related, is it possible to add this to like global.lua or lib files so instead of adding all the lines to every script with [removeMoney] I can just write ".. str .."?
 

dami1310

◄ Unidentified ►
Joined
Jan 27, 2013
Messages
590
Solutions
8
Reaction score
500
Location
Poland
Works very good.
I have another question related, is it possible to add this to like global.lua or lib files so instead of adding all the lines to every script with [removeMoney] I can just write ".. str .."?
It is possible, but you will have to handle the other parts of the message by yourself.
Code:
function getCoinString(price)
    local str = ""
    local cc = price - (price % 10000)
    local pc = price - cc - (price % 100)
    local gc = price - cc - pc

    if cc ~= 0 then
        str = str .. cc / 10000 .. " crystal coins"
    end
    if pc ~= 0 then
        if cc ~= 0 and gc == 0 then
            str = str .. " and "
        elseif cc ~= 0 and gc ~= 0 then
            str = str .. ", "
        end
        str = str .. pc / 100 .. " platinum coins"
    end
    if gc ~= 0 then
        if cc ~= 0 or pc ~= 0 then
            str = str .. " and "
        end
        str = str .. gc .. " gold coins"
    end
    
    return str
end

Now if you want to use it you can do it like that for example:
Code:
player:sendTextMessage(MESSAGE_INFO_DESCR, 'You need ' .. getCoinString(getconfig.shopItem.cost) .. ' to buy '.. config.itemType:getName() .. '.')
 
Solution

Xikini

I whore myself out for likes
Support Team
Joined
Nov 17, 2010
Messages
5,352
Solutions
350
Reaction score
3,463
Works very good.
I have another question related, is it possible to add this to like global.lua or lib files so instead of adding all the lines to every script with [removeMoney] I can just write ".. str .."?
Of course.
Just make a function that converts a number into a string.
Put this function into any global area, then use it like any other function.

Lua:
function convertCostIntoMoneyString(number)
    local str = ""
    local cc = number - (number % 10000)
    local pc = number - cc - (number % 100)
    local gc = number - cc - pc
    if cc ~= 0 then
        str = str .. cc / 10000 .. " crystal coins"
    end
    if pc ~= 0 then
    if cc ~= 0 and gc == 0 then
        str = str .. " and "
    elseif cc ~= 0 and gc ~= 0 then
        str = str .. ", "
    end
        str = str .. pc / 100 .. " platinum coins"
    end
    if gc ~= 0 then
    if cc ~= 0 or pc ~= 0 then
        str = str .. " and "
    end
        str = str .. gc .. " gold coins"
    end
    return str
end
 
Top