Graal Forums  

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

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 03-18-2012, 03:43 PM
Emera Emera is offline
Delterian Hybrid
Emera's Avatar
Join Date: Mar 2011
Location: Newcastle Upon-Tyne
Posts: 1,704
Emera is a jewel in the roughEmera is a jewel in the rough
triggeraction all NPC's in the level?

I'm trying to code a hat system, and I'm having a little bit of trouble. To bring up the shop GUI with all the information on the hat, you have to click the hat image in the level. All of the hat images have the same class joined to them, object_hat. Now, I'm using a triggeraction when the player clicks the buy button, and instead of the player buying just that hat, all the NPC's in the level with the class joined to them get the triggeraction too, and I end up buying 6 or 7 hats.

PHP Code:
function onActionBuyHat() {
  
temp.hat_name params[1];
  
temp.hat_price params[2];
  if (
temp.hat_name in clientr.questhats.tokenize(",")) {
    return;
  } else {
    if (!(
player.rupees => temp.hat_price)) {
      echo(
player.account SPC "doesn't have enough!");
    } else {
      
player.rupees -= temp.hat_price;
      
player.clientr.questhats.add(temp.hat_name);
    }
  }

This is the triggeraction.
PHP Code:
triggeraction(this.x,this.y,"BuyHat","",this.hat_name,this.hat_price); 
I don't want all the NPC's with the class joined to receive the triggeraction.
Am I doing something wrong? Also, I tend to script something and get it working and then clean the script up a bit, so it's a little messy :P
__________________
Reply With Quote
  #2  
Old 03-18-2012, 04:01 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 sounds like you're using the same name for the button for all of the NPCs. You didn't paste enough code to be sure, but I'd bet you're doing something like

PHP Code:
function BuyHat_Buy.onAction() {
  
triggeraction(this.x,this.y,"BuyHat","",this.hat_name,this.hat_price);  

This function is going to be called on every script in the level. The easiest way to fix it is to specify the NPC when creating the window:

PHP Code:
// in the npc that creates the window
BuyHat_Window.npc this
and then in the event:
PHP Code:
function BuyHat_Buy.onAction() {
  if (
BuyHat_Window.npc == this) {
    
triggeraction(this.x,this.y,"BuyHat","",this.hat_name,this.hat_price);
  }

__________________
Reply With Quote
  #3  
Old 03-18-2012, 04:05 PM
Emera Emera is offline
Delterian Hybrid
Emera's Avatar
Join Date: Mar 2011
Location: Newcastle Upon-Tyne
Posts: 1,704
Emera is a jewel in the roughEmera is a jewel in the rough
Yeah, that's what I'm doing. Thanks for the help!
__________________
Reply With Quote
  #4  
Old 03-18-2012, 04:18 PM
Emera Emera is offline
Delterian Hybrid
Emera's Avatar
Join Date: Mar 2011
Location: Newcastle Upon-Tyne
Posts: 1,704
Emera is a jewel in the roughEmera is a jewel in the rough
I'm having some issues. It's not sending the trigger at all now. I don't know what I'm doing wrong. Here's the whole code. It wouldn't let me post it using php tags since incapsula got me D:

http://pastebin.com/p4p4MTFF
__________________
Reply With Quote
  #5  
Old 03-18-2012, 04:59 PM
ffcmike ffcmike is offline
Banned
Join Date: Jul 2004
Location: London
Posts: 2,029
ffcmike has a reputation beyond reputeffcmike has a reputation beyond reputeffcmike has a reputation beyond reputeffcmike has a reputation beyond reputeffcmike has a reputation beyond reputeffcmike has a reputation beyond reputeffcmike has a reputation beyond reputeffcmike has a reputation beyond repute
Send a message via AIM to ffcmike Send a message via MSN to ffcmike
I would place the GUI display and action script within a weapon, have the NPC call a function to that weapon passing itself as a parameter, then store that reference within the GUI object, and refer to it upon the action.

Weapon:

PHP Code:
function onCreated(){
  
SomeWeaponReference this;
}

public function 
displayBuyHat(temp.owner){
  new 
GUIControl(BuyHat_Buy){
    
this.owner temp.owner;
  }
}

function 
BuyHat_Buy.onAction(){
  
BuyHat_Buy.owner.buyHatPressed();
  
BuyHat_Buy.destroy();

NPC:

PHP Code:
function onPlayerTouchsMe(){
  
SomeWeaponReference.displayBuyHat(this);
}

public function 
buyHatPressed(){
  
triggeraction(stuff);

Reply With Quote
  #6  
Old 03-18-2012, 05:14 PM
Emera Emera is offline
Delterian Hybrid
Emera's Avatar
Join Date: Mar 2011
Location: Newcastle Upon-Tyne
Posts: 1,704
Emera is a jewel in the roughEmera is a jewel in the rough
Oh, I see what you mean :P Thanks <3 I'll tweak mah code then

Edit:
Whoever it was who gave me a red pepper saying "worst scripter 2012", I'm in the process of something called "learning", and also the negative reputation for Graal pastebin, my browser refused to load it after 10 minutes of trying D: Sorry about that. I would post the old code on pastebin since it's working now, but I don't see the point since I've solved the issue already!
__________________

Last edited by Emera; 03-18-2012 at 06:54 PM..
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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:38 AM.


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