Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   Code Gallery (https://forums.graalonline.com/forums/forumdisplay.php?f=179)
-   -   Interactive NPCs (https://forums.graalonline.com/forums/showthread.php?t=73906)

Chandler 05-10-2007 07:10 PM

Interactive NPCs
 
Well, I was asked to explain how one NPC could interact with another in the same level! Here's what I came up with.

Here's what calls the object.

PHP Code:

function onCreated()
{
  
this.setShape(13232);

  
this.setImg("block.png");
}

  
//So, the player touches the object
function onPlayerTouchsMe()
{
    
//If the NPC has already been touched
  
if (this.hasCalled
  {
    
//Then ignore the rest of this code and just return nothing
    
return false;
    
//Else carry on with the script 
  
}
  
    
//Now, we say that the NPC has already been touched!
  
this.hasCalled true;

  
//Now, look below and we have the line  'level.objectPosition'
  //Well, this is a global variable inside of the level! We can call this
  //variable from any NPC in the level.
  
triggeraction(level.objectPosition[0], level.objectPosition[1], "Called""");


Here's the object that shall start interactive once the above object has been touched.

PHP Code:

function onCreated()
{
  
this.showCharacter();

    
//This is needed for the action to be called
  
this.setshape(13232);
  
    
//This is a GLOBAL LEVEL VARIABLE
  
level.objectPosition = {this.xthis.y};
}

function 
onActionCalled()
{
    
//Make some fancy messages to display
  
temp.messageInformation = {
    
"I see, that you've found my hidden object!",
    
"Just for that, you shall perish!",
    
"It's been a pleasure talking with you though!",
    
" "
  
};   
    
    
//Now display these messages to the player
  
this.chat temp.messageInformation[this.messageDisplay];
  
    
//If the chat is displayed as nothing, make sure that it
    //doesn't carry on doing the rest of the script
  
if (this.chat == " ")
  {
    return 
false;
  }
    
//Now, basically it displays the messageInformation
    //at a specific index, 'this.messageDisplay' will control
    //which index to display
  
this.messageDisplay++;
  
    
//Repeat this process every five seconds!
  
this.scheduleevent(5"ActionCalled""");



I hope this explains a few things!

Novo 05-14-2007 08:54 PM

One minor problem: this.chat == " " <= There is a space in there... ( (this.chat == false) != (this.chat == " ") ) Why not do something like...

PHP Code:

if ( temp.messageInformation.size() >= this.messageDisplay )
  return; 

Like that, if the person doesn't say something for a while ( maybe two interacting NPC's!), then it wouldn't stop the timer...

Rapidwolve 05-17-2007 10:40 PM

PHP Code:

this.messageDisplay = (this.messageDisplay this.messageInformation.size()? this.messageDisplay 1); 

Returns to the first message.


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

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