Graal Forums  

Go Back   Graal Forums > Development Forums > NPC Scripting > Code Gallery
FAQ Members List Calendar Today's Posts

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 09-04-2011, 09:42 PM
Emera Emera is offline
Delterian Hybrid
Emera's Avatar
Join Date: Mar 2011
Location: Newcastle Upon-Tyne
Posts: 1,704
Emera is a jewel in the roughEmera is a jewel in the rough
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();
  }

__________________
Reply With Quote
  #2  
Old 09-04-2011, 10:01 PM
SoundFreak SoundFreak is offline
Music Artist
SoundFreak's Avatar
Join Date: Aug 2011
Posts: 15
SoundFreak is on a distinguished road
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.
Reply With Quote
  #3  
Old 09-04-2011, 10:52 PM
Emera Emera is offline
Delterian Hybrid
Emera's Avatar
Join Date: Mar 2011
Location: Newcastle Upon-Tyne
Posts: 1,704
Emera is a jewel in the roughEmera is a jewel in the rough
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();
  }

__________________
Reply With Quote
  #4  
Old 09-04-2011, 11:28 PM
Emera Emera is offline
Delterian Hybrid
Emera's Avatar
Join Date: Mar 2011
Location: Newcastle Upon-Tyne
Posts: 1,704
Emera is a jewel in the roughEmera is a jewel in the rough
I have no idea on how to make public functions.
__________________
Reply With Quote
  #5  
Old 09-04-2011, 11:50 PM
salesman salesman is offline
Finger lickin' good.
salesman's Avatar
Join Date: Nov 2008
Location: Colorado
Posts: 1,865
salesman has much to be proud ofsalesman has much to be proud ofsalesman has much to be proud ofsalesman has much to be proud ofsalesman has much to be proud ofsalesman has much to be proud ofsalesman has much to be proud of
Should look into sendtext() and irc for a chat room system
__________________
Reply With Quote
  #6  
Old 09-04-2011, 11:51 PM
Emera Emera is offline
Delterian Hybrid
Emera's Avatar
Join Date: Mar 2011
Location: Newcastle Upon-Tyne
Posts: 1,704
Emera is a jewel in the roughEmera is a jewel in the rough
Quote:
Originally Posted by salesman View Post
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.
__________________
Reply With Quote
  #7  
Old 09-05-2011, 12:04 AM
cbk1994 cbk1994 is offline
the fake one
cbk1994's Avatar
Join Date: Mar 2003
Location: San Francisco
Posts: 10,718
cbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond repute
Send a message via AIM to cbk1994
Quote:
Originally Posted by Emera View Post
I have no idea on how to make public functions.
Quote:
Originally Posted by cbk1994 View Post
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.
..
__________________
Reply With Quote
  #8  
Old 09-05-2011, 12:07 AM
Emera Emera is offline
Delterian Hybrid
Emera's Avatar
Join Date: Mar 2011
Location: Newcastle Upon-Tyne
Posts: 1,704
Emera is a jewel in the roughEmera is a jewel in the rough
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
__________________
Reply With Quote
  #9  
Old 09-05-2011, 12:23 AM
furry_mougle furry_mougle is offline
big heart
furry_mougle's Avatar
Join Date: Aug 2011
Posts: 42
furry_mougle is an unknown quantity at this point
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.
__________________
Quote:
Originally Posted by ffcmike View Post
But make sure to change beer.png to Orange Juice.
pay bills to play graal
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +2. The time now is 09:15 PM.


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