View Single Post
  #3  
Old 05-24-2009, 04:15 AM
cbk1994 cbk1994 is offline
the fake one
cbk1994's Avatar
Join Date: Mar 2003
Location: San Francisco
Posts: 10,718
cbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond repute
Send a message via AIM to cbk1994
Stryke is correct, but I would do something like

PHP Code:
temp.npc putnpc2(player.1.5 vecx(player.dir) * 2player.vecy(player.dir) * 2"");
npc.join("classname"); 
though you'd have to play with the coordinates.

As far as the script, you create a new class called 'classname' or whatever you specify it as in the other script, and put in your script as (for example)

PHP Code:
function onCreated() {
  
setimg("bomb.png");
  
  for (
temp.30--) {
    
sleep(1);
  }
  
  
putexplosion(2this.xthis.y);
  
destroy();

When you use putnpc2, you create a new NPC. I'll explain the rest in comments.

PHP Code:
putnpc2(3232""); // third param is the script, you can also do
putnpc2(3232"this.x = 10;"); // or any other script you want, but it's really annoying to script like that, and is considered bad practice.

// normally, you should join a class; there are a few ways to do this.
putnpc2(3232"join classname;"); // this isn't preferred since it's using GS1

  // the following class joining examples are all GS2
  
putnpc2(3232"join(\"classname\");"); // notice the confusing escape slashes; the other ones are much easier.
  
  // or ...
  
with (putnpc2(3232"")) {
    
join("classname");
  }
  
  
// or ...
  
  
temp.npc putnpc(3232"");
  
npc.join("classname"); // I prefer this way, because it keeps the stuff in scope, which means you can do
  
npc.dropper player.account// this

  
// Since NPCs are objects, you can access them from the laying script.

echo(npc.x); // would echo 32
echo("Chat:" SPC npc.chat); // would echo "Chat:" because there is no chat. If there was chat, it would be "Chat: Hello, world!" or whatever the chat is

// you can also perform functions on the npc or call events
npc.warpto("level.name"3029);
npc.chat "Hello, world!";
npc.trigger("Test"); // calls the event "onTest()" in the script.
npc.destroy(); // removes the NPC; make sure to do this when done with it, or within the class (which is preferred) 
__________________

Last edited by cbk1994; 05-24-2009 at 04:22 AM.. Reason: explaining putnpc2 better
Reply With Quote