NPC: Mail
PHP Code:
function onCreated()
createVariables();
function createVariables(){
setVars();
calcMostSent();
this.mailIDs = {"Example Box", "Mailbox 1", "the Bank",
"etc"}; // Add as many as you wish
}
function setVars(){
for (i: allplayers){
temp.player = findPlayer(i);
if (temp.player != null){
this.sentmail.(@temp.player) = temp.player.clientr.sentmailamt;
}
}
}
public function calcMostSent(){
setVars();
temp.keys = getstringkeys("this.sentmail.");
setarray(temp.mostsent, 2);
for (temp.i = 0; temp.i < temp.keys.size(); temp.i ++) {
temp.current = makevar("this.sentmail." @ temp.keys[temp.i]);
if (temp.current > temp.mostsent[1]) {
temp.mostsent[1] = temp.current;
temp.mostsent[0] = temp.keys[temp.i];
}
}
serverr.mail.mostsent = {temp.mostsent[0],temp.mostsent[1]};
return temp.mostsent[0];
}
Class: postoffice-getmail
PHP Code:
function onCreated(){
setshape(1,32,32);
}
function onActionGrabbed(){
if (clientr.sentmail == false)
{
if (clientr.sendmailto == null)
{
findNPC("Mail").calcMostSent();
temp.num = findNPC("Mail").mailIDs.size();
temp.mailID = findNPC("Mail").mailIDs[random(0,temp.num)];
clientr.sendmailto = temp.mailID;
temp.msg = "Hmm... this letter is for someone at " @ clientr.sendmailto;
player.chat = temp.msg;
return;
}
else
{
temp.msg = clientr.sendmailto @ " is expecting a letter from you!";
player.chat = temp.msg
return;
}
}
if (clientr.sentmail == true)
{
findNPC("Mail").calcMostSent();
temp.paydol = int(random(4,6));
player.rupees += temp.paydol;
clientr.sendmailto = null;
clientr.sentmail = false;
player.chat = format("Recieved %i rupees", temp.paydol);
return;
}
}
//#CLIENTSIDE
function onCreated() {
setshape(1,32,32);
}
Class: postoffice-stats
PHP Code:
/*
Post Office System
by RW*
*/
//#CLIENTSIDE
function onCreated()
onTimeout();
function onTimeout(){
showText(2, x, y, "Tahoma", "b", format("%s has the most sent letters with %s", serverr.mail.mostsent[0],serverr.mail.mostsent[1]));
changeimgzoom(2, .60);
showText(3, x, y+1, "Tahome", "b", format("You have sent %s letter(s)", clientr.sentmailamt));
changeimgzoom(3, .60);
setTimer(.1);
}
Class: mailbox
PHP Code:
function onCreated(){
setimg("oakdale_mailbox-1.gif"); // replace with your mailbox image
}
function onActionGrabbed(acc){
if (player.dir == 0){
if (clientr.sendmailto == null) say2(this.mailboxID);
if (clientr.sendmailto != null {
if (clientr.sendmailto == this.mailboxID){
findNPC("Mail").calcMostSent();
clientr.sentmailamt++;
clientr.sentmail = true;
clientr.sendmailto = null;
player.chat = "Sent The Letter!";
}
else
{
player.chat = "Wrong Mailbox!";
}
}
}
}
Post Office:
Create a level for the post office.
Add this code, put it againts a wall or something because it is invisible. You must grab it to get a new letter
PHP Code:
join("postoffice-getmail");
Add this code to show statistics.
PHP Code:
join("postoffice-stats");
Mailboxes:
Add this code into a level
PHP Code:
join("mailbox");
this.mailboxID = "Example Box"; // The mailbox ID must exist in the Mail NPC 'this.mailIDs' array