Graal Forums  

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

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 08-03-2011, 10:09 AM
Gunderak Gunderak is offline
Coder
Gunderak's Avatar
Join Date: Jun 2011
Location: Australia
Posts: 795
Gunderak is on a distinguished road
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?
__________________

Gund for president.

Remote PM {P*}x (Graal813044) from eraiphone -> Stefan: I hav 1 qustion
*Gunderak: he hav 1
*Gunderak: qustion
Reply With Quote
  #2  
Old 08-03-2011, 10:35 AM
Mark Sir Link Mark Sir Link is offline
Kevin Azite
Mark Sir Link's Avatar
Join Date: Sep 2005
Posts: 1,489
Mark Sir Link is just really niceMark Sir Link is just really nice
Send a message via AIM to Mark Sir Link
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();

Reply With Quote
  #3  
Old 08-03-2011, 10:44 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
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.
__________________
Reply With Quote
  #4  
Old 08-03-2011, 11:41 AM
Mark Sir Link Mark Sir Link is offline
Kevin Azite
Mark Sir Link's Avatar
Join Date: Sep 2005
Posts: 1,489
Mark Sir Link is just really niceMark Sir Link is just really nice
Send a message via AIM to Mark Sir Link
Quote:
Originally Posted by cbk1994 View Post
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.
Reply With Quote
  #5  
Old 08-03-2011, 04:30 PM
Gunderak Gunderak is offline
Coder
Gunderak's Avatar
Join Date: Jun 2011
Location: Australia
Posts: 795
Gunderak is on a distinguished road
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!
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.
__________________

Gund for president.

Remote PM {P*}x (Graal813044) from eraiphone -> Stefan: I hav 1 qustion
*Gunderak: he hav 1
*Gunderak: qustion
Reply With Quote
  #6  
Old 08-03-2011, 05:16 PM
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 Gunderak View Post
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.
__________________
Reply With Quote
  #7  
Old 08-04-2011, 12:35 AM
Gunderak Gunderak is offline
Coder
Gunderak's Avatar
Join Date: Jun 2011
Location: Australia
Posts: 795
Gunderak is on a distinguished road
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
__________________

Gund for president.

Remote PM {P*}x (Graal813044) from eraiphone -> Stefan: I hav 1 qustion
*Gunderak: he hav 1
*Gunderak: qustion
Reply With Quote
  #8  
Old 08-04-2011, 08:09 AM
Gunderak Gunderak is offline
Coder
Gunderak's Avatar
Join Date: Jun 2011
Location: Australia
Posts: 795
Gunderak is on a distinguished road
writing Guiname.addtext(player.nick@": "@player.chat); doesnt work..
any ideas?
__________________

Gund for president.

Remote PM {P*}x (Graal813044) from eraiphone -> Stefan: I hav 1 qustion
*Gunderak: he hav 1
*Gunderak: qustion
Reply With Quote
  #9  
Old 08-04-2011, 10:32 AM
iBeatz iBeatz is offline
Kavan
iBeatz's Avatar
Join Date: Dec 2010
Location: Northern Ireland, UK
Posts: 154
iBeatz will become famous soon enough
Send a message via Yahoo to iBeatz
Quote:
Originally Posted by Gunderak View Post
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.
__________________

Intelligence without ambition is like a bird without wings.

Reply With Quote
  #10  
Old 08-04-2011, 12:16 PM
Mark Sir Link Mark Sir Link is offline
Kevin Azite
Mark Sir Link's Avatar
Join Date: Sep 2005
Posts: 1,489
Mark Sir Link is just really niceMark Sir Link is just really nice
Send a message via AIM to Mark Sir Link
Quote:
Originally Posted by iBeatz View Post
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
Reply With Quote
  #11  
Old 08-04-2011, 01:01 PM
Gunderak Gunderak is offline
Coder
Gunderak's Avatar
Join Date: Jun 2011
Location: Australia
Posts: 795
Gunderak is on a distinguished road
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.
__________________

Gund for president.

Remote PM {P*}x (Graal813044) from eraiphone -> Stefan: I hav 1 qustion
*Gunderak: he hav 1
*Gunderak: qustion
Reply With Quote
  #12  
Old 08-04-2011, 01:23 PM
Mark Sir Link Mark Sir Link is offline
Kevin Azite
Mark Sir Link's Avatar
Join Date: Sep 2005
Posts: 1,489
Mark Sir Link is just really niceMark Sir Link is just really nice
Send a message via AIM to Mark Sir Link
this is not the approach you should be using at all
Reply With Quote
  #13  
Old 08-04-2011, 01:30 PM
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 Gunderak View Post
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 View Post
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.
__________________

Last edited by cbk1994; 08-04-2011 at 02:16 PM..
Reply With Quote
  #14  
Old 08-04-2011, 03:35 PM
ff7chocoboknight ff7chocoboknight is offline
Skyzer Zolderon
ff7chocoboknight's Avatar
Join Date: Dec 2006
Location: New Hampshire, United States
Posts: 725
ff7chocoboknight is a name known to allff7chocoboknight is a name known to allff7chocoboknight is a name known to allff7chocoboknight is a name known to all
Send a message via AIM to ff7chocoboknight Send a message via MSN to ff7chocoboknight
Why are there three threads for this chat system?
__________________
Reply With Quote
  #15  
Old 08-05-2011, 12:25 AM
Gunderak Gunderak is offline
Coder
Gunderak's Avatar
Join Date: Jun 2011
Location: Australia
Posts: 795
Gunderak is on a distinguished road
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.
__________________

Gund for president.

Remote PM {P*}x (Graal813044) from eraiphone -> Stefan: I hav 1 qustion
*Gunderak: he hav 1
*Gunderak: qustion
Reply With Quote
  #16  
Old 08-05-2011, 12:30 AM
fowlplay4 fowlplay4 is offline
team canada
fowlplay4's Avatar
Join Date: Jul 2004
Location: Canada
Posts: 5,200
fowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond repute
Quote:
Originally Posted by Gunderak View Post
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.
__________________
Quote:
Reply With Quote
  #17  
Old 08-05-2011, 12:07 PM
Gunderak Gunderak is offline
Coder
Gunderak's Avatar
Join Date: Jun 2011
Location: Australia
Posts: 795
Gunderak is on a distinguished road
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 :$
__________________

Gund for president.

Remote PM {P*}x (Graal813044) from eraiphone -> Stefan: I hav 1 qustion
*Gunderak: he hav 1
*Gunderak: qustion
Reply With Quote
  #18  
Old 08-05-2011, 12:13 PM
Gunderak Gunderak is offline
Coder
Gunderak's Avatar
Join Date: Jun 2011
Location: Australia
Posts: 795
Gunderak is on a distinguished road
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?
__________________

Gund for president.

Remote PM {P*}x (Graal813044) from eraiphone -> Stefan: I hav 1 qustion
*Gunderak: he hav 1
*Gunderak: qustion
Reply With Quote
  #19  
Old 08-05-2011, 03:19 PM
iBeatz iBeatz is offline
Kavan
iBeatz's Avatar
Join Date: Dec 2010
Location: Northern Ireland, UK
Posts: 154
iBeatz will become famous soon enough
Send a message via Yahoo to iBeatz
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.
__________________

Intelligence without ambition is like a bird without wings.

Reply With Quote
  #20  
Old 08-05-2011, 04:02 PM
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 iBeatz View Post
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).
__________________
Reply With Quote
  #21  
Old 08-05-2011, 05:15 PM
Mark Sir Link Mark Sir Link is offline
Kevin Azite
Mark Sir Link's Avatar
Join Date: Sep 2005
Posts: 1,489
Mark Sir Link is just really niceMark Sir Link is just really nice
Send a message via AIM to Mark Sir Link
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.
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 04:21 PM.


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