Thread: Npc to Npc
View Single Post
  #13  
Old 02-17-2011, 06:34 AM
fowlplay4 fowlplay4 is offline
team canada
fowlplay4's Avatar
Join Date: Jul 2004
Location: Canada
Posts: 5,200
fowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond repute
Well for the most part because it is server-side you don't have to do the..

SwitchDB = findnpc("SwitchDB");

because the NPC is accessible via it's name without having to declare a global variable.

Following KISS theory...

SwitchDB

PHP Code:
// Empty Script
// Just using it to hold variables for now. 
Switch

PHP Code:
function onCreated() {
  
this.doorid "door_1";
  
this.image "block.png";
  echo(
this.doorid "'s switch has been created!");
}

function 
onPlayerTouchsMe() {
  echo(
player.account " touched the switch for door " this.doorid);
  
SwitchDB.door.(@this.switchid).trigger("DoorOpened"player.account);

Door

PHP Code:
function onCreated() {
  
this.doorid "door_1";
  
this.image "door.png";
  
SwitchDB.door.(@this.doorid) = this;
  echo(
this.doorid "'s door has been created!");
}

function 
onDoorOpened(acct) {
  echo(
this.doorid " has been opened by " acct "!");
  
hide();
  
sleep(3);
  
show();

From there we can work off the base and create the proper SwitchDB and classes that we require.

In my own "switch" system I store the main controller object (i.e: the door) and it's respective array of switches, and send a trigger to the main controller when a switch is updated (pressed on and off for instance) and the controller loops through the switches and performs the necessary logic (all switches are pressed down) and acts accordingly.
__________________
Quote:

Last edited by fowlplay4; 02-17-2011 at 07:45 PM..
Reply With Quote