Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   NPC Scripting (https://forums.graalonline.com/forums/forumdisplay.php?f=8)
-   -   Custom Chat System (https://forums.graalonline.com/forums/showthread.php?t=134264080)

Gunderak 08-03-2011 10:09 AM

Custom Chat System
 
Come on guys, you know the good old online rpg games!
anyway basically iv got a script where when the player chats it shows all players chat in a window. the only problem is it only will show one players chat then when another player chats it disappears.
how would i make this so when you chat it shows it and when someone else chats your chat gets pushed up and theirs goes where yours was?

PHP Code:

//#CLIENTSIDE
function onPlayerChats(){
server.chat player.chat;
}
function 
onCreated() {
ChatBar.width 600;
ChatBar.alpha 0.6;
ChatBar.useownprofile true;
ChatBar.profile.bitmap "Test_textedit.png";
ChatBar.height 25;
ChatBar.783;
ChatBar.0;
 new 
GuiWindowCtrl("MyGUI_Window1") {
    
profile GuiBlueWindowProfile;
    
clientrelative true;
    
clientextent "588,100";

    
canclose false;
    
canmaximize false;
    
canminimize false;
    
canmove false;
    
canresize false;
    
closequery false;
    
destroyonhide false;
    
alpha 0.6;
    
0;
    
653;
  }
    
setTimer(0.05);
}
function 
onTimeout() {
  for (
temp.pplayers) {
    
temp.player_chat temp.p.chat.trim();
    if (
temp.p.chat != "") {
      new 
GuiTextCtrl("PlayersChat") {
      
profile GuiBlueTextProfile;
      
height 20;
      
width 600;
      
text temp.p.nick@": "@server.chat;
      
width 200;
      
7;
      
757;
    }
    }
  }
  
setTimer(0.05);


Just wondering if its even possible?

Mark Sir Link 08-03-2011 10:35 AM

you are redefining the PlayerChat GUI constantly and not even placing it within your original GUI. You should also be using a GuiMLTextCtrl, for multiple lines of chat. Quick example, not tested.

PHP Code:

//#CLIENTSIDE
function onCreated(){
  new 
GuiWindowCtrl("Chat_Window"){
    
profile GuiBlueWindowProfile;
    new 
GuiMLTextCtrl("Chat_Text"){
      
profile GuiBlueMLTextCtrl;
    }
  }
}

function 
onPlayerChats(){
  
addChat(player.nickplayer.chat);
}

function 
onRemotePlayerChats(temp.pltemp.txt){
  
addChat(pl.nicktxt);
}

function 
addChat(temp.srctemp.txt){
  
Chat_Text.addtext(src @":" SPC txt);
  
Chat_Text.scrolltobottom();



cbk1994 08-03-2011 10:44 AM

The above example looks right except for one thing.

PHP Code:

Chat_Text.addtext(src @":" SPC txt); 

should probably be

PHP Code:

Chat_Text.addtext("\n" src @":" SPC txt); 

so that eat piece of chat is on its own line.

Mark Sir Link 08-03-2011 11:41 AM

Quote:

Originally Posted by cbk1994 (Post 1661440)
The above example looks right except for one thing.

PHP Code:

Chat_Text.addtext(src @":" SPC txt); 

should probably be

PHP Code:

Chat_Text.addtext("\n" src @":" SPC txt); 

so that eat piece of chat is on its own line.

or <br> since htmltags are probably enabled by default for MLTextCtrls.

Probably want to append it to the end rather than the beginning so you don't create a blank line right away.

Gunderak 08-03-2011 04:30 PM

wow a new gui i didnt even know about lol.. i havnt been able to test around with your example and tweak it yet seeming im not at home. id there any way to make a scroll bar which wiuld allow you to view previous text?
thanks guys for your help.
id be stuck without it! :D
As you guys can probably tell im extremly new to scripting.
iv only been scripting for about two months now.
im also trying to learn javascript which iv noticed is extremly simmilar.
would this benefit my scripting ability on graal in any way shape or form?
thanks again.

cbk1994 08-03-2011 05:16 PM

Quote:

Originally Posted by Gunderak (Post 1661460)
wow a new gui i didnt even know about lol.. i havnt been able to test around with your example and tweak it yet seeming im not at home. id there any way to make a scroll bar which wiuld allow you to view previous text?

You need to put the GuiMLTextCtrl inside a GuiScrollCtrl.

PHP Code:

new GuiWindowCtrl("Test_Window") {
  
profile GuiBlueWindowProfile;
  
  
width 200;
  
height 200;
  
  
clientRelative true;
  
  new 
GuiScrollCtrl("Test_Scroll") {
    
profile GuiBlueScrollProfile;

    
5;
    
5;

    
width 190;
    
height 190;

    new 
GuiMLTextCtrl("Test_Text") {
      
profile GuiBlueMLTextProfile;
      
      
0;
      
0;
      
      
text "This is a multi-line text control."
    
}
  }


Quote:

im also trying to learn javascript which iv noticed is extremly simmilar.
would this benefit my scripting ability on graal in any way shape or form?
thanks again.
Learning any other language will improve your scripting ability in Graal, but JavaScript is especially beneficial as it's highly useful and its syntax is nearly identical to GScript's.

Gunderak 08-04-2011 12:35 AM

Quote:

Learning any other language will improve your scripting ability in Graal, but JavaScript is especially beneficial as it's highly useful and its syntax is nearly identical to GScript's.
I guess this javascript will prove to be useful after all :D

Gunderak 08-04-2011 08:09 AM

writing Guiname.addtext(player.nick@": "@player.chat); doesnt work..
any ideas?

iBeatz 08-04-2011 10:32 AM

Quote:

Originally Posted by Gunderak (Post 1661641)
writing Guiname.addtext(player.nick@": "@player.chat); doesnt work..
any ideas?

That should probably be Guiname.text = str or Guiname.settext(str), either of the two is fine.

Mark Sir Link 08-04-2011 12:16 PM

Quote:

Originally Posted by iBeatz (Post 1661660)
That should probably be Guiname.text = str or Guiname.settext(str), either of the two is fine.

the real problem was missing the 2nd parameter which was a boolean for whether text should reflow or not

Gunderak 08-04-2011 01:01 PM

iv finally got all that working correctly. now to get the add text right its not working.
it now displays the message to all players. once u chat it sets server.temp.chat to ur chat and server.temp.nick to your nick and then adds the chat but on the add chat because its clientside its not reading server.temp.nick or server.temp.chat..
any suggestions?
im completly stuck, almost to the point of pulling my hair out.

Mark Sir Link 08-04-2011 01:23 PM

this is not the approach you should be using at all

cbk1994 08-04-2011 01:30 PM

Quote:

Originally Posted by Gunderak (Post 1661675)
iv finally got all that working correctly. now to get the add text right its not working.
it now displays the message to all players. once u chat it sets server.temp.chat to ur chat and server.temp.nick to your nick and then adds the chat but on the add chat because its clientside its not reading server.temp.nick or server.temp.chat..
any suggestions?
im completly stuck, almost to the point of pulling my hair out.

First, server. variables are only accessible serverside. You're looking for serverr. variables, which can only be written serverside but are readable clientside.

Second,

Quote:

Originally Posted by Mark Sir Link (Post 1661677)
this is not the approach you should be using at all

Use onRemotePlayerChats(temp.pl, temp.chat) on clientside instead. I don't understand your obsession with storing everything in server variables. There are very, very few instances where using server variables is advisable.

ff7chocoboknight 08-04-2011 03:35 PM

Why are there three threads for this chat system?

Gunderak 08-05-2011 12:25 AM

Correction Two.
One is just because i was getting confused about flags.
also if i dont store it serverside it will only display it clientside.
if you would like to show me how i can no store it server side and still have it display correctly your more than welcome to.

fowlplay4 08-05-2011 12:30 AM

Quote:

Originally Posted by Gunderak (Post 1661837)
Correction Two.
One is just because i was getting confused about flags.
also if i dont store it serverside it will only display it clientside.
if you would like to show me how i can no store it server side and still have it display correctly your more than welcome to.

Look at Mark Sir Link's first post, it clearly shows how to.

Gunderak 08-05-2011 12:07 PM

i really dont understand mark sir links first one, the whole idea confuses me.
can someone explain exactly what each bit does so im not so confused?
mainly the onremoteplayerchats is that rc chatter?
also the temp. stuff confuses me :$

Gunderak 08-05-2011 12:13 PM

the temp.pl doesnt make sense of what i understand, wouldnt you need to put for( pl = allplayers) or somthing? or am i misunderstanding the whole concept of it?

iBeatz 08-05-2011 03:19 PM

The temp.pl thing you are describing is most likely a loop, declared as such:
PHP Code:

for(temp.pl allplayers) { 

What this does is loops through all the players on the server, but it behaves differently depending on whether it is clientside or serverside.
On the clientside, it will loop through all the players on the server and irc channels.
On the serverside, it will just loop through all the players on the server.

How it works is that each player it loops through will become the object (temp.pl), and you can read many different things such as .account, .x, .y, etc of that player.
Things like:

PHP Code:

temp.pl.// Will display player's x position
temp.pl.communityname // Will display community name 

For example:
PHP Code:

function onCreated() {
 for(
temp.pl allplayers){ // Loops through all players on the server
  
temp.playerArray.add(temp.pl); // Adds players to the array
 
}
 
player.chat temp.playerArray// Displays the array via player chat


Hope this helped, Gunderak.

cbk1994 08-05-2011 04:02 PM

Quote:

Originally Posted by iBeatz (Post 1661976)
For example:
PHP Code:

function onCreated() {
 for(
temp.pl allplayers){ // Loops through all players on the server
  
temp.playerArray.add(temp.pl); // Adds players to the array
 
}
 
player.chat temp.playerArray// Displays the array via player chat


Hope this helped, Gunderak.

Be careful when doing this. You're adding player objects to the array, not accounts, so you shouldn't try to represent them as a string like that (it may work, though).

Mark Sir Link 08-05-2011 05:15 PM

the temp.pl in my original post refers to the object parameter thrown in
PHP Code:

function onRemotePlayerChats(temp.objtemp.text

I personally use pl as a shorthand to indicate that it is a player object I am dealing with, so I can keep track of what I am attempting to manipulate.

addChat was then added with two parameters, both strings, to indicate the sender's nickname, and sender's text. That function was created to avoid having to copy and paste virtually the same execution within both functions, and can be made public so it can be called elsewhere should you want to add messages from the server or something.


All times are GMT +2. The time now is 03:13 PM.

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