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

Lua Mail System Limit

LeOnArd0

Member
Joined
Jan 24, 2010
Messages
76
Reaction score
14
Hello guys!

I would like to implement a system to limit the sending of parcels in mailboxes with +500 items inside.

Could someone help me with an idea of a script that counts how many items are inside the parcel and does not accept the shipment (it can fall on top of the mailbox or before it drops, it gives a message warning that there are +500 items inside).

I know it's a stopgap solution, but I believe that the official function that was implemented by tibia itself would be more complex, right?

Tibia solution for mail (but no have limit of items inside):
  • Have you sent a lot of mail recently? There is a muting system in place to prevent mail spam. The following rules apply for mass sending of mail:
    • You cannot send to a single recipient more than 10 times within an hour.
    • You cannot send to anyone more than 20 times within 10 minutes.
    • You cannot send to anyone more than 100 times within a day.

Thank you very much!!
Leo
 
Try this

data/scripts

Lua:
local parcelId = 2595
local parcelItemCap = 500

local parcelMailingItemLimit = EventCallback

parcelMailingItemLimit.onMoveItem = function(self, item, count, fromPosition, toPosition, fromCylinder, toCylinder)
    if item:getId() ~= parcelId then
        print("Not a parcel being moved.")
        return true
    end
 
    if toPosition.x == CONTAINER_POSITION then
        print("Parcel moved to a container.")
        return true
    end
 
    local mailboxPosition = Position(toPosition)
    if not mailboxPosition then
        print("Parcel attempted to be moved to a position in the void?")
        return true
    end
 
    local mailboxTile = Tile(mailboxPosition)
    if not mailboxTile then
        print("Parcel attempted to be moved to a tile in the void?")
        return true
    end
 
    local mailbox = mailboxTile:getItemByType(ITEM_TYPE_MAILBOX)
    if mailbox == nil then
        print("Parcel was moved to a location without a mailbox.")
        return true
    end
 
    local parcelItems = item:getItems(true)
    if #parcelItems > parcelItemCap then
        print("The parcel was attempted to be sent, however it is holding too many items. (" .. #parcelItems .. "/" .. parcelItemCap .. ")")
        return false
    end
 
    print("Parcel sent successfully.")
    return true
end

parcelMailingItemLimit:register()
 
Last edited:
Hi @Xikini

Thanks for the answer.

Return this error:
2023-04-06_16-25-31.692703 Lua Script Error: [Event Interface]
2023-04-06_16-25-31.692953 data/events/scripts/player.lua:player@onMoveItem
2023-04-06_16-25-31.693191 /home/Servidor/data/scripts/parcel.lua:29: attempt to index global 'tile' (a nil value)
2023-04-06_16-25-31.693286 stack traceback:
2023-04-06_16-25-31.693368 [C]: in function '__index'
2023-04-06_16-25-31.693450 /home/Servidor/data/scripts/parcel.lua:29: in function 'callback'
2023-04-06_16-25-31.693658 /home/Servidor/data/scripts/lib/event_callbacks.lua:131: in function </home/Servidor/data/scripts/lib/event_callbacks.lua:124>

P.S: Parcel ID is 2595 xd
 
Hi @Xikini

Thanks for the answer.

Return this error:


P.S: Parcel ID is 2595 xd
change
Lua:
local mailbox = tile:getItemByType(ITEM_TYPE_MAILBOX)
to
Lua:
local mailbox = mailboxTile:getItemByType(ITEM_TYPE_MAILBOX)

or just copy code from above. I edited it with the fix.
 
change
Lua:
local mailbox = tile:getItemByType(ITEM_TYPE_MAILBOX)
to
Lua:
local mailbox = mailboxTile:getItemByType(ITEM_TYPE_MAILBOX)

or just copy code from above. I edited it with the fix.

Perfect!!

Worked perfectly.

Thank you very much, you are a monster.

623c5cfcf82a0029c0eb91e025ff57cf.png


@Xikini, only question.

How do I show a message to the player trying to send the package saying that his package is out of limit?

I try add player on this function and add in line 37 player:sendTextMessage(MESSAGE_INFO_DESCR, 'MSG') but it did not work.
 
Last edited:
Perfect!!

Worked perfectly.

Thank you very much, you are a monster.

623c5cfcf82a0029c0eb91e025ff57cf.png


@Xikini, only question.

How do I show a message to the player trying to send the package saying that his package is out of limit?

I try add player on this function and add in line 37 player:sendTextMessage(MESSAGE_INFO_DESCR, 'MSG') but it did not work.
change
Lua:
    local parcelItems = item:getItems(true)
    if #parcelItems > parcelItemCap then
        print("The parcel was attempted to be sent, however it is holding too many items. (" .. #parcelItems .. "/" .. parcelItemCap .. ")")
        return false
    end
to
Lua:
    local parcelItems = item:getItems(true)
    if #parcelItems > parcelItemCap then
        local text = "The parcel was attempted to be sent, however it is holding too many items. (" .. #parcelItems .. "/" .. parcelItemCap .. ")"
        print(text)
        self:sendTextMessage(MESSAGE_INFO_DESCR, text)
        return false
    end
 
change
Lua:
    local parcelItems = item:getItems(true)
    if #parcelItems > parcelItemCap then
        print("The parcel was attempted to be sent, however it is holding too many items. (" .. #parcelItems .. "/" .. parcelItemCap .. ")")
        return false
    end
to
Lua:
    local parcelItems = item:getItems(true)
    if #parcelItems > parcelItemCap then
        local text = "The parcel was attempted to be sent, however it is holding too many items. (" .. #parcelItems .. "/" .. parcelItemCap .. ")"
        print(text)
        self:sendTextMessage(MESSAGE_INFO_DESCR, text)
        return false
    end

Perfect!!

Thank you very much!
 
Back
Top