• 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 Sending parcel with Lua script [TFS 1.4]

krafttomten

Well-Known Member
Joined
Jul 23, 2017
Messages
103
Solutions
1
Reaction score
75
Location
Sweden
Greetings!

I'm struggling to find a way to send parcels with a Lua script. I want a NPC that sends quest reward in a parcel. I know how to set everything up except for the actual parceling part. Anyone know how to do this? Any help would be much appreciated!
 
Last edited:
Solution
You can't 'send parcel' from Lua. There are 2 ways:
  • create parcel, add 'label' inside, set text on label (player name) and teleport that parcel to some mailbox position on map - it will move parcel into player inbox
  • just add thing to player inbox, without label

Second option is easier. Something like that:
Lua:
local inbox = player:getInbox()
if inbox then
    local parcel = Game.createContainer(ITEM_PARCEL, 10)
    parcel:add(2400) -- add magic sword to parcel
    inbox:addItemEx(parcel)
else
    print('ERROR: Cannot load player Inbox', player:getName())
end
Not tested.
You can't 'send parcel' from Lua. There are 2 ways:
  • create parcel, add 'label' inside, set text on label (player name) and teleport that parcel to some mailbox position on map - it will move parcel into player inbox
  • just add thing to player inbox, without label

Second option is easier. Something like that:
Lua:
local inbox = player:getInbox()
if inbox then
    local parcel = Game.createContainer(ITEM_PARCEL, 10)
    parcel:add(2400) -- add magic sword to parcel
    inbox:addItemEx(parcel)
else
    print('ERROR: Cannot load player Inbox', player:getName())
end
Not tested.
 
Solution
You can't 'send parcel' from Lua. There are 2 ways:
  • create parcel, add 'label' inside, set text on label (player name) and teleport that parcel to some mailbox position on map - it will move parcel into player inbox
  • just add thing to player inbox, without label

Second option is easier. Something like that:
Lua:
local inbox = player:getInbox()
if inbox then
    local parcel = Game.createContainer(ITEM_PARCEL, 10)
    parcel:add(2400) -- add magic sword to parcel
    inbox:addItemEx(parcel)
else
    print('ERROR: Cannot load player Inbox', player:getName())
end
Not tested.
Haha! I kind of like the first method because it's so hacky, but I'll try the second method first and make sure that it works. Thanks for helping out!

Edit*
For some reason I cannot get it to work. I have changed around a couple of things to avoid crashes, but the items never arrive in the inbox. I don't feel entirely comfortable with testing too much, because I have no idea where the items are ending up. I've tried changing the inbox() to direct it towards town IDs, but it doesn't seem to make a difference. I will try the hacky method instead..

Lua:
local function sendReward(plr)
    local inbox = plr:getInbox(2) -- I tried different town ID's without success
    if inbox then
        local parcel = Game.createItem(2596, 1) -- This is a stamped parcel
        if parcel:addItemEx(2400)) ~= RETURNVALUE_NOERROR then
            if inbox:addItemEx(parcel, 1) ~= RETURNVALUE_NOERROR then
            else
                print("Could not add parcel to inbox")
            end
        else
            print("Could not add item to parcel")
        end
        return true
    else
        return print('ERROR: Cannot load player Inbox', plr:getName()) and false
    end
end

*second edit
I got the hacky version to work. I guess the inbox version would be a cleaner solution, but I'm happy for now. Here's the working code:

Lua:
local function sendReward(player)
    local parcel = Game.createItem(ITEM_PARCEL, 1)
    local label = Game.createItem(2599, 1)
    local mailbox = Tile({x = 1494, y = 1256, z = 7, STACKPOS_GROUND})
    doSetItemText(label.uid, player:getName())
    parcel:addItem(2400), 1)
    parcel:addItemEx(label)
    mailbox:addItemEx(parcel)
end
 
Last edited:
Back
Top