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

Lua NPC Banks understand "1k", "1kk", "8kk"

kito2

www.masteria.net
Joined
Mar 9, 2009
Messages
3,764
Solutions
1
Reaction score
227
Location
Chile, Santiago
Hey all,

On my OT an idea has came to our minds and is to let NPC Banks understand money "strings", like 1kk, 8kk, etc.

We have developed this function:

LUA:
function testMoney(str)
    if (tonumber( str)) then
        return tonumber(str)
    end

    local number = string.match(str, '^%d+')
    if (number) then
        local ks = string.match(str, '[k]+')
        if (ks and ks:len() > 0) then
           
            local exp = 1000 ^ ks:len()

            return number * exp
        end
    end

    return 0
end

Now the idea would be to integrate this function to all strings messages related to NPC Banks.

Right now I am in a middle of lot of work, so I am not able to continue more than this right now. So I am creating this post, cause it can be an idea which more people would like to work on, integrate and finish it.

Thanks in advice if you want to help with it ;)
 
If you are using the default banker NPC (scripts/bank.lua) you could simply do this, I suppose;

Change
LUA:
count[cid] = getCount(msg)
npcHandler:say('Would you really like to deposit ' .. count[cid] .. ' gold?', cid)
Topic[cid] = 2
to this
LUA:
count[cid] = convertMoney(msg)
npcHandler:say('Would you really like to deposit ' .. count[cid] .. ' gold?', cid)
Topic[cid] = 2

Don't forget to add your function to the script too, and rename i to convertMoney
 
Thanks, but I think this two functions should be merged in to one:

LUA:
function stringToMoney(str)
    if (tonumber( str)) then
        return tonumber(str)
    end

    local number = string.match(str, '^%d+')
    if (number) then
        local ks = string.match(str, '[k]+')
        if (ks and ks:len() > 0) then
           
            local exp = 1000 ^ ks:len()

            return number * exp
        end
    end

    return 0
end

LUA:
function getMoneyCount(string)
    local b, e = string:find("%d+")
    local money = b and e and tonumber(string:sub(b, e)) or -1
    if isValidMoney(money) then
        return money
    end
    return -1
end
 
LUA:
function strToMoney(str)

    local digits = string.gsub(str, "%D", "")

    if tonumber(digits) == nil or tonumber(digits) == 0 then
        return 0
    end

    local converted = string.gsub(str, "k", "000")
    local extracted = string.gsub(converted, "[^0]", "")

    return tonumber(digits .. extracted)
end
 
Back
Top