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 04-25-2012, 06:17 AM
garglius1 garglius1 is offline
Butcher of the Kingdoms
Join Date: Mar 2004
Location: Montreal, Quebec
Posts: 213
garglius1 is on a distinguished road
Send a message via MSN to garglius1
if (playerchats) question

I've been working on my house level in graal kingdoms (my first experience with level design/scripting NPCs), and I'd like to make it so an NPC acts when I say a certain word. Right now I can have it act whenever I say anything with the

if (playerchats) {
}

command, but I'd like it to act when I say a specific word rather than any word. I've been trying to figure it out by watching some of your videos/reading guides but I can't get the solution to my specific issue, and I thought you'd be the one to ask.

Thanks for your help!
__________________
-Garg, the former GK Pro-

5813... WHAT!
Reply With Quote
  #2  
Old 04-25-2012, 06:24 AM
xXziroXx xXziroXx is offline
Malorian
xXziroXx's Avatar
Join Date: May 2004
Posts: 5,289
xXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant future
First of all, try learning GS2 instead of using GS1. In GS2 you'd do:

PHP Code:
function onPlayerChats()
{

To be able to read what the player said, you can read the player.chat string. An example of this would be:

PHP Code:
function onPlayerChats()
{
  if (
player.chat == "hello world") {
    
// do stuff
  
}

__________________
Follow my work on social media post-Graal:Updated august 2025.
Reply With Quote
  #3  
Old 04-25-2012, 06:27 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
Graal has used two main scripting languages to date: GScript 1 (GS1) and GScript 2 (GS2). We now exclusively use GS2, which is the newest (and much improved) scripting language. Tig won't accept your level upload unless your scripts are written in GS2.

Events like "playerChats" which use an if-statement are using a GS1 convention, which should be avoided in new code. It's simple to write it in GS2:

PHP Code:
function onPlayerChats() {
  
// the player said something

It sounds like you're just getting started, so I'd highly recommend you look at Jer's excellent scripting guide. It's not completed, but the first few lessons are, and it's been very helpful to a lot of new scripters.

The property you're looking for is the player's chat; this is written simply as "player.chat":

PHP Code:
function onPlayerChats() {
  echo(
player.chat);

You're going to want to use an if-statement to see if the player said your special word.

PHP Code:
function onPlayerChats() {
  if (
player.chat == "my word") {
    
// perform whatever you want to do here
  
}

Again, I highly recommend reading Jer's guide as it will explain this and more to you. Note that any scripts you write in GS1 will not work in the offline level editor. To test them, you should upload the level to a server (you can signup for Testbed if you aren't staff on any other servers).

edit: ziro beat me to it, but I'll leave this here as it provides a bit more info on getting started w/ GScript
__________________
Reply With Quote
  #4  
Old 04-25-2012, 06:42 AM
garglius1 garglius1 is offline
Butcher of the Kingdoms
Join Date: Mar 2004
Location: Montreal, Quebec
Posts: 213
garglius1 is on a distinguished road
Send a message via MSN to garglius1
Quote:
Again, I highly recommend reading Jer's guide as it will explain this and more to you. Note that any scripts you write in GS1 will not work in the offline level editor. To test them, you should upload the level to a server (you can signup for Testbed if you aren't staff on any other servers).
GS2 is the newer one that doesn't work offline right? And GS1 is what I was trying to script in before?
__________________
-Garg, the former GK Pro-

5813... WHAT!
Reply With Quote
  #5  
Old 04-25-2012, 06:47 AM
Tricxta Tricxta is offline
The Muffin Man
Tricxta's Avatar
Join Date: Oct 2010
Location: Australia
Posts: 563
Tricxta is just really niceTricxta is just really nice
Quote:
Originally Posted by garglius1 View Post
GS2 is the newer one that doesn't work offline right? And GS1 is what I was trying to script in before?
Yep, Stefan's as of yet to design support for gs2 offline, although I think that
might be a different case with rumours of this new level editor I'm hearing about.
Reply With Quote
  #6  
Old 04-25-2012, 06:50 AM
xXziroXx xXziroXx is offline
Malorian
xXziroXx's Avatar
Join Date: May 2004
Posts: 5,289
xXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant future
Quote:
Originally Posted by garglius1 View Post
GS2 is the newer one that doesn't work offline right? And GS1 is what I was trying to script in before?
Yep, but that's what Testbed is for.
__________________
Follow my work on social media post-Graal:Updated august 2025.
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 07:23 AM.


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