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

Problem with scripts for leavers tfs 1.3

vexler222

Active Member
Joined
Apr 22, 2012
Messages
714
Solutions
15
Reaction score
46
Hi, i have problem with this script, all work good but when player have full backpack, he can buy item and he lose money but didn't get item to mailbox


Lua:
local items = Action()
local levers = {
    [2655] = {id = 9693, count = 1, value = 45},
    [2656] = {id = 12411, count = 1, value = 50},
    [2657] = {id = 12640, count = 1, value = 100},
    [2658] = {id = 8978, count = 1, value = 0},
    [2659] = {id = 12544, count = 1, value = 190},
}

function items.onUse(player, item, fromPosition, target, toPosition, isHotkey)

    local choose = levers[item.actionid]

    if not choose then
        return false
    end

    if player:getStorageValue(77124) >= os.time() then
        player:sendCancelMessage("Você precisa esperar 2 segundos entre uma compra e outa.")
        player:getPosition():sendMagicEffect(CONST_ME_POFF)
        return true
    end

    local userItem = ItemType(choose.id)
    local itemWeight = userItem:getWeight() * choose.count

    if player:getFreeCapacity() < itemWeight then
        player:sendCancelMessage("Você não tem espaço suficiente.")
        player:getPosition():sendMagicEffect(CONST_ME_POFF)
        return true
    end

    if not player:removeMoney(choose.value) then
        player:sendCancelMessage("Você não tem dinheiro suficiente.")
        player:getPosition():sendMagicEffect(CONST_ME_POFF)
        return true
    end
   
    local buy = Game.createItem(choose.id, choose.count)
    if player:addItemEx(buy) == RETURNVALUE_CONTAINERNOTENOUGHROOM then
        sendMailbox(player:getId(), choose.id, choose.count)
        player:sendTextMessage(MESSAGE_STATUS_BLUE_LIGHT, "Você não possui espaço em sua backpack e seu item foi enviado para o mailbox.")
    end

    player:sendCancelMessage("Você comprou ".. choose.count .."x ".. userItem:getName() ..".")
    player:getPosition():sendMagicEffect(29)
    player:setStorageValue(77124, os.time() + 2)

    item:transform(item.itemid == 1945 and 1946 or 1945)

    return true
end

items:aid(2655,2656,2657,2658,2659)
items:register()
 
Last edited by a moderator:
Solution
Try
Lua:
local items = Action()
local levers = {
    [2655] = {reward = 9693, count = 1, prince = 45},
    [2656] = {reward = 12411, count = 1, prince = 50},
    [2657] = {reward = 12640, count = 1, prince = 100},
    [2658] = {reward = 8978, count = 1, prince = 0},
    [2659] = {reward = 12544, count = 1, prince = 190},
}

function items.onUse(player, item, fromPosition, target, toPosition, isHotkey)

local config = levers[item.actionid]
     if player:getStorageValue(77124) > os.time() then
         player:getPosition():sendMagicEffect(CONST_ME_POFF)
         return player:sendCancelMessage("Você precisa esperar 2 segundos entre uma compra e outa.")
     end
    
    
    local playerCap = player:getFreeCapacity()
    local bp =...
Yeah, that sendMailbox function is custom.
I'm inclined to believe it is the issue as well.

Post the sendMailbox function, please.
 
Yeah, that sendMailbox function is custom.
I'm inclined to believe it is the issue as well.

Post the sendMailbox function, please.

Okey, i found the function in datapack where i find script, and i added it to my global.xml but still not working

Lua:
sendMailbox = function(playerId, id, count)
    local player = Player(playerId)

    if not id then
        print("Erro falta id (sendMailbox) - global.lua")
        return false
    elseif not count then
        print("Erro falta count (sendMailbox) - global.lua")
        return false
    end

    local item = Game.createItem(tonumber(id), tonumber(count))

    if player then
        player:getInbox():addItemEx(item, INDEX_WHEREEVER, FLAG_NOLIMIT)
        player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "Você recebeu ".. tonumber(count).. "x ".. ItemType(tonumber(id)):getName() .." no Mailbox! Confira no seu Depot!")
        player:save()
    else
        player = Player(playerId, true)
        player:getInbox():addItemEx(item, INDEX_WHEREEVER, FLAG_NOLIMIT)
        player:save()
        player:delete()
    end
    return true
end
 
Last edited by a moderator:
It's your custom function. xD

I've no idea where you've placed it.

data/lib/core is where I'd place it tho.

Not my xD i found this script in brazil datapack

here is function from global.xml

Lua:
sendMailbox = function(playerId, id, count)
    local player = Player(playerId)

    if not id then
        print("Erro falta id (sendMailbox) - global.lua")
        return false
    elseif not count then
        print("Erro falta count (sendMailbox) - global.lua")
        return false
    end

    local item = Game.createItem(tonumber(id), tonumber(count))

    if player then
        player:getInbox():addItemEx(item, INDEX_WHEREEVER, FLAG_NOLIMIT)
        player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "Você recebeu ".. tonumber(count).. "x ".. ItemType(tonumber(id)):getName() .." no Mailbox! Confira no seu Depot!")
        player:save()
    else
        player = Player(playerId, true)
        player:getInbox():addItemEx(item, INDEX_WHEREEVER, FLAG_NOLIMIT)
        player:save()
        player:delete()
    end
    return true
end
 
Last edited by a moderator:
Try
Lua:
local items = Action()
local levers = {
    [2655] = {reward = 9693, count = 1, prince = 45},
    [2656] = {reward = 12411, count = 1, prince = 50},
    [2657] = {reward = 12640, count = 1, prince = 100},
    [2658] = {reward = 8978, count = 1, prince = 0},
    [2659] = {reward = 12544, count = 1, prince = 190},
}

function items.onUse(player, item, fromPosition, target, toPosition, isHotkey)

local config = levers[item.actionid]
     if player:getStorageValue(77124) > os.time() then
         player:getPosition():sendMagicEffect(CONST_ME_POFF)
         return player:sendCancelMessage("Você precisa esperar 2 segundos entre uma compra e outa.")
     end
    
    
    local playerCap = player:getFreeCapacity()
    local bp = player:getSlotItem(CONST_SLOT_BACKPACK)
    local freeSlotsInBp = bp and math.max(1, bp:getEmptySlots(bp)) or 0
    if playerCap >= ItemType(item.itemid):getWeight(item.type or 1) then
        if freeSlotsInBp > 1 then
        local info, count = ItemType(config.reward), config.count
            if count > 1 then
                text = count .. " " .. info:getPluralName()
            else
                text = info:getArticle() .. " " .. info:getName()
            end
        local weight = ItemType(config.reward):getWeight()
            if player:getFreeCapacity() < weight then
                player:getPosition():sendMagicEffect(CONST_ME_POFF)
                player:sendCancelMessage(string.format('%s weighing %.2f oz. You have no capacity.', text, (weight / 100)))
            else
                if player:getMoney() >= config.prince then
                    player:removeMoney(config.prince)
                    text = "You have received " .. text .. "."
                    player:addItem(config.reward)
                    player:sendTextMessage(MESSAGE_INFO_DESCR, text)
                    player:setStorageValue(77124, os.time() + 2)
                else
                    player:getPosition():sendMagicEffect(CONST_ME_POFF)
                    player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You dont have ".. config.prince .." gold coins.")
                    return true
                end
            end
     else
            player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "Você não possui espaço em sua backpack.")
    return true
        end
    end
 return true
end
items:aid(2655,2656,2657,2658,2659)
items:register()
 
Solution
Back
Top