Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   NPC Scripting (https://forums.graalonline.com/forums/forumdisplay.php?f=8)
-   -   Triggering another npc in the level? (https://forums.graalonline.com/forums/showthread.php?t=86283)

Cubes 06-11-2009 05:58 PM

Triggering another npc in the level?
 
I know how to trigger different weapons but how would I trigger an npc in another npc in the same level. Like lets say there was a switch you had to to and it would then like open a door or something. Could anyone give me an example of how I could do it?

[email protected] 06-11-2009 06:02 PM

Well, if you know the x/y use triggeraction.

Here's the door
HTML Code:

function onCreated() {
  this.setShape(1, 32, 32);
  level.doorPosition = {this.x, this.y};
}

function onActionOpenDoor(player) {
  //The door has been opened
}

Here's the switch to open the door
HTML Code:

function onCreated() {
  this.setShape(1, 32, 32);
}

function onPlayerTouchsMe() {
    //Let's just send the trigger every 3 seconds, between another touch
  if (this.lastsend > timevar2) return;
  this.lastsend = timevar2 + 3;

  triggeraction(level.doorPosition[0], level.doorPosition[1], "OpenDoor", player);
}

You'll notice that I saved the doors position in a global level variable. Easier than finding out the right position of the object, where ever it's moved it'll be in that position.

cbk1994 06-11-2009 06:30 PM

It's probably better do do something like this:

PHP Code:

function onCreated() {
  
level.door this;
  
this.hidden false;
}
function 
onOpen() {
  if (! 
this.hidden) {
    return;
  }
  
  
this.hidden true;
  
hide();
  
scheduleevent(3"Show");
}
function 
onShow() {
  
this.hidden false;
  
show();


and then in the other script

PHP Code:

function onPlayerTouchsMe() {
  if (
level.door.hidden) {
    return;
  }
  
  
level.door.trigger("Open");


Notice I'm putting the actual NPC object in a level variable, not the x and y. This ensures that you'll always get to that NPC, even if there's another NPC on top of it, which could cause problems when using triggeraction.

Cubes 06-11-2009 06:33 PM

Can you set level.lol clientside?
Edit:
Also can I use Andys XY triggeraction to trigger serverside in the same npc?

Gambet 06-11-2009 06:50 PM

Quote:

Originally Posted by Cubes (Post 1498668)
can I use Andys XY triggeraction to trigger serverside in the same npc?

You are triggering serverside since it's a level npc. Level npcs trigger to the serverside to the function denoted by onActionFunctionName().

Quote:

Originally Posted by cbk1994 (Post 1498667)
This ensures that you'll always get to that NPC, even if there's another NPC on top of it, which could cause problems when using triggeraction.

It isn't really a problem unless both NPCs have the same function name, but yes, probably better to rely on the object rather than an x/y position.

Cubes 06-11-2009 06:59 PM

Quote:

Originally Posted by Gambet (Post 1498674)
You are triggering serverside since it's a level npc. Level npcs trigger to the serverside to the function denoted by onActionFunctionName().



It isn't really a problem unless both NPCs have the same function name, but yes, probably better to rely on the object rather than an x/y position.

Well this is what I tried and I cannot get it to work, I have no clue what's wrong with it.
Quote:

function onActionTestT(){
level.rofltest = "works";
player.chat = level.rofltest;
}
//#CLIENTSIDE
function onCreated(){
onTestTrigger()
}
function onTestTrigger(){
triggeraction(this.x, this.y, "TestT", NULL);
}

Gambet 06-11-2009 07:00 PM

Quote:

Originally Posted by Cubes (Post 1498679)
Well this is what I tried and I cannot get it to work, I have no clue what's wrong with it.


You haven't defined a shape for the object, you need a setShape() in the serverside.

Cubes 06-11-2009 07:09 PM

Alright awesome thanks, it was the setshape that was giving me a problem because I wasn't aware that it was needed.

[email protected] 06-11-2009 07:11 PM

Quote:

Originally Posted by cbk1994 (Post 1498667)
It's probably better do do something like this:

PHP Code:

function onCreated() {
  
level.door this;
  
this.hidden false;
}
function 
onOpen() {
  if (! 
this.hidden) {
    return;
  }
  
  
this.hidden true;
  
hide();
  
scheduleevent(3"Show");
}
function 
onShow() {
  
this.hidden false;
  
show();


and then in the other script

PHP Code:

function onPlayerTouchsMe() {
  if (
level.door.hidden) {
    return;
  }
  
  
level.door.trigger("Open");


Notice I'm putting the actual NPC object in a level variable, not the x and y. This ensures that you'll always get to that NPC, even if there's another NPC on top of it, which could cause problems when using triggeraction.

That's a good idea actually, yeah. I didn't think of that- thanks! :D

Codein 06-11-2009 07:21 PM

Quote:

Originally Posted by [email protected] (Post 1498683)
That's a good idea actually, yeah. I didn't think of that- thanks! :D

Same, I'll also remember that one.


All times are GMT +2. The time now is 01:49 AM.

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