Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   Code Gallery (https://forums.graalonline.com/forums/forumdisplay.php?f=179)
-   -   Chat Room (https://forums.graalonline.com/forums/showthread.php?t=134264476)

Emera 09-04-2011 09:42 PM

Chat Room
 
I have constructed a simple chat room GUI, with the help of players on the forums, so many thanks to them. It enables you to chat with a neat GUI interface to the servers players, that is, if the players have the weapon! There isn't really any cool features I have added to it, but feel free to add them or suggest some ideas. Here is the code.
PHP Code:

function onActionServerSide() {
  if (
params[0] == "sendtext") {
    for (
temp.plallplayers) {
      if (
temp.pl.level != NULL) {
        
temp.pl.triggerclient(this.name"gettext"params[1], player.nick);
      }
    }
  }
}

//#CLIENTSIDE
function onCreated() {
  new 
GuiWindowCtrl("Msg_Window1") {
    
profile GuiBlueWindowProfile;
    
clientrelative true;
    
clientextent "320,240";
    
canmaximize false;
    
canmove true;
    
canresize false;
    
closequery false;
    
destroyonhide true;
    
text "Staff Chat Channel";
    
517;
    
203;
    new 
GuiScrollCtrl("Msg_Chatbox_Scroll") {
      
profile GuiBlueScrollProfile;
      
height 215;
      
hscrollbar "dynamic";
      
vscrollbar "dynamic";
      
width 316;
      
2;
      
2;
      new 
GuiMLTextCtrl("Msg_Chatbox") {
        
profile GuiBlueMLTextProfile;
        
height 17;
        
horizsizing "width";
        
text "<b><font color = white>System</b>: Input /clear to clear the message box.";
        
width 312;
        
profile.fontsize 14.3;
        
profile.fonttype "Arial";
        
profile.textshadow true;
      }
    }
    new 
GuiTextEditCtrl("Msg_ChatBar") {
      
profile GuiBlueTextEditProfile;
      
height 20;
      
width 316;
      
2;
      
219;
    }
  }
}

function 
Msg_ChatBar.onAction() {
  
temp.msg "";
  if (
Msg_ChatBar.text == "/clear") {
    
Msg_Chatbox.text "Cleared!";
  } else {
    if (
Msg_ChatBar.text != NULL) {
      
temp.msg Msg_ChatBar.text;
      
triggerserver("weapon"this.name"sendtext"temp.msg);
      
Msg_ChatBar.text "";
    }
  }
  if (
temp.msg.starts("/font ")) {
    
say2("Works");
  }
}

function 
onActionClientSide() {
  if (
params[0] == "gettext") {
    
Msg_Chatbox.addtext("<br><b><font color = cyan>" params[2] @ "</b>: " params[1], false);
    
Msg_ChatBox.scrolltobottom();
  }



SoundFreak 09-04-2011 10:01 PM

What would really be nice mate is if you made a little *blip* sound when you receive a message. I can cook you up one if you like. <3
Also, couldn't you make a public function to add messages, so you can add messages to the system with other scripts, like a miniature RC? Say if a player logged in, you could then add a message like...
PHP Code:

sendtochatroom("Message Here""Title (System:)"redgreenblue); 

Could you guys help him out with doing that? I would really like to see that done.

Emera 09-04-2011 10:52 PM

Trashed the window and added a border instead. Looks much nicer.
PHP Code:

function onActionServerSide() {
  if (
params[0] == "sendtext2") {
    for (
temp.plallplayers) {
      if (
temp.pl.level != NULL) {
        
temp.pl.triggerclient(this.name"gettext2"params[1], player.nick);
      }
    }
  }
}

//#CLIENTSIDE
function onCreated() {
  new 
GuiControl("Msg2_Window1") {
    
useownprofile true;
    
profile.border 1;
    
profile.opaque true;
    
profile.fillColor = {055150225};
    
width 328.5;
    
destroyonhide true;
    
height 250;
    
canmove true;
    
517;
    
203;
    new 
GuiScrollCtrl("Msg2_Chatbox_Scroll") {
      
profile GuiBlueScrollProfile;
      
height 215;
      
hscrollbar "dynamic";
      
vscrollbar "dynamic";
      
width 316;
      
6.5;
      
6.5;
      new 
GuiMLTextCtrl("Msg2_Chatbox") {
        
profile GuiBlueMLTextProfile;
        
height 17;
        
horizsizing "width";
        
text "<b><font color = white>System</b>: Input /clear to clear the message box.";
        
width 312;
        
profile.fontsize 14.3;
        
profile.fonttype "Arial";
        
profile.textshadow false;
      }
    }
    new 
GuiTextEditCtrl("Msg2_ChatBar") {
      
profile GuiBlueTextEditProfile;
      
height 20;
      
width 316;
      
6;
      
225;
    }
  }
}

function 
Msg2_ChatBar.onAction() {
  
temp.msg2 "";
  if (
Msg2_ChatBar.text == "/clear") {
    
Msg2_Chatbox.text "Cleared!";
  } else {
    if (
Msg2_ChatBar.text != NULL) {
      
temp.msg2 Msg2_ChatBar.text;
      
triggerserver("weapon"this.name"sendtext2"temp.msg2);
      
Msg2_ChatBar.text "";
    }
  }
  if (
temp.msg2.starts("/font ")) {
    
say2("Works");
  }
}

function 
onActionClientSide() {
  if (
params[0] == "gettext2") {
    
Msg2_Chatbox.addtext("<br><b><font color = cyan>" params[2] @ "</b>: " params[1], false);
    
Msg2_ChatBox.scrolltobottom();
  }



Emera 09-04-2011 11:28 PM

I have no idea on how to make public functions.

salesman 09-04-2011 11:50 PM

Should look into sendtext() and irc for a chat room system

Emera 09-04-2011 11:51 PM

Quote:

Originally Posted by salesman (Post 1667060)
Should look into sendtext() and irc for a chat room system

I did but I don't want to add anything like that yet. This is purely for me to learn.

cbk1994 09-05-2011 12:04 AM

Quote:

Originally Posted by Emera (Post 1667059)
I have no idea on how to make public functions.

Quote:

Originally Posted by cbk1994 (Post 1633023)
Let's say you have a level NPC with this code:
PHP Code:

function hit() {
  
this.chat "I was hit!";


If you tried to call this function from another script, you wouldn't be able to.

PHP Code:

myNPC.hit(); 

You would see a "function not accessible" error.

When you make it public, it can be called by another script. To make something public, all you need to do is change "function" to "public function".

For example, if you have a system named Health, and you wanted to add a function for healing a player, your code might look like this:

PHP Code:

// weapon Health
//#CLIENTSIDE
public function heal() {
  
player.hearts player.fullhearts;


then, in any other clientside script, you could do

PHP Code:

Health.heal(); 

in order to call the 'heal' function in the Health weapon.

In object-oriented programming, it's good style to make all of your internal functions private. The idea is to provide easy functions like "player.heal()" or "player.hurt()". Then, if you ever change how your HP system works, you don't have to change any scripts that use those public functions. You want to hide the nitty-gritty stuff and just provide functions for doing certain tasks.

..

Emera 09-05-2011 12:07 AM

I am trying to post the code but my browser returns an incapsula error saying the server is protecting me from a risk. I think it might be detecting something with my scripting. Is it that bad xD
Pastebin file
:O Never mind fixed it. The RGBA doesn't work though

furry_mougle 09-05-2011 12:23 AM

If you join an NPC with a class I think you can execute a function even if it's not declared public, don't quote me on that though.


All times are GMT +2. The time now is 11:47 PM.

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2026, vBulletin Solutions Inc.
Copyright (C) 1998-2019 Toonslab All Rights Reserved.