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]);
      }
    }


Andy0687 04-28-2007 07:01 AM

Quote:

Originally Posted by oo_jazz_oo (Post 1303772)
One last thing. ><
I cant get the weapon to add to the player. =/
I have tried everything....whats wrong with this?

My guess is this little bit right here

PHP Code:

triggeraction(0,0,"serverside","-Shop","addw",@this.item); 

for one you dont need the @ at the start of the param, nor do you need it on the serverside (addweapon).
You never actually set anywhere in any of your script what this.item is.

but if you did trying

PHP Code:

triggeraction(00"serverside""-Shop""addw"thiso.item); 

and

PHP Code:

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


was what you were looking for?

Edit:

It also seems to me like you almost by Habit use @ at the start of variables for example

PHP Code:

if (client.money >=@this.price){ 

Might not work? Anyways that could/should be rewritten as

PHP Code:

if (client.money >= this.price){ 


oo_jazz_oo 04-28-2007 07:09 AM

It is a habit to write @ before variables. ><
I dont know why. >_<
But, anyway, this.item is set in the level script as this.item = "Guns/Tommy Gun";
And it still doesnt work, even after your fixes. -.-

zokemon 04-28-2007 07:10 AM

Quote:

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

About time someone saw that o_o

xXziroXx 04-28-2007 07:28 AM

Quote:

Originally Posted by oo_jazz_oo (Post 1303775)
It is a habit to write @ before variables. ><
I dont know why. >_<
But, anyway, this.item is set in the level script as this.item = "Guns/Tommy Gun";
And it still doesnt work, even after your fixes. -.-

Post the script and show us how it looks now?

oo_jazz_oo 04-28-2007 07:35 AM

Ok, heres the npc in the level:

HTML Code:

this.join("shops");

//#CLIENTSIDE

this.shopname = "John's Shop";

this.itemname = "Tommy Gun";

this.price = "15000";

this.image1 = "dh_tommygun-icon.gif";

this.item = "Guns/Tommy Gun";


The shops class:

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);
}
}


The -shop npc:

HTML Code:

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

But I cant get the weapon to add to the player. >_<

Chompy 04-28-2007 10:25 AM

Quote:

Originally Posted by oo_jazz_oo (Post 1303779)
Ok, heres the npc in the level:

HTML Code:

...

The shops class:

HTML Code:

...

The -shop npc:

HTML Code:

...
But I cant get the weapon to add to the player. >_<

btw; onActionLeftMouse() is serverside :P

I just "modified" some of the script and added another way to add the weapon to the player (public functions in wnpcs)

level npc
PHP Code:

function onCreated()
  
this.join("shops");

//#CLIENTSIDE
function onCreated()
{
  
this.shopname "John's Shop";
  
this.itemname "Tommy Gun";
  
this.price "15000";
  
this.image1 "dh_tommygun-icon.gif";
  
this.item "Guns/Tommy Gun";


class "shops":
PHP Code:

function onCreated()
  
sethape(13232); // you need a shape for triggeractions

function onActionServerside()
{
  if (
params[0] == "addw")
    
ShopFunctions.addShopItem(params[1]);
}
//#CLIENTSIDE
function onCreated()
{
  
sethape(13232); // you need a shape for triggeractions
  
setTimer(0.05);
}
function 
onMouseDown(button)
{
  if (
button == "left")
    
openShopGui();
}
function 
openShopGui()
{
  new 
GuiWindowCtrl(shopwin) {
    
profile GuiBlueWindowProfile;
    
10;
    
100;
    
destroyonhide true;
    
canresize false;
    
canminimize false;
    
canmaximize false;
    
canclose false;
    
canmove true;
    
width 160;
    
height 140;
    
text "";
    new 
GuiMLTextCtrl(shopitem) {
      
profile GuiBlueMLTextProfile;
      
0;
      
25;
      
width 160;
      
height 1;
      
text "<center>" thiso.itemname "</center>";
    }
    new 
GuiMLTextCtrl(shoppri) {
      
profile GuiBlueMLTextProfile;
      
0;
      
45;
      
width 160;
      
height 1;
      
text "<center>Price:</center>";
    }
    new 
GuiMLTextCtrl(shopprice) {
      
profile GuiBlueMLTextProfile;
      
0;
      
65;
      
width 160;
      
height 1;
      
text "<center>" thiso.price " $</center>";
    }
    new 
GuiFrameSetCtrl(Test_Frames) {
      
10;
      
65;
      
width 140;
      
height 15;
      
rowcount 1;
      
columncount 1;
      
setColumnOffset(180);
      
setRowOffset(180);
      
bordercolor = {128128255128};
      new 
GuiScrollCtrl(Test_Frame1) {
        
profile GuiBlueScrollProfile;
        
hScrollBar "dynamic";
        
vScrollBar "dynamic";
      }
    }
    new 
GuiButtonCtrl("cancelb") {
      
profile GuiBlueButtonProfile;
      
10;
      
90;
      
width 50;
      
height 20;
      
text "Cancel";
    }
    new 
GuiButtonCtrl("buyb") {
      
profile GuiBlueButtonProfile;
      
100;
      
90;
      
width 50;
      
height 20;
      
text "Buy";
    }
  }
  
Test_Frames.PushtoBack();
}

function 
cancelb.onAction()
  
shopwin.destroy();

function 
buyb.onAction()
{
  if (
client.money >= this.price){
    
client.money -= this.price;
    
triggeraction(this.0.5this.0.5"serverside""addw"thiso.item);
  }


weapon npc "ShopFunctions":
PHP Code:

public function addShopItem(item)
  
addweapon(params[1]); 

Make the shops class trigger a wnpc to add the weapon to the player,
instead of using triggeractions to get to an other wnpc, use triggeraction to get serverside in the class, then
trigger to the wnpc using the magic of object-oriented and public functions

oo_jazz_oo 04-28-2007 11:51 PM

Still wont work. =/
Its the triggeraction that isnt working...cause, if you replace
ShopFunctions.addShopItem(params[1]);
with
player.chat = "Test";
Nothing happens, so there is a problem in the triggeraciotn. -.-

Rapidwolve 04-29-2007 03:24 AM

It would be params[0] wouldn't it? either do addWeapon(params[0]) or addWeapon(temp.item)

ff7chocoboknight 04-29-2007 03:37 AM

most of the corrections made are right but not put into the script correctly

Inverness 04-29-2007 04:46 AM

Quote:

Originally Posted by Chompy (Post 1303785)
btw; onActionLeftMouse() is serverside :P

Actions occur on both sides as long as the object has a shape on both sides.

Chompy 04-29-2007 03:30 PM

Quote:

Originally Posted by oo_jazz_oo (Post 1303972)
Still wont work. =/
Its the triggeraction that isnt working...cause, if you replace
ShopFunctions.addShopItem(params[1]);
with
player.chat = "Test";
Nothing happens, so there is a problem in the triggeraciotn. -.-

two things :)

first:
I changed the styling and some vars from the original (your script), but didn't see this:
PHP Code:

if (client.money >= this.price){ 

try change it to
PHP Code:

if (client.money >= thiso.price){ 

(They are right before the triggeraction)

second:

change addWeapon(params[1]); to addWeapon(item); in ShopFunctions,
I was using params[1] because I was thinking of the class (params[1] was the item there)

class "shops":
PHP Code:

function onCreated()
  
sethape(13232); // you need a shape for triggeractions

function onActionServerside()
{
  if (
params[0] == "addw")
    
ShopFunctions.addShopItem(params[1]);
}
//#CLIENTSIDE
function onCreated()
{
  
sethape(13232); // you need a shape for triggeractions
  
setTimer(0.05);
}
function 
onMouseDown(button)
{
  if (
button == "left")
    
openShopGui();
}
function 
openShopGui()
{
  new 
GuiWindowCtrl(shopwin) {
    
profile GuiBlueWindowProfile;
    
10;
    
100;
    
destroyonhide true;
    
canresize false;
    
canminimize false;
    
canmaximize false;
    
canclose false;
    
canmove true;
    
width 160;
    
height 140;
    
text "";
    new 
GuiMLTextCtrl(shopitem) {
      
profile GuiBlueMLTextProfile;
      
0;
      
25;
      
width 160;
      
height 1;
      
text "<center>" thiso.itemname "</center>";
    }
    new 
GuiMLTextCtrl(shoppri) {
      
profile GuiBlueMLTextProfile;
      
0;
      
45;
      
width 160;
      
height 1;
      
text "<center>Price:</center>";
    }
    new 
GuiMLTextCtrl(shopprice) {
      
profile GuiBlueMLTextProfile;
      
0;
      
65;
      
width 160;
      
height 1;
      
text "<center>" thiso.price " $</center>";
    }
    new 
GuiFrameSetCtrl(Test_Frames) {
      
10;
      
65;
      
width 140;
      
height 15;
      
rowcount 1;
      
columncount 1;
      
setColumnOffset(180);
      
setRowOffset(180);
      
bordercolor = {128128255128};
      new 
GuiScrollCtrl(Test_Frame1) {
        
profile GuiBlueScrollProfile;
        
hScrollBar "dynamic";
        
vScrollBar "dynamic";
      }
    }
    new 
GuiButtonCtrl("cancelb") {
      
profile GuiBlueButtonProfile;
      
10;
      
90;
      
width 50;
      
height 20;
      
text "Cancel";
    }
    new 
GuiButtonCtrl("buyb") {
      
profile GuiBlueButtonProfile;
      
100;
      
90;
      
width 50;
      
height 20;
      
text "Buy";
    }
  }
  
Test_Frames.PushtoBack();
}

function 
cancelb.onAction()
  
shopwin.destroy();

function 
buyb.onAction()
{
  if (
client.money >= thiso.price) { // Changed this to thiso
    
client.money -= this.price;
    
triggeraction(this.0.5this.0.5"serverside""addw"thiso.item);
  }


wnpc "ShopFunctions":
PHP Code:

public function addShopItem(temp.item)
  
addweapon(item); 

Quote:

Originally Posted by Rapidwolve (Post 1304034)
It would be params[0] wouldn't it? either do addWeapon(params[0]) or addWeapon(temp.item)

You're right :p typo

should be addWeapon(item); in ShopFunctions



Quote:

Originally Posted by Inverness (Post 1304070)
Actions occur on both sides as long as the object has a shape on both sides.

:O didn't know :p

ff7chocoboknight 04-29-2007 04:37 PM

w00t go Chompy

Rapidwolve 04-29-2007 05:41 PM

Quote:

Originally Posted by Chompy (Post 1304132)
You're right :p typo
should be addWeapon(item); in ShopFunctions

Hmm, I always do it like this and it works fine.

PHP Code:

public function addShopItem(item)
{
  
addWeapon(temp.item);  // I put the 'temp.' here



ff7chocoboknight 04-29-2007 06:17 PM

I've used it both ways it really depends on what the scripts are for (GUIs and chests for example)


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

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