Graal Forums  

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

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 05-10-2007, 07:10 PM
Chandler Chandler is offline
Banned
Join Date: Jan 2007
Posts: 656
Chandler will become famous soon enough
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!

Last edited by Chandler; 05-10-2007 at 07:57 PM..
Reply With Quote
  #2  
Old 05-14-2007, 08:54 PM
Novo Novo is offline
[TServerDeveloper]
Join Date: Jun 2006
Posts: 448
Novo will become famous soon enough
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...
Reply With Quote
  #3  
Old 05-17-2007, 10:40 PM
Rapidwolve Rapidwolve is offline
Registered User
Join Date: Jul 2006
Posts: 1,241
Rapidwolve is an unknown quantity at this point
PHP Code:
this.messageDisplay = (this.messageDisplay this.messageInformation.size()? this.messageDisplay 1); 
Returns to the first message.
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:28 PM.


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