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

doPlayerReceiveLetter and doPlayerReceiveParcel

AGS

DeathSouls Owner
Joined
Oct 29, 2007
Messages
400
Reaction score
10
Location
Mexico
I always wanted a function like doPlayerAddDepotItems, so this is the nearest thing I could make.

First of all, Kinight gave me the idea, and I made all the scripting.
Add this to global.lua or functions.lua or whatever you use :D:
PHP:
TOWN_NAMES = {"Rookgaard", "Selentia", "Keltenia"}
MAILBOX_POS = {x=1187, y=1240, z=7}

function doPlayerReceiveLetter(name, town, text)
	if getPlayerGUIDByName(name) ~= 0 then
		if type(town) == 'number' then
			town = TOWN_NAMES[town]
		end
		local letter = doCreateItemEx(2597)
		doSetItemText(letter,name.."\n"..town.."\n\n"..text)
		doTileAddItemEx(MAILBOX_POS,letter)
	else
		debugPrint("doPlayerSendLetter: Player not found")
	end
end

function doPlayerReceiveParcel(name, town, items)
	if getPlayerGUIDByName(name) ~= 0 then
		if type(town) == 'number' then
			town = TOWN_NAMES[town]
		end
		local parcel = doCreateItemEx(2595)
		local label = doAddContainerItem(parcel, 2599)
		doSetItemText(label,name.."\n"..town)
		for i = 1, #items do
			if type(items[i]) == 'table' then
				local tempitem = doAddContainerItem(parcel,items[i].id,items[i].count or 1)
				doSetItemText(tempitem,items[i].text or "")
				doSetItemSpecialDescription(tempitem,items[i].desc or "")				
				if items[i].aid ~= nil then
					doSetItemActionId(tempitem,items[i].aid)
				end
			else
				doAddContainerItem(parcel, items[i], 1)
			end
		end
		doTileAddItemEx(MAILBOX_POS,parcel)
	else
		debugPrint("doPlayerSendParcel: Player not found")
	end
end

So, here's how it works:
First of all, you need to edit two variables:
MAILBOX_POS = This is the position of any mailbox in the map, it doesn't matter where it is, but using an unreachable mailbox is adviced, so if you use a wrong town name or something like that, nobody can take the parcel/letter.
TOWN_NAMES = This array must have all the names of the towns of your map, in the same order they were added, so they match with the town id.

Now, the functions:
-doPlayerReceiveLetter(name,town,text)
name = Name of the player who is going to recieve the letter.
town = Name of the town or Id of the town
text = The text that will be written in the letter(the Adress is already added)
--Examples:
---doPlayerReceiveLetter("God Lord","Selentia","Hello")
---doPlayerReceiveLetter("Kinight",3,"Bye")

-doPlayerReceiveParcel(name,town,items)
name = Name of the player who is going to recieve the parcel
town = Name of the town or Id of the town
items = This may be a little complicated, there are two ways to add the items, in a simple array like {4364,2148,2472}, that will add one of each of the items in the array; You can also use arrays inside the array, like this: {4364,{id = 2148, count = 100},2495}.
You can also add descriptions(desc), text(text) or action Ids(aid).
The label is already added
-Examples
--doPlayerReceiveParcel("God Lord","Selentia",{{id = 2090, aid = 4532, desc = "This key opens the secret chamber"}, {id = 2160, count = 15}, 2472}) -- That will add a crystal key with an action id and a description, 15 crystal coins and 1 magic plate armor.

And that's it, please tell me if you find any bug.
Hope you like it.
 
Last edited:
You gave me credits for an idea? Now THAT'S scary.

Well done, if i had done it, it would be like 120381028408123 lines long...
 
Smart done, but about the mailbox, I'd say you MUST have an unreachable one, as people can block it by throwing trash over the mailbox! Unless that is changed, which I cannot remember xD
 
I tested that, and parcels are still sent even if there's trash over the mailbox.
But yeah, an unreachable mailbox is still adviced in case you write a wrong address nobody can take the parcel or letter.

By the way, no shortening Colandus? :(
I was expecting you to shorthen my scripts as usual :p
 
Last edited:
yeh maybe:
remove the var townText and change all townText to town and then:
Code:
if type(town) == 'number' then 
    town = TOWN_NAMES[town] 
end

And you get rid of an unnecessary variable and 2 lines!

PLEASE USE LOCAL VARIABLES!!
 
Ok, calm down, you don't have to yell at me :(

Anyways, edited it.
 
Whats the format I need to use when i want more than 1 or these {x=1187, y=1240, z=7} ?
 
If you want different items:
doPlayerReceiveParcel("God Lord","Selentia",{2472, 2475,2546, 3473})

If you want more than one item of the same type:
doPlayerReceiveParcel("God Lord","Selentia",{{id=2472,count=3},{id=2475,count=50}})
 
If you want different items:
doPlayerReceiveParcel("God Lord","Selentia",{2472, 2475,2546, 3473})

If you want more than one item of the same type:
doPlayerReceiveParcel("God Lord","Selentia",{{id=2472,count=3},{id=2475,count=50}})

Thanks I just see it for the first time now :O. I wanted to make a script like this so i'm going to use your script as basic. Saves me some time^^ thanks;)
 
Back
Top