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=87496)

littlekinky 08-20-2009 01:01 AM

Custom Chat System
 
Ok, Custom Chat system some people mgiht no what this is some people might not

Well on graal at the moment when a player talks text appears above the players head, i am wondering can it be done where when player talks a chat bubble appears above there head and text inside it could anyone give me a simple script to show this?

thanks

fowlplay4 08-20-2009 01:17 AM

I am pretty sure you can disable chat being shown with the enablefeatures function, then have a script loop through the players in the level, and draw using your bubble chat function.

A crude example that should work:

PHP Code:

//#CLIENTSIDE
function onCreated() {
  
// Enablefeatures except for chat text
  
enablefeatures(allfeatures-0x80);
  
// Begin looping
  
setTimer(0.05);
}

function 
onTimeout() {
  
// Hide Last Drawn Chat
  
hideimgs(2001000);
  
// Loop through Players in the level
  
for (temp.pplayers) {
    
// Record their chat and trim it.
    
temp.player_chat temp.p.chat.trim();
    if (
temp.p.chat != "") {
      
// Draw the Text over the player.
      
with (findimg(200 temp.p.id)) {
        
temp.p.1.5;
        
temp.p.0.5;
        
style "c";
        
text temp.player_chat;
      }
    }
  }
  
// Continue Looping
  
setTimer(0.05);


Obviously build from this example, and try to optimize the drawing routine instead of hiding and redrawing every time.

Other functions that may be of help:

onRemotePlayerChats(player_obj, player_chat);

papajchris 08-20-2009 01:37 AM

Its definitely possible as its been done numerous times on UC servers.

littlekinky 08-20-2009 01:51 AM

Nice example thanks, also how to change the colour of it and also add a chat bubble ?

fowlplay4 08-20-2009 01:58 AM

Quote:

Originally Posted by littlekinky (Post 1516502)
Nice example thanks, also how to change the colour of it and also add a chat bubble ?

You'll have to write a script to draw a bubble behind the text, you will have to either:

- Use polygon in findimg, or:
- Use a bubble image, stretchx, and stretchy.

To change the color, you can change it like so:

PHP Code:

// Code
with (findimg(200)) {
  
text "Rawr.";
  
red 1;
  
green 0;
  
blue 0;
}
// Other Code 

But you should do some reading on your on now.

littlekinky 08-20-2009 02:16 AM

So i could make a bubble image and out the x and y

fowlplay4 08-20-2009 02:31 AM

Here's an example of how to draw an image and stretch it accordingly.

PHP Code:

//#CLIENTSIDE
function onCreated() {
  
// Draw Stretched Block
  
temp.img onDrawImage(200"block.png"4848);
  
// Adjust Blocks X + Y for example purposes.
  
with (temp.img) {
     
player.x;
     
player.y;
  }
}

// Draws an Image and stretches to the desired width and height.

function onDrawImage(img_idimg_nameimg_widthimg_height) {
  
// Initialize Image Object
  
with (findimg(img_id)) {
    
// Specify Image
    
image img_name;
    
// Determine Real Width & Height of Image
    
temp.real_width getimgwidth(image);
    
temp.real_height getimgheight(image);
    
// Default stretch values = 1, so if you want to stretch it twice it's width, you'd have to use 2.
    // Therefore: stretch = new_width / real_width;
    
stretchx img_width temp.real_width;
    
stretchy img_height temp.real_height;
  }
  
// Return Image Object for Manipulation
  
return findimg(img_id);


Instead of a block, you could use an image of a bubble instead, however a more complicated solution may be needed to make it look good.

littlekinky 08-20-2009 02:36 AM

Ok now can you make a complete script so it works for an example wud be very helpfull

pooper200000 08-20-2009 02:54 AM

Just to quote the scripting forum rules, although I'm sure you all do not need the reminder.

Quote:

1. Be clear on your ability level. In other words, do not post asking for scripts, or asking people to fix scripts that are above your ability level. If you are writing a script to aid learning, then try writing a simpler script. If you are looking for a script for a server, then the best solution is probably to hire a scripter.

2. Similarly, do not just post whole scripts for people as a response to their difficulties. If you wish to post a wordy solution, then please feel free; however, please do not post things that people can just copy and paste. It isn't helping people to learn just by doing so. If you'd like to show off your scripts to others, post them in the Code Gallery subforum.

Deas_Voice 08-20-2009 02:09 PM

Quote:

Originally Posted by littlekinky (Post 1516535)
Ok now can you make a complete script so it works for an example wud be very helpfull

so u can copy/past? x_x

sssssssssss 10-20-2009 08:30 AM

Old script, but I'm not getting on where the player chat should go after drawing the image.

coreys 10-20-2009 11:12 PM

Just a note:
On Maloria and other servers that have done this, the script for displaying the chat is done in a gani, so that the text doesn't lag behind when the player is moving.

DustyPorViva 10-20-2009 11:15 PM

Text should not lag behind a player if scripted correctly. Stefan has also stated it is more efficient and faster to run a loop of all players and display things like chat that way rather than using a gani.

sssssssssss 10-23-2009 05:09 AM

any pointers on where to run after getting the image drawn?

Switch 10-23-2009 05:16 AM

Get the text in.

sssssssssss 10-23-2009 06:51 AM

Nevermind


All times are GMT +2. The time now is 06:16 PM.

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