Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   NPC Scripting (https://forums.graalonline.com/forums/forumdisplay.php?f=8)
-   -   if (playerchats) question (https://forums.graalonline.com/forums/showthread.php?t=134266319)

garglius1 04-25-2012 06:17 AM

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!

xXziroXx 04-25-2012 06:24 AM

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
  
}



cbk1994 04-25-2012 06:27 AM

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

garglius1 04-25-2012 06:42 AM

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?

Tricxta 04-25-2012 06:47 AM

Quote:

Originally Posted by garglius1 (Post 1692935)
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.

xXziroXx 04-25-2012 06:50 AM

Quote:

Originally Posted by garglius1 (Post 1692935)
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.


All times are GMT +2. The time now is 08:27 PM.

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