Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   NPC Scripting (https://forums.graalonline.com/forums/forumdisplay.php?f=8)
-   -   trigger problems (https://forums.graalonline.com/forums/showthread.php?t=81193)

Frankie 08-13-2008 07:06 AM

trigger problems
 
a friend of mine made a script but something odd is going wrong.
PHP Code:

function onActionGrab()
{
  
triggeraction(level.chairxlevel.chairy"Shock""");


PHP Code:

function onCreated()
{
  
setshape(13232);

  
/*
  showcharacter();
  this.headimg = "era_personal_understood-noobhulk.gif";
  this.colors[0] = "green";
  this.colors[1] = "darkpurple";
  this.colors[2] = "darkpurple";
  this.colors[3] = "green";
  this.colors[4] = "darkpurple";
  this.colors[5] = "black";
  this.colors[6] = "white";
  this.shieldimg = "no-shield.png";
  this.bodyimg = "wad-muscle-body.png";
  dir = 2;
  setcharani("era_prison-elect-idle", "");
  */

  
level.chairx this.x;
  
level.chairy this.y;
}

function 
onActionShock()
{
  
this.setcharani("era_prison-elect-shock""");
  
message("Did someone just push the button?...");
  
sleep(3);
  
message("#$!, I've gotta get out of here...");
  
sleep(3.00);
  
message("SHI--");
  
sleep(.5);
  
message("");


it doesn't work unless I take out all the attribute stuff. (the stuff commented out) can I get an explanation? :[

Dan 08-13-2008 12:34 PM

Quote:

Originally Posted by Frankie (Post 1413819)
it doesn't work unless I take out all the attribute stuff. (the stuff commented out) can I get an explanation? :[

Try to trigger level.chairx + 1 and level.chair + 1 when using setshape.

Inverness 08-13-2008 03:22 PM

Here is an alternative.
PHP Code:

function onActionGrab() {
  
this.level.chair.trigger("ActionShock""");


PHP Code:

function onCreated() {
  
this.setshape(13232);
  
this.level.chair this;
}
function 
onActionShock() {
  
// do stuff


The this. prefix isn't required in this instance but it is my preference to do it like that so you clearly know what the variable belongs to.

The_Kez 08-16-2008 08:47 AM

I used to have an issue with triggeraction where I could only trigger an NPC with triggeraction if the NPC had an image set to it when the trigger reaches it. Don't know if that is true anymore, just a thought.

xXziroXx 08-16-2008 03:18 PM

Quote:

Originally Posted by The_Kez (Post 1414859)
I used to have an issue with triggeraction where I could only trigger an NPC with triggeraction if the NPC had an image set to it when the trigger reaches it. Don't know if that is true anymore, just a thought.

That sounds like setshape issues to me.

Chompy 08-16-2008 03:43 PM

Quote:

Originally Posted by The_Kez (Post 1414859)
I used to have an issue with triggeraction where I could only trigger an NPC with triggeraction if the NPC had an image set to it when the trigger reaches it. Don't know if that is true anymore, just a thought.

Hmm, when you set an image, if no shape is set, the npc will take shape as the shape of the image if I'm not wrong ;o

[email protected] 08-17-2008 01:41 PM

Quote:

Originally Posted by Inverness (Post 1413861)
Here is an alternative.
PHP Code:

function onActionGrab() {
  
this.level.chair.trigger("ActionShock""");


PHP Code:

function onCreated() {
  
this.setshape(13232);
  
this.level.chair this;
}
function 
onActionShock() {
  
// do stuff


The this. prefix isn't required in this instance but it is my preference to do it like that so you clearly know what the variable belongs to.

I like this idea, I didn't think of this! [However, you'd need to remove the 'this.level.chair' to replace it with 'level.chat' and also make the 'onActionShock' a public function]

Inverness 08-17-2008 01:54 PM

Quote:

Originally Posted by [email protected] (Post 1415098)
However, you'd need to remove the 'this.level.chair' to replace it with 'level.chat'

No you don't. And I assume you meant level.chair. In an NPC, this.level.chair is the same as level.chair because static (built-in) variables can be accessed with or without the this. prefix.
Quote:

Originally Posted by [email protected] (Post 1415098)
and also make the 'onActionShock' a public function

No you don't, it only needs to be public if you're calling it. You can trigger events even if they're not public.

Function Call: this.level.chair.onActionShock();
Calling a function means its on the same thread so that function must complete before the script can continue to next statement. To call a function in a different object it needs to be public.

Event Trigger: this.level.chair.trigger("ActionShock", null);
Triggering an event means its on a different thread, so it means the script that triggered it will continue to next statement while the onActionShock executes at the same time. An event does not need to be public to trigger it because the trigger function is public and that is the function you are using.


All times are GMT +2. The time now is 09:43 AM.

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