View Single Post
  #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