Young Jordie requested i make a chat box for him. Thought i may as well share it around.
so badum. here it is. Not sure if it works, but i tested it with myself and it seemed fine. If it’s faulty, i’ll be back later to fix and edit this post.
This shud hopefully display a litte box in the bottom left and show the last 10 things said… No scroller, the buffer is only 10 vars large. eh.
btw, if this is already somewhere on the forums, facepalm wasted time. neways, its almost 2am, time to try sleep.
Here you go:
// NPC made by potato
if (created||playerenters) {
timereverywhere;
this.drawIndexStart = 500;
this.chatLines = 10;
this.chatIndex = 0;
setarray this.chatText, this.chatLines;
setarray this.chatName, this.chatLines;
timeout = .1;
}
if(playerenters){
toweapons -chat;
}
if(playerchats){
//transmit chat
for(this.i=0;this.i<playerscount;this.i++){
triggeraction players[this.i].x+1.45,players[this.i].y+1.45,SendChat,#a,#c;
}
}
if(actionSendChat){
//store chat into local array
setstring this.chatName[#v(this.chatIndex)], #p(0): ;
setstring this.chatText[#v(this.chatIndex)], #p(1);
this.chatIndex++;
if(this.chatIndex == this.chatLines){
this.chatIndex = 0;
}
}
if(timeout){
//reset box position
//divided by 16 to get tiles -> pixel
rect.x = playerx-18.5;
rect.y = playery+4.6;
rect.width = 24;
rect.height = 12;
//restrict to screen values
if( rect.x < 0 ){ rect.x = 0; }
if( rect.y < 0 ){ rect.y = 0; }
if( rect.width > screenwidth/16 ){ rect.width = screenwidth/16; }
if( rect.hieght > screenwidth/16 ){ rect.hieght = screenhieght/16; }
if( rect.x+rect.width > 64 ){ rect.x = 64-rect.width; }
if( rect.y+rect.height > 64 ){ rect.y = 64-rect.height; }
//show bg
showimg 260,chat_background.png,rect.x-.5, rect.y-.5;
changeimgcolors 260,1,1,1,.1;
changeimgvis 260, 2;
//draw box title
showimg 256,@TEMPSITC.TTF@@Chat,rect.x+.5, rect.y;
changeimgcolors 256,.2,.2,.7,1;
changeimgzoom 256, .6;
changeimgvis 256, 3;
//draw chat
this.drawIndex = this.drawIndexStart;
this.chatIndexRead = this.chatIndex-1;
if(this.chatIndexRead < 0 ){ this.chatIndexRead = 0; }
for(this.i = 0; this.i < this.chatLines; this.i++){
setstring this.chatname, #s(this.chatName[#v(this.chatIndexRead)]);
setstring this.chattext, #s(this.chatText[#v(this.chatIndexRead)]);
showimg this.drawIndex,@TEMPSITC.TTF@bold@#s(this.chatname),rect.x+.5, rect.y+this.chatLines-this.i;
if( startswith(#a,#s(this.chatname)) ){
changeimgcolors this.drawIndex,.7,1,.7,1;
} else {
changeimgcolors this.drawIndex,1,1,1,1;
}
changeimgzoom this.drawIndex, .6;
changeimgvis this.drawIndex, 3;
this.drawIndex++;
showimg this.drawIndex,@TEMPSITC.TTF@@#s(this.chattext),rect.x+.8+(textwidth(.6,TEMPSITC.TTF,bold,#s(this.chatname))/16), rect.y+this.chatLines-this.i;
if( startswith(#a,#s(this.chatname)) ){
changeimgcolors this.drawIndex,.7,1,.7,1;
} else {
changeimgcolors this.drawIndex,1,1,1,1;
}
changeimgzoom this.drawIndex, .6;
changeimgvis this.drawIndex, 3;
this.drawIndex++;
this.chatIndexRead--;
if(this.chatIndexRead == -1){
this.chatIndexRead = this.chatLines-1;
}
}
timeout = .05;
}