NOTE: First of all, I'd like to say that no one is allowed to use this script for his/her own server, or a server he/she works on. I'm just showing this because I can't find a problem in it, but there is.
The problem: The first time I add a few messages, everything works perfect, but as soon as I use my (tempory) commands like; /msg <msg>, /adm <msg> and/or /sys <msg>, things go wrong.
What goes wrong?
The 5 between params[ 0] and params[ 1] in the serverside part (i.triggerClient ... line) stands for the seconds the message should show.
The first time I do a message, after all the other messages, which I added at onCreated() ..., are hidden (using '/msg' or any of the other commands) it still works fine.
But when I wait one second after the first time, and then add another message, it SHOULD be like, the first message has 4 seconds left of showing, and the new message 5 seconds. But what happens? They both hide after 4 seconds. So yeah.. that pretty much "sucks" xD Especially if I wait 4 seconds and then add a new message, because then, they'll both hide after 1 second.
I hope anyone gets what I mean, and is able to help me.
PHP Code:
function onActionServerSide() {
for ( i: allplayers)
i.triggerClient( "gui", "*Messages", params[ 0], 5, params[ 1]);
}
//#CLIENTSIDE
function onCreated() {
newMessage( "System", 10, "Welcome to Bomy Islands!");
newMessage( "contiga", 6, "*test 123 test*");
newMessage( "Stefan", 9, "I'll come to G2k1 immediately, to script you guys a better bomypet!!!");
newMessage( "Konidias", 14, "Lalaaalaaa :D");
newMessage( "Admin", 14, "Testmsgg");
newMessage( "contiga", 15, "Test");
this.lastdeltime = this.shortesttime = NULL;
this.laststart = timevar2;
this.maxlines = 16;
}
function onPlayerChats() { // just temp, to test
if ( player.chat.starts( "/msg"))
triggerServer( "gui", name, player.account, player.chat.substring( 5));
if ( player.chat.starts( "/sys"))
triggerServer( "gui", name, "System", player.chat.substring( 5));
if ( player.chat.starts( "/adm"))
triggerServer( "gui", name, "Admin", player.chat.substring( 5));
}
function onActionClientSide()
newMessage( params[ 0], params[ 1], params[ 2]);
function updateList() {
hideImgs( 200, 400);
cancelEvents( "delmessage");
if ( this.msgs.size() == NULL) {
this.lastdeltime = NULL;
return "";
}
this.linestaken = NULL;
this.shortesttime = 50;
this.destroylist = "";
this.laststart = timevar2;
for ( ind = 0; ind < this.msgs.size(); ind ++) {
this.msgs[ ind][ 1] = this.msgs[ ind][ 1] - this.lastdeltime;
this.linestakenbefore = this.linestaken;
this.cmsgt = this.msgs[ ind][ 1];
if ( this.cmsgt < this.shortesttime) {
this.shortesttime = this.cmsgt;
this.destroylist = ind @ ",";
}
else if ( this.cmsgt == this.shortesttime)
this.destroylist @= ind @ ",";
this.cmsg = this.msgs[ ind][ 2];
this.cmsgp = 0;
for ( i: this.cmsg) {
with ( findImg( 201 + this.linestaken)) {
text = i;
x = 32 + ( ( thiso.cmsg.index( i) < thiso.cmsg.size() - 1) ? 16 : 0);
y = screenheight - 56 - ( thiso.linestaken * 18);
shadowoffset = { - 1, + 1};
shadowcolor = { 0, 0, 0};
textshadow = true;
font = "Arial";
style = "b";
zoom = 0.8;
layer = 6;
}
this.linestaken ++;
this.cmsgp ++;
}
this.poly_x = 28;
this.poly_y = screenheight - 37 - ( ( this.linestakenbefore + this.cmsgp) * 18);
this.poly_w = 324;
this.poly_h = thiso.cmsgp * 18;
this.poly_a = { this.poly_x, this.poly_y, this.poly_x + this.poly_w, this.poly_y, this.poly_x + this.poly_w, this.poly_y + this.poly_h, this.poly_x, this.poly_y + this.poly_h};
if ( this.msgs[ ind][ 0] == "System")
this.poly_c = { 1, 0.8, 0};
else if ( this.msgs[ ind][ 0] == "Admin")
this.poly_c = { 1, 0, 0};
else
this.poly_c = { 0.2, 1, 0.2};
with ( findImg( 300 + ind)) {
polygon = thiso.poly_a;
alpha = ( ind % 2 == 1) ? 0.5 : 0.6;
green = thiso.poly_c[ 1];
blue = thiso.poly_c[ 2];
red = thiso.poly_c[ 0];
layer = 5;
mode = 1;
}
}
this.poly_x = 28;
this.poly_y = screenheight - 37 - ( ( this.linestakenbefore + this.cmsgp) * 18);
this.poly_w = 324;
this.poly_h = this.linestaken * 18;
this.poly_a = { this.poly_x, this.poly_y, this.poly_x + this.poly_w, this.poly_y, this.poly_x + this.poly_w, this.poly_y + this.poly_h, this.poly_x, this.poly_y + this.poly_h};
with ( findImg( 200)) {
polygon = thiso.poly_a;
alpha = 0.8;
red = green = blue = 0;
layer = 4;
mode = 1;
}
scheduleEvent( this.shortesttime, "DelMessage", this.shortesttime);
}
function onDelMessage( dt) {
for ( dmsg: this.destroylist)
this.msgs.delete( dmsg - this.destroylist.index( dmsg));
if ( this.msgs.size() == NULL) this.lastdeltime = NULL;
else this.lastdeltime = dt;
updateList();
}
public function newMessage( sender, time, msg) {
this.lastdeltime = int( timevar2 - this.laststart);
if ( this.lastdeltime > 50) this.msgs = NULL;
if ( this.msgs.size() == NULL) this.lastdeltime = NULL;
position = this.msgs.size() + 1;
this.msgs.insert( 0, { sender, time, turnAround( wraptext2( 300, 0.8, " ", "@Arial@b@*" @ sender @ ": " @ msg))});
updateList();
}
function turnAround( cmsg) {
temp.msg = "";
for ( temp.c: cmsg)
temp.msg.insert( 0, temp.c);
return temp.msg;
}
Ps. I didn't style this script like I should style it yet, I just kept a lot of space to keep the script well-organized because of the errors in it.