[Realm Relay] Mailbox + Chat timestamp

Posts 1–12 of 12 · Page 1 of 1
[Realm Relay] Mailbox + Chat timestamp
Info:

/!\ Put your name on line 9 /!\
Stored messages will be cleared each time you change realm, so this script is useful only for people who tend to be sometimes afk



Usage:

-Toggle the timestamp for the chat ( Disabled by default )
/timestamp

- Show the mailbox
/mail

- Clear the mailbox
/mail clear


Screen:




Code:

Code:
// Put your name on line 9
var ID_NOTIFICATION = $.findPacketId("NOTIFICATION");
var ID_PLAYER_TEXT = $.findPacketId("PLAYERTEXT");
var ID_TEXT = $.findPacketId("TEXT");
var ID_CREATE_SUCCESS = $.findPacketId("CREATE_SUCCESS");
var ID_MOVE = $.findPacketId("MOVE");


var me = "Put Your Name Here";
var name = "";
var chatMsg = "";
var privateMessages = new Array();
var chatTemp = "";

var player_id = -1;

var toggleTimestamp = false;



function onServerPacket(event) {
    var packet = event.getPacket();
    switch (packet.id()) {
    case ID_CREATE_SUCCESS:
        {
            player_id = packet.objectId;
            break;
        }
    case ID_TEXT:
        {
            var today = new Date();
            var h = today.getHours().toString();
            var m = today.getMinutes().toString();
            var s = today.getSeconds().toString();
            var timeStamp = "";
            var playerName = packet.name;
            var chat = packet.text;
            timeStamp = "[" + h + ":" + m + ":" + s + "]";

           
            if (packet.numStars >= 0 && toggleTimestamp == true) {
                packet.text = timeStamp +" "+ chat;
            }



            if (packet.recipient == me) {
                this.displayNotification(event, player_id, 0x33b5e5, "<" + playerName + ">" + packet.text);
                privateMessages.push("<" + packet.name + ">" + packet.text);

            }
            //Bonus :3
            if (packet.name == "Bandit Leader")break;
            if (packet.name == "Rock Construct")break;
        }
    }
}



function onClientPacket(event) {
    var packet = event.getPacket();
    switch (packet.id()) {
    case ID_PLAYER_TEXT:
        {
            var text = packet.text;
            if (text == "/mail") {
                event.cancel();
                var count = privateMessages.length;
                if (count == 0) displayChatNotif(event, "Mailbox", "You have 0 new mail.");
                if (count >= 1) {
                    displayChatNotif(event, "Mailbox", "You have " + count + " new mail.");
                    for (var j = 0; j <= count; j++) {
                        displayChatNotif(event, "Mailbox", privateMessages[j].toString());
                    }
                }



            }
            if (text == "/mail clear") {
                event.cancel();
                privateMessages.length = 0;
                displayChatNotif(event, "Mailbox", "Mailbox is now empty.");

            }
            if (text == "/timestamp") {
                event.cancel();
                toggleTimestamp = !toggleTimestamp;
            }
            break;
        }
    }
}

function displayNotification(event, playerObjectId, color, text) {
    var notificationPacket = event.createPacket(ID_NOTIFICATION);
    notificationPacket.objectId = playerObjectId;
    notificationPacket.message = "{\"key\":\"blank\",\"tokens\":{\"data\":\"" + text + "\"}}";
    notificationPacket.color = color;
    event.sendToClient(notificationPacket);
}

function displayChatNotif(event, name, text) {
    var chatNotifPacket = event.createPacket(ID_TEXT);
    chatNotifPacket.name = name;
    chatNotifPacket.objectId = -1;
    chatNotifPacket.numStars = -1;
    chatNotifPacket.bubbleTime = 0;
    chatNotifPacket.recipient = "";
    chatNotifPacket.text = text;
    chatNotifPacket.cleanText = "";
    event.sendToClient(chatNotifPacket);
}
If someone know how to put a new line on text packet please let me know
cool

Quote Originally Posted by IziLife View Post
If someone know how to put a new line on text packet please let me know
try \n
You could have coded a persistent mailbox on the player's computer, it would've been better imho.
Quote Originally Posted by Trapped View Post
You could have coded a persistent mailbox on the player's computer, it would've been better imho.
I tried, but i wasn't able to create a file, @DeVoidCoder haven't implemented all JS functions
This is the best way i found to create a decent mailbox on vanilla RR
Global variables... It's not the best idea but you could have retained the mailbox this way
Quote Originally Posted by Knorrex View Post
Global variables... It's not the best idea but you could have retained the mailbox this way
Could you give me a minimal code example which shows me how global variables persists across map changes?
Quote Originally Posted by fuckyoutwo View Post
Could you give me a minimal code example which shows me how global variables persists across map changes?
I hope the definition of global variable in RR will help enough:

Code:
public void setGlobal(String var, Object value) {
		this.globalVarMap.put(var, value);
	}
Code:
public Object getGlobal(String var) {
		return this.globalVarMap.get(var);
	}
also an example:

Code:
if (packet.gameId != -2 && packet.gameId != -5) {
                event.setGlobal("reconPacket", packet);
            }
Code:
else if (text_ == "/recon") {
            reconPacket = event.createPacket(ID_RECONNECT);
            reconPacket.name = "Reconnecting..."
            reconPacket.host = event.getGlobal("reconPacket").host;
            reconPacket.port = event.getGlobal("reconPacket").port;
            [...]
Quote Originally Posted by Knorrex View Post
I hope the definition of global variable in RR will help enough:

Code:
public void setGlobal(String var, Object value) {
		this.globalVarMap.put(var, value);
	}
Code:
public Object getGlobal(String var) {
		return this.globalVarMap.get(var);
	}
also an example:

Code:
if (packet.gameId != -2 && packet.gameId != -5) {
                event.setGlobal("reconPacket", packet);
            }
Code:
else if (text_ == "/recon") {
            reconPacket = event.createPacket(ID_RECONNECT);
            reconPacket.name = "Reconnecting..."
            reconPacket.host = event.getGlobal("reconPacket").host;
            reconPacket.port = event.getGlobal("reconPacket").port;
            [...]
Oh thanks a lot, when the server will be UP i'll update the script
This is so kwl!
could you possibly make it reply to people saying that you are afk or something?
Looks great >.<
EDIT: Lel. "This game won't save characters when I die"
Posts 1–12 of 12 · Page 1 of 1

Post a Reply

Similar Threads

Talk with us