Thread: Npc to Npc
View Single Post
  #23  
Old 02-03-2011, 11:22 PM
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
A simple bomb demonstration and how to use getareanpcs.

class: bomb

PHP Code:
function onCreated() {
  
this.image "wbomb1.png";
  
// Set Timer to Go Off in a Few Seconds
  
setTimer(int(random(37)));
}

function 
onTimeout() {
  
// Explode Bomb
  
explodeBomb();
}

function 
explodeBomb() {
  if (!
this.exploded) {
    
// Set Flag to Prevent Double Explosion
    
this.exploded true;
    
// Trigger/Notify NPCs around it in a 4 tile square that it exploded
    
for (temp.ngetareanpcs(this.4this.488)) {
      
temp.n.trigger("ExplosionHit""");
    }
    
// Destroy Bomb
    
destroy();
  }
}

function 
onExplosionHit() {
  
explodeBomb();

class: block_explodable

PHP Code:
function onCreated() {
  
this.image "block.png";
}

function 
onExplosionHit() {
  
// Make sure Block hasn't Exploded
  
if (!this.exploded) {
    
// Set Image to Fire
    
this.image "g4_animation_fire.gif";
    
// Set Flag to Exploded
    
this.exploded true;
    
// Set Timer to Go Off in 3 Seconds
    
setTimer(3);
  }
}

function 
onTimeout() {
  
// Destroy the Fire
  
destroy();

Lay a bunch of them in a level using a level script or putnpc2:

Level script for bomb:

PHP Code:
function onCreated() {
  
this.join("bomb");

Level script for explodable block:

PHP Code:
function onCreated() {
  
this.join("block_explodable");

__________________
Quote:
Reply With Quote