Graal Forums  

Go Back   Graal Forums > Development Forums > NPC Scripting
FAQ Members List Calendar Today's Posts

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 06-11-2009, 05:58 PM
Cubes Cubes is offline
Registered User
Cubes's Avatar
Join Date: Dec 2005
Location: Chesapeake, Virginia
Posts: 498
Cubes is a jewel in the roughCubes is a jewel in the rough
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?
Reply With Quote
  #2  
Old 06-11-2009, 06:02 PM
[email protected] sid.gottlieb@googlemail.com is offline
Banned
Join Date: Mar 2008
Posts: 861
sid.gottlieb@googlemail.com will become famous soon enough
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.
Reply With Quote
  #3  
Old 06-11-2009, 06:30 PM
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
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.
__________________
Reply With Quote
  #4  
Old 06-11-2009, 06:33 PM
Cubes Cubes is offline
Registered User
Cubes's Avatar
Join Date: Dec 2005
Location: Chesapeake, Virginia
Posts: 498
Cubes is a jewel in the roughCubes is a jewel in the rough
Can you set level.lol clientside?
Edit:
Also can I use Andys XY triggeraction to trigger serverside in the same npc?
Reply With Quote
  #5  
Old 06-11-2009, 06:50 PM
Gambet Gambet is offline
Registered User
Join Date: Oct 2003
Posts: 2,712
Gambet is on a distinguished road
Quote:
Originally Posted by Cubes View Post
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 View Post
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.
Reply With Quote
  #6  
Old 06-11-2009, 06:59 PM
Cubes Cubes is offline
Registered User
Cubes's Avatar
Join Date: Dec 2005
Location: Chesapeake, Virginia
Posts: 498
Cubes is a jewel in the roughCubes is a jewel in the rough
Quote:
Originally Posted by Gambet View Post
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);
}
Reply With Quote
  #7  
Old 06-11-2009, 07:00 PM
Gambet Gambet is offline
Registered User
Join Date: Oct 2003
Posts: 2,712
Gambet is on a distinguished road
Quote:
Originally Posted by Cubes View Post
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.
Reply With Quote
  #8  
Old 06-11-2009, 07:09 PM
Cubes Cubes is offline
Registered User
Cubes's Avatar
Join Date: Dec 2005
Location: Chesapeake, Virginia
Posts: 498
Cubes is a jewel in the roughCubes is a jewel in the rough
Alright awesome thanks, it was the setshape that was giving me a problem because I wasn't aware that it was needed.
Reply With Quote
  #9  
Old 06-11-2009, 07:11 PM
[email protected] sid.gottlieb@googlemail.com is offline
Banned
Join Date: Mar 2008
Posts: 861
sid.gottlieb@googlemail.com will become famous soon enough
Quote:
Originally Posted by cbk1994 View Post
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!
Reply With Quote
  #10  
Old 06-11-2009, 07:21 PM
Codein Codein is offline
jwd
Codein's Avatar
Join Date: Oct 2005
Location: Greater Manchester
Posts: 2,423
Codein has a spectacular aura aboutCodein has a spectacular aura about
Send a message via AIM to Codein Send a message via MSN to Codein
Quote:
Originally Posted by [email protected] View Post
That's a good idea actually, yeah. I didn't think of that- thanks!
Same, I'll also remember that one.
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +2. The time now is 07:30 PM.


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