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 09-16-2011, 05:06 AM
pig132 pig132 is offline
professional troll
Join Date: May 2006
Posts: 260
pig132 will become famous soon enough
GUI Class triggeraction/triggerserver

Alright, so I am making a shop GUI (in a class) but I can't seem to get the triggers work. For example, when the buy button is clicked, it won't trigger and i've read that you can't triggerserver in classes, but triggeraction won't seem to work either. This is my current code (onaction at the top and the trigger at the bottom)

PHP Code:
function onCreated()
{
  
setshape(13232);
}

function 
onActionBuy()
{
  
player.chat "HELLO";
}
//#CLIENTSIDE
function onActionLeftMouse()
{
  
onCreated();
}

function 
onCreated()
{
  
setshape(1,32,32);
  new 
GuiWindowCtrl("shop_window")
  {
    
profile GuiBlueWindowProfile;
    
screenwidth 2.5;
    
screenheight 2.5;
    
text "Zoraa's Shop";
    
width 210;
    
height 150;
    
destroyonhide true;
    
closequery true;
    
    
canresize 
    
canminimize =
    
canclose =
    
canmaximize false;
    
  new 
GuiButtonCtrl("shop_close")
  {
    
profile GuiBlueButtonProfile;
    
65;
    
120;
    
width 75;
    
height 20;
    
text "Close";
  }
  
  new 
GuiButtonCtrl("shop_bomb")
  {
    
profile GuiBlueButtonProfile;
    
10;
    
28;
    
width 60;
    
height 60;
    
  new 
GuiShowImgCtrl("shop_disp_bomb")
  {
    
15;
    
15;
    
width 32;
    
height 32;
    
image "bomb.png";
    
layer 4;
  }
  }
  
  new 
GuiButtonCtrl("shop_arrow")
  {
    
profile GuiBlueButtonProfile;
    
75;
    
28;
    
width 60;
    
height 60;
    
  new 
GuiShowImgCtrl("shop_disp_arrow")
  {
    
25;
    
15;
    
width 10;
    
height 30;
    
image "arrow.png";
    
layer 4;
    
  }
  }
  
  new 
GuiButtonCtrl("shop_fullheart")
  {
    
profile GuiBlueButtonProfile;    
    
140;
    
28;
    
width 60;
    
height 60;
  
  new 
GuiShowImgCtrl("shop_disp_heart")
  {
    
15;
    
15;
    
width 31;
    
height 33;
    
image "state.png";
    
offsetx = -80;
    
offsety 0;
    
layer 4;
  }
  }
  
  new 
GuiTextCtrl("shop_bomb_amount")
  {
    
profile GuiBlueTextProfile;
    
25;
    
85;
    
text "Price:";
  }
  
  new 
GuiTextCtrl("shop_bomb_amount2")
  {
    
profile GuiBlueTextProfile;
    
10;
    
98;
    
text "25 for 10g";
  }
  
  new 
GuiTextCtrl("shop_arrow_amount")
  {
    
profile GuiBlueTextProfile;
    
90;
    
85;
    
text "Price:";
  }
  
  new 
GuiTextCtrl("shop_arrow_amount2")
  {
    
profile GuiBlueTextProfile;
    
75;
    
98;
    
text "30 for 10g";
  }
  
  new 
GuiTextCtrl("shop_heart_amount")
  {
    
profile GuiBlueTextProfile;
    
155;
    
85;
    
text "Price:";
  }
  
  new 
GuiTextCtrl("shop_heart_amount2")
  {
    
profile GuiBlueTextProfile;
    
145;
    
98;
    
text "3 for 25g";
  }
  } 
// main window
}

function 
shop_close.onAction()
{
  
shop_window.destroy();
  
player.chat "Thanks for shopping!";
}

function 
shop_bomb.onAction()
{
  
triggeraction(this.xthis.y"Buy"null);

If anyone could help me with this and/or possibly help me optimize my code that would be great. Thanks
Reply With Quote
  #2  
Old 09-16-2011, 06:09 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
Don't use an NPC for that. Strip the GUI and serverside code from that and put it in a weapon.

Using triggerAction for stuff like this is seldom a good idea.

In your level NPCs, you can do this to trigger a weapon:


Quote:
Originally Posted by cbk1994 View Post
It's actually cleaner since it keeps all your code in one place and lets you trigger it, if you do it right.

PHP Code:
//#CLIENTSIDE
function onPlayerTouchsMe() {
  (@ 
"-SkiLift").trigger("startLift");

PHP Code:
//#CLIENTSIDE
function onStartLift() {
  
setTimer(1); // etc

__________________
Reply With Quote
  #3  
Old 09-16-2011, 06:14 AM
pig132 pig132 is offline
professional troll
Join Date: May 2006
Posts: 260
pig132 will become famous soon enough
The thing is, it is for a shop (in a level). Unless I can trigger a weapon from a level npc? If not, i'm not really sure what you mean
Reply With Quote
  #4  
Old 09-16-2011, 06:44 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
Quote:
Originally Posted by pig132 View Post
The thing is, it is for a shop (in a level). Unless I can trigger a weapon from a level npc? If not, i'm not really sure what you mean
Yes, you can.

In the level NPC:

PHP Code:
(@ "-Shop").trigger("showBuyWindow"temp.itemName, ...); 
then in -Shop

PHP Code:
function onShowBuyWindow(temp.itemName, ...) {
  
// show GUI

__________________
Reply With Quote
  #5  
Old 09-16-2011, 08:04 AM
pig132 pig132 is offline
professional troll
Join Date: May 2006
Posts: 260
pig132 will become famous soon enough
Oh, awesome, thank you very much
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 04:34 AM.


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