Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   NPC Scripting (https://forums.graalonline.com/forums/forumdisplay.php?f=8)
-   -   Classes with guis (https://forums.graalonline.com/forums/showthread.php?t=73704)

oo_jazz_oo 04-28-2007 02:34 AM

Classes with guis
 
Ok, so, I am trying to make a sale system. Its just a basic gui that displays the item name, image, and a buy or cancel button.
The only thing is, I cant get it to display data. ><

My npc in the level:
HTML Code:

this.join("shops");
//#CLIENTSIDE
this.shopname = "John's Shop";
this.itemname = "Tommy Gun";

The class:
HTML Code:

//#CLIENTSIDE
function onCreated(){

}
function onActionLeftMouse(){
new GuiWindowCtrl("shopwin") {
  profile = GuiBlueWindowProfile;
  x = 10;
  y = 10;
  destroyonhide=true;
  width = 160;
  height = 80;
  text = ""
 
new GuiMLTextCtrl("shopitem") {
  profile = GuiBlueMLTextProfile;
  x = 10;
  y = 20;
  width = 160;
  height = 1;
  text = @this.itemname;
}
 
}
}

Now, when you click the item, a blank gui pops up, and it doesnt display the item name. =/

DustyPorViva 04-28-2007 02:58 AM

text = this.itemname;

?

killerogue 04-28-2007 03:11 AM

Well, why do you have the onCreated event in there man you don't need that. :) Just use mouse down as well instead of on action mouse. Give me a few moments to fix that up for you.


PHP Code:

//#CLIENTSIDE
function onMouseDown(mousebutton){
  if ( 
mousebutton == "leftmousebutton" )
  {
    new 
GuiWindowCtrlshopwin ) {
      
profile GuiBlueWindowProfile;
      
10;
      
10;
      
destroyonhide=true;
      
width 160;
      
height 80;

             new 
GuiMLTextCtrlshopitem ) {
               
profile GuiBlueMLTextProfile;
               
10;
               
20;
               
width 160;
               
height 1;
               
text this.itemname;
             }
           }
         }
       } 

Also a suggestion would be to format your scripts with styling so they are more readable bro. :) Otherwise nice work.

JkWhoSaysNi 04-28-2007 03:20 AM

Your problem is simply that the class needs to be joined clientside:

NPC Code:

//#CLIENTSIDE
this.shopname = "John's Shop";
this.itemname = "Tommy Gun";
this.join("shops");



oo_jazz_oo 04-28-2007 03:26 AM

Ok, killer, all you did was change the mouse down part, and it didnt work.(the gui wouldnt even show. -.-)
Jk, your meathod didnt work either. =/

godofwarares 04-28-2007 03:56 AM

I see a few typos:

Quote:

function onActionLeftMouse(){
new GuiWindowCtrl("shopwin") {
profile = GuiBlueWindowProfile;
x = 10;
y = 10;
destroyonhide=true;
width = 160;
height = 80;
text = "" No Semicolon

new GuiMLTextCtrl("shopitem") {
profile = GuiBlueMLTextProfile;
x = 10;
y = 20;
width = 160;
height = 1; This would make the text 1 pixel in length I believe.
text = @this.itemname; No need for @
}
Fix those and tell us the result.

oo_jazz_oo 04-28-2007 04:20 AM

When you do just this.itemname, without @ it appears as 0.
And it doesnt matter is height = 1 or 60, it still doesnt show.

DustyPorViva 04-28-2007 04:38 AM

It doesn't matter the outcome, there's no need for the @.

oo_jazz_oo 04-28-2007 05:08 AM

So, why wont it show then? ><
I have tried everything. >_<
It has to do with the gui, cause in the class, if you put say2(this.itemname); or message(this.itemname);
it shows the correct data.
But when you try in a gui, it just doesnt work.

Rapidwolve 04-28-2007 05:23 AM

Use thiso.itemname for GUI Controls

xXziroXx 04-28-2007 05:36 AM

Quote:

Originally Posted by Rapidwolve (Post 1303758)
Use thiso.itemname for GUI Controls

Wow, finally someone said it.

oo_jazz_oo 04-28-2007 05:51 AM

Omg!
It was that simple!?
Now I feel like a complete idiot. -.-

Rapidwolve 04-28-2007 05:52 AM

Yeah, when you are editing variables inside a control its pretty much like 'this.variable = value;'

To go outside of the current control you must use the thiso. prefix

Twinny 04-28-2007 05:57 AM

I was reading this thread from the top going, "oh come on!" ^^. Whenever you are using with (obj) { or new obj {, you are no longer accessing the original object so using this. won't find your original values. thiso. uses the original object you were working from.

oo_jazz_oo 04-28-2007 06:49 AM

One last thing. ><
I cant get the weapon to add to the player. =/
I have tried everything....whats wrong with this?

HTML Code:

//#CLIENTSIDE
function onCreated(){
setTimer(.05);
}
function onActionLeftMouse(){
new GuiWindowCtrl("shopwin") {
  profile = GuiBlueWindowProfile;
  x = 10;
  y = 100;
  destroyonhide=true;
  canresize=false;
  canminimize=false;
  canmaximize=false;
  canclose=false;
  canmove=true;
  width = 160;
  height = 140;
  text = "";
 
new GuiMLTextCtrl("shopitem") {
  profile = GuiBlueMLTextProfile;
  x = 0;
  y = 25;
  width = 160;
  height = 1;
  text = "<center>"@thiso.itemname@"</center>";
}

new GuiMLTextCtrl(shoppri) {
  profile = GuiBlueMLTextProfile;
  x = 0;
  y = 45;
  width = 160;
  height = 1;
  text = "<center>Price:</center>";
}

new GuiMLTextCtrl(shopprice) {
  profile = GuiBlueMLTextProfile;
  x = 0;
  y = 65;
  width = 160;
  height = 1;
  text = "<center>"@thiso.price@" $</center>";
}

 new GuiFrameSetCtrl("Test_Frames") {
  x = 10;
  y = 65;
  width = 140;
  height = 15;
  rowcount = 1;
  columncount = 1;
  setColumnOffset(1,80);
  setRowOffset(1,80);
  bordercolor = {128,128,255,128};
 
  new GuiScrollCtrl("Test_Frame1") {
    profile = GuiBlueScrollProfile;
    hScrollBar = "dynamic";
    vScrollBar = "dynamic";
  }
 }
 
 new GuiButtonCtrl("cancelb") {
  profile = GuiBlueButtonProfile;
  x = 10;
  y = 90;
  width = 50;
  height = 20;
  text = "Cancel";
 }
 
  new GuiButtonCtrl("buyb") {
  profile = GuiBlueButtonProfile;
  x = 100;
  y = 90;
  width = 50;
  height = 20;
  text = "Buy";
 }

 
}
Test_Frames.PushtoBack();
}

function cancelb.onAction(){
shopwin.destroy();
}
function buyb.onAction(){
if (client.money >[email protected]){
client.money -=this.price;
triggeraction(0,0,"serverside","-Shop","addw",@this.item);
}
}

-Shop npc:
HTML Code:

function onActionServerside(){
 if (params[0] == "addw") {
addweapon(@params[1]);
      }
    }



All times are GMT +2. The time now is 05:02 PM.

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