Author Topic: My New Alert System  (Read 267 times)

Offline robgob

  • Adamant Member
  • *
  • Posts: 120
  • Rep 5
  • I swarm like locust
  • Location: Michigan
    • View Profile
My New Alert System
« on: March 10, 2011, 11:12:31 pm »
I origionally posted this on rune-server and silabsoft. But ill re-post it here to get some flow in the forums ;)

My New Alert System

.::Video Result::.


First off You're going to have to add 2 classes to your client files.

AlertHandler.java
Code: [Select]
import java.util.ArrayList;
import java.util.List;

public class AlertHandler {

public boolean hovered = false;
public boolean close = false;
public boolean show = false;
public boolean remove = false;
public Alert alert = null;
public client c;

public AlertHandler(client c) {
this.c = c;
}
public void close() {
close = true;
}
public void processAlerts() {

if(alert == null)
return;
if (alert.active()) {
if (close) {
alert.close();
close = false;
}
if (!alert.isClosed() && alert.getOpacity() < 90 && alert.extraY > 0) {
alert.opacity += 5;
if(alert.extraY > 0)
alert.extraY -= (c.isFullScreen ? 10 : 5);
if(alert.extraY < 0)
alert.extraY = 0;
c.alertBack.drawSpriteOpacity(alert.getX(), alert.getY()+alert.extraY, alert.getOpacity());
} else if (alert.isClosed()) {
alert.extraY += 5;
if(alert.getOpacity() > 0)
alert.opacity -= 5;
else {
remove = true;
show = false;
alert.active = false;
}
c.alertBack.drawSpriteOpacity(alert.getX(), alert.getY()+alert.extraY, alert.getOpacity());
} else {
if(alert.getOpacity() < 90)
alert.opacity = 90;
if (show) {
c.alertBack.drawSpriteOpacity(alert.getX(), alert.getY(), hovered ? alert.getOpacity()+25 : alert.getOpacity());
if(hovered)
c.alertBorderH.drawSprite(alert.getX(), alert.getY());
else
c.alertBorder.drawSprite(alert.getX(), alert.getY());
}

c.aTextDrawingArea_1271.drawText(0, alert.getTitle(), alert.getY()+16, alert.getX()+243);
c.aTextDrawingArea_1271.drawText(alert.getTitleColor(), alert.getTitle(), alert.getY()+15, alert.getX()+242);
c.smallText.drawText(0, alert.getLine(1), alert.getY()+36, alert.getX()+243);
c.smallText.drawText(alert.getColor(2), alert.getLine(1), alert.getY()+35, alert.getX()+242);
c.smallText.drawText(0, alert.getLine(2), alert.getY()+56, alert.getX()+243);
c.smallText.drawText(alert.getColor(2), alert.getLine(2), alert.getY()+55, alert.getX()+242);
show = true;
}
}
if (remove) {
alert = null;
remove = false;
}
}
public void processMouse(int x, int y) {
if(alert == null)
return;
if (alert.active()) {
hovered = (x >= alert.getX() && x <= alert.getX()+484 && y >= alert.getY() && y <= alert.getY()+79);
if(hovered) {
c.menuActionName[1] = "Dismiss";
c.menuActionID[1] = 476;
c.menuActionRow = 2;
}
}
}
}
Alert.java
Code: [Select]
/**
* @Author Robgob
* Do whatever you want.
*/
public class Alert {

public Alert(String title, String line1, String line2) {
this.title = title;
this.line1 = line1;
this.line2 = line2;
titleColor = 0xff0000;
color1 = 0xffffff;
color2 = 0xffffff;
active = true;
}
public Alert(String title, String line1, String line2, int c1, int c2, int c3) {
this.title = title;
this.line1 = line1;
this.line2 = line2;
titleColor = c1;
color1 = c2;
color2 = c3;
active = true;
}

public String getTitle() {
return title;
}
public String getLine(int i) {
return (i == 1 ? line1 : line2);
}
public int getTitleColor() {
return titleColor;
}
public int getColor(int i) {
return (i == 1 ? color1 : color2);
}
public boolean active() {
return active;
}
public void close() {
closed = true;
}
public boolean opening() {
return open;
}
public int getOpacity() {
return opacity;
}
public boolean isClosed() {
return closed;
}
public int getX() {
return x;
}
public int getY() {
return y;
}
/*
* Holds the text for the Notification
*/
private String title;
private String line1;
private String line2;

/*
* Holds the Colors for the Notification
*/
private int titleColor;
private int color1;
private int color2;

/*
* is the notification active; visible.
*/
public boolean active = false;

/*
* is the notification closed by the user?
*/
private boolean closed = false;
/*
* is the notification opening?
*/
public boolean open = true;

/*
* How visible the Notification is
* 0 = not at all || 50 = barely || 255 = fully visible
*/
public int opacity = 0;

/*
* Holds the Screen position
*/
private int x = 14;
private int y = 250;
public int extraX = 0;
public int extraY = 40;
}

After that you're going to need to add the Sprites


 - save as: alertback.png

 - save as: alertborder.png

 - save as: alertborderh.png

Now for the coding; Open up your client.java

add this somewhere in:
Code: [Select]
public AlertHandler alertHandler;
public Sprite alertBack;
public Sprite alertBorder;
public Sprite alertBorderH;

Then search for: 
Code: [Select]
void resetLogout()
and under that line add:
Code: [Select]
alertHandler.alert = null;
then search for:
Code: [Select]
/* Null pointers for custom sprites */
add this under it:
Code: [Select]
alertBack = null;
alertBorder = null;
alertBorderH = null;
now search for:
Code: [Select]
void doAction(int i)and in that method where you see
Code: [Select]
if(l >= 2000)
l -= 2000;
add this right under it:
Code: [Select]
if (l == 476) {
alertHandler.close();
}

Now search for:
Code: [Select]
rightClickChatButtons();
add this under it:
Code: [Select]
alertHandler.processMouse(super.mouseX, super.mouseY);
Now search for:
Code: [Select]
scrollBar2 = new Sprite(streamLoader_2, "scrollbar", 1);
and add this below it:
Code: [Select]
alertBack = new Sprite("alertback");
alertBorder = new Sprite("alertborder");
alertBorderH = new Sprite("alertborderh");

Next search for:
Code: [Select]
void draw3dScreen()
and add this right below it:
Code: [Select]
alertHandler.processAlerts();


Next search for:
Code: [Select]
case 253:
It should look something like this..
Code: [Select]
case 253:
String s = inStream.readString();
if(s.endsWith(":tradereq:")) {
String s3 = s.substring(0, s.indexOf(":"));
long l17 = TextClass.longForName(s3);
boolean flag2 = false;
for(int j27 = 0; j27 < ignoreCount; j27++) {
if(ignoreListAsLongs[j27] != l17)
continue;
flag2 = true;

}
if(!flag2 && anInt1251 == 0)
pushMessage("wishes to trade with you.", 4, s3);
} else if(s.endsWith("#url#")) {
String link = s.substring(0, s.indexOf("#"));
pushMessage("Join us at: ", 9, link);
} else if(s.endsWith(":duelreq:")) {
String s4 = s.substring(0, s.indexOf(":"));
long l18 = TextClass.longForName(s4);
boolean flag3 = false;
for(int k27 = 0; k27 < ignoreCount; k27++) {
if(ignoreListAsLongs[k27] != l18)
continue;
flag3 = true;

}
if(!flag3 && anInt1251 == 0)
pushMessage("wishes to duel with you.", 8, s4);
} else if(s.endsWith(":chalreq:")) {
String s5 = s.substring(0, s.indexOf(":"));
long l19 = TextClass.longForName(s5);
boolean flag4 = false;
for(int l27 = 0; l27 < ignoreCount; l27++) {
if(ignoreListAsLongs[l27] != l19)
continue;
flag4 = true;

}
if(!flag4 && anInt1251 == 0) {
String s8 = s.substring(s.indexOf(":") + 1, s.length() - 9);
pushMessage(s8, 8, s5);
}
} else {
pushMessage(s, 0, "");
}
pktType = -1;
return true;

So right under where it says:
Code: [Select]
String s = inStream.readString();add this right below it:
Code: [Select]
if(s.startsWith("Alert##")) {
String[] args = s.split("##");
if (args.length == 3) {
alertHandler.alert = new Alert("Notification", args[1], args[2]);
} else if (args.length == 4) {
alertHandler.alert = new Alert(args[1], args[2], args[3]);
}
pktType = -1;
return true;
}

Next search for:
Code: [Select]
public client() {(sometimes private client())

under that add:
Code: [Select]
alertHandler = new AlertHandler(this);

And the last part make sure that these variables have public access in the client
so change these:
Code: [Select]
private TextDrawingArea smallText;
private TextDrawingArea aTextDrawingArea_1271;
private String[] menuActionName;
private int[] menuActionID;
private int menuActionRow;
to these:
Code: [Select]
public TextDrawingArea smallText;
public TextDrawingArea aTextDrawingArea_1271;
public String[] menuActionName;
public int[] menuActionID;
public int menuActionRow;


So that should be about it for the client

Now in your server to get the alert to work you need a message to be sent.
For the welcome screen add this wherever your welcome message is initiated:
Code: [Select]
sendMessage("Alert##Welcome to YOUR SERVER NAME!##This is Robgob's new Alert system!##He's a sexy Beast ;]");

For an alert command[PI]:
Code: [Select]
if (playerCommand.startsWith("alert") && c.playerRights > 1) {
String msg = playerCommand.substring(6);
for (int i = 0; i < Config.MAX_PLAYERS; i++) {
if (Server.playerHandler.players[i] != null) {
c.sendMessage("Alert##Notification##" + msg + "##By: " + c.playerName);
}
}
}
For an alert command[Allstar]:
Code: [Select]
if (command.startsWith("alert") && playerRights > 1) {
String msg = playerCommand.substring(6);
PlayerHandler.messageToAll = "Alert##Notification##" + msg + "##By: " + playerName;
}


Here's your end result:

Share on Bluesky Share on Facebook


Offline AdotSells

  • Firecape Member
  • *
  • Posts: 300
  • Rep 4
    • View Profile
Re: My New Alert System
« Reply #1 on: March 10, 2011, 11:21:40 pm »
Verryy nice mate!!! 
Rep :) :uj: :uj: :uj: :uj: :uj: :uj: :uj: :uj: :uj: :uj: :uj: :uj: :tf: :tf: :tf: :tf: :tf: :tf: :tf: :tf:

Offline brandon

  • Veteran
  • Dragon Member
  • *
  • Posts: 240
  • Rep 12
    • View Profile
Re: My New Alert System
« Reply #2 on: March 10, 2011, 11:49:48 pm »
Very nice, I will Rep++ you as well, by the way, link to your server? Thanks

Offline robgob

  • Adamant Member
  • *
  • Posts: 120
  • Rep 5
  • I swarm like locust
  • Location: Michigan
    • View Profile
Re: My New Alert System
« Reply #3 on: March 11, 2011, 12:05:37 am »
Thanks for the rep ^_^
and Ill pm you, Brandon.

Offline Moe505

  • Veteran
  • Firecape Member
  • *
  • Posts: 293
  • Rep 187
  • Location: Australia
    • View Profile
Re: My New Alert System
« Reply #4 on: March 11, 2011, 12:37:01 am »
Looks good, you can improve it a little bit though.
I like your ideas ;).

Offline robgob

  • Adamant Member
  • *
  • Posts: 120
  • Rep 5
  • I swarm like locust
  • Location: Michigan
    • View Profile
Re: My New Alert System
« Reply #5 on: March 11, 2011, 01:09:52 am »
How so?

Offline Moe505

  • Veteran
  • Firecape Member
  • *
  • Posts: 293
  • Rep 187
  • Location: Australia
    • View Profile
Re: My New Alert System
« Reply #6 on: March 11, 2011, 02:43:18 am »
Making it go from left to right, or just fade away (GFX content).
Code wise, their OK.No need improvements.
If it was server sided I'd be more specific, I suck at client.

Offline robgob

  • Adamant Member
  • *
  • Posts: 120
  • Rep 5
  • I swarm like locust
  • Location: Michigan
    • View Profile
Re: My New Alert System
« Reply #7 on: March 11, 2011, 05:23:59 am »
It fades in and out, and moves up and down. Did you not watch the video?

Offline brandon

  • Veteran
  • Dragon Member
  • *
  • Posts: 240
  • Rep 12
    • View Profile
Re: My New Alert System
« Reply #8 on: March 11, 2011, 12:05:28 pm »
It fades in and out, and moves up and down. Did you not watch the video?

The only thing which I didn't like was when you kill someone in ::funpk it sends the message.

Offline AdotSells

  • Firecape Member
  • *
  • Posts: 300
  • Rep 4
    • View Profile
Re: My New Alert System
« Reply #9 on: March 11, 2011, 12:50:12 pm »
I dont really have a problem with it at all I think its the bestt :)

Offline robgob

  • Adamant Member
  • *
  • Posts: 120
  • Rep 5
  • I swarm like locust
  • Location: Michigan
    • View Profile
Re: My New Alert System
« Reply #10 on: March 11, 2011, 05:57:35 pm »
It fades in and out, and moves up and down. Did you not watch the video?

The only thing which I didn't like was when you kill someone in ::funpk it sends the message.
Thats not apart of this tutorial at all lol, that was apart of my server.

Offline brandon

  • Veteran
  • Dragon Member
  • *
  • Posts: 240
  • Rep 12
    • View Profile
Re: My New Alert System
« Reply #11 on: March 11, 2011, 06:09:19 pm »
True, I didn't try it out yet, but I may add it in.

Offline Scar

  • Steel Member
  • *
  • Posts: 34
  • Rep 1
    • View Profile
Re: My New Alert System
« Reply #12 on: March 12, 2011, 04:35:40 am »
It fades in and out, and moves up and down. Did you not watch the video?
I think he meant,
Something like this;
ALERY SYSTEM BOIS

Offline robgob

  • Adamant Member
  • *
  • Posts: 120
  • Rep 5
  • I swarm like locust
  • Location: Michigan
    • View Profile
Re: My New Alert System
« Reply #13 on: March 12, 2011, 03:54:38 pm »
its not hard to add that in :]

Offline Scar

  • Steel Member
  • *
  • Posts: 34
  • Rep 1
    • View Profile
Re: My New Alert System
« Reply #14 on: March 13, 2011, 01:45:27 am »
For him it is, He sucks at clients so do I.