Post Office System
Posted: Tue Feb 15, 2022 11:48 pm
Credits:
Xuri for all the help in teaching me how to write and read a new data file.
Post Office System Version 1.1
Have you ever wanted to send items or containers to players but the are offline or just busy killing other players, dungeon crawling or even just ignoring you. Well its your time to shine as you can now head to the Post Office and send them items even bombs or poison. All you need to do is record them in your address book. Once recorded there a friend for life.
Address Book
Post Office Stone
Go open global.js in the server folder
and add this to the onlogin function
under that add this new function for the gump
letter.js for your players to send msgs back and forth
Now Open your jse_fileassociations and add this
19000=custom/addressbook.js
19001=custom/postofficestone.js
19002=custom/letter.js
Now you will need to add the items into your items folder
Xuri for all the help in teaching me how to write and read a new data file.
Post Office System Version 1.1
Have you ever wanted to send items or containers to players but the are offline or just busy killing other players, dungeon crawling or even just ignoring you. Well its your time to shine as you can now head to the Post Office and send them items even bombs or poison. All you need to do is record them in your address book. Once recorded there a friend for life.
Address Book
function onUseChecked(pUser, iUsed)
{
var socket = pUser.socket;
if ( pUser.visible == 1 || pUser.visible == 2 )
{
pUser.visible = 0;
socket.SysMessage(" You can not do this while hiding or stealthed.");
return false;
}
if (socket && iUsed && iUsed.isItem)
{
var itemOwner = GetPackOwner( iUsed, 0 );
//Check to see if it's locked down
if( iUsed.movable == 2 || iUsed.movable == 3 )
{
socket.SysMessage( GetDictionaryEntry( 774, socket.language )); // That is locked down and you cannot use it
return false;
}
// Check make sure item is in the pack
if( itemOwner == null || itemOwner.serial != pUser.serial )
{
pUser.SysMessage( "The adddress book must be in your pack to use it.");
return false;
}
adddressbook(pUser, iUsed);
}
return false;
}
function adddressbook(pUser, iUsed)
{
var socket = pUser.socket;
var book = new Gump;
var blank = "No Friend";
socket.tempObj = iUsed;
book.AddPage(0);
book.AddBackground(0, 0, 0, 0, 0);
book.AddGump(39, 90, 2201);
book.AddText(93, 109, 0, "Address Book");
book.AddText(67, 150, 0, "Here you can store");
book.AddText(67, 165, 0, "The names of your");
book.AddText(67, 180, 0, "Friends so that there");
book.AddText(67, 195, 0, "Is no mix-up on people");
book.AddText(67, 210, 0, "With the same name");
book.AddText(67, 225, 0, "as Your Friends...");
book.AddButton(230, 110, 2117, 2118, 1, 0, 1);
book.AddButton(230, 130, 2117, 2118, 1, 0, 2);
book.AddButton(230, 150, 2117, 2118, 1, 0, 3);
book.AddButton(230, 170, 2117, 2118, 1, 0, 4);
book.AddButton(230, 190, 2117, 2118, 1, 0, 5);
book.AddButton(230, 210, 2117, 2118, 1, 0, 6);
book.AddButton(230, 230, 2117, 2118, 1, 0, 7);
book.AddButton(230, 250, 2117, 2118, 1, 0, 8);
if (iUsed.GetTag("Friend1"))
{
book.AddText(250, 110, 0, iUsed.GetTag("Friend1"));
}
else
{
book.AddText(250, 110, 0, blank);
}
if (iUsed.GetTag("Friend2"))
{
book.AddText(250, 130, 0, iUsed.GetTag("Friend2"));
}
else
{
book.AddText(250, 130, 0, blank);
}
if (iUsed.GetTag("Friend3"))
{
book.AddText(250, 150, 0, iUsed.GetTag("Friend3"));
}
else
{
book.AddText(250, 150, 0, blank);
}
if (iUsed.GetTag("Friend4"))
{
book.AddText(250, 170, 0, iUsed.GetTag("Friend4"));
}
else
{
book.AddText(250, 170, 0, blank);
}
if (iUsed.GetTag("Friend5"))
{
book.AddText(250, 190, 0, iUsed.GetTag("Friend5"));
}
else
{
book.AddText(250, 190, 0, blank);
}
if (iUsed.GetTag("Friend6"))
{
book.AddText(250, 210, 0, iUsed.GetTag("Friend6"));
}
else
{
book.AddText(250, 210, 0, blank);
}
if (iUsed.GetTag("Friend7"))
{
book.AddText(250, 230, 0, iUsed.GetTag("Friend7"));
}
else
{
book.AddText(250, 230, 0, blank);
}
if (iUsed.GetTag("Friend8"))
{
book.AddText(250, 250, 0, iUsed.GetTag("Friend8"));
}
else
{
book.AddText(250, 250, 0, blank);
}
book.Send(socket);
book.Free();
}
function onGumpPress(pSock, pButton, gumpData)
{
var pUser = pSock.currentChar;
var Msg = "Target Player to Record Name in your Book";
switch (pButton)
{
case 0:break;
case 1:
pSock.tempint = 1;
pUser.CustomTarget( 1, Msg); break;
case 2:
pSock.tempint = 2;
pUser.CustomTarget( 1, Msg); break;
case 3:
pSock.tempint = 3;
pUser.CustomTarget( 1, Msg); break;
case 4:
pSock.tempint = 4;
pUser.CustomTarget( 1, Msg); break;
case 5:
pSock.tempint = 5;
pUser.CustomTarget( 1, Msg); break;
case 6:
pSock.tempint = 6;
pUser.CustomTarget( 1, Msg); break;
case 7:
pSock.tempint = 7;
pUser.CustomTarget( 1, Msg); break;
case 8:
pSock.tempint = 8;
pUser.CustomTarget( 1, Msg); break;
}
}
function onCallback1( socket, myTarget )
{
var friendSlot = socket.tempint;
var iUsed = socket.tempObj;
var pUser = socket.currentChar;
// Read address book
var myArray = ReadAddressBook( pUser );
// Next up, we want to loop through myArray, and make sure our friend is not already there
var slotUsed = false;
var indexOfSlot = -1;
if ( pUser.visible == 1 || pUser.visible == 2 )
{
pUser.visible = 0;
socket.SysMessage(" You can not do this while hiding or stealthed.");
adddressbook(pUser, iUsed);
return;
}
if (!socket.GetWord(1) && ValidateObject(myTarget) && myTarget.isChar)
{
if (myTarget.npc)
{
pUser.SysMessage("You need a real player to add to the book.");
adddressbook(pUser, iUsed);
return;
}
else if (!myTarget.InRange(pUser, 7))
{
socket.SysMessage(GetDictionaryEntry(393, socket.language)); // That is out of range
adddressbook(pUser, iUsed);
return;
}
else if (!pUser.CanSee(myTarget))
{
socket.SysMessage(GetDictionaryEntry(1646, socket.language)); // You cannot see that
adddressbook(pUser, iUsed);
return;
}
for (let i = 0; i < myArray.length; i++)
{
var myFriend = myArray[i].split(",");
if (myFriend[1] == myTarget.serial)
{
// Friend is already in the book! Abort
pUser.socket.SysMessage("Friend already in address book, in slot " + i);
adddressbook(pUser, iUsed);
return;
}
else if (myFriend[0] == friendSlot)
{
slotUsed = true;
indexOfSlot = i;
}
}
// Next, remove the existing entry for the selected slot from myArray!
if (slotUsed)
{
myArray.splice(indexOfSlot, 1);
}
// Ok, if friend wasn't found in the array, store him in the slot we selected earlier
myArray.push(friendSlot.toString() + "," + (myTarget.serial).toString() + "," + myTarget.name);
if (WriteAdddressBook(pUser, myArray))
{
// Also store our new friend in tags on the address book item, for quick and dirty access later
iUsed.SetTag("Friend" + friendSlot, myTarget.name);
iUsed.SetTag("Friend" + friendSlot + "Serial", (myTarget.serial).toString());
pUser.SysMessage("You add your " + myTarget.name + " to the adddress book");
adddressbook(pUser, iUsed);
}
}
else
{
pUser.SysMessage("You need a real Player to add to the book.");
adddressbook(pUser, iUsed);
return;
}
}
// Write Address Book back to file
function WriteAdddressBook( pUser, myArray )
{
// Create a new file object
var mFile = new UOXCFile();
var userAccount = pUser.account;
var fileName = "Account_"+userAccount.id+".jsdata";
mFile.Open(fileName, "w", "Adddressbook"); // Open file for Writing
if (mFile != null)
{
// Loop through each entry in myArray and save it to a new line
for( let i = 0; i < myArray.length; i++ )
{
mFile.Write( myArray[i] + "\n" );
}
// Close and free the file
mFile.Close()
mFile.Free();
return true;
}
return false;
}
// Read contents of Address Book
function ReadAddressBook( pUser )
{
// Create a new file object
var mFile = new UOXCFile();
var userAccount = pUser.account;
var fileName = "Account_"+userAccount.id+".jsdata";
// Create an array variable to store contents of address book
var myArray = [];
mFile.Open( fileName, "r", "Adddressbook" );
if( mFile && mFile.Length() >= 0 )
{
// Read until we reach the end of the file, or until we find a match for the visitor
while( !mFile.EOF() )
{
// Read a line of text from the file
var line = mFile.ReadUntil( "\n" );
if( line.length <= 1 || line == "" )
continue;
// Store each line from file in myArray
myArray.push( line );
}
mFile.Close();
// Frees memory allocated by file object
mFile.Free();
}
return myArray;
}
{
var socket = pUser.socket;
if ( pUser.visible == 1 || pUser.visible == 2 )
{
pUser.visible = 0;
socket.SysMessage(" You can not do this while hiding or stealthed.");
return false;
}
if (socket && iUsed && iUsed.isItem)
{
var itemOwner = GetPackOwner( iUsed, 0 );
//Check to see if it's locked down
if( iUsed.movable == 2 || iUsed.movable == 3 )
{
socket.SysMessage( GetDictionaryEntry( 774, socket.language )); // That is locked down and you cannot use it
return false;
}
// Check make sure item is in the pack
if( itemOwner == null || itemOwner.serial != pUser.serial )
{
pUser.SysMessage( "The adddress book must be in your pack to use it.");
return false;
}
adddressbook(pUser, iUsed);
}
return false;
}
function adddressbook(pUser, iUsed)
{
var socket = pUser.socket;
var book = new Gump;
var blank = "No Friend";
socket.tempObj = iUsed;
book.AddPage(0);
book.AddBackground(0, 0, 0, 0, 0);
book.AddGump(39, 90, 2201);
book.AddText(93, 109, 0, "Address Book");
book.AddText(67, 150, 0, "Here you can store");
book.AddText(67, 165, 0, "The names of your");
book.AddText(67, 180, 0, "Friends so that there");
book.AddText(67, 195, 0, "Is no mix-up on people");
book.AddText(67, 210, 0, "With the same name");
book.AddText(67, 225, 0, "as Your Friends...");
book.AddButton(230, 110, 2117, 2118, 1, 0, 1);
book.AddButton(230, 130, 2117, 2118, 1, 0, 2);
book.AddButton(230, 150, 2117, 2118, 1, 0, 3);
book.AddButton(230, 170, 2117, 2118, 1, 0, 4);
book.AddButton(230, 190, 2117, 2118, 1, 0, 5);
book.AddButton(230, 210, 2117, 2118, 1, 0, 6);
book.AddButton(230, 230, 2117, 2118, 1, 0, 7);
book.AddButton(230, 250, 2117, 2118, 1, 0, 8);
if (iUsed.GetTag("Friend1"))
{
book.AddText(250, 110, 0, iUsed.GetTag("Friend1"));
}
else
{
book.AddText(250, 110, 0, blank);
}
if (iUsed.GetTag("Friend2"))
{
book.AddText(250, 130, 0, iUsed.GetTag("Friend2"));
}
else
{
book.AddText(250, 130, 0, blank);
}
if (iUsed.GetTag("Friend3"))
{
book.AddText(250, 150, 0, iUsed.GetTag("Friend3"));
}
else
{
book.AddText(250, 150, 0, blank);
}
if (iUsed.GetTag("Friend4"))
{
book.AddText(250, 170, 0, iUsed.GetTag("Friend4"));
}
else
{
book.AddText(250, 170, 0, blank);
}
if (iUsed.GetTag("Friend5"))
{
book.AddText(250, 190, 0, iUsed.GetTag("Friend5"));
}
else
{
book.AddText(250, 190, 0, blank);
}
if (iUsed.GetTag("Friend6"))
{
book.AddText(250, 210, 0, iUsed.GetTag("Friend6"));
}
else
{
book.AddText(250, 210, 0, blank);
}
if (iUsed.GetTag("Friend7"))
{
book.AddText(250, 230, 0, iUsed.GetTag("Friend7"));
}
else
{
book.AddText(250, 230, 0, blank);
}
if (iUsed.GetTag("Friend8"))
{
book.AddText(250, 250, 0, iUsed.GetTag("Friend8"));
}
else
{
book.AddText(250, 250, 0, blank);
}
book.Send(socket);
book.Free();
}
function onGumpPress(pSock, pButton, gumpData)
{
var pUser = pSock.currentChar;
var Msg = "Target Player to Record Name in your Book";
switch (pButton)
{
case 0:break;
case 1:
pSock.tempint = 1;
pUser.CustomTarget( 1, Msg); break;
case 2:
pSock.tempint = 2;
pUser.CustomTarget( 1, Msg); break;
case 3:
pSock.tempint = 3;
pUser.CustomTarget( 1, Msg); break;
case 4:
pSock.tempint = 4;
pUser.CustomTarget( 1, Msg); break;
case 5:
pSock.tempint = 5;
pUser.CustomTarget( 1, Msg); break;
case 6:
pSock.tempint = 6;
pUser.CustomTarget( 1, Msg); break;
case 7:
pSock.tempint = 7;
pUser.CustomTarget( 1, Msg); break;
case 8:
pSock.tempint = 8;
pUser.CustomTarget( 1, Msg); break;
}
}
function onCallback1( socket, myTarget )
{
var friendSlot = socket.tempint;
var iUsed = socket.tempObj;
var pUser = socket.currentChar;
// Read address book
var myArray = ReadAddressBook( pUser );
// Next up, we want to loop through myArray, and make sure our friend is not already there
var slotUsed = false;
var indexOfSlot = -1;
if ( pUser.visible == 1 || pUser.visible == 2 )
{
pUser.visible = 0;
socket.SysMessage(" You can not do this while hiding or stealthed.");
adddressbook(pUser, iUsed);
return;
}
if (!socket.GetWord(1) && ValidateObject(myTarget) && myTarget.isChar)
{
if (myTarget.npc)
{
pUser.SysMessage("You need a real player to add to the book.");
adddressbook(pUser, iUsed);
return;
}
else if (!myTarget.InRange(pUser, 7))
{
socket.SysMessage(GetDictionaryEntry(393, socket.language)); // That is out of range
adddressbook(pUser, iUsed);
return;
}
else if (!pUser.CanSee(myTarget))
{
socket.SysMessage(GetDictionaryEntry(1646, socket.language)); // You cannot see that
adddressbook(pUser, iUsed);
return;
}
for (let i = 0; i < myArray.length; i++)
{
var myFriend = myArray[i].split(",");
if (myFriend[1] == myTarget.serial)
{
// Friend is already in the book! Abort
pUser.socket.SysMessage("Friend already in address book, in slot " + i);
adddressbook(pUser, iUsed);
return;
}
else if (myFriend[0] == friendSlot)
{
slotUsed = true;
indexOfSlot = i;
}
}
// Next, remove the existing entry for the selected slot from myArray!
if (slotUsed)
{
myArray.splice(indexOfSlot, 1);
}
// Ok, if friend wasn't found in the array, store him in the slot we selected earlier
myArray.push(friendSlot.toString() + "," + (myTarget.serial).toString() + "," + myTarget.name);
if (WriteAdddressBook(pUser, myArray))
{
// Also store our new friend in tags on the address book item, for quick and dirty access later
iUsed.SetTag("Friend" + friendSlot, myTarget.name);
iUsed.SetTag("Friend" + friendSlot + "Serial", (myTarget.serial).toString());
pUser.SysMessage("You add your " + myTarget.name + " to the adddress book");
adddressbook(pUser, iUsed);
}
}
else
{
pUser.SysMessage("You need a real Player to add to the book.");
adddressbook(pUser, iUsed);
return;
}
}
// Write Address Book back to file
function WriteAdddressBook( pUser, myArray )
{
// Create a new file object
var mFile = new UOXCFile();
var userAccount = pUser.account;
var fileName = "Account_"+userAccount.id+".jsdata";
mFile.Open(fileName, "w", "Adddressbook"); // Open file for Writing
if (mFile != null)
{
// Loop through each entry in myArray and save it to a new line
for( let i = 0; i < myArray.length; i++ )
{
mFile.Write( myArray[i] + "\n" );
}
// Close and free the file
mFile.Close()
mFile.Free();
return true;
}
return false;
}
// Read contents of Address Book
function ReadAddressBook( pUser )
{
// Create a new file object
var mFile = new UOXCFile();
var userAccount = pUser.account;
var fileName = "Account_"+userAccount.id+".jsdata";
// Create an array variable to store contents of address book
var myArray = [];
mFile.Open( fileName, "r", "Adddressbook" );
if( mFile && mFile.Length() >= 0 )
{
// Read until we reach the end of the file, or until we find a match for the visitor
while( !mFile.EOF() )
{
// Read a line of text from the file
var line = mFile.ReadUntil( "\n" );
if( line.length <= 1 || line == "" )
continue;
// Store each line from file in myArray
myArray.push( line );
}
mFile.Close();
// Frees memory allocated by file object
mFile.Free();
}
return myArray;
}
function onUseChecked(pUser, iUsed)
{
var socket = pUser.socket;
if (pUser.visible == 1 || pUser.visible == 2)
{
pUser.visible = 0;
socket.SysMessage(" You can not do this while hiding or stealthed.");
return false;
}
else if (!iUsed.InRange(pUser, 7))
{
socket.SysMessage(GetDictionaryEntry(393, socket.language)); // That is out of range;
return false;
}
else if (!pUser.CanSee(iUsed))
{
socket.SysMessage(GetDictionaryEntry(1646, socket.language)); // You cannot see that
return false;
}
else
{
PostOfficeStone(pUser, iUsed);
}
}
function PostOfficeStone(pUser, iUsed)
{
var myArray = ReadAdddressBook(pUser, iUsed);
var socket = pUser.socket;
var postal = new Gump;
socket.tempObj = iUsed;
postal.AddPage(0);
postal.AddBackground(27, 22, 400, 400, 3500)
postal.AddGump(-20, -1, 10440);
postal.AddGump(316, 53, 5536);
postal.AddText(155, 87, 0, ".:::Post Office:::.");
postal.AddGump(95, 80, 92);
postal.AddGump(147, 80, 93);
postal.AddGump(154, 80, 93);
postal.AddGump(265, 80, 94);
postal.AddGump(110, 155, 1418);
for (let i = 0; i < myArray.length; i++)
{
var myFriendData = myArray[i].split(",");
var myFriendSlot = myFriendData[0];
var myFriendName = myFriendData[2];
var index = i % 10;
postal.AddText(148, 150 + (index * 20), 0, myFriendName);
postal.AddButton(120, 150 + (index * 20), 2117, 2118, 1, 0, 1 * myFriendSlot);
}
postal.AddGump(41, 336, 52);
postal.AddText(88, 340, 0, "10g Per Stone");
postal.Send(socket);
postal.Free();
}
function onGumpPress(socket, pButton, gumpData)
{
var pUser = socket.currentChar;
var msg = "Target item or container to send.";
switch (pButton)
{
case 0:break;
case 1:
socket.tempint = 1;
pUser.CustomTarget( 1, msg); break;
case 2:
socket.tempint = 2;
pUser.CustomTarget( 1, msg); break;
case 3:
socket.tempint = 3;
pUser.CustomTarget( 1, msg); break;
case 4:
socket.tempint = 4;
pUser.CustomTarget( 1, msg); break;
case 5:
socket.tempint = 5;
pUser.CustomTarget( 1, msg); break;
case 6:
socket.tempint = 6;
pUser.CustomTarget( 1, msg); break;
case 7:
socket.tempint = 7;
pUser.CustomTarget( 1, msg); break;
case 8:
socket.tempint = 8;
pUser.CustomTarget( 1, msg); break;
}
}
function onCallback1(socket, myTarget)
{
var bankbox;
var friendSlot = socket.tempint;
var pUser = socket.currentChar;
var iUsed = socket.tempObj;
var amount = 10 * (myTarget.weight / 100);
// Read address book
var myArray = ReadAddressBook( pUser );
if ( pUser.visible == 1 || pUser.visible == 2 )
{
pUser.visible = 0;
socket.SysMessage(" You can not do this while hiding or stealthed.");
PostOfficeStone(pUser, iUsed);
return;
}
//Check to see if it's locked down
if( myTarget.movable == 2 || myTarget.movable == 3 )
{
socket.SysMessage( GetDictionaryEntry( 774, socket.language )); // That is locked down and you cannot use it
PostOfficeStone(pUser, iUsed);
return false;
}
if (myTarget && myTarget.isItem)
{
var itemOwner = GetPackOwner(myTarget, 0);
// Check make sure item is in the pack
if (itemOwner == null || itemOwner.serial != pUser.serial)
{
pUser.SysMessage("The item your trying to send must be in your pack");
PostOfficeStone(pUser, iUsed);
return false;
}
// Next up, we want to loop through myArray, and make sure our friend is not already there
for (let i = 0; i < myArray.length; i++)
{
var myFriend = myArray[i].split(",");
var myFriendSerial = myFriend[1];
if (myFriend[0] == friendSlot)
{
var myFriendSerial = myFriend[1];
var friend = CalcCharFromSer(parseInt(myFriendSerial));// checking for serial of friend
if (ValidateObject(myTarget))
{
bankbox = friend.FindItemLayer(29);
friend.SetTag("newMail", true); // sets the tag on the person you sending mail to so they get gump.
friend.SetTag("itemName", myTarget.name); // sets the tag on the person you sending mail to so it says name of item in gump.
if (ValidateObject(bankbox))
{
if (pUser.ResourceCount(0x0eed) < amount)
{
pUser.SysMessage("You need "+ amount+" gold to send "+ myTarget.name);
PostOfficeStone(pUser, iUsed);
return false;
}
else
{
myTarget.container = bankbox;
pUser.UseResource(amount, 0x0eed)
pUser.SysMessage("You sent " + myTarget.name+ " for the amount of " + amount+ " gold");
PostOfficeStone(pUser, iUsed);
myTarget.Refresh();
}
}
}
return;
}
}
}
else
{
pUser.SysMessage( "Must be a item or Container");
PostOfficeStone(pUser, iUsed);
return false;
}
}
function ReadAdddressBook(pUser, iUsed)
{
var userAccount = pUser.account;
var fileName = "Account_" + userAccount.id + ".jsdata";
var mFile = new UOXCFile();
var myArray = [];
mFile.Open(fileName, "r", "Adddressbook");
if (mFile && mFile.Length() >= 0)
{
// Read until we reach the end of the file, or until we find a match for the visitor
while (!mFile.EOF()) {
// Read a line of text from the file
var line = mFile.ReadUntil("\n");
if (line.length <= 1 || line == "")
continue;
myArray.push( line );
}
mFile.Close();
// Frees memory allocated by file object
mFile.Free();
}
return myArray;
}
{
var socket = pUser.socket;
if (pUser.visible == 1 || pUser.visible == 2)
{
pUser.visible = 0;
socket.SysMessage(" You can not do this while hiding or stealthed.");
return false;
}
else if (!iUsed.InRange(pUser, 7))
{
socket.SysMessage(GetDictionaryEntry(393, socket.language)); // That is out of range;
return false;
}
else if (!pUser.CanSee(iUsed))
{
socket.SysMessage(GetDictionaryEntry(1646, socket.language)); // You cannot see that
return false;
}
else
{
PostOfficeStone(pUser, iUsed);
}
}
function PostOfficeStone(pUser, iUsed)
{
var myArray = ReadAdddressBook(pUser, iUsed);
var socket = pUser.socket;
var postal = new Gump;
socket.tempObj = iUsed;
postal.AddPage(0);
postal.AddBackground(27, 22, 400, 400, 3500)
postal.AddGump(-20, -1, 10440);
postal.AddGump(316, 53, 5536);
postal.AddText(155, 87, 0, ".:::Post Office:::.");
postal.AddGump(95, 80, 92);
postal.AddGump(147, 80, 93);
postal.AddGump(154, 80, 93);
postal.AddGump(265, 80, 94);
postal.AddGump(110, 155, 1418);
for (let i = 0; i < myArray.length; i++)
{
var myFriendData = myArray[i].split(",");
var myFriendSlot = myFriendData[0];
var myFriendName = myFriendData[2];
var index = i % 10;
postal.AddText(148, 150 + (index * 20), 0, myFriendName);
postal.AddButton(120, 150 + (index * 20), 2117, 2118, 1, 0, 1 * myFriendSlot);
}
postal.AddGump(41, 336, 52);
postal.AddText(88, 340, 0, "10g Per Stone");
postal.Send(socket);
postal.Free();
}
function onGumpPress(socket, pButton, gumpData)
{
var pUser = socket.currentChar;
var msg = "Target item or container to send.";
switch (pButton)
{
case 0:break;
case 1:
socket.tempint = 1;
pUser.CustomTarget( 1, msg); break;
case 2:
socket.tempint = 2;
pUser.CustomTarget( 1, msg); break;
case 3:
socket.tempint = 3;
pUser.CustomTarget( 1, msg); break;
case 4:
socket.tempint = 4;
pUser.CustomTarget( 1, msg); break;
case 5:
socket.tempint = 5;
pUser.CustomTarget( 1, msg); break;
case 6:
socket.tempint = 6;
pUser.CustomTarget( 1, msg); break;
case 7:
socket.tempint = 7;
pUser.CustomTarget( 1, msg); break;
case 8:
socket.tempint = 8;
pUser.CustomTarget( 1, msg); break;
}
}
function onCallback1(socket, myTarget)
{
var bankbox;
var friendSlot = socket.tempint;
var pUser = socket.currentChar;
var iUsed = socket.tempObj;
var amount = 10 * (myTarget.weight / 100);
// Read address book
var myArray = ReadAddressBook( pUser );
if ( pUser.visible == 1 || pUser.visible == 2 )
{
pUser.visible = 0;
socket.SysMessage(" You can not do this while hiding or stealthed.");
PostOfficeStone(pUser, iUsed);
return;
}
//Check to see if it's locked down
if( myTarget.movable == 2 || myTarget.movable == 3 )
{
socket.SysMessage( GetDictionaryEntry( 774, socket.language )); // That is locked down and you cannot use it
PostOfficeStone(pUser, iUsed);
return false;
}
if (myTarget && myTarget.isItem)
{
var itemOwner = GetPackOwner(myTarget, 0);
// Check make sure item is in the pack
if (itemOwner == null || itemOwner.serial != pUser.serial)
{
pUser.SysMessage("The item your trying to send must be in your pack");
PostOfficeStone(pUser, iUsed);
return false;
}
// Next up, we want to loop through myArray, and make sure our friend is not already there
for (let i = 0; i < myArray.length; i++)
{
var myFriend = myArray[i].split(",");
var myFriendSerial = myFriend[1];
if (myFriend[0] == friendSlot)
{
var myFriendSerial = myFriend[1];
var friend = CalcCharFromSer(parseInt(myFriendSerial));// checking for serial of friend
if (ValidateObject(myTarget))
{
bankbox = friend.FindItemLayer(29);
friend.SetTag("newMail", true); // sets the tag on the person you sending mail to so they get gump.
friend.SetTag("itemName", myTarget.name); // sets the tag on the person you sending mail to so it says name of item in gump.
if (ValidateObject(bankbox))
{
if (pUser.ResourceCount(0x0eed) < amount)
{
pUser.SysMessage("You need "+ amount+" gold to send "+ myTarget.name);
PostOfficeStone(pUser, iUsed);
return false;
}
else
{
myTarget.container = bankbox;
pUser.UseResource(amount, 0x0eed)
pUser.SysMessage("You sent " + myTarget.name+ " for the amount of " + amount+ " gold");
PostOfficeStone(pUser, iUsed);
myTarget.Refresh();
}
}
}
return;
}
}
}
else
{
pUser.SysMessage( "Must be a item or Container");
PostOfficeStone(pUser, iUsed);
return false;
}
}
function ReadAdddressBook(pUser, iUsed)
{
var userAccount = pUser.account;
var fileName = "Account_" + userAccount.id + ".jsdata";
var mFile = new UOXCFile();
var myArray = [];
mFile.Open(fileName, "r", "Adddressbook");
if (mFile && mFile.Length() >= 0)
{
// Read until we reach the end of the file, or until we find a match for the visitor
while (!mFile.EOF()) {
// Read a line of text from the file
var line = mFile.ReadUntil("\n");
if (line.length <= 1 || line == "")
continue;
myArray.push( line );
}
mFile.Close();
// Frees memory allocated by file object
mFile.Free();
}
return myArray;
}
and add this to the onlogin function
if (pChar.GetTag("newMail"))
{
newMail(pChar);
}
{
newMail(pChar);
}
function newMail(pChar)
{
var socket = pChar.socket;
var myGump = new Gump;
myGump.AddPage(0);
myGump.AddBackground(100, 50, 300, 200, 3500);
myGump.AddHTMLGump( 120, 70, 260, 160, true, false, "<BR><BR><center>You have received new mail!<BR><BR>Please check for the " + pChar.GetTag("itemName").toString() + " in your bank box.</center>");
myGump.Send(socket);
myGump.Free();
}
function onGumpPress(socket, pButton, gumpData)
{
var pUser = socket.currentChar;
switch (pButton)
{
case 0:
pUser.SetTag("itemName", null);
pUser.SetTag("newMail", false);
break;
}
}
{
var socket = pChar.socket;
var myGump = new Gump;
myGump.AddPage(0);
myGump.AddBackground(100, 50, 300, 200, 3500);
myGump.AddHTMLGump( 120, 70, 260, 160, true, false, "<BR><BR><center>You have received new mail!<BR><BR>Please check for the " + pChar.GetTag("itemName").toString() + " in your bank box.</center>");
myGump.Send(socket);
myGump.Free();
}
function onGumpPress(socket, pButton, gumpData)
{
var pUser = socket.currentChar;
switch (pButton)
{
case 0:
pUser.SetTag("itemName", null);
pUser.SetTag("newMail", false);
break;
}
}
function onUseChecked(pUser, iUsed)
{
var socket = pUser.socket;
if ( pUser.visible == 1 || pUser.visible == 2 )
{
pUser.visible = 0;
socket.SysMessage(" You can not do this while hiding or stealthed.");
return false;
}
if (socket && iUsed && iUsed.isItem)
{
var itemOwner = GetPackOwner( iUsed, 0 );
//Check to see if it's locked down
if( iUsed.movable == 2 || iUsed.movable == 3 )
{
socket.SysMessage( GetDictionaryEntry( 774, socket.language )); // That is locked down and you cannot use it
return false;
}
// Check make sure item is in the pack
if( itemOwner == null || itemOwner.serial != pUser.serial )
{
pUser.SysMessage( "The letter must be in your pack to use it.");
return false;
}
socket.tempObj = iUsed;
letter(pUser, iUsed);
}
return false;
}
function letter(pUser, iUsed)
{
var socket = pUser.socket;
var letter = new Gump;
socket.tempObj = iUsed;
letter.AddPage(0);
letter.AddBackground(29, 49, 384, 350, 3000);
letter.AddGump(40, 64, 95);
letter.AddGump(47, 73, 96);
letter.AddGump(214, 73, 96);
letter.AddGump(392, 64, 97);
letter.AddText(84, 110, 0, "To ");
letter.AddGump(340, 111, 1261);
letter.AddText(281, 138, 0, "UOX3");
letter.AddGump(32, 101, 52);
letter.AddGump(40, 364, 95);
letter.AddGump(47, 373, 96);
letter.AddGump(214, 373, 96);
letter.AddGump(392, 364, 97);
letter.AddGump(269, 163, 9000);
letter.AddText(264, 266, 0, "Post System");
letter.AddButton(70, 322, 5601, 5605, 1, 0, 0);//close
letter.AddText(90, 320, 0, "Close");
if (iUsed.GetTag("ToName") && iUsed.GetTag("Message"))
{
letter.AddText(103, 110, 0, iUsed.GetTag("ToName"));
letter.AddHTMLGump(63, 143, 200, 150, false, false, iUsed.GetTag("Message"));
}
else
{
letter.AddText(90, 300, 0, "Done");
letter.AddButton(70, 302, 5601, 5605, 1, 0, 1);//done
letter.AddText(93, 200, 0, "<-Message Here->");
letter.AddTextEntry(103, 110, 99, 20, 0, 0, 8, " ");
letter.AddTextEntry(63, 143, 190, 137, 0, 0, 9, " ");
}
letter.Send(socket);
letter.Free();
}
function onGumpPress(pSock, pButton, gumpData)
{
var pUser = pSock.currentChar;
var iUsed = pSock.tempObj;
var Name = gumpData.getEdit(0);
var Message = gumpData.getEdit(1);
switch (pButton)
{
case 0:break;
case 1:
if (Name.length <= 2 || Name.length > 13) // Estimated longest name that fits inside gump
{
pUser.SysMessage("Your Name must be at least 2 letters or numbers.");
letter(pUser, iUsed);
break;
}
if (Message.length <= 2 || Message.length > 255) // Estimated longest name that fits inside gump
{
pUser.SysMessage("Your Message must be at least 2 letters or numbers.");
letter(pUser, iUsed);
break;
}
else
{
iUsed.SetTag("FromName", pUser.name);
iUsed.SetTag("ToName", Name);
iUsed.SetTag("Message", Message);
letter(pUser, iUsed);
break;
}
}
}
function onTooltip(myObj)
{
var tooltipText = "";
if (myObj.GetTag("FromName"))
{
tooltipText = ("From: " + myObj.GetTag("FromName"));
}
return tooltipText;
}
{
var socket = pUser.socket;
if ( pUser.visible == 1 || pUser.visible == 2 )
{
pUser.visible = 0;
socket.SysMessage(" You can not do this while hiding or stealthed.");
return false;
}
if (socket && iUsed && iUsed.isItem)
{
var itemOwner = GetPackOwner( iUsed, 0 );
//Check to see if it's locked down
if( iUsed.movable == 2 || iUsed.movable == 3 )
{
socket.SysMessage( GetDictionaryEntry( 774, socket.language )); // That is locked down and you cannot use it
return false;
}
// Check make sure item is in the pack
if( itemOwner == null || itemOwner.serial != pUser.serial )
{
pUser.SysMessage( "The letter must be in your pack to use it.");
return false;
}
socket.tempObj = iUsed;
letter(pUser, iUsed);
}
return false;
}
function letter(pUser, iUsed)
{
var socket = pUser.socket;
var letter = new Gump;
socket.tempObj = iUsed;
letter.AddPage(0);
letter.AddBackground(29, 49, 384, 350, 3000);
letter.AddGump(40, 64, 95);
letter.AddGump(47, 73, 96);
letter.AddGump(214, 73, 96);
letter.AddGump(392, 64, 97);
letter.AddText(84, 110, 0, "To ");
letter.AddGump(340, 111, 1261);
letter.AddText(281, 138, 0, "UOX3");
letter.AddGump(32, 101, 52);
letter.AddGump(40, 364, 95);
letter.AddGump(47, 373, 96);
letter.AddGump(214, 373, 96);
letter.AddGump(392, 364, 97);
letter.AddGump(269, 163, 9000);
letter.AddText(264, 266, 0, "Post System");
letter.AddButton(70, 322, 5601, 5605, 1, 0, 0);//close
letter.AddText(90, 320, 0, "Close");
if (iUsed.GetTag("ToName") && iUsed.GetTag("Message"))
{
letter.AddText(103, 110, 0, iUsed.GetTag("ToName"));
letter.AddHTMLGump(63, 143, 200, 150, false, false, iUsed.GetTag("Message"));
}
else
{
letter.AddText(90, 300, 0, "Done");
letter.AddButton(70, 302, 5601, 5605, 1, 0, 1);//done
letter.AddText(93, 200, 0, "<-Message Here->");
letter.AddTextEntry(103, 110, 99, 20, 0, 0, 8, " ");
letter.AddTextEntry(63, 143, 190, 137, 0, 0, 9, " ");
}
letter.Send(socket);
letter.Free();
}
function onGumpPress(pSock, pButton, gumpData)
{
var pUser = pSock.currentChar;
var iUsed = pSock.tempObj;
var Name = gumpData.getEdit(0);
var Message = gumpData.getEdit(1);
switch (pButton)
{
case 0:break;
case 1:
if (Name.length <= 2 || Name.length > 13) // Estimated longest name that fits inside gump
{
pUser.SysMessage("Your Name must be at least 2 letters or numbers.");
letter(pUser, iUsed);
break;
}
if (Message.length <= 2 || Message.length > 255) // Estimated longest name that fits inside gump
{
pUser.SysMessage("Your Message must be at least 2 letters or numbers.");
letter(pUser, iUsed);
break;
}
else
{
iUsed.SetTag("FromName", pUser.name);
iUsed.SetTag("ToName", Name);
iUsed.SetTag("Message", Message);
letter(pUser, iUsed);
break;
}
}
}
function onTooltip(myObj)
{
var tooltipText = "";
if (myObj.GetTag("FromName"))
{
tooltipText = ("From: " + myObj.GetTag("FromName"));
}
return tooltipText;
}
19000=custom/addressbook.js
19001=custom/postofficestone.js
19002=custom/letter.js
Now you will need to add the items into your items folder
[addressbook]
{
get=base_item
name=adddress book
id=0xfef
decay=1
weight=100
SCRIPT=19000
}
[postofficestone]
{
get=base_item
name=post office stone
id=0xED4
decay=0
movable=2
SCRIPT=19001
}
[letter]
{
get=base_item
name=a letter
id=0x14ED
decay=1
weight=100
colour=1150
SCRIPT=19002
}
{
get=base_item
name=adddress book
id=0xfef
decay=1
weight=100
SCRIPT=19000
}
[postofficestone]
{
get=base_item
name=post office stone
id=0xED4
decay=0
movable=2
SCRIPT=19001
}
[letter]
{
get=base_item
name=a letter
id=0x14ED
decay=1
weight=100
colour=1150
SCRIPT=19002
}