Jump to content
×
×
  • Create New...
  • 0

Vault Com Limite!!


Question

Versão do Servidor: TFS - 0.3.4
Tipo de Script: actions
Código:
 
local vaultStorage = 99991 -- storage em que ficara armazenado os golds

------------------//* Functions //-------------------
local function getPlayerFreeSpace(cid) -- by MaTTch
    local checkSlots, space = {3,5,6,10}, 0
    local function getContainerFree(container)
        local free = 0
        if(not isContainer(container.uid)) then
            return free
        end
        for i = 0, (getItemInfo(container.itemid).maxItems -1) do
            local item = getContainerItem(container.uid, i)
            if(item.itemid == 0) then
                free = free + 1
            elseif(isContainer(item.uid)) then
                free = free + getContainerFree(item)
            end
        end
        return free
    end
    for _, i in ipairs(checkSlots) do
        local slotItem = getPlayerSlotItem(cid, i)
        if(i ~= CONST_SLOT_BACKPACK and slotItem.itemid == 0) then
            space = space + 1
        elseif(isContainer(slotItem.uid)) then
            space = space + getContainerFree(slotItem)
        end
    end
    return space
end

local function withdrawMoneySecurity(cid, value, storage) -- by MaTTch
    local storageMoney, countValue = getPlayerStorageValue(cid, storage), 0
    local config = {
        [1] = {18828, math.floor(value/getItemInfo(18828).worth)},
        [2] = {2160, math.floor((value/getItemInfo(2160).worth)-(math.floor(value/getItemInfo(18828).worth)*100))},
        [3] = {2152, math.floor((value/getItemInfo(2152).worth)-(math.floor(value/getItemInfo(2160).worth)*100))},
        [4] = {2148, math.floor((value/getItemInfo(2148).worth)-(math.floor(value/getItemInfo(2152).worth)*100))},
        [5] = {12416, math.floor(value%100)}
    }
    for i = 1, #config do
        local count = config[i][2]
        if(count > 0) then
            while(count > 0) do
                storageMoney = getPlayerStorageValue(cid, storage)
                local a, itemCap = count > 100 and 100 or count, getItemInfo(config[i][1]).weight
                if(getPlayerFreeCap(cid) >= (itemCap*a)) then
                    if(getPlayerFreeSpace(cid) >= 1) then
                        doPlayerAddItem(cid, config[i][1], a)
                        setPlayerStorageValue(cid, storage, (storageMoney - (getItemInfo(config[i][1]).worth * a)))
                        countValue = countValue + (getItemInfo(config[i][1]).worth * a)
                        count = count - a
                    else
                        return doPlayerSendTextMessage(cid, MESSAGE_EVENT_ADVANCE, "You do not have enough space in container. You have took "..countValue.." gold"..(countValue > 1 and "s" or "").." from vault.")
                    end
                else
                    return doPlayerSendTextMessage(cid, MESSAGE_EVENT_ADVANCE, "You do not have enough cap. You have took "..countValue.." gold"..(countValue > 1 and "s" or "").." from vault.")
                end
            end
        end
    end
    return doPlayerSendTextMessage(cid, MESSAGE_EVENT_ADVANCE, "You have took "..countValue.." gold"..(countValue > 1 and "s" or "").." from vault.")
end
------------------//* End Functions //-------------------


function onUse(cid, item, fromPosition, itemEx, toPosition)
    local cidMoney, vaultMoney = getPlayerMoney(cid), getPlayerStorageValue(cid, vaultStorage)
    if(vaultMoney <= 0) then
        if(cidMoney <= 0) then
            return doPlayerSendTextMessage(cid, MESSAGE_EVENT_ADVANCE, "You do not have money.")
        end
        doPlayerRemoveMoney(cid, cidMoney)
        setPlayerStorageValue(cid, vaultStorage, cidMoney)
        doPlayerSendTextMessage(cid, MESSAGE_EVENT_ADVANCE, "You have added "..cidMoney.." gold"..(cidMoney > 1 and "s" or "").." to vault. Now your money is kept in the vault chest, you can take it whenever you want.")
    else
        withdrawMoneySecurity(cid, vaultMoney, vaultStorage)
    end
    return true
end

Galerinha seguinte....
quero colocar um limite maximo de money no Vault, tipo uns 20KK apenas seria possivel?

Link to post
Share on other sites

0 answers to this question

Recommended Posts

There have been no answers to this question yet

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now